Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/bitstring.h
| Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | 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); | ||||
| if (_bitstr == _stopbitstr) { | if (_bitstr == _stopbitstr) { | ||||
| *_bitstr |= _bit_make_mask(_start, _stop); | *_bitstr |= _bit_make_mask(_start, _stop); | ||||
| } else { | } else { | ||||
| *_bitstr |= _bit_make_mask(_start, _BITSTR_BITS - 1); | if (_bit_offset(_stop) == _BITSTR_BITS - 1) | ||||
| while (++_bitstr < _stopbitstr) | ++_stopbitstr; | ||||
| *_bitstr = _BITSTR_MASK; | else | ||||
| *_stopbitstr |= _bit_make_mask(0, _stop); | *_stopbitstr |= _bit_make_mask(0, _stop); | ||||
| if (_bit_offset(_start) != 0) | |||||
| *_bitstr++ |= _bit_make_mask(_start, _BITSTR_BITS - 1); | |||||
| while (_bitstr < _stopbitstr) | |||||
| *_bitstr++ = _BITSTR_MASK; | |||||
| } | } | ||||
| } | } | ||||
| /* Clear bits start ... stop inclusive in bit string. */ | /* Clear bits start ... stop inclusive in bit string. */ | ||||
| static inline void | static inline void | ||||
| bit_nclear(bitstr_t *_bitstr, int _start, int _stop) | bit_nclear(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); | ||||
| if (_bitstr == _stopbitstr) { | if (_bitstr == _stopbitstr) { | ||||
| *_bitstr &= ~_bit_make_mask(_start, _stop); | *_bitstr &= ~_bit_make_mask(_start, _stop); | ||||
| } else { | } else { | ||||
| *_bitstr &= ~_bit_make_mask(_start, _BITSTR_BITS - 1); | if (_bit_offset(_stop) == _BITSTR_BITS - 1) | ||||
| while (++_bitstr < _stopbitstr) | ++_stopbitstr; | ||||
| *_bitstr = 0; | else | ||||
| *_stopbitstr &= ~_bit_make_mask(0, _stop); | *_stopbitstr &= ~_bit_make_mask(0, _stop); | ||||
| if (_bit_offset(_start) != 0) | |||||
| *_bitstr++ &= ~_bit_make_mask(_start, _BITSTR_BITS - 1); | |||||
| while (_bitstr < _stopbitstr) | |||||
| *_bitstr++ = 0; | |||||
| } | } | ||||
| } | } | ||||
| /* Find the first bit set in bit string at or after bit start. */ | /* Find the first '_match'-bit in bit string at or after bit start. */ | ||||
| static inline void | static inline void | ||||
| bit_ffs_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) | bit_ff_at(bitstr_t *_bitstr, int _start, int _nbits, int _match, | ||||
| int *_result) | |||||
markj: This function should be documented in bitstring.3. | |||||
| { | { | ||||
| bitstr_t *_curbitstr; | bitstr_t *_curbitstr; | ||||
| bitstr_t *_stopbitstr; | bitstr_t *_stopbitstr; | ||||
| bitstr_t _mask; | |||||
| bitstr_t _test; | bitstr_t _test; | ||||
| int _value, _offset; | int _value; | ||||
| if (_start >= _nbits) { | if (_start >= _nbits || _nbits <= 0) { | ||||
| *_result = -1; | *_result = -1; | ||||
| return; | return; | ||||
| } | } | ||||
| if (_nbits > 0) { | |||||
| _curbitstr = _bitstr + _bit_idx(_start); | _curbitstr = _bitstr + _bit_idx(_start); | ||||
| _stopbitstr = _bitstr + _bit_idx(_nbits - 1); | _stopbitstr = _bitstr + _bit_idx(_nbits - 1); | ||||
| _mask = _match ? 0 : _BITSTR_MASK; | |||||
| _test = *_curbitstr; | _test = _mask ^ *_curbitstr; | ||||
| if (_bit_offset(_start) != 0) | if (_bit_offset(_start) != 0) | ||||
| _test &= _bit_make_mask(_start, _BITSTR_BITS - 1); | _test &= _bit_make_mask(_start, _BITSTR_BITS - 1); | ||||
| while (_test == 0 && _curbitstr < _stopbitstr) | while (_test == 0 && _curbitstr < _stopbitstr) | ||||
| _test = *(++_curbitstr); | _test = _mask ^ *(++_curbitstr); | ||||
| _offset = ffsl(_test); | _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + ffsl(_test) - 1; | ||||
| _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1; | if (_test == 0 || | ||||
| if (_offset == 0 || _value >= _nbits) | (_bit_offset(_nbits) != 0 && _value >= _nbits)) | ||||
| _value = -1; | _value = -1; | ||||
| } else { | |||||
| _value = -1; | |||||
| } | |||||
| *_result = _value; | *_result = _value; | ||||
| } | } | ||||
| /* Find the first bit clear in bit string at or after bit start. */ | /* Find the first bit set in bit string at or after bit start. */ | ||||
| static inline void | static inline void | ||||
| bit_ffc_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) | bit_ffs_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) | ||||
| { | { | ||||
| bitstr_t *_curbitstr; | bit_ff_at(_bitstr, _start, _nbits, 1, _result); | ||||
| bitstr_t *_stopbitstr; | |||||
| bitstr_t _test; | |||||
| int _value, _offset; | |||||
| if (_start >= _nbits) { | |||||
| *_result = -1; | |||||
| return; | |||||
| } | } | ||||
| if (_nbits > 0) { | /* Find the first bit clear in bit string at or after bit start. */ | ||||
| _curbitstr = _bitstr + _bit_idx(_start); | static inline void | ||||
| _stopbitstr = _bitstr + _bit_idx(_nbits - 1); | bit_ffc_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result) | ||||
| { | |||||
| _test = *_curbitstr; | bit_ff_at(_bitstr, _start, _nbits, 0, _result); | ||||
| if (_bit_offset(_start) != 0) | |||||
| _test |= _bit_make_mask(0, _start - 1); | |||||
| while (_test == _BITSTR_MASK && _curbitstr < _stopbitstr) | |||||
| _test = *(++_curbitstr); | |||||
| _offset = ffsl(~_test); | |||||
| _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1; | |||||
| if (_offset == 0 || _value >= _nbits) | |||||
| _value = -1; | |||||
| } else { | |||||
| _value = -1; | |||||
| } | |||||
| *_result = _value; | |||||
| } | } | ||||
| /* Find the first bit set in bit string. */ | /* Find the first bit set in bit string. */ | ||||
| static inline void | static inline void | ||||
| bit_ffs(bitstr_t *_bitstr, int _nbits, int *_result) | bit_ffs(bitstr_t *_bitstr, int _nbits, int *_result) | ||||
| { | { | ||||
| bit_ffs_at(_bitstr, /*start*/0, _nbits, _result); | bit_ffs_at(_bitstr, /*start*/0, _nbits, _result); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 169 Lines • Show Last 20 Lines | |||||
This function should be documented in bitstring.3.