Commit a5ab348f authored by Tristan Matthews's avatar Tristan Matthews

fixed: make left shift macros use unsigned to avoid undefined behaviour

Backported from opus commit 1ee139bca076a1a3606a8a924a698d356d40cbb8
parent 6916e56d
......@@ -122,7 +122,7 @@ static inline short _SHL16(int a, int shift, char *file, int line)
{
fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line);
}
res = a<<shift;
res = (int)((unsigned)a<<shift);
if (!VERIFY_SHORT(res))
fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, file, line);
spx_mips++;
......@@ -151,7 +151,7 @@ static inline int SHL32(long long a, int shift)
{
fprintf (stderr, "SHL32: inputs are not int: %d %d\n", (int)a, shift);
}
res = a<<shift;
res = (long long)((unsigned long long)a<<shift);
if (!VERIFY_INT(res))
{
fprintf (stderr, "SHL32: output is not int: %d\n", (int)res);
......
......@@ -43,9 +43,9 @@
#define EXTRACT16(x) ((spx_word16_t)(x))
#define EXTEND32(x) ((spx_word32_t)(x))
#define SHR16(a,shift) ((a) >> (shift))
#define SHL16(a,shift) ((a) << (shift))
#define SHL16(a,shift) ((spx_int16_t)((spx_uint16_t)(a) << (shift)))
#define SHR32(a,shift) ((a) >> (shift))
#define SHL32(a,shift) ((a) << (shift))
#define SHL32(a,shift) ((spx_int32_t)((spx_uint32_t)(a) << (shift)))
#define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift))
#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift))
#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
......@@ -53,7 +53,7 @@
#define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
#define SHR(a,shift) ((a) >> (shift))
#define SHL(a,shift) ((spx_word32_t)(a) << (shift))
#define SHL(a,shift) ((spx_int32_t)((spx_uint32_t)(a) << (shift)))
#define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift))
#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment