Functions
MathExtras.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static int64_t abs64 (int64_t x)
 
static double BitsToDouble (uint64_t Bits)
 
static float BitsToFloat (uint32_t Bits)
 
static unsigned CountLeadingOnes_32 (uint32_t Value)
 
static unsigned CountLeadingOnes_64 (uint64_t Value)
 
static unsigned int countLeadingZeros (int x)
 Count number of 0's from the most significant bit to the least stopping at the first 1. More...
 
static unsigned CountLeadingZeros_32 (uint32_t Value)
 
static unsigned CountLeadingZeros_64 (uint64_t Value)
 
static unsigned CountPopulation_32 (uint32_t Value)
 
static unsigned CountPopulation_64 (uint64_t Value)
 
static unsigned CountTrailingOnes_32 (uint32_t Value)
 
static unsigned CountTrailingOnes_64 (uint64_t Value)
 
static unsigned CountTrailingZeros_32 (uint32_t Value)
 
static unsigned CountTrailingZeros_64 (uint64_t Value)
 
static uint64_t DoubleToBits (double Double)
 
static uint32_t FloatToBits (float Float)
 
static uint64_t GreatestCommonDivisor64 (uint64_t A, uint64_t B)
 
static uint32_t Hi_32 (uint64_t Value)
 Hi_32 - This function returns the high 32 bits of a 64 bit value. More...
 
static bool isMask_32 (uint32_t Value)
 
static bool isMask_64 (uint64_t Value)
 
static bool isPowerOf2_32 (uint32_t Value)
 
static bool isShiftedMask_32 (uint32_t Value)
 
static bool isShiftedMask_64 (uint64_t Value)
 
static bool isUIntN (unsigned N, uint64_t x)
 
static uint32_t Lo_32 (uint64_t Value)
 Lo_32 - This function returns the low 32 bits of a 64 bit value. More...
 
static unsigned Log2_32 (uint32_t Value)
 
static unsigned Log2_32_Ceil (uint32_t Value)
 
static unsigned Log2_64 (uint64_t Value)
 
static unsigned Log2_64_Ceil (uint64_t Value)
 
static uint64_t MinAlign (uint64_t A, uint64_t B)
 
static uint64_t NextPowerOf2 (uint64_t A)
 
static uint64_t OffsetToAlignment (uint64_t Value, uint64_t Align)
 
static uint64_t RoundUpToAlignment (uint64_t Value, uint64_t Align)
 
static int32_t SignExtend32 (uint32_t X, unsigned B)
 Sign extend number in the bottom B bits of X to a 32-bit int. Requires 0 < B <= 32. More...
 
static int64_t SignExtend64 (uint64_t X, unsigned B)
 Sign extend number in the bottom B bits of X to a 64-bit int. Requires 0 < B <= 64. More...
 

Function Documentation

◆ abs64()

static int64_t abs64 ( int64_t  x)
inlinestatic

abs64 - absolute value of a 64-bit int. Not all environments support "abs" on whatever their name for the 64-bit int type is. The absolute value of the largest negative number is undefined, as with "abs".

Definition at line 401 of file MathExtras.h.

◆ BitsToDouble()

static double BitsToDouble ( uint64_t  Bits)
inlinestatic

BitsToDouble - This function takes a 64-bit integer and returns the bit equivalent double.

Definition at line 309 of file MathExtras.h.

◆ BitsToFloat()

static float BitsToFloat ( uint32_t  Bits)
inlinestatic

BitsToFloat - This function takes a 32-bit integer and returns the bit equivalent float.

Definition at line 320 of file MathExtras.h.

◆ CountLeadingOnes_32()

static unsigned CountLeadingOnes_32 ( uint32_t  Value)
inlinestatic

CountLeadingOnes_32 - this function performs the operation of counting the number of ones from the most significant bit to the first zero bit. Ex. CountLeadingOnes_32(0xFF0FFF00) == 8. Returns 32 if the word is all ones.

Definition at line 124 of file MathExtras.h.

◆ CountLeadingOnes_64()

static unsigned CountLeadingOnes_64 ( uint64_t  Value)
inlinestatic

CountLeadingOnes_64 - This function performs the operation of counting the number of ones from the most significant bit to the first zero bit (64 bit edition.) Returns 64 if the word is all ones.

Definition at line 182 of file MathExtras.h.

◆ countLeadingZeros()

static unsigned int countLeadingZeros ( int  x)
inlinestatic

Count number of 0's from the most significant bit to the least stopping at the first 1.

