11 #pragma intrinsic(_BitScanForward)
18 #define M_E 2.7182818284590452354
21 #define M_LN2 0.69314718055994530942
24 #define M_LN10 2.30258509299404568402
27 #define M_PI 3.14159265358979323846
39 [[nodiscard]] constexpr T
log2p1(T
x) noexcept
57 [[nodiscard]] constexpr
bool ispow2(T
x) noexcept
59 return x && ((
x & (
x - 1)) == 0);
74 x |=
x >> ((
sizeof(
x) >= 2) ? 8 : 0);
75 x |=
x >> ((
sizeof(
x) >= 4) ? 16 : 0);
76 x |=
x >> ((
sizeof(
x) >= 8) ? 32 : 0);
85 [[nodiscard]] constexpr T
ceil2(T
x) noexcept
102 static_assert((-1 >> 1) == -1,
"right-shift must preserve sign");
103 return likely(int16_t(
x) ==
x) ?
x : (0x7FFF - (
x >> 31));
111 static_assert((-1 >> 1) == -1,
"right-shift must preserve sign");
112 return likely(uint8_t(
x) ==
x) ?
x : ~(
x >> 31);
123 ret = (ret << 1) | (
x & 1);
182 return (((a * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL) >> 32;
185 return (((a * 0x0802 & 0x22110) | (a * 0x8020 & 0x88440)) * 0x10101) >> 16;
196 return __builtin_clz(
x);
200 if (
x <= 0x0000ffff) { lz += 16;
x <<= 16; }
201 if (
x <= 0x00ffffff) { lz += 8;
x <<= 8; }
202 if (
x <= 0x0fffffff) { lz += 4;
x <<= 4; }
203 lz += (0x55ac >> ((
x >> 27) & 0x1e)) & 0x3;
214 #if defined(__GNUC__)
215 return __builtin_ffs(
x);
216 #elif defined(_MSC_VER)
218 return _BitScanForward(&index,
x) ? index + 1 : 0;
220 if (
x == 0)
return 0;
222 if ((
x & 0xffff) == 0) { pos += 16;
x >>= 16; }
223 if ((
x & 0x00ff) == 0) { pos += 8;
x >>= 8; }
224 if ((
x & 0x000f) == 0) { pos += 4;
x >>= 4; }
225 if ((
x & 0x0003) == 0) { pos += 2;
x >>= 2; }
226 if ((
x & 0x0001) == 0) { pos += 1; }
246 assert(0.0f <=
x); assert(
x <= 1.0f);
247 float a = -0.5f*y[-1] + 1.5f*y[0] - 1.5f*y[1] + 0.5f*y[2];
248 float b = y[-1] - 2.5f*y[0] + 2.0f*y[1] - 0.5f*y[2];
249 float c = -0.5f*y[-1] + 0.5f*y[1];
253 return a*x3 + b*x2 + c*
x + d;
constexpr unsigned reverseNBits(unsigned x, unsigned bits)
Reverse the lower N bits of a given value.
constexpr T floodRight(T x) noexcept
Returns the smallest number of the form 2^n-1 that is greater or equal to the given number.
constexpr T ceil2(T x) noexcept
Returns the smallest number that is both >=a and a power of two.
uint8_t clipIntToByte(int x)
Clip x to range [0,255].
constexpr T log2p1(T x) noexcept
Returns the number of bits needed to store the value 'x', that is: for x==0 : 0 for x!...
constexpr unsigned countLeadingZeros(unsigned x)
Count the number of leading zero-bits in the given word.
unsigned findFirstSet(unsigned x)
Find the least significant bit that is set.
constexpr uint8_t reverseByte(uint8_t a)
Reverse the bits in a byte.
constexpr bool ispow2(T x) noexcept
Is the given number an integral power of two? That is, does it have exactly one 1-bit in binary repre...
int16_t clipIntToShort(int x)
Clip x to range [-32768,32767].
constexpr float cubicHermite(const float *y, float x)
constexpr KeyMatrixPosition x
Keyboard bindings.