#ifndef BITS_H
#define BITS_H
#define UINT64_SUM_OVERFLOWS(a, b) \
(a > (uint64_t)-1 - b)
/* Returns x, such that x is the smallest power of 2 >= num. */
/* Returns TRUE if 2^x=num, i.e. if num has only a single bit set to 1. */
static inline bool ATTR_CONST
{
}
static inline unsigned int ATTR_CONST
{
}
static inline unsigned int ATTR_CONST
static inline unsigned int ATTR_CONST
static inline unsigned int ATTR_CONST
{
}
#else
static inline
{
}
static inline
{
}
static inline
{
}
#endif
static inline uint64_t
{
}
static inline uint32_t
{
}
static inline uint64_t
{
}
static inline uint32_t
{
}
/* These functions look too big to be inline, but in almost all expected
uses, 'fracbits' will be a compile-time constant, and most of the
expressions will simplify greatly.
*/
/* Perform a piecewise-linear approximation to a log2, with fracbits "fractional" bits.
Best explained with examples:
With 2 fractional bits splitting each power of 2 into 4 bands:
00, 01, 10, 11 -> 00, 01, 10, 11 (small corner cases)
100, 101, 110, 111 -> 100, 101, 110, 111 ([4-8) split into 4 bands)
1000, 1001, 1010, 1011 -> 1000, 1000, 1001, 1001 ([8-15) split ...
1100, 1101, 1110, 1111 -> 1010, 1010, 1011, 1011 ... into 4 bands)
[16..31) -> 11bb
[32..63) -> 100bb
[64..127) -> 101bb
[128..255) -> 110bb
e.g. 236 = 11101100 -> ((8-2)<<2 == 11000) + (111.....>> 5 == 111) - 100 == 11011
*/
static inline unsigned int ATTR_CONST
{
return val;
return bucket;
}
static inline unsigned int ATTR_CONST
{
if (bandnum <= 1)
return bucket;
if (fracbits == 0)
return bandstart;
}
static inline unsigned int ATTR_CONST
{
if (bandnum <= 1)
return bucket;
if (fracbits == 0)
return nextbandstart - 1;
}
/* UNSAFE: multiple use of parameter (but expecting a constant in reality).
But a macro as it's most likely to be used to declare an array size.
*/
#endif