1234567891011121314151617181920212223242526272829303132333435 |
- // SPDX-License-Identifier: GPL-3.0-or-later
- // Copyright © 2018-2019 Ariadne Devos
- /* sHT -- array of bits */
- #ifndef _sHT_BITVEC_H
- #define _sHT_BITVEC_H
- #include <stdint.h>
- #include <sHT/test.h>
- /** Test if a bit is set.
- @var{bits}: a bit array. Bits are numbered from the first byte to the last,
- from the least-significant bit to the most-significant.
- @var{index}: the index of the bit. It is within bounds.
- The bit should be set more often than it is not.
- No bounds checking is performed. This must be called in control position. */
- __attribute__((always_inline))
- __attribute__((pure))
- static inline _Bool
- sHT_bit_test(const uint8_t *bits, unsigned int index)
- {
- /* x86 has a special instruction for testing a bit (bt), which GCC
- doesn't generate automatically, but it is tricky to use -- as of
- now, to no avail. There are tests for the courageous, in
- <tests/bitvec.c>.
- There seems to be no code size difference in
- different choices of uintN_t. */
- return sHT_and_any(bits[index / 8], 1u << (index % 8));
- }
- #endif
|