Audio Format: Improve sat_int24 function

- Added detailed function documentation.
- Changed from AE_SRAI32(AE_SLAI32S(x, 8), 8) to AE_SAT24S for
  more accurate 24-bit saturation.
- Used ae_f32x2 type to ensure correct input handling.
- No performance degradation observed.

This check-in enhances the sat_int24 function by improving its logic
and documentation to ensure more accurate 32-bit to 24-bit conversion.

Signed-off-by: Shriram Shastry <malladi.sastry@intel.com>
This commit is contained in:
Shriram Shastry 2024-08-04 22:40:47 +05:30 committed by Liam Girdwood
parent c5e73a8402
commit 94412f8116
1 changed files with 15 additions and 1 deletions

View File

@ -53,9 +53,23 @@ static inline ae_int32x2 vec_sat_int32x2(int64_t x, int64_t y)
/* Round and saturate both 64-bit values to 32-bit and pack them */ /* Round and saturate both 64-bit values to 32-bit and pack them */
return (ae_int32x2)AE_ROUND32X2F64SSYM(d0, d1); return (ae_int32x2)AE_ROUND32X2F64SSYM(d0, d1);
} }
/**
* @brief Saturate and round a 32-bit integer to 24-bit.
*
* @param x 32-bit integer.
* @return 24-bit saturated integer.
*
* This function takes a 32-bit integer and saturates it to a 24-bit integer
* using saturating arithmetic instructions.
*/
static inline int32_t sat_int24(int32_t x) static inline int32_t sat_int24(int32_t x)
{ {
return AE_SRAI32(AE_SLAI32S(x, 8), 8); /* Move 32-bit value to ae_f32x2 type */
ae_f32x2 d0 = AE_MOVDA32(x);
/* Saturate to 24-bit */
return (ae_int32)AE_SAT24S(d0);
} }
static inline int16_t sat_int16(int32_t x) static inline int16_t sat_int16(int32_t x)