class Bitwise

Class for manipulating bit patterns.

Public

Methods

staticNextPow2

static u32 NextPow2(u32 n)

Returns the power-of-two number greater or equal to the provided value.

staticClosestPow2

static u32 ClosestPow2(u32 n)

Returns the power-of-two number closest to the provided value.

staticBitsLog2

static constexpr u32 BitsLog2(u32 v)

Returns base-2 logarithm for common bit counts (8, 16, 32, 64), as a constant expression.

staticModPow

static u32 ModPow(u32 val1, u32 val2, u32 t)

Returns modular exponentiation for integers.

staticMostSignificantBit

static u32 MostSignificantBit(u32 val)

Finds the most-significant non-zero bit in the provided value and returns the index of that bit.

staticLeastSignificantBit

static u32 LeastSignificantBit(u32 val)

Finds the least-significant non-zero bit in the provided value and returns the index of that bit.

staticMostSignificantBit

static u32 MostSignificantBit(u64 val)

Finds the most-significant non-zero bit in the provided value and returns the index of that bit.

staticLeastSignificantBit

static u32 LeastSignificantBit(u64 val)

Finds the least-significant non-zero bit in the provided value and returns the index of that bit.

staticCountSetBits

static uint32_t CountSetBits(uint32_t val)

Count the number of set bits in a mask.

staticFixedToFixed

static uint32_t FixedToFixed(u32 value, uint32_t n, uint32_t p)

Convert N bit color channel value to P bits.

It fills P bits with the bit pattern repeated. (this is /((1

<

<n

)-1) in fixed point).

staticUnormToUint

static uint32_t UnormToUint(float value, uint32_t bits)

Converts floating point value in range [0, 1] to an unsigned integer of a certain number of bits.

Works for any value of bits between 0 and 31.

staticSnormToUint

static uint32_t SnormToUint(float value, uint32_t bits)

Converts floating point value in range [-1, 1] to an unsigned integer of a certain number of bits.

Works for any value of bits between 0 and 31.

staticUintToUnorm

static float UintToUnorm(uint32_t value, uint32_t bits)

Converts an unsigned integer to a floating point in range [0, 1].

staticUintToSnorm

static float UintToSnorm(uint32_t value, uint32_t bits)

Converts an unsigned integer to a floating point in range [-1, 1].

staticLerpByte

static uint32_t LerpByte(uint32_t from, uint32_t to, uint32_t t)

Interpolates between two values using the parameter.

All parameters must be in [0, 255] range. When is zero, value will be returned, and when it is 255 value will be returned, and interpolation between and will occurr for in-between values.

staticLerpWord

static uint32_t LerpWord(uint32_t from, uint32_t to, uint32_t t)

Interpolates between two values using the parameter.

All parameters must be in [0, 65536] range. When is zero, value will be returned, and when it is 65536 value will be returned, and interpolation between and will occurr for in-between values.

staticInvLerpByte

static uint32_t InvLerpByte(uint32_t from, uint32_t to, uint32_t val)

Determines the position of the parameter in the [from, to] range, returned in [0, 255] range where 0 is returned if is less or equal than , and 255 is returned if is equal to greater to , and in-between values returned accordingly.

All values must be in [0, 255] range.

staticInvLerpWord

static uint32_t InvLerpWord(uint32_t from, uint32_t to, uint32_t val)

Determines the position of the parameter in the [from, to] range, returned in [0, 65536] range where 0 is returned if is less or equal than , and 65536 is returned if is equal to greater to , and in-between values returned accordingly.

All values must be in [0, 65536] range.

staticIntWrite

static void IntWrite(void *dest, const int32_t n, const uint32_t value)

Write a n*8 bits integer value to memory in native endian.

staticIntRead

static uint32_t IntRead(const void *src, int32_t n)

Read a n*8 bits integer value to memory in native endian.

staticFloatToHalf

static u16 FloatToHalf(float i)

Convert a float32 to a float16 (NV_half_float).

staticFloatToHalfI

static u16 FloatToHalfI(u32 i)

Converts float in u32 format to a a half in u16 format.

staticHalfToFloat

static float HalfToFloat(u16 y)

Convert a float16 (NV_half_float) to a float32.

staticHalfToFloatI

static u32 HalfToFloatI(u16 y)

Converts a half in u16 format to a float in u32 format.

staticFloatToFloat10

static u32 FloatToFloat10(float v)

Converts a 32-bit float to a 10-bit float according to OpenGL packed_float extension.

staticFloatToFloat11

static u32 FloatToFloat11(float v)

Converts a 32-bit float to a 11-bit float according to OpenGL packed_float extension.

staticFloat10ToFloat

static float Float10ToFloat(u32 v)

Converts a 10-bit float to a 32-bit float according to OpenGL packed_float extension.

staticFloat11ToFloat

static float Float11ToFloat(u32 v)

Converts a 11-bit float to a 32-bit float according to OpenGL packed_float extension.

staticEncodeVarInt

static u32 EncodeVarInt(u32 value, u8 *output)

Encodes a 32-bit integer value as a base-128 varint.

Varints are a method of serializing integers using one or more bytes, where smaller values use less bytes.

value
Value to encode.
output
Buffer to store the encoded bytes in. Must be at least 5 bytes in length.

Returns: Number of bytes required to store the value, in range [1, 5]

staticDecodeVarInt

static u32 DecodeVarInt(u32 &outValue, const u8 *input, u32 size)

Decodes a value encoded using encodeVarInt(u32, u8*).

outValue
Variable to receive the decoded value.
input
Input buffer to decode the data from.
size
Size of the input buffer.

Returns: Number of bytes read.

staticEncodeVarInt

static u32 EncodeVarInt(i32 value, u8 *output)

staticDecodeVarInt

static u32 DecodeVarInt(i32 &outValue, const u8 *input, u32 size)

staticEncodeVarInt

static u32 EncodeVarInt(u64 value, u8 *output)

Encodes a 64-bit integer value as a base-128 varint.

Varints are a method of serializing integers using one or more bytes, where smaller values use less bytes.

value
Value to encode.
output
Buffer to store the encoded bytes in. Must be at least 10 bytes in length.

Returns: Number of bytes required to store the value, in range [1, 10]

staticDecodeVarInt

static u32 DecodeVarInt(u64 &outValue, const u8 *input, u32 size)

Decodes a value encoded using encodeVarInt(u64, u8*).

outValue
Variable to receive the decoded value.
input
Input buffer to decode the data from.
size
Size of the input buffer.

Returns: Number of bytes read.

staticEncodeVarInt

static u32 EncodeVarInt(i64 value, u8 *output)

staticDecodeVarInt

static u32 DecodeVarInt(i64 &outValue, const u8 *input, u32 size)

staticQuantize8BitSigned

static u8 Quantize8BitSigned(float v)

Converts a float in range [-1,1] into an unsigned 8-bit integer.

staticQuantize8BitUnsigned

static u8 Quantize8BitUnsigned(float v)

Converts a float in range [0,1] into an unsigned 8-bit integer.