Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/bitstring.h
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
/* clear bit N of bit string name */ | /* clear bit N of bit string name */ | ||||
static inline void | static inline void | ||||
bit_clear(bitstr_t *_bitstr, int _bit) | bit_clear(bitstr_t *_bitstr, int _bit) | ||||
{ | { | ||||
_bitstr[_bit_idx(_bit)] &= ~_bit_mask(_bit); | _bitstr[_bit_idx(_bit)] &= ~_bit_mask(_bit); | ||||
} | } | ||||
/* Test bit N, then set it */ | |||||
static inline int | |||||
bit_test_and_set(bitstr_t *_bitstr, int _bit) | |||||
{ | |||||
int _result = bit_test(_bitstr, _bit); | |||||
bit_set(_bitstr, _bit); | |||||
return _result; | |||||
} | |||||
/* Test bit N, then clear it */ | |||||
static inline int | |||||
bit_test_and_clear(bitstr_t *_bitstr, int _bit) | |||||
{ | |||||
int _result = bit_test(_bitstr, _bit); | |||||
bit_clear(_bitstr, _bit); | |||||
return _result; | |||||
} | |||||
/* Set bits start ... stop inclusive in bit string. */ | /* Set bits start ... stop inclusive in bit string. */ | ||||
static inline void | static inline void | ||||
bit_nset(bitstr_t *_bitstr, int _start, int _stop) | bit_nset(bitstr_t *_bitstr, int _start, int _stop) | ||||
{ | { | ||||
bitstr_t *_stopbitstr; | bitstr_t *_stopbitstr; | ||||
_stopbitstr = _bitstr + _bit_idx(_stop); | _stopbitstr = _bitstr + _bit_idx(_stop); | ||||
_bitstr += _bit_idx(_start); | _bitstr += _bit_idx(_start); | ||||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | if (_nbits > 0) { | ||||
mask = _bit_make_mask(0, _bit_offset(_nbits - 1)); | mask = _bit_make_mask(0, _bit_offset(_nbits - 1)); | ||||
_value += __bitcountl(*_curbitstr & mask); | _value += __bitcountl(*_curbitstr & mask); | ||||
} | } | ||||
out: | out: | ||||
*_result = _value; | *_result = _value; | ||||
} | } | ||||
/* Computes _dstbitstr as the bitwise and of the two _srcbitstr */ | |||||
static inline void | |||||
bitstr_and(bitstr_t *_dstbitstr, bitstr_t *_src1bitstr, | |||||
bitstr_t *_src2bitstr, int _nbits) | |||||
{ | |||||
bitstr_t mask; | |||||
while (_nbits >= (int)_BITSTR_BITS) { | |||||
*_dstbitstr++ = *_src1bitstr++ & *_src2bitstr++; | |||||
_nbits -= _BITSTR_BITS; | |||||
} | |||||
if (_nbits > 0) { | |||||
mask = _bit_make_mask(0, _bit_offset(_nbits - 1)); | |||||
*_dstbitstr = (*_src1bitstr & *_src2bitstr) & mask; | |||||
} | |||||
} | |||||
/* Computes _dstbitstr as the bitwise or of the two _srcbitstr */ | |||||
static inline void | |||||
bitstr_or(bitstr_t *_dstbitstr, bitstr_t *_src1bitstr, | |||||
bitstr_t *_src2bitstr, int _nbits) | |||||
{ | |||||
bitstr_t mask; | |||||
while (_nbits >= (int)_BITSTR_BITS) { | |||||
*_dstbitstr++ = *_src1bitstr++ | *_src2bitstr++; | |||||
_nbits -= _BITSTR_BITS; | |||||
} | |||||
if (_nbits > 0) { | |||||
mask = _bit_make_mask(0, _bit_offset(_nbits - 1)); | |||||
*_dstbitstr = (*_src1bitstr | *_src2bitstr) & mask; | |||||
} | |||||
} | |||||
#endif /* _SYS_BITSTRING_H_ */ | #endif /* _SYS_BITSTRING_H_ */ |