1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved.
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /* Bit vector functions */
|
---|
8 |
|
---|
9 | #ifndef CR_BITS_H
|
---|
10 | #define CR_BITS_H
|
---|
11 |
|
---|
12 |
|
---|
13 | #include "cr_compiler.h"
|
---|
14 |
|
---|
15 |
|
---|
16 | #define CR_MAX_CONTEXTS 512
|
---|
17 | #define CR_MAX_BITARRAY (CR_MAX_CONTEXTS / 32) /* 32 contexts per uint */
|
---|
18 |
|
---|
19 | #ifdef __cplusplus
|
---|
20 | extern "C" {
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | static INLINE void RESET( unsigned int *b, const unsigned int *d )
|
---|
24 | {
|
---|
25 | int j;
|
---|
26 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
27 | b[j] |= d[j];
|
---|
28 | }
|
---|
29 | static INLINE void DIRTY( unsigned int *b, const unsigned int *d )
|
---|
30 | {
|
---|
31 | int j;
|
---|
32 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
33 | b[j] = d[j];
|
---|
34 | }
|
---|
35 | static INLINE void FILLDIRTY( unsigned int *b )
|
---|
36 | {
|
---|
37 | int j;
|
---|
38 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
39 | b[j] = 0xffffffff;
|
---|
40 | }
|
---|
41 | static INLINE void CLEARDIRTY( unsigned int *b, const unsigned int *d )
|
---|
42 | {
|
---|
43 | int j;
|
---|
44 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
45 | b[j] &= d[j];
|
---|
46 | }
|
---|
47 |
|
---|
48 | /* As above, but complement the bits here instead of in the calling code */
|
---|
49 | static INLINE void CLEARDIRTY2( unsigned int *b, const unsigned int *d )
|
---|
50 | {
|
---|
51 | int j;
|
---|
52 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
53 | b[j] &= ~d[j];
|
---|
54 | }
|
---|
55 |
|
---|
56 | static INLINE int CHECKDIRTY( const unsigned int *b, const unsigned int *d )
|
---|
57 | {
|
---|
58 | int j;
|
---|
59 |
|
---|
60 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
61 | if (b[j] & d[j])
|
---|
62 | return 1;
|
---|
63 |
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | static INLINE int CHECKBIT( const unsigned int *b, const unsigned int bit )
|
---|
68 | {
|
---|
69 | unsigned int node32 = bit >> 5;
|
---|
70 | unsigned int node = bit & 0x1f;
|
---|
71 |
|
---|
72 | return !!(b[node32] & (1 < node));
|
---|
73 | }
|
---|
74 |
|
---|
75 | static INLINE void CLEARBIT( unsigned int *b, const unsigned int bit )
|
---|
76 | {
|
---|
77 | unsigned int node32 = bit >> 5;
|
---|
78 | unsigned int node = bit & 0x1f;
|
---|
79 |
|
---|
80 | b[node32] &= ~(1 << node);
|
---|
81 | }
|
---|
82 |
|
---|
83 | static INLINE void SETBIT( unsigned int *b, const unsigned int bit )
|
---|
84 | {
|
---|
85 | unsigned int node32 = bit >> 5;
|
---|
86 | unsigned int node = bit & 0x1f;
|
---|
87 |
|
---|
88 | b[node32] |= (1 << node);
|
---|
89 | }
|
---|
90 |
|
---|
91 | static INLINE int HASBITS( const unsigned int *b )
|
---|
92 | {
|
---|
93 | int j;
|
---|
94 |
|
---|
95 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
96 | if (b[j])
|
---|
97 | return 1;
|
---|
98 |
|
---|
99 | return 0;
|
---|
100 | }
|
---|
101 |
|
---|
102 | static INLINE void CLEARBITS( unsigned int *b )
|
---|
103 | {
|
---|
104 | int j;
|
---|
105 |
|
---|
106 | for (j=0;j<CR_MAX_BITARRAY;j++)
|
---|
107 | b[j] = 0;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | #ifdef __cplusplus
|
---|
112 | }
|
---|
113 | #endif
|
---|
114 |
|
---|
115 |
|
---|
116 | #endif /* CR_BITS_H */
|
---|