Fix up various mixed unsigned/signed comparisons.

This silences MSVC warning C4018 and fixes a bug with the intra
decision and improves portability to 16 bit platforms.
This commit is contained in:
Gregory Maxwell 2011-08-30 18:35:06 -04:00 committed by Jean-Marc Valin
parent 927488b292
commit 17a29c2567
8 changed files with 19 additions and 26 deletions

View file

@ -45,13 +45,6 @@
# endif # endif
# endif # endif
# if defined(_MSC_VER)
# pragma warning(disable:4554)
# endif
# if __GNUC_PREREQ(4,2)
# pragma GCC diagnostic ignored "-Wparentheses"
# endif
#define CELT_SIG_SCALE 32768.f #define CELT_SIG_SCALE 32768.f
#define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);

View file

@ -150,7 +150,7 @@ unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){
unsigned s; unsigned s;
_this->ext=_this->rng>>_bits; _this->ext=_this->rng>>_bits;
s=(unsigned)(_this->val/_this->ext); s=(unsigned)(_this->val/_this->ext);
return (1<<_bits)-EC_MINI(s+1,1<<_bits); return (1U<<_bits)-EC_MINI(s+1U,1U<<_bits);
} }
void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){ void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
@ -231,14 +231,14 @@ opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){
opus_uint32 ret; opus_uint32 ret;
window=_this->end_window; window=_this->end_window;
available=_this->nend_bits; available=_this->nend_bits;
if(available<_bits){ if((unsigned)available<_bits){
do{ do{
window|=(ec_window)ec_read_byte_from_end(_this)<<available; window|=(ec_window)ec_read_byte_from_end(_this)<<available;
available+=EC_SYM_BITS; available+=EC_SYM_BITS;
} }
while(available<=EC_WINDOW_SIZE-EC_SYM_BITS); while(available<=EC_WINDOW_SIZE-EC_SYM_BITS);
} }
ret=(opus_uint32)window&((opus_uint32)1<<_bits)-1; ret=(opus_uint32)window&((opus_uint32)1<<_bits)-1U;
window>>=_bits; window>>=_bits;
available-=_bits; available-=_bits;
_this->end_window=window; _this->end_window=window;

View file

@ -140,10 +140,10 @@ void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){
opus_uint32 r; opus_uint32 r;
r=_this->rng>>_bits; r=_this->rng>>_bits;
if(_fl>0){ if(_fl>0){
_this->val+=_this->rng-IMUL32(r,((1<<_bits)-_fl)); _this->val+=_this->rng-IMUL32(r,((1U<<_bits)-_fl));
_this->rng=IMUL32(r,(_fh-_fl)); _this->rng=IMUL32(r,(_fh-_fl));
} }
else _this->rng-=IMUL32(r,((1<<_bits)-_fh)); else _this->rng-=IMUL32(r,((1U<<_bits)-_fh));
ec_enc_normalize(_this); ec_enc_normalize(_this);
} }

View file

