77# define BU_BITV_SHIFT 3
79# define BU_BITV_SHIFT 4
81# define BU_BITV_SHIFT 5
83# define BU_BITV_SHIFT 6
86# define BU_BITV_SHIFT bu_bitv_shift()
90#define BU_BITV_MASK ((1<<BU_BITV_SHIFT)-1)
114#define BU_BITV_NULL ((struct bu_bitv *)0)
119#define BU_CK_BITV(_bp) BU_CKMAG(_bp, BU_BITV_MAGIC, "bu_bitv")
125#define BU_BITV_INIT(_bp) { \
126 BU_LIST_INIT_MAGIC(&(_bp)->l, BU_BITV_MAGIC); \
128 (_bp)->bits[0] = 0; \
129 (_bp)->bits[1] = 0; \
136#define BU_BITV_INIT_ZERO { {BU_BITV_MAGIC, BU_LIST_NULL, BU_LIST_NULL}, 0, {0, 0} }
141#define BU_BITV_IS_INITIALIZED(_bp) (((struct bu_bitv *)(_bp) != BU_BITV_NULL) && LIKELY((_bp)->l.magic == BU_BITV_MAGIC))
155#define BU_WORDS2BITS(_nw) ((size_t)(_nw>0?_nw:0)*sizeof(bitv_t)*8)
161#define BU_BITS2WORDS(_nb) (((size_t)(_nb>0?_nb:0)+BU_BITV_MASK)>>BU_BITV_SHIFT)
167#define BU_BITS2BYTES(_nb) (BU_BITS2WORDS(_nb)*sizeof(bitv_t))
171#define BU_BITTEST(_bv, bit) \
172 (((_bv)->bits[(bit)>>BU_BITV_SHIFT] & (((bitv_t)1)<<((bit)&BU_BITV_MASK)))!=0)
174static __inline__
int BU_BITTEST(
volatile void * addr,
int nr)
178 __asm__ __volatile__(
179 "btl %2, %1\n\tsbbl %0, %0"
181 :
"m" (addr),
"Ir" (nr));
186#define BU_BITSET(_bv, bit) \
187 ((_bv)->bits[(bit)>>BU_BITV_SHIFT] |= (((bitv_t)1)<<((bit)&BU_BITV_MASK)))
188#define BU_BITCLR(_bv, bit) \
189 ((_bv)->bits[(bit)>>BU_BITV_SHIFT] &= ~(((bitv_t)1)<<((bit)&BU_BITV_MASK)))
194#define BU_BITV_ZEROALL(_bv) \
196 if (LIKELY((_bv) && (_bv)->nbits != 0)) { \
197 unsigned char *bvp = (unsigned char *)(_bv)->bits; \
198 size_t nbytes = BU_BITS2BYTES((_bv)->nbits); \
200 *bvp++ = (unsigned char)0; \
201 } while (--nbytes != 0); \
207#ifdef NO_BOMBING_MACROS
208# define BU_BITV_BITNUM_CHECK(_bv, _bit) (void)(_bv)
210# define BU_BITV_BITNUM_CHECK(_bv, _bit) \
211 if (UNLIKELY(((unsigned)(_bit)) >= (_bv)->nbits)) {\
212 bu_log("BU_BITV_BITNUM_CHECK bit number (%u) out of range (0..%u)\n", \
213 ((unsigned)(_bit)), (_bv)->nbits); \
214 bu_bomb("process self-terminating\n");\
218#ifdef NO_BOMBING_MACROS
219# define BU_BITV_NBITS_CHECK(_bv, _nbits) (void)(_bv)
221# define BU_BITV_NBITS_CHECK(_bv, _nbits) \
222 if (UNLIKELY(((unsigned)(_nbits)) > (_bv)->nbits)) {\
223 bu_log("BU_BITV_NBITS_CHECK number of bits (%u) out of range (> %u)", \
224 ((unsigned)(_nbits)), (_bv)->nbits); \
225 bu_bomb("process self-terminating"); \
246#define BU_BITV_LOOP_START(_bv) \
250 for (_wd=BU_BITS2WORDS((_bv)->nbits)-1; _wd>=0; _wd--) { \
253 if ((_val = (_bv)->bits[_wd])==0) continue; \
254 for (_b=0; _b < BU_BITV_MASK+1; _b++, _val >>= 1) { \
255 if (!(_val & 1)) continue;
261#define BU_BITV_LOOP_INDEX ((_wd << BU_BITV_SHIFT) | _b)
266#define BU_BITV_LOOP_END } \
430 const char *label,
unsigned long bits,
Header file for the BRL-CAD common definitions.
struct bu_bitv * bu_hex_to_bitv(const char *str)
struct bu_bitv * bu_bitv_new(size_t nbits)
void bu_bitv_to_binary(struct bu_vls *v, const struct bu_bitv *bv)
struct bu_bitv * bu_binary_to_bitv2(const char *str, const int nbytes)
struct bu_bitv * bu_binary_to_bitv(const char *str)
void bu_bitv_free(struct bu_bitv *bv)
int bu_bitv_compare_equal2(const struct bu_bitv *, const struct bu_bitv *)
void bu_bitv_to_hex(struct bu_vls *v, const struct bu_bitv *bv)
void bu_bitv_and(struct bu_bitv *ov, const struct bu_bitv *iv)
void bu_bitv_vls(struct bu_vls *v, const struct bu_bitv *bv)
#define BU_BITTEST(_bv, bit)
void bu_bitv_clear(struct bu_bitv *bv)
int bu_binstr_to_hexstr(const char *binstr, struct bu_vls *h)
void bu_bitv_or(struct bu_bitv *ov, const struct bu_bitv *iv)
size_t bu_bitv_shift(void)
struct bu_bitv * bu_bitv_dup(const struct bu_bitv *bv)
int bu_bitv_compare_equal(const struct bu_bitv *, const struct bu_bitv *)
void bu_printb(const char *label, unsigned long bits, const char *format)
Bit field printing implementation.
int bu_hexstr_to_binstr(const char *hexstr, struct bu_vls *b)
void bu_pr_bitv(const char *str, const struct bu_bitv *bv)
void bu_vls_printb(struct bu_vls *vls, const char *label, unsigned long bits, const char *format)
Global registry of recognized magic numbers.