Only unsigned integral types are allowed.

Parameters
ZBthe behavior on an input of 0. Only ZB_Width and ZB_Undefined are valid arguments.

Definition at line 424 of file MathExtras.h.

◆ CountLeadingZeros_32()

static unsigned CountLeadingZeros_32 ( uint32_t  Value)
inlinestatic

CountLeadingZeros_32 - this function performs the platform optimal form of counting the number of zeros from the most significant bit to the first one bit. Ex. CountLeadingZeros_32(0x00F000FF) == 8. Returns 32 if the word is zero.

Definition at line 95 of file MathExtras.h.

◆ CountLeadingZeros_64()

static unsigned CountLeadingZeros_64 ( uint64_t  Value)
inlinestatic

CountLeadingZeros_64 - This function performs the platform optimal form of counting the number of zeros from the most significant bit to the first one bit (64 bit edition.) Returns 64 if the word is zero.

Definition at line 132 of file MathExtras.h.

◆ CountPopulation_32()

static unsigned CountPopulation_32 ( uint32_t  Value)
inlinestatic

CountPopulation_32 - this function counts the number of set bits in a value. Ex. CountPopulation(0xF000F000) = 8 Returns 0 if the word is zero.

Definition at line 247 of file MathExtras.h.

◆ CountPopulation_64()

static unsigned CountPopulation_64 ( uint64_t  Value)
inlinestatic

CountPopulation_64 - this function counts the number of set bits in a value, (64 bit edition.)

Definition at line 259 of file MathExtras.h.

◆ CountTrailingOnes_32()

static unsigned CountTrailingOnes_32 ( uint32_t  Value)
inlinestatic

CountTrailingOnes_32 - this function performs the operation of counting the number of ones from the least significant bit to the first zero bit. Ex. CountTrailingOnes_32(0x00FF00FF) == 8. Returns 32 if the word is all ones.

Definition at line 210 of file MathExtras.h.

◆ CountTrailingOnes_64()

static unsigned CountTrailingOnes_64 ( uint64_t  Value)
inlinestatic

CountTrailingOnes_64 - This function performs the operation of counting the number of ones from the least significant bit to the first zero bit (64 bit edition.) Returns 64 if the word is all ones.

Definition at line 240 of file MathExtras.h.

◆ CountTrailingZeros_32()

static unsigned CountTrailingZeros_32 ( uint32_t  Value)
inlinestatic

CountTrailingZeros_32 - this function performs the platform optimal form of counting the number of zeros from the least significant bit to the first one bit. Ex. CountTrailingZeros_32(0xFF00FF00) == 8. Returns 32 if the word is zero.

Definition at line 190 of file MathExtras.h.

◆ CountTrailingZeros_64()

static unsigned CountTrailingZeros_64 ( uint64_t  Value)
inlinestatic

CountTrailingZeros_64 - This function performs the platform optimal form of counting the number of zeros from the least significant bit to the first one bit (64 bit edition.) Returns 64 if the word is zero.

Definition at line 218 of file MathExtras.h.

◆ DoubleToBits()

static uint64_t DoubleToBits ( double  Double)
inlinestatic

DoubleToBits - This function takes a double and returns the bit equivalent 64-bit integer. Note that copying doubles around changes the bits of NaNs on some hosts, notably x86, so this routine cannot be used if these bits are needed.

Definition at line 333 of file MathExtras.h.

◆ FloatToBits()

static uint32_t FloatToBits ( float  Float)
inlinestatic

FloatToBits - This function takes a float and returns the bit equivalent 32-bit integer. Note that copying floats around changes the bits of NaNs on some hosts, notably x86, so this routine cannot be used if these bits are needed.

Definition at line 346 of file MathExtras.h.

◆ GreatestCommonDivisor64()

static uint64_t GreatestCommonDivisor64 ( uint64_t  A,
uint64_t  B 
)
inlinestatic

GreatestCommonDivisor64 - Return the greatest common divisor of the two values using Euclid's algorithm.

Definition at line 298 of file MathExtras.h.

◆ Hi_32()

static uint32_t Hi_32 ( uint64_t  Value)
inlinestatic

Hi_32 - This function returns the high 32 bits of a 64 bit value.

Definition at line 37 of file MathExtras.h.

◆ isMask_32()

static bool isMask_32 ( uint32_t  Value)
inlinestatic

isIntN - Checks if an signed integer fits into the given (dynamic) bit width. isMask_32 - This function returns true if the argument is a sequence of ones starting at the least significant bit with the remainder zero (32 bit version). Ex. isMask_32(0x0000FFFFU) == true.

