-
Notifications
You must be signed in to change notification settings - Fork 2
/
countbits.h
58 lines (51 loc) · 1.93 KB
/
countbits.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
Copyright (c) 2020 Vicente Romero Calero. All rights reserved.
Licensed under the MIT License.
See LICENSE file in the project root for full license information.
*/
#ifndef VTENC_COUNTBITS_H_
#define VTENC_COUNTBITS_H_
#include "bits.h"
#define BINSEARCH \
do { \
size_t half; \
\
if (values_len == 0) return 0; \
\
while (values_len > 1) { \
half = values_len >> 1; \
base = ((base[half] & mask) == 0) ? &base[half] : base; \
values_len -= half; \
} \
\
return ((*base & mask) == 0) + base - values; \
} while (0)
static inline size_t count_zeros_at_bit_pos8(const uint8_t *values,
size_t values_len, unsigned int bit_pos)
{
const uint8_t mask = BITS_POS_MASK8[bit_pos];
const uint8_t *base = values;
BINSEARCH;
}
static inline size_t count_zeros_at_bit_pos16(const uint16_t *values,
size_t values_len, unsigned int bit_pos)
{
const uint16_t mask = BITS_POS_MASK16[bit_pos];
const uint16_t *base = values;
BINSEARCH;
}
static inline size_t count_zeros_at_bit_pos32(const uint32_t *values,
size_t values_len, unsigned int bit_pos)
{
const uint32_t mask = BITS_POS_MASK32[bit_pos];
const uint32_t *base = values;
BINSEARCH;
}
static inline size_t count_zeros_at_bit_pos64(const uint64_t *values,
size_t values_len, unsigned int bit_pos)
{
const uint64_t mask = BITS_POS_MASK64[bit_pos];
const uint64_t *base = values;
BINSEARCH;
}
#endif /* VTENC_COUNTBITS_H_ */