Bit Intrinsicsο
Bit intrinsics are functions that map as closely as possible to behavior and functionality in ISAs without needing to deal with the undefined behavior and nonportability of said architectures. It provides vital functionality that can greatly speed up work on specific kinds of bit operations. The provided intrinsics here are a large subset of the most efficient operations, offered in various flavors for easeofuse.
βLeadingβ refers to the most significant bit in a given value. This is the βleft sideβ of an integer when writing source code, such that 0b10
has a most significant bit of 1
. βTrailingβ refers to the least significant bit in a given value. This is the βleft sideβ of an integer when writing source code, such that 0b10
has a least significant bit of 0
.

ztdc_count_ones(...)ο
Counts the number of ones in a given unsigned integer.
 Parameters
... β [in] The input value.
 Returns
An
int
(or suitably large signed integer type) with the count.

ztdc_count_zeros(...)ο
Counts the number of zeros in a given unsigned integer.
 Parameters
... β [in] The input value.
 Returns
An
int
(or suitably large signed integer type) with the count.

ztdc_count_leading_zeros(...)ο
Counts the number of leading zeros in a given unsigned integer.
 Parameters
... β [in] The input value.
 Returns
An
int
(or suitably large signed integer type) with the count.

ztdc_count_trailing_zeros(...)ο
Counts the number of trailing zeros in a given unsigned integer.
 Parameters
... β [in] The input value.
 Returns
An
int
(or suitably large signed integer type) with the count.

ztdc_count_leading_ones(...)ο
Counts the number of leading ones in a given unsigned integer.
 Parameters
... β [in] The input value.
 Returns
An
int
(or suitably large signed integer type) with the count.

ztdc_count_trailing_ones(...)ο
Counts the number of trailing ones in a given unsigned integer.
 Parameters
... β [in] The input value.
 Returns
An
int
(or suitably large signed integer type) with the count.

ztdc_first_leading_zero(...)ο
Finds the first trailing zero in a given unsigned integer value.
 Parameters
... β [in] The input value.
 Returns
If the bit is not found, returns
0
. Otherwise, returns anint
(or suitably large enough signed integer) indicating the index of the found bit, plus one.

ztdc_first_trailing_zero(...)ο
Finds the first trailing zero in a given unsigned integer value.
 Parameters
... β [in] The input value.
 Returns
If the bit is not found, returns
0
. Otherwise, returns anint
(or suitably large enough signed integer) indicating the index of the found bit, plus one.

ztdc_first_leading_one(...)ο
Finds the first leading one in a given unsigned integer value.
 Parameters
... β [in] The input value.
 Returns
If the bit is not found, returns
0
. Otherwise, returns anint
(or suitably large enough signed integer) indicating the index of the found bit, plus one.

ztdc_first_trailing_one(...)ο
Finds the first trailing one in a given unsigned integer value.
 Parameters
... β [in] The input value.
 Returns
If the bit is not found, returns
0
. Otherwise, returns anint
(or suitably large enough signed integer) indicating the index of the found bit, plus one.

ztdc_rotate_left(_VALUE, ...)ο
Performs a cyclical shift left.
Remark
If the rotation value is negative, calls ztdc_rotate_right with the negated modulus of the rotation.
 Parameters
_VALUE β [in] The value to perform the cyclical shift left.
... β [in] The rotation value.

ztdc_rotate_right(_VALUE, ...)ο
Performs a cyclical shift right.
Remark
If the rotation value is negative, calls ztdc_rotate_right with the negated modulus of the rotation.
 Parameters
_VALUE β [in] The value to perform the cyclical shift right.
... β [in] The rotation value.

ztdc_has_single_bit(...)ο
Returns whether or not there is a single bit set in this unsigned integer value (this making it a power of 2).
 Parameters
... β [in] The input value.

ztdc_bit_width(...)ο
Returns the number of bits needed to represent the value exactly.
 Parameters
... β [in] The input value.

ztdc_bit_ceil(...)ο
Returns the value that is the greatest power of 2 that is less than the input value.
 Parameters
... β [in] The input value.
 Returns
0
when the input value is0
. Otherwise, produces the greatest power of 2 that is less than the input value.

ztdc_bit_floor(...)ο
Returns the value that is the next power of 2.
 Parameters
... β [in] The input value.
 Returns
1
when the input value is less than or equal to1
. Otherwise, produces the power of 2 that is higher than the input value.