Definition at line 61 of file MathExtras.h.

◆ isMask_64()

static bool isMask_64 ( uint64_t  Value)
inlinestatic

isMask_64 - This function returns true if the argument is a sequence of ones starting at the least significant bit with the remainder zero (64 bit version).

Definition at line 68 of file MathExtras.h.

◆ isPowerOf2_32()

static bool isPowerOf2_32 ( uint32_t  Value)
inlinestatic

isPowerOf2_32 - This function returns true if the argument is a power of two > 0. Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.)

Definition at line 87 of file MathExtras.h.

◆ isShiftedMask_32()

static bool isShiftedMask_32 ( uint32_t  Value)
inlinestatic

isShiftedMask_32 - This function returns true if the argument contains a sequence of ones with the remainder zero (32 bit version.) Ex. isShiftedMask_32(0x0000FF00U) == true.

Definition at line 75 of file MathExtras.h.

◆ isShiftedMask_64()

static bool isShiftedMask_64 ( uint64_t  Value)
inlinestatic

isShiftedMask_64 - This function returns true if the argument contains a sequence of ones with the remainder zero (64 bit version.)

Definition at line 81 of file MathExtras.h.

◆ isUIntN()

static bool isUIntN ( unsigned  N,
uint64_t  x 
)
inlinestatic

isUIntN - Checks if an unsigned integer fits into the given (dynamic) bit width.

Definition at line 48 of file MathExtras.h.

◆ Lo_32()

static uint32_t Lo_32 ( uint64_t  Value)
inlinestatic

Lo_32 - This function returns the low 32 bits of a 64 bit value.

Definition at line 42 of file MathExtras.h.

◆ Log2_32()

static unsigned Log2_32 ( uint32_t  Value)
inlinestatic

Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero. (32 bit edition.) Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2

Definition at line 273 of file MathExtras.h.

◆ Log2_32_Ceil()

static unsigned Log2_32_Ceil ( uint32_t  Value)
inlinestatic

Log2_32_Ceil - This function returns the ceil log base 2 of the specified value, 32 if the value is zero. (32 bit edition). Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3

Definition at line 286 of file MathExtras.h.

◆ Log2_64()

static unsigned Log2_64 ( uint64_t  Value)
inlinestatic

Log2_64 - This function returns the floor log base 2 of the specified value, -1 if the value is zero. (64 bit edition.)

Definition at line 279 of file MathExtras.h.

◆ Log2_64_Ceil()

static unsigned Log2_64_Ceil ( uint64_t  Value)
inlinestatic

Log2_64_Ceil - This function returns the ceil log base 2 of the specified value, 64 if the value is zero. (64 bit edition.)

Definition at line 292 of file MathExtras.h.

◆ MinAlign()

static uint64_t MinAlign ( uint64_t  A,
uint64_t  B 
)
inlinestatic

MinAlign - A and B are either alignments or offsets. Return the minimum alignment that may be assumed after adding the two together.

Definition at line 357 of file MathExtras.h.

◆ NextPowerOf2()

static uint64_t NextPowerOf2 ( uint64_t  A)
inlinestatic

NextPowerOf2 - Returns the next power of two (in 64-bits) that is strictly greater than A. Returns zero on overflow.

Definition at line 368 of file MathExtras.h.

◆ OffsetToAlignment()

static uint64_t OffsetToAlignment ( uint64_t  Value,
uint64_t  Align 
)
inlinestatic

Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Align. Align must be non-zero.

Definition at line 394 of file MathExtras.h.

◆ RoundUpToAlignment()

static uint64_t RoundUpToAlignment ( uint64_t  Value,
uint64_t  Align 
)
inlinestatic

Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Align. Align must be non-zero.

Examples:

Definition at line 387 of file MathExtras.h.

◆ SignExtend32()

static int32_t SignExtend32 ( uint32_t  X,
unsigned  B 
)
inlinestatic

Sign extend number in the bottom B bits of X to a 32-bit int. Requires 0 < B <= 32.

Definition at line 407 of file MathExtras.h.

◆ SignExtend64()

static int64_t SignExtend64 ( uint64_t  X,
unsigned  B 
)
inlinestatic

Sign extend number in the bottom B bits of X to a 64-bit int. Requires 0 < B <= 64.

Definition at line 413 of file MathExtras.h.

RoundUpToAlignment
static uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align)
Definition: MathExtras.h:387
LL
#define LL(x)


grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:23