Miscellaneous scalar API¶
- group Miscellaneous Scalar API
Functions
-
static inline unsigned u32_ceil_log2(unsigned N)¶
Get the size of a 32-bit unsigned number.
This function reports the size of the number as \(a\), the number of bits required to store unsigned integer \(N\). This is equivalent to \( ceil\left(log_2\left(N\right)\right) \).
Nis the input \(N\).- Operation Performed
- \[\begin{split}\begin{aligned} a \leftarrow \begin{cases} 0 & N = 0 \\ \lceil log_2\left( N \right) \rceil & otherwise \end{cases} \end{aligned}\end{split}\]
- Parameters:
N – [in] Number to get the size of
- Returns:
Number of bits \(a\) required to store \(N\)
- static inline int32_t s64_to_s32(
- exponent_t *a_exp,
- const int64_t b,
- const exponent_t b_exp,
Convert a 64-bit floating-point scalar to a 32-bit floating-point scalar.
Converts a 64-bit floating-point scalar, represented by the 64-bit mantissa
band exponentb_exp, into a 32-bit floating-point scalar, represented by the 32-bit returned mantissa and output exponenta_exp.- Parameters:
a_exp – [out] Output exponent
b – [in] 64-bit input mantissa
b_exp – [in] Input exponent
- Returns:
32-bit output mantissa
-
static inline float_s32_t float_s64_to_float_s32(const float_s64_t x)¶
Convert a float_s64_t to a float_s32_t.
Note
This operation may result in precision loss.
- Parameters:
x – [in] Input value
- Returns:
float_s32_trepresentation ofx
- static inline int32_t float_s64_to_s32(
- const float_s64_t x,
- const exponent_t out_exp,
Convert a float_s64_t to a fixed-point
int32_twith a specified exponent.Returns the
int32_tvalue \(a\) such that \(a \cdot 2^{out\_exp} \approx x\).This is equivalent to converting \(x\) to float_s32_t via float_s64_to_float_s32() and then calling float_s32_to_s32().
Note
This operation may result in precision loss due to the 64-to-32-bit mantissa conversion.
- Parameters:
x – [in] Input value \(x\)
out_exp – [in] Exponent of the output fixed-point representation
- Returns:
Fixed-point integer \(a\) such that \(a \cdot 2^{out\_exp} \approx x\)
-
int64_t s64_ashr(const int64_t x, const right_shift_t shr)¶
Arithmetic shift right of a 64-bit integer.
When a positive
shris given, returnsxright-shifted byshrbits, filling the most significant bits with the sign bit. Ifshris larger than 63, returns 0 for non-negativexor -1 for negativex.When a negative
shris given, returnsxleft-shifted by|shr|bits, saturating toINT64_MAXorINT64_MINif the result overflows.- Parameters:
x – [in] Input value
shr – [in] Right shift to apply to the input
- Returns:
int64_t Shifted result
-
static inline unsigned u32_ceil_log2(unsigned N)¶