modules/up/src/gnug++/bitprims.h
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- _BS_WORDS_NEEDED
- _BS_BITMASK
- _BS_BITMASK
- _BS_ADJUST_ALIGNED
- _BS_NORMALIZE
- _BS_INDEX
- _BS_POS
- _BS_copy_0
1 #ifndef _BS_PRIMS
2 #define _BS_PRIMS
3
4 /* A bitstring is an array of _BS_word. */
5 typedef unsigned long _BS_word;
6
7 #define _BS_CHAR_BIT 8
8 #define _BS_BITS_PER_WORD (_BS_CHAR_BIT*sizeof(_BS_word))
9 #define _BS_WORDS_NEEDED(NBITS) ((NBITS+_BS_BITS_PER_WORD-1)/_BS_BITS_PER_WORD)
/* [<][>][^][v][top][bottom][index][help] */
10
11 /* For now, we number the bits in a _BS_word in little-endian order.
12 Later, might use machine order. */
13 #ifdef CHILL_LIB
14 #ifndef BITS_BIG_ENDIAN
15 #include "config.h"
16 #endif
17 #define _BS_BIGENDIAN BITS_BIG_ENDIAN
18 #else
19 #define _BS_BIGENDIAN 0
20 #endif
21
22 /* By "left" we mean where bit number 0 is.
23 Hence, so left shift is << if we're numbering the bits in big-endian oder,
24 and >> if we're numbering the bits in little-endian order.
25 Currently, we always use little-endian order.
26 Later, we might use machine-endian order. */
27 #if _BS_BIGENDIAN
28 #define _BS_LEFT <<
29 #define _BS_RIGHT >>
30 #else
31 #define _BS_LEFT >>
32 #define _BS_RIGHT <<
33 #endif
34
35 #if _BS_BIGENDIAN
36 #define _BS_BITMASK(BITNO) ((_BS_word)1 << (_BS_BITS_PER_WORD - 1 - (BITNO)))
/* [<][>][^][v][top][bottom][index][help] */
37 #else
38 #define _BS_BITMASK(BITNO) ((_BS_word)1 << (BITNO))
/* [<][>][^][v][top][bottom][index][help] */
39 #endif
40
41 /* Given a PTR which may not be aligned on a _BS_word boundary,
42 set NEW_PTR to point to (the beginning of) the corresponding _BS_word.
43 Adjust the bit-offset OFFSET to compensate for the difference. */
44 #define _BS_ADJUST_ALIGNED(NEW_PTR, PTR, OFFSET) \
/* [<][>][^][v][top][bottom][index][help] */
45 ( (NEW_PTR) = (_BS_word*)(((char*)(PTR)-(char*)0) & ~(sizeof(_BS_word)-1)), \
46 (OFFSET) += (char*)(PTR) - (char*)(NEW_PTR) )
47
48 /* Given a bit pointer (PTR, OFFSET) normalize it so that
49 OFFSET < _BS_BITS_PER_WORD. */
50 #define _BS_NORMALIZE(PTR, OFFSET) \
/* [<][>][^][v][top][bottom][index][help] */
51 { _BS_size_t __tmp_ind = _BS_INDEX (OFFSET); \
52 (PTR) += __tmp_ind; \
53 (OFFSET) -= __tmp_ind * _BS_BITS_PER_WORD; }
54
55 #define _BS_INDEX(I) ((unsigned)(I) / _BS_BITS_PER_WORD)
/* [<][>][^][v][top][bottom][index][help] */
56 #define _BS_POS(I) ((I) & (_BS_BITS_PER_WORD -1 ))
/* [<][>][^][v][top][bottom][index][help] */
57
58 #ifndef _BS_size_t
59 #if __GNUC__ > 1
60 #define _BS_size_t __SIZE_TYPE__
61 #else
62 #define _BS_size_t unsigned long
63 #endif
64 #endif
65
66 #ifndef __P
67 #ifdef __STDC__
68 #define __P(protos) protos
69 #else
70 #define __P(protos) ()
71 #endif
72 #endif /*!__P*/
73 #if !defined(__STDC__) && !defined(const)
74 #define const
75 #endif
76 #if !defined(__STDC__) && !defined(void)
77 #define void int
78 #endif
79
80 /* The 16 2-operand raster-ops:
81 These match the correspodning GX codes in X11. */
82 enum _BS_alu {
83 _BS_alu_clear = 0 /* 0 */,
84 _BS_alu_and = 1 /* src & dst */,
85 _BS_alu_andReverse = 2 /* src & ~dst */,
86 _BS_alu_copy = 3 /* src */,
87 _BS_alu_andInverted = 4 /* ~src & dst */,
88 _BS_alu_noop = 5 /* dst */,
89 _BS_alu_xor = 6 /* src ^ dst */,
90 _BS_alu_or = 7 /* src | dst */,
91 _BS_alu_nor = 8 /* ~src & ~dst */,
92 _BS_alu_equiv = 9 /* ~(src ^ dst) */,
93 _BS_alu_invert = 10 /* ~dst */,
94 _BS_alu_orReverse = 11 /* src | ~dst */,
95 _BS_alu_copyInverted = 12 /* ~src */,
96 _BS_alu_orInverted = 13 /* ~src | dst */,
97 _BS_alu_nand = 14 /* ~src | d~st */,
98 _BS_alu_set = 15 /* ~src | dst */
99 };
100 #define _BS
101 #define _BS
102
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106
107 extern void _BS_and __P((_BS_word*,int, const _BS_word*, int, _BS_size_t));
108 extern void _BS_blt __P((enum _BS_alu,
109 _BS_word*,int, const _BS_word*,int, _BS_size_t));
110 extern void _BS_copy __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
111 #define _BS_copy_0(DS, SS, LENGTH) _BS_copy(DS, 0, SS, 0, LENGTH)
/* [<][>][^][v][top][bottom][index][help] */
112 extern int _BS_count __P((const _BS_word*, int, _BS_size_t));
113 extern int _BS_any __P((const _BS_word*, int, _BS_size_t));
114 extern void _BS_clear __P((_BS_word*, int, _BS_size_t));
115 extern void _BS_set __P((_BS_word*, int, _BS_size_t));
116 extern void _BS_invert __P((_BS_word*, int, _BS_size_t));
117 int _BS_lcompare_0 __P((const _BS_word*, _BS_size_t,
118 const _BS_word*, _BS_size_t));
119 extern void _BS_xor __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif /* !_BS_PRIMS */