Count the number of bits set in a bitstr of size _nbits at or after _start */
| 385 | |
| 386 | /* Count the number of bits set in a bitstr of size _nbits at or after _start */ |
| 387 | static inline void |
| 388 | bit_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 | |
| 418 | out: |
| 419 | *_result = _value; |
| 420 | } |
| 421 | |
| 422 | #endif /* _SYS_BITSTRING_H_ */ |
no test coverage detected