-
Notifications
You must be signed in to change notification settings - Fork 10
/
bit.h
35 lines (27 loc) · 843 Bytes
/
bit.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
//---------------------------------------------------------------------------
#pragma once
#include <stddef.h>
#include <stdint.h>
//---------------------------------------------------------------------------
template <size_t N> class Bit {};
template <> class Bit<4> {
public:
static inline uint32_t CountTrailingZeros(uint32_t v) {
return __builtin_ctz(v);
}
#if JAVELIN_USE_CUSTOM_POP_COUNT
static uint32_t PopCount(uint32_t v);
#else
static inline uint32_t PopCount(uint32_t v) { return __builtin_popcount(v); }
#endif
};
template <> class Bit<8> {
public:
static inline uint64_t CountTrailingZeros(uint64_t v) {
return __builtin_ctzll(v);
}
static inline uint64_t PopCount(uint64_t v) {
return __builtin_popcountll(v);
}
};
//---------------------------------------------------------------------------