@ -262,12 +262,12 @@ static void ki_bfly3(
kiss_fft_cpx * Fout, kiss_fft_cpx * Fout,
const size_t fstride, const size_t fstride,
const kiss_fft_state *st, const kiss_fft_state *st,
size_t m, int m,
int N, int N,
int mm int mm
) )
{ {
size_t i, k; int i, k;
const size_t m2 = 2*m; const size_t m2 = 2*m;
const kiss_twiddle_cpx *tw1,*tw2; const kiss_twiddle_cpx *tw1,*tw2;
kiss_fft_cpx scratch[5]; kiss_fft_cpx scratch[5];

View file

@ -40,14 +40,14 @@
direction). */ direction). */
#define LAPLACE_NMIN (16) #define LAPLACE_NMIN (16)
static int ec_laplace_get_freq1(int fs0, int decay) static unsigned ec_laplace_get_freq1(unsigned fs0, int decay)
{ {
opus_int32 ft; unsigned ft;
ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN) - fs0; ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN) - fs0;
return ft*(16384-decay)>>15; return ft*(16384-decay)>>15;
} }
void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay) void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay)
{ {
unsigned fl; unsigned fl;
int val = *value; int val = *value;
@ -57,7 +57,7 @@ void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay)
int s; int s;
int i; int i;
s = -(val<0); s = -(val<0);
val = val+s^s; val = (val+s)^s;
fl = fs; fl = fs;
fs = ec_laplace_get_freq1(fs, decay); fs = ec_laplace_get_freq1(fs, decay);
/* Search the decaying part of the PDF.*/ /* Search the decaying part of the PDF.*/
@ -77,7 +77,7 @@ void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay)
di = IMIN(val - i, ndi_max - 1); di = IMIN(val - i, ndi_max - 1);
fl += (2*di+1+s)*LAPLACE_MINP; fl += (2*di+1+s)*LAPLACE_MINP;
fs = IMIN(LAPLACE_MINP, 32768-fl); fs = IMIN(LAPLACE_MINP, 32768-fl);
*value = i+di+s^s; *value = (i+di+s)^s;
} }
else else
{ {
@ -90,11 +90,11 @@ void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay)
ec_encode_bin(enc, fl, fl+fs, 15); ec_encode_bin(enc, fl, fl+fs, 15);
} }
int ec_laplace_decode(ec_dec *dec, int fs, int decay) int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay)
{ {
int val=0; int val=0;
unsigned fl; unsigned fl;
int fm; unsigned fm;
fm = ec_decode_bin(dec, 15); fm = ec_decode_bin(dec, 15);
fl = 0; fl = 0;
if (fm >= fs) if (fm >= fs)

View file

@ -36,7 +36,7 @@
@param fs Probability of 0, multiplied by 32768 @param fs Probability of 0, multiplied by 32768
@param decay Probability of the value +/- 1, multiplied by 16384 @param decay Probability of the value +/- 1, multiplied by 16384
*/ */
void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay); void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay);
/** Decode a value that is assumed to be the realisation of a /** Decode a value that is assumed to be the realisation of a
Laplace-distributed random process Laplace-distributed random process
@ -45,4 +45,4 @@ void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay);
@param decay Probability of the value +/- 1, multiplied by 16384 @param decay Probability of the value +/- 1, multiplied by 16384
@return Value decoded @return Value decoded
*/ */
int ec_laplace_decode(ec_dec *dec, int fs, int decay); int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay);

View file

@ -148,7 +148,7 @@ static inline opus_val16 celt_log2(opus_val32 x)
opus_val16 n, frac; opus_val16 n, frac;
/* -0.41509302963303146, 0.9609890551383969, -0.31836011537636605, /* -0.41509302963303146, 0.9609890551383969, -0.31836011537636605,
0.15530808010959576, -0.08556153059057618 */ 0.15530808010959576, -0.08556153059057618 */
static const opus_val16 C[5] = {-6801+(1<<13-DB_SHIFT), 15746, -5217, 2545, -1401}; static const opus_val16 C[5] = {-6801+(1<<(13-DB_SHIFT)), 15746, -5217, 2545, -1401};
if (x==0) if (x==0)
return -32767; return -32767;
i = celt_ilog2(x); i = celt_ilog2(x);

View file

@ -306,7 +306,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
if (!intra) if (!intra)
{ {
ec_enc enc_intra_state; ec_enc enc_intra_state;
int tell_intra; opus_int32 tell_intra;
opus_uint32 nstart_bytes; opus_uint32 nstart_bytes;
opus_uint32 nintra_bytes; opus_uint32 nintra_bytes;
int badness2; int badness2;
@ -329,7 +329,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget, badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget,
tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay); tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay);
if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ec_tell_frac(enc)+intra_bias > tell_intra))) if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ((opus_int32)ec_tell_frac(enc))+intra_bias > tell_intra)))
{ {
*enc = enc_intra_state; *enc = enc_intra_state;
/* Copy intra bits to bit-stream */ /* Copy intra bits to bit-stream */