Problem with `SATURATE` and `SROUND16 ` macros?
Please have a look at below macros from celt/fixed_generic.h:
#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
#define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x)))
/** Shift by a and round-to-neareast 32-bit value. Result is a saturated 16-bit value */
#define SROUND16(x,a) EXTRACT16(SATURATE(PSHR32(x,a), 32767));
As one can see clearly that macros SATURATE
and SATURATE16
are not similar when SATURATE
is used for value 32767 or 32768.
Shouldn't the macro SATURATE be like:
#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a + 1) ? -(a + 1) : (x)))
or is it good as it is?
The macro SROUND16
uses SATURATE
with value 32767.
Shouldn't it use SATURATE16 instead as it considers lower bound for 16 bits; -32768 as well?
Please note that this will in turn also enable some platform optimised instructions which saturate the value in certain bits.