9#ifndef SGL_FIXED_POINT_GENERIC_H_
10#define SGL_FIXED_POINT_GENERIC_H_
26#define SGL_Q11_FRAC_BITS (11U)
28#define SGL_Q11_ONE (2048)
30#define SGL_Q11_HALF (1024)
32#define SGL_Q11_MASK (2047U)
34#define SGL_Q16_FRAC_BITS (16U)
36#define SGL_Q16_ONE (65536)
38#define SGL_Q16_HALF (32768)
40#define SGL_Q16_MASK (65535U)
42#define SGL_FIXED_I64_BITS (64U)
44#define SGL_FIXED_INT32_MAX (2147483647)
46#define SGL_FIXED_INT32_MIN (-2147483647 - 1)
48#define SGL_FIXED_INT16_MAX (32767)
50#define SGL_FIXED_INT16_MIN (-32767 - 1)
120 shifted = magnitude >> shift;
125 shifted = magnitude >> shift;
153 shifted = magnitude >> shift;
158 shifted = magnitude >> shift;
162 else if (value < 0) {
369 if ((val & ~0xFF) != 0) {
#define SGL_ALWAYS_INLINE
Requests compiler-enforced inlining.
static sgl_uint8_t sgl_clamp_u8_i32(sgl_int32_t val)
Saturates a signed 32-bit channel value to 0 through 255.
static sgl_int16_t sgl_fixed_clamp_i32_to_i16(sgl_int32_t value)
Saturates a signed 32-bit value to the signed 16-bit range.
static sgl_int64_t sgl_fixed_floor_pow2_i64(sgl_int64_t value, sgl_uint32_t shift)
Divides by a power of two while rounding toward negative infinity.
#define SGL_Q16_ONE
Q16 representation of 1.0 (1 << 16).
static sgl_q11_t sgl_q11_mul(sgl_q11_t a, sgl_q11_t b)
Multiplies two Q11 values with rounding and saturation.
static sgl_q11_ext_t sgl_int_to_q11(sgl_q11_ext_t value)
Converts an integer to extended Q11 with saturation.
#define SGL_FIXED_INT16_MIN
Minimum signed 16-bit value without standard-library constants.
static sgl_q11_ext_t sgl_q11_get_int_part(sgl_q11_ext_t value)
Extracts the integer part of an extended Q11 value.
sgl_int64_t sgl_q16_ext_t
Extended signed Q16 value stored in 64 bits.
#define SGL_Q11_FRAC_BITS
Number of fractional bits in a Q11 value.
static sgl_q11_ext_t sgl_q11_round_up(sgl_q11_ext_t value)
Adds the Q11 half-unit used before rounded conversion.
static sgl_int32_t sgl_q16_round_to_int32(sgl_q16_ext_t value)
Rounds an extended Q16 value to the nearest signed 32-bit integer.
#define SGL_FIXED_INT32_MAX
Maximum signed 32-bit value without standard-library constants.
#define SGL_Q16_HALF
Q16 representation of 0.5.
#define SGL_Q11_ONE
Q11 representation of 1.0 (1 << 11).
#define SGL_Q11_HALF
Q11 representation of 0.5.
#define SGL_Q11_MASK
Mask selecting all eleven Q11 fractional bits.
sgl_int32_t sgl_q11_ext_t
Extended signed Q11 value stored in 32 bits.
#define SGL_FIXED_INT32_MIN
Minimum signed 32-bit value without standard-library constants.
#define SGL_Q16_FRAC_BITS
Number of fractional bits in a Q16 value.
static sgl_q11_ext_t sgl_q11_ext_mul(sgl_q11_ext_t a, sgl_q11_ext_t b)
Multiplies two extended Q11 values with rounding and saturation.
static sgl_int64_t sgl_fixed_div_pow2_i64(sgl_int64_t value, sgl_uint32_t shift)
Divides by a power of two with C99 signed-division semantics.
static sgl_q11_ext_t sgl_q11_shift_down(sgl_q11_ext_t value)
Removes Q11 fractional bits while rounding toward negative infinity.
static sgl_int32_t sgl_fixed_clamp_i64_to_i32(sgl_int64_t value)
Saturates a signed 64-bit value to the signed 32-bit range.
static sgl_q16_ext_t sgl_int_to_q16(sgl_int32_t value)
Converts a signed 32-bit integer to extended Q16.
#define SGL_FIXED_I64_BITS
Bit width used by the portable signed-division helpers.
sgl_int32_t sgl_q16_t
Signed Q16 value stored in 32 bits.
#define SGL_FIXED_INT16_MAX
Maximum signed 16-bit value without standard-library constants.
sgl_int16_t sgl_q11_t
Signed Q11 value stored in 16 bits.
static sgl_q11_ext_t sgl_q11_get_frac_part(sgl_q11_ext_t value)
Extracts the signed fractional part of an extended Q11 value.
signed short sgl_int16_t
Signed integer with exactly 16 value bits.
unsigned long long sgl_uint64_t
Unsigned integer with exactly 64 value bits.
signed long long sgl_int64_t
Signed integer with exactly 64 value bits.
signed int sgl_int32_t
Signed integer with exactly 32 value bits.
unsigned int sgl_uint32_t
Unsigned integer with exactly 32 value bits.
unsigned char sgl_uint8_t
Unsigned integer with exactly 8 value bits.