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

Function bit_ffc_at

freebsd/sys/bitstring.h:231–262  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

229
230/* Find the first bit clear in bit string at or after bit start. */
231static inline void
232bit_ffc_at(bitstr_t *_bitstr, int _start, int _nbits, int *_result)
233{
234 bitstr_t *_curbitstr;
235 bitstr_t *_stopbitstr;
236 bitstr_t _test;
237 int _value, _offset;
238
239 if (_start >= _nbits) {
240 *_result = -1;
241 return;
242 }
243
244 if (_nbits > 0) {
245 _curbitstr = _bitstr + _bit_idx(_start);
246 _stopbitstr = _bitstr + _bit_idx(_nbits - 1);
247
248 _test = *_curbitstr;
249 if (_bit_offset(_start) != 0)
250 _test |= _bit_make_mask(0, _start - 1);
251 while (_test == _BITSTR_MASK && _curbitstr < _stopbitstr)
252 _test = *(++_curbitstr);
253
254 _offset = ffsl(~_test);
255 _value = ((_curbitstr - _bitstr) * _BITSTR_BITS) + _offset - 1;
256 if (_offset == 0 || _value >= _nbits)
257 _value = -1;
258 } else {
259 _value = -1;
260 }
261 *_result = _value;
262}
263
264/* Find the first bit set in bit string. */
265static inline void

Callers 5

bit_ffcFunction · 0.85
pmap_alloc_asidFunction · 0.85
fork_findpidFunction · 0.85
tid_allocFunction · 0.85
iflib_fl_refillFunction · 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