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

Function bit_count

freebsd/sys/bitstring.h:387–420  ·  view source on GitHub ↗

Count the number of bits set in a bitstr of size _nbits at or after _start */

Source from the content-addressed store, hash-verified

385
386/* Count the number of bits set in a bitstr of size _nbits at or after _start */
387static inline void
388bit_count(bitstr_t *_bitstr, int _start, int _nbits, int *_result)
389{
390 bitstr_t *_curbitstr, mask;
391 int _value = 0, curbitstr_len;
392
393 if (_start >= _nbits)
394 goto out;
395
396 _curbitstr = _bitstr + _bit_idx(_start);
397 _nbits -= _BITSTR_BITS * _bit_idx(_start);
398 _start -= _BITSTR_BITS * _bit_idx(_start);
399
400 if (_start > 0) {
401 curbitstr_len = (int)_BITSTR_BITS < _nbits ?
402 (int)_BITSTR_BITS : _nbits;
403 mask = _bit_make_mask(_start, _bit_offset(curbitstr_len - 1));
404 _value += __bitcountl(*_curbitstr & mask);
405 _curbitstr++;
406 _nbits -= _BITSTR_BITS;
407 }
408 while (_nbits >= (int)_BITSTR_BITS) {
409 _value += __bitcountl(*_curbitstr);
410 _curbitstr++;
411 _nbits -= _BITSTR_BITS;
412 }
413 if (_nbits > 0) {
414 mask = _bit_make_mask(0, _bit_offset(_nbits - 1));
415 _value += __bitcountl(*_curbitstr & mask);
416 }
417
418out:
419 *_result = _value;
420}
421
422#endif /* _SYS_BITSTRING_H_ */

Callers 3

reserve_pv_entriesFunction · 0.85
reserve_pv_entriesFunction · 0.85
check_unrhdrFunction · 0.85

Calls 3

_bit_idxFunction · 0.85
_bit_make_maskFunction · 0.85
_bit_offsetFunction · 0.85

Tested by

no test coverage detected