MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bit_ffs_at

Function bit_ffs_at

freebsd/sys/bitstring.h:197–228  ·  view source on GitHub ↗

Find the first bit set in bit string at or after bit start. */

Source from the content-addressed store, hash-verified

195
196/* Find the first bit set in bit string at or after bit start. */
197static inline void
198bit_ffs_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result)
199{
200 bitstr_t *_curbitstr;
201 bitstr_t *_stopbitstr;
202 bitstr_t _test;
203 int _value, _offset;
204
205 if (_start >= _nbits) {
206 *_result = -1;
207 return;
208 }
209
210 if (_nbits > 0) {
211 _curbitstr = _bitstr + _bit_idx(_start);
212 _stopbitstr = _bitstr + _bit_idx(_nbits - 1);
213
214 _test = *_curbitstr;
215 if (_bit_offset(_start) != 0)
216 _test &= _bit_make_mask(_start, _BITSTR_BITS - 1);
217 while (_test == 0 && _curbitstr < _stopbitstr)
218 _test = *(++_curbitstr);
219
220 _offset = ffsl(_test);
221 _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1;
222 if (_offset == 0 || _value >= _nbits)
223 _value = -1;
224 } else {
225 _value = -1;
226 }
227 *_result = _value;
228}
229
230/* Find the first bit clear in bit string at or after bit start. */
231static inline void

Callers 1

bit_ffsFunction · 0.85

Calls 4

_bit_idxFunction · 0.85
_bit_offsetFunction · 0.85
_bit_make_maskFunction · 0.85
ffslFunction · 0.50

Tested by

no test coverage detected