Skip to content
Snippets Groups Projects
Commit 1ee139bc authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Making the left shift macros use unsigned to avoid undefined behaviour

Result should be bit-identical on most machines/compilers, minus the undefined
behaviour
parent 44ce46dc
No related branches found
No related tags found
No related merge requests found
......@@ -64,11 +64,11 @@
/** Arithmetic shift-right of a 16-bit value */
#define SHR16(a,shift) ((a) >> (shift))
/** Arithmetic shift-left of a 16-bit value */
#define SHL16(a,shift) ((a) << (shift))
#define SHL16(a,shift) ((opus_int16)((opus_uint16)(a)<<(shift)))
/** Arithmetic shift-right of a 32-bit value */
#define SHR32(a,shift) ((a) >> (shift))
/** Arithmetic shift-left of a 32-bit value */
#define SHL32(a,shift) ((opus_val32)(a) << (shift))
#define SHL32(a,shift) ((opus_int32)((opus_uint32)(a)<<(shift)))
/** 32-bit arithmetic shift right with rounding-to-nearest instead of rounding down */
#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift))
......@@ -77,7 +77,7 @@
/** "RAW" macros, should not be used outside of this header file */
#define SHR(a,shift) ((a) >> (shift))
#define SHL(a,shift) ((opus_val32)(a) << (shift))
#define SHL(a,shift) SHL32(a,shift)
#define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift))
#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
......
......@@ -439,7 +439,7 @@ static inline void silk_noise_shape_quantizer_del_dec(
/* Flip sign depending on dither */
r_Q10 = r_Q10 ^ dither;
r_Q10 = silk_LIMIT_32( r_Q10, -31 << 10, 30 << 10 );
r_Q10 = silk_LIMIT_32( r_Q10, -(31 << 10), 30 << 10 );
/* Find two quantization level candidates and measure their rate-distortion */
q1_Q10 = silk_SUB32( r_Q10, offset_Q10 );
......
......@@ -494,10 +494,10 @@ static inline opus_int32 silk_ROR32( opus_int32 a32, opus_int rot )
#define silk_ADD_POS_SAT32(a, b) ((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)))
#define silk_ADD_POS_SAT64(a, b) ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b)))
#define silk_LSHIFT8(a, shift) ((a)<<(shift)) /* shift >= 0, shift < 8 */
#define silk_LSHIFT16(a, shift) ((a)<<(shift)) /* shift >= 0, shift < 16 */
#define silk_LSHIFT32(a, shift) ((a)<<(shift)) /* shift >= 0, shift < 32 */
#define silk_LSHIFT64(a, shift) ((a)<<(shift)) /* shift >= 0, shift < 64 */
#define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift))) /* shift >= 0, shift < 8 */
#define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shift))) /* shift >= 0, shift < 16 */
#define silk_LSHIFT32(a, shift) ((opus_int32)((opus_uint32)(a)<<(shift))) /* shift >= 0, shift < 32 */
#define silk_LSHIFT64(a, shift) ((opus_int64)((opus_uint64)(a)<<(shift))) /* shift >= 0, shift < 64 */
#define silk_LSHIFT(a, shift) silk_LSHIFT32(a, shift) /* shift >= 0, shift < 32 */
#define silk_RSHIFT8(a, shift) ((a)>>(shift)) /* shift >= 0, shift < 8 */
......@@ -512,7 +512,6 @@ static inline opus_int32 silk_ROR32( opus_int32 a32, opus_int rot )
#define silk_LSHIFT_SAT32(a, shift) (silk_LSHIFT32( silk_LIMIT( (a), silk_RSHIFT32( silk_int32_MIN, (shift) ), \
silk_RSHIFT32( silk_int32_MAX, (shift) ) ), (shift) ))
#define silk_LSHIFT_ovflw(a, shift) ((a)<<(shift)) /* shift >= 0, allowed to overflow */
#define silk_LSHIFT_uint(a, shift) ((a)<<(shift)) /* shift >= 0 */
#define silk_RSHIFT_uint(a, shift) ((a)>>(shift)) /* shift >= 0 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment