Fix clang warnings for left-shift of signed int

This commit is contained in:
Ken Cooke 2017-10-10 09:13:06 -07:00
parent 4f19366349
commit b026a0461d
2 changed files with 36 additions and 30 deletions

View file

@ -135,6 +135,7 @@ static const int32_t exp2Table[1 << EXP2_TABBITS][3] = {
static const int IEEE754_FABS_MASK = 0x7fffffff; static const int IEEE754_FABS_MASK = 0x7fffffff;
static const int IEEE754_MANT_BITS = 23; static const int IEEE754_MANT_BITS = 23;
static const int IEEE754_EXPN_BITS = 8;
static const int IEEE754_EXPN_BIAS = 127; static const int IEEE754_EXPN_BIAS = 127;
// //
@ -152,7 +153,7 @@ static inline int32_t peaklog2(float* input) {
// split into e and x - 1.0 // split into e and x - 1.0
int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int32_t x = (peak << (31 - IEEE754_MANT_BITS)) & 0x7fffffff; int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff;
// saturate // saturate
if (e > 31) { if (e > 31) {
@ -191,7 +192,7 @@ static inline int32_t peaklog2(float* input0, float* input1) {
// split into e and x - 1.0 // split into e and x - 1.0
int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int32_t x = (peak << (31 - IEEE754_MANT_BITS)) & 0x7fffffff; int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff;
// saturate // saturate
if (e > 31) { if (e > 31) {
@ -234,7 +235,7 @@ static inline int32_t peaklog2(float* input0, float* input1, float* input2, floa
// split into e and x - 1.0 // split into e and x - 1.0
int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int32_t x = (peak << (31 - IEEE754_MANT_BITS)) & 0x7fffffff; int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff;
// saturate // saturate
if (e > 31) { if (e > 31) {
@ -259,30 +260,30 @@ static inline int32_t peaklog2(float* input0, float* input1, float* input2, floa
// Count Leading Zeros // Count Leading Zeros
// Emulates the CLZ (ARM) and LZCNT (x86) instruction // Emulates the CLZ (ARM) and LZCNT (x86) instruction
// //
static inline int CLZ(uint32_t x) { static inline int CLZ(uint32_t u) {
if (x == 0) { if (u == 0) {
return 32; return 32;
} }
int e = 0; int e = 0;
if (x < 0x00010000) { if (u < 0x00010000) {
x <<= 16; u <<= 16;
e += 16; e += 16;
} }
if (x < 0x01000000) { if (u < 0x01000000) {
x <<= 8; u <<= 8;
e += 8; e += 8;
} }
if (x < 0x10000000) { if (u < 0x10000000) {
x <<= 4; u <<= 4;
e += 4; e += 4;
} }
if (x < 0x40000000) { if (u < 0x40000000) {
x <<= 2; u <<= 2;
e += 2; e += 2;
} }
if (x < 0x80000000) { if (u < 0x80000000) {
e += 1; e += 1;
} }
return e; return e;
@ -290,19 +291,19 @@ static inline int CLZ(uint32_t x) {
// //
// Compute -log2(x) for x=[0,1] in Q31, result in Q26 // Compute -log2(x) for x=[0,1] in Q31, result in Q26
// x = 0 returns 0x7fffffff // x <= 0 returns 0x7fffffff
// x < 0 undefined
// //
static inline int32_t fixlog2(int32_t x) { static inline int32_t fixlog2(int32_t x) {
if (x == 0) { if (x <= 0) {
return 0x7fffffff; return 0x7fffffff;
} }
// split into e and x - 1.0 // split into e and x - 1.0
int e = CLZ((uint32_t)x); uint32_t u = (uint32_t)x;
x <<= e; // normalize to [0x80000000, 0xffffffff] int e = CLZ(u);
x &= 0x7fffffff; // x - 1.0 u <<= e; // normalize to [0x80000000, 0xffffffff]
x = u & 0x7fffffff; // x - 1.0
int k = x >> (31 - LOG2_TABBITS); int k = x >> (31 - LOG2_TABBITS);
@ -320,13 +321,18 @@ static inline int32_t fixlog2(int32_t x) {
// //
// Compute exp2(-x) for x=[0,32] in Q26, result in Q31 // Compute exp2(-x) for x=[0,32] in Q26, result in Q31
// x < 0 undefined // x <= 0 returns 0x7fffffff
// //
static inline int32_t fixexp2(int32_t x) { static inline int32_t fixexp2(int32_t x) {
if (x <= 0) {
return 0x7fffffff;
}
// split into e and 1.0 - x // split into e and 1.0 - x
int e = x >> LOG2_FRACBITS; uint32_t u = (uint32_t)x;
x = ~(x << LOG2_INTBITS) & 0x7fffffff; int e = u >> LOG2_FRACBITS;
x = ~(u << LOG2_INTBITS) & 0x7fffffff;
int k = x >> (31 - EXP2_TABBITS); int k = x >> (31 - EXP2_TABBITS);

View file

@ -40,7 +40,7 @@ class MonoDCBlock {
public: public:
void process(int32_t& x) { void process(int32_t& x) {
x <<= 15; // scale to Q30 x *= (1 << 15); // scale to Q30
x -= _dcOffset; // remove DC x -= _dcOffset; // remove DC
_dcOffset += x >> 13; // pole = (1.0 - 2^-13) = 0.9999 _dcOffset += x >> 13; // pole = (1.0 - 2^-13) = 0.9999
} }
@ -53,8 +53,8 @@ class StereoDCBlock {
public: public:
void process(int32_t& x0, int32_t& x1) { void process(int32_t& x0, int32_t& x1) {
x0 <<= 15; x0 *= (1 << 15);
x1 <<= 15; x1 *= (1 << 15);
x0 -= _dcOffset[0]; x0 -= _dcOffset[0];
x1 -= _dcOffset[1]; x1 -= _dcOffset[1];
@ -71,10 +71,10 @@ class QuadDCBlock {
public: public:
void process(int32_t& x0, int32_t& x1, int32_t& x2, int32_t& x3) { void process(int32_t& x0, int32_t& x1, int32_t& x2, int32_t& x3) {
x0 <<= 15; x0 *= (1 << 15);
x1 <<= 15; x1 *= (1 << 15);
x2 <<= 15; x2 *= (1 << 15);
x3 <<= 15; x3 *= (1 << 15);
x0 -= _dcOffset[0]; x0 -= _dcOffset[0];
x1 -= _dcOffset[1]; x1 -= _dcOffset[1];