Add intrinsics saturation feature

This commit is contained in:
Antoine SOULIER
2022-05-04 13:58:30 +02:00
parent 40849c3fa9
commit 29421b2259
2 changed files with 17 additions and 5 deletions

View File

@@ -29,11 +29,16 @@
#include <limits.h>
#include <string.h>
#ifdef __ARM_ARCH
#include <arm_acle.h>
#endif
/**
* Macros
* MIN/MAX Minimum and maximum between 2 values
* CLIP Clip a value between low and high limits
* SATXX Saturation on 'xx' bits
* ABS Return the absolute value
*/
@@ -41,9 +46,18 @@
#define LC3_MAX(a, b) ( (a) > (b) ? (a) : (b) )
#define LC3_CLIP(v, min, max) LC3_MIN(LC3_MAX(v, min), max)
#ifdef __ARM_FEATURE_SAT
#define LC3_SAT16(v) __ssat(v, 16)
#define LC3_SAT24(v) __ssat(v, 24)
#else
#define LC3_SAT16(v) LC3_CLIP(v, -(1 << 15), (1 << 15) - 1)
#define LC3_SAT24(v) LC3_CLIP(v, -(1 << 23), (1 << 23) - 1)
#endif
#define LC3_ABS(n) ( (n) < 0 ? -(n) : (n) )
/**
* Convert `dt` in us and `sr` in KHz
*/