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) \).

N is 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 b and exponent b_exp, into a 32-bit floating-point scalar, represented by the 32-bit returned mantissa and output exponent a_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_t representation of x

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_t with a specified exponent.

Returns the int32_t value \(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 shr is given, returns x right-shifted by shr bits, filling the most significant bits with the sign bit. If shr is larger than 63, returns 0 for non-negative x or -1 for negative x.

When a negative shr is given, returns x left-shifted by |shr| bits, saturating to INT64_MAX or INT64_MIN if the result overflows.

Parameters:
  • x[in] Input value

  • shr[in] Right shift to apply to the input

Returns:

int64_t Shifted result