Contains support classes and functions that may be used by AsmJit source and header files.
Anything defined here is considered internal and should not be used outside of AsmJit and related projects like AsmTK.
typedef
uint32_t FastUInt8typedef Internal::StdInt<
sizeof(
uintptr_t), 1>::Type
BitWord
static constexpr bool isUnsigned() noexcept
template<typename T>
static
constexpr Internal::Int32Or64<T, 0>::Type
asInt(
const T& x)
noexcepttemplate<typename T>
static
constexpr Internal::Int32Or64<T, 1>::Type
asUInt(
const T& x)
noexcepttemplate<typename T>
static
constexpr Internal::Int32Or64<T>::Type
asNormalized(
const T& x)
noexcepttemplate<typename T>
static
constexpr Internal::StdInt<
sizeof(T), isUnsigned<T> ()>::Type
asStdInt(
const T& x)
noexcepttemplate<typename Dst, typename Src>
static Dst
bitCast(
const Src& x)
noexceptstatic constexpr uint32_t bitSizeOf() noexcept
template<typename T>
static
constexpr T
neg(
const T& x)
noexceptstatic constexpr T allOnes() noexcept
template<typename X, typename Y>
static
constexpr X
shl(
const X& x,
const Y& y)
noexcepttemplate<typename X, typename Y>
static
constexpr X
shr(
const X& x,
const Y& y)
noexcepttemplate<typename X, typename Y>
static
constexpr X
sar(
const X& x,
const Y& y)
noexcepttemplate<typename X, typename Y> static constexpr X ror(const X& x, const Y& y) noexcept
template<typename X, typename Y>
static
constexpr X
or_shr(
const X& x,
const Y& y)
noexcepttemplate<typename T>
static
constexpr T
blsi(T x)
noexcepttemplate<typename T, typename IndexT>
static
constexpr bool bitTest(T x, IndexT n)
noexceptstatic constexpr bool isLsbMask(const T& value)
static constexpr bool isConsecutiveMask(const T& value)
template<typename T, typename CountT>
static
constexpr T
lsbMask(
const CountT& n)
noexcepttemplate<typename T, typename CountT>
static
constexpr T
msbMask(
const CountT& n)
noexcepttemplate<typename Index>
static
constexpr uint32_t bitMask(
const Index& x)
noexcepttemplate<typename Index, typename... Args>
static
constexpr uint32_t bitMask(
const Index& x, Args... args)
noexcepttemplate<typename DstT, typename SrcT>
template<typename A, typename B>
static
constexpr bool test(A a, B b)
noexceptstatic constexpr T fillTrailingBits(const T& x) noexcept
template<typename T>
static
uint32_t clz(T x)
noexcepttemplate<typename T>
static
uint32_t ctz(T x)
noexcepttemplate<typename T>
static
uint32_t popcnt(T x)
noexcepttemplate<typename T>
static constexpr T min(const T& a, const T& b) noexcept
template<typename T, typename... Args> static constexpr T min(const T& a, const T& b, Args&&... args) noexcept
static constexpr T max(const T& a, const T& b) noexcept
template<typename T, typename... Args> static constexpr T max(const T& a, const T& b, Args&&... args) noexcept
static int64_t immediateFromT(const T& x) noexcept
static T immediateToT(int64_t x) noexcept
static T addOverflow(const T& x, const T& y, FastUInt8* of) noexcept
static T subOverflow(const T& x, const T& y, FastUInt8* of) noexcept
static T mulOverflow(const T& x, const T& y, FastUInt8* of) noexcept
template<typename X, typename Y> static constexpr bool isAligned(X base, Y alignment) noexcept
template<typename T>
template<typename X, typename Y> static constexpr X alignUp(X x, Y alignment) noexcept
static constexpr T alignUpPowerOf2(T x) noexcept
template<typename X, typename Y>
static
constexpr Internal::StdInt<
sizeof(X), 1>::Type
alignUpDiff(X base, Y alignment)
noexcepttemplate<typename X, typename Y> static constexpr X alignDown(X x, Y alignment) noexcept
template<typename X, typename Y>
template<typename T>
static
constexpr bool isBetween(
const T& x,
const T& a,
const T& b)
noexcepttemplate<typename T>
static
constexpr bool isInt4(T x)
noexcepttemplate<typename T>
static
constexpr bool isInt7(T x)
noexcepttemplate<typename T>
static
constexpr bool isInt8(T x)
noexcepttemplate<typename T>
static
constexpr bool isInt9(T x)
noexcepttemplate<typename T>
static
constexpr bool isInt10(T x)
noexcepttemplate<typename T>
static
constexpr bool isInt16(T x)
noexcepttemplate<typename T>
static
constexpr bool isInt32(T x)
noexcepttemplate<typename T>
static
constexpr bool isUInt4(T x)
noexcepttemplate<typename T>
static
constexpr bool isUInt8(T x)
noexcepttemplate<typename T>
static
constexpr bool isUInt12(T x)
noexcepttemplate<typename T>
static
constexpr bool isUInt16(T x)
noexcepttemplate<typename T>
static
constexpr bool isUInt32(T x)
noexcepttemplate<typename T>
static
bool isEncodableOffset32(
int32_t offset,
uint32_t nBits)
noexceptstatic
bool isEncodableOffset64(
int64_t offset,
uint32_t nBits)
noexceptstatic
uint16_t byteswap16(
uint16_t x)
noexceptstatic
uint32_t byteswap32(
uint32_t x)
noexceptstatic
uint64_t byteswap64(
uint64_t x)
noexceptstatic
constexpr uint32_t bytepack32_4x8(
uint32_t a,
uint32_t b,
uint32_t c,
uint32_t d)
noexceptstatic constexpr uint32_t unpackU32At0(T x) noexcept
static constexpr uint32_t unpackU32At1(T x) noexcept
static
uint32_t byteShiftOfDWordStruct(
uint32_t index)
noexceptstatic constexpr T asciiToLower(T c) noexcept
static constexpr T asciiToUpper(T c) noexcept
static
size_t strLen(
const char* s,
size_t maxSize)
noexceptstatic
constexpr uint32_t hashRound(
uint32_t hash,
uint32_t c)
noexceptstatic
uint32_t hashString(
const char* data,
size_t size)
noexceptstatic
const char*
findPackedString(
const char* p,
uint32_t id)
noexceptstatic
int compareStringViews(
const char* aData,
size_t aSize,
const char* bData,
size_t bSize)
noexceptstatic
uint8_t readU8(
const void* p)
noexceptstatic
int8_t readI8(
const void* p)
noexceptstatic uint16_t readU16x(const void* p) noexcept
template<size_t Alignment = 1> static uint16_t readU16u(const void* p) noexcept
template<size_t Alignment = 1> static uint16_t readU16uLE(const void* p) noexcept
template<size_t Alignment = 1> static uint16_t readU16uBE(const void* p) noexcept
static
uint16_t readU16a(
const void* p)
noexceptstatic
uint16_t readU16aLE(
const void* p)
noexceptstatic
uint16_t readU16aBE(
const void* p)
noexceptstatic int16_t readI16x(const void* p) noexcept
template<size_t Alignment = 1> static int16_t readI16u(const void* p) noexcept
template<size_t Alignment = 1> static int16_t readI16uLE(const void* p) noexcept
template<size_t Alignment = 1> static int16_t readI16uBE(const void* p) noexcept
static
int16_t readI16a(
const void* p)
noexceptstatic
int16_t readI16aLE(
const void* p)
noexceptstatic
int16_t readI16aBE(
const void* p)
noexceptstatic uint32_t readU24u(const void* p) noexcept
static
uint32_t readU24uLE(
const void* p)
noexceptstatic
uint32_t readU24uBE(
const void* p)
noexceptstatic uint32_t readU32x(const void* p) noexcept
template<size_t Alignment = 1> static uint32_t readU32u(const void* p) noexcept
template<size_t Alignment = 1> static uint32_t readU32uLE(const void* p) noexcept
template<size_t Alignment = 1> static uint32_t readU32uBE(const void* p) noexcept
static
uint32_t readU32a(
const void* p)
noexceptstatic
uint32_t readU32aLE(
const void* p)
noexceptstatic
uint32_t readU32aBE(
const void* p)
noexceptstatic uint32_t readI32x(const void* p) noexcept
template<size_t Alignment = 1> static int32_t readI32u(const void* p) noexcept
template<size_t Alignment = 1> static int32_t readI32uLE(const void* p) noexcept
template<size_t Alignment = 1> static int32_t readI32uBE(const void* p) noexcept
static
int32_t readI32a(
const void* p)
noexceptstatic
int32_t readI32aLE(
const void* p)
noexceptstatic
int32_t readI32aBE(
const void* p)
noexceptstatic uint64_t readU64x(const void* p) noexcept
template<size_t Alignment = 1> static uint64_t readU64u(const void* p) noexcept
template<size_t Alignment = 1> static uint64_t readU64uLE(const void* p) noexcept
template<size_t Alignment = 1> static uint64_t readU64uBE(const void* p) noexcept
static
uint64_t readU64a(
const void* p)
noexceptstatic
uint64_t readU64aLE(
const void* p)
noexceptstatic
uint64_t readU64aBE(
const void* p)
noexceptstatic int64_t readI64x(const void* p) noexcept
template<size_t Alignment = 1> static int64_t readI64u(const void* p) noexcept
template<size_t Alignment = 1> static int64_t readI64uLE(const void* p) noexcept
template<size_t Alignment = 1> static int64_t readI64uBE(const void* p) noexcept
static
int64_t readI64a(
const void* p)
noexceptstatic
int64_t readI64aLE(
const void* p)
noexceptstatic
int64_t readI64aBE(
const void* p)
noexceptstatic
void writeU8(
void* p,
uint8_t x)
noexceptstatic
void writeI8(
void* p,
int8_t x)
noexcepttemplate<ByteOrder BO = ByteOrder::kNative, size_t Alignment = 1> static void writeU16x(void* p, uint16_t x) noexcept
template<size_t Alignment = 1> static void writeU16uLE(void* p, uint16_t x) noexcept
template<size_t Alignment = 1> static void writeU16uBE(void* p, uint16_t x) noexcept
static
void writeU16a(
void* p,
uint16_t x)
noexceptstatic
void writeU16aLE(
void* p,
uint16_t x)
noexceptstatic
void writeU16aBE(
void* p,
uint16_t x)
noexcepttemplate<ByteOrder BO = ByteOrder::kNative, size_t Alignment = 1> static void writeI16x(void* p, int16_t x) noexcept
template<size_t Alignment = 1> static void writeI16uLE(void* p, int16_t x) noexcept
template<size_t Alignment = 1> static void writeI16uBE(void* p, int16_t x) noexcept
static
void writeI16a(
void* p,
int16_t x)
noexceptstatic
void writeI16aLE(
void* p,
int16_t x)
noexceptstatic
void writeI16aBE(
void* p,
int16_t x)
noexceptstatic void writeU24u(void* p, uint32_t v) noexcept
static
void writeU24uLE(
void* p,
uint32_t v)
noexceptstatic
void writeU24uBE(
void* p,
uint32_t v)
noexcepttemplate<ByteOrder BO = ByteOrder::kNative, size_t Alignment = 1> static void writeU32x(void* p, uint32_t x) noexcept
template<size_t Alignment = 1> static void writeU32u(void* p, uint32_t x) noexcept
template<size_t Alignment = 1> static void writeU32uLE(void* p, uint32_t x) noexcept
template<size_t Alignment = 1> static void writeU32uBE(void* p, uint32_t x) noexcept
static
void writeU32a(
void* p,
uint32_t x)
noexceptstatic
void writeU32aLE(
void* p,
uint32_t x)
noexceptstatic
void writeU32aBE(
void* p,
uint32_t x)
noexcepttemplate<ByteOrder BO = ByteOrder::kNative, size_t Alignment = 1> static void writeI32x(void* p, int32_t x) noexcept
template<size_t Alignment = 1> static void writeI32u(void* p, int32_t x) noexcept
template<size_t Alignment = 1> static void writeI32uLE(void* p, int32_t x) noexcept
template<size_t Alignment = 1> static void writeI32uBE(void* p, int32_t x) noexcept
static
void writeI32a(
void* p,
int32_t x)
noexceptstatic
void writeI32aLE(
void* p,
int32_t x)
noexceptstatic
void writeI32aBE(
void* p,
int32_t x)
noexcepttemplate<ByteOrder BO = ByteOrder::kNative, size_t Alignment = 1> static void writeU64x(void* p, uint64_t x) noexcept
template<size_t Alignment = 1> static void writeU64u(void* p, uint64_t x) noexcept
template<size_t Alignment = 1> static void writeU64uLE(void* p, uint64_t x) noexcept
template<size_t Alignment = 1> static void writeU64uBE(void* p, uint64_t x) noexcept
static
void writeU64a(
void* p,
uint64_t x)
noexceptstatic
void writeU64aLE(
void* p,
uint64_t x)
noexceptstatic
void writeU64aBE(
void* p,
uint64_t x)
noexcepttemplate<ByteOrder BO = ByteOrder::kNative, size_t Alignment = 1> static void writeI64x(void* p, int64_t x) noexcept
template<size_t Alignment = 1> static void writeI64u(void* p, int64_t x) noexcept
template<size_t Alignment = 1> static void writeI64uLE(void* p, int64_t x) noexcept
template<size_t Alignment = 1> static void writeI64uBE(void* p, int64_t x) noexcept
static
void writeI64a(
void* p,
int64_t x)
noexceptstatic
void writeI64aLE(
void* p,
int64_t x)
noexceptstatic
void writeI64aBE(
void* p,
int64_t x)
noexcepttemplate<typename T>
template<typename T>
template<typename T>
template<typename T>
static
void bitVectorFill(T* buf,
size_t index,
size_t count)
noexcepttemplate<typename T>
static
void bitVectorClear(T* buf,
size_t index,
size_t count)
noexceptstatic size_t bitVectorIndexOf(T* buf, size_t start, bool value) noexcept
template<typename T, typename CompareT = Compare<SortOrder::kAscending>>
static
void iSort(T* base,
size_t size,
const CompareT& cmp = CompareT())
noexcepttemplate<typename T, class CompareT = Compare<SortOrder::kAscending>>
static
void qSort(T* base,
size_t size,
const CompareT& cmp = CompareT())
noexcept
typedef Internal::StdInt<sizeof(uintptr_t), 1>::Type Support::BitWord◆
Storage used to store a pack of bits (should by compatible with a machine word).
Sort order.
Constant | Description |
---|
kAscending | Ascending order.
Descending order.
|
template<typename T>
Internal::Int32Or64<T, 0>::Type Support::asInt(const T& x)constexprstaticconstexprnoexcept◆
Casts an integer x
to either int32_t
or int64_t
depending on T
.
template<typename T>
Internal::Int32Or64<T, 1>::Type Support::asUInt(const T& x)constexprstaticconstexprnoexcept◆
Casts an integer x
to either uint32_t
or uint64_t
depending on T
.
template<typename T>
Internal::Int32Or64<T>::Type Support::asNormalized(const T& x)constexprstaticconstexprnoexcept◆
Casts an integer x
to either int32_t
, uint32_t,
int64_t, or
uint64_tdepending on
T`.
template<typename T>
Internal::StdInt<sizeof(T), isUnsigned<T> ()>::Type Support::asStdInt(const T& x)constexprstaticconstexprnoexcept◆
Casts an integer x
to the same type as defined by <stdint.h>
.
template<typename Dst, typename Src>
Dst Support::bitCast(const Src& x)staticnoexcept◆
Bit-casts from Src
type to Dst
type.
Useful to bit-cast between integers and floating points.
template<typename T>
T Support::neg(const T& x)constexprstaticconstexprnoexcept◆
Returns 0 - x
in a safe way (no undefined behavior), works for unsigned numbers as well.
template<typename X, typename Y>
X Support::shl(const X& x, const Y& y)constexprstaticconstexprnoexcept◆
Returns x << y
(shift left logical) by explicitly casting x
to an unsigned type and back.
template<typename X, typename Y>
X Support::shr(const X& x, const Y& y)constexprstaticconstexprnoexcept◆
Returns x >> y
(shift right logical) by explicitly casting x
to an unsigned type and back.
template<typename X, typename Y>
X Support::sar(const X& x, const Y& y)constexprstaticconstexprnoexcept◆
Returns x >> y
(shift right arithmetic) by explicitly casting x
to a signed type and back.
template<typename X, typename Y>
X Support::or_shr(const X& x, const Y& y)constexprstaticconstexprnoexcept◆
Returns x | (x >> y)
- helper used by some bit manipulation helpers.
template<typename T>
T Support::blsi(T x)constexprstaticconstexprnoexcept◆
Returns x & -x
- extracts lowest set isolated bit (like BLSI instruction).
template<typename T, typename IndexT>
bool Support::bitTest(T x, IndexT n)constexprstaticconstexprnoexcept◆
Tests whether the given value x
has n
th bit set.
template<typename T, typename CountT>
T Support::lsbMask(const CountT& n)constexprstaticconstexprnoexcept◆
Generates a trailing bit-mask that has n
least significant (trailing) bits set.
template<typename T, typename CountT>
T Support::msbMask(const CountT& n)constexprstaticconstexprnoexcept◆
Generates a leading bit-mask that has n
most significant (leading) bits set.
template<typename Index>
uint32_t Support::bitMask(const Index& x)constexprstaticconstexprnoexcept[1/2]◆
Returns a bit-mask that has x
bit set.
template<typename Index, typename... Args>
uint32_t Support::bitMask(const Index& x, Args... args)constexprstaticconstexprnoexcept[2/2]◆
Returns a bit-mask that has x
bit set (multiple arguments).
template<typename DstT, typename SrcT>
DstT Support::bitMaskFromBool(SrcT b)constexprstaticconstexprnoexcept◆
Converts a boolean value b
to zero or full mask (all bits set).
template<typename A, typename B>
bool Support::test(A a, B b)constexprstaticconstexprnoexcept◆
Tests whether a & b
is non-zero.
template<typename T>
uint32_t Support::clz(T x)staticnoexcept◆
Count leading zeros in x
(returns a position of a first bit set in x
).
- Note
- The input MUST NOT be zero, otherwise the result is undefined.
template<typename T>
uint32_t Support::ctz(T x)staticnoexcept◆
Count trailing zeros in x
(returns a position of a first bit set in x
).
- Note
- The input MUST NOT be zero, otherwise the result is undefined.
template<typename T>
uint32_t Support::popcnt(T x)staticnoexcept◆
Calculates count of bits in x
.
template<typename T>
uint32_t Support::constPopcnt(T x)staticnoexcept◆
Calculates count of bits in x
(useful in constant expressions).
template<typename T>
bool Support::isPowerOf2(T x)constexprstaticconstexprnoexcept◆
Tests whether the x
is a power of two (only one bit is set).
template<typename X, typename Y>
Internal::StdInt<sizeof(X), 1>::Type Support::alignUpDiff(X base, Y alignment)constexprstaticconstexprnoexcept◆
Returns either zero or a positive difference between base
and base
when aligned to alignment
.
template<typename X, typename Y>
X Support::numGranularized(X base, Y granularity)constexprstaticconstexprnoexcept◆
Calculates the number of elements that would be required if base
is granularized by granularity
.
This function can be used to calculate the number of BitWords to represent N bits, for example.
template<typename T>
bool Support::isBetween(const T& x, const T& a, const T& b)constexprstaticconstexprnoexcept◆
Checks whether x
is greater than or equal to a
and lesser than or equal to b
.
template<typename T>
bool Support::isInt4(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 4-bit signed integer.
template<typename T>
bool Support::isInt7(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 7-bit signed integer.
template<typename T>
bool Support::isInt8(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to an 8-bit signed integer.
template<typename T>
bool Support::isInt9(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 9-bit signed integer.
template<typename T>
bool Support::isInt10(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 10-bit signed integer.
template<typename T>
bool Support::isInt16(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 16-bit signed integer.
template<typename T>
bool Support::isInt32(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 32-bit signed integer.
template<typename T>
bool Support::isUInt4(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 4-bit unsigned integer.
template<typename T>
bool Support::isUInt8(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to an 8-bit unsigned integer.
template<typename T>
bool Support::isUInt12(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 12-bit unsigned integer (ARM specific).
template<typename T>
bool Support::isUInt16(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 16-bit unsigned integer.
template<typename T>
bool Support::isUInt32(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 32-bit unsigned integer.
template<typename T>
bool Support::isIntOrUInt32(T x)constexprstaticconstexprnoexcept◆
Checks whether the given integer x
can be casted to a 32-bit unsigned integer.
uint32_t Support::bytepack32_4x8(uint32_t a, uint32_t b, uint32_t c, uint32_t d)constexprstaticconstexprnoexcept◆
Pack four 8-bit integer into a 32-bit integer as it is an array of {b0,b1,b2,b3}
.
int Support::compareStringViews(const char* aData, size_t aSize, const char* bData, size_t bSize)staticnoexcept◆
Compares two string views.
template<typename T>
bool Support::bitVectorGetBit(T* buf, size_t index)staticnoexcept◆
Sets bit in a bit-vector buf
at index
.
template<typename T>
void Support::bitVectorSetBit(T* buf, size_t index, bool value)staticnoexcept◆
Sets bit in a bit-vector buf
at index
to value
.
template<typename T>
void Support::bitVectorFlipBit(T* buf, size_t index)staticnoexcept◆
Sets bit in a bit-vector buf
at index
to value
.
template<typename T>
void Support::bitVectorFill(T* buf, size_t index, size_t count)staticnoexcept◆
Fills count
bits in bit-vector buf
starting at bit-index index
.
template<typename T>
void Support::bitVectorClear(T* buf, size_t index, size_t count)staticnoexcept◆
Clears count
bits in bit-vector buf
starting at bit-index index
.
template<typename T, typename CompareT = Compare<SortOrder::kAscending>>
void Support::iSort(T* base, size_t size, const CompareT& cmp = CompareT()
)staticnoexcept◆
template<typename T, class CompareT = Compare<SortOrder::kAscending>>
void Support::qSort(T* base, size_t size, const CompareT& cmp = CompareT()
)staticnoexcept◆
Quick sort implementation.
The main reason to provide a custom qsort implementation is that we needed something that will never throw bad_alloc
exception. This implementation doesn't use dynamic memory allocation.
uint32_t Support::kBitWordSizeInBits = bitSizeOf<BitWord>()constexprstaticconstexpr◆
Number of bits stored in a single BitWord
.