1
#if defined(_WIN32) || defined(_WIN64)
4
typedef UINT16 uint16_t;
5
typedef UINT32 uint32_t;
13
#define max4(a,b,c,d) max2(max2(a,b),max2(c,d))
14
#define max3(a,b,c) max2(max2(a,b),c)
15
#define max2(a,b) (((a)>(b))?(a):(b))
16
#define min2(a,b) (((a)<(b))?(a):(b))
18
#define calc_alloc(size,rounding) ((((size)/(rounding)) + (((size)%(rounding))?1:0))*(rounding))
19
#define calc_blocks(size,rounding) (((size)/(rounding)) + (((size)%(rounding))?1:0))
21
static const char debruijn[32] = {
22
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
23
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
26
static inline int next_power(int n) {
28
n |= n >> 1; // Divide by 2^k for consecutive doublings of k up to 32,
29
n |= n >> 2; // and then or the results.
33
n++; // The result is a number of 1 bits equal to the number
34
// of bits in the original number, plus 1. That's the
35
// next highest power of 2.
39
static inline int get_power(int n) {
40
if (n&(n-1)) return -1;
41
else return debruijn[((uint32_t)n * 0x077CB531) >> 27];