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

No longer trying to save bits when encoding integers near the upper limit

(and fix for celt_div with 16-bit numerator on a 16-bit CPU)
parent 22823834
No related branches found
No related tags found
No related merge requests found
......@@ -111,7 +111,6 @@ ec_uint64 ec_dec_bits64(ec_dec *_this,int _ftb){
}
ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
ec_uint32 mask;
ec_uint32 t;
unsigned ft;
unsigned s;
......@@ -119,25 +118,23 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
t=0;
_ft--;
ftb=EC_ILOG(_ft);
while(ftb>EC_UNIT_BITS){
if(ftb>EC_UNIT_BITS){
ftb-=EC_UNIT_BITS;
ft=(unsigned)(_ft>>ftb)+1;
s=ec_decode(_this,ft);
ec_dec_update(_this,s,s+1,ft);
t=t<<EC_UNIT_BITS|s;
if(s<ft-1)return t<<ftb|ec_dec_bits(_this,ftb);
mask=((ec_uint32)1<<ftb)-1;
_ft=_ft&mask;
return t<<ftb|ec_dec_bits(_this,ftb);
} else {
_ft++;
s=ec_decode(_this,(unsigned)_ft);
ec_dec_update(_this,s,s+1,(unsigned)_ft);
t=t<<ftb|s;
return t;
}
_ft++;
s=ec_decode(_this,(unsigned)_ft);
ec_dec_update(_this,s,s+1,(unsigned)_ft);
t=t<<ftb|s;
return t;
}
ec_uint64 ec_dec_uint64(ec_dec *_this,ec_uint64 _ft){
ec_uint64 mask;
ec_uint64 t;
unsigned ft;
unsigned s;
......@@ -145,19 +142,18 @@ ec_uint64 ec_dec_uint64(ec_dec *_this,ec_uint64 _ft){
t=0;
_ft--;
ftb=EC_ILOG64(_ft);
while(ftb>EC_UNIT_BITS){
if(ftb>EC_UNIT_BITS){
ftb-=EC_UNIT_BITS;
ft=(unsigned)(_ft>>ftb)+1;
s=ec_decode(_this,ft);
ec_dec_update(_this,s,s+1,ft);
t=t<<EC_UNIT_BITS|s;
if(s<ft-1)return t<<ftb|ec_dec_bits64(_this,ftb);
mask=((ec_uint64)1<<ftb)-1;
_ft=_ft&mask;
return t<<ftb|ec_dec_bits64(_this,ftb);
} else {
_ft++;
s=ec_decode(_this,(unsigned)_ft);
ec_dec_update(_this,s,s+1,(unsigned)_ft);
t=t<<ftb|s;
return t;
}
_ft++;
s=ec_decode(_this,(unsigned)_ft);
ec_dec_update(_this,s,s+1,(unsigned)_ft);
t=t<<ftb|s;
return t;
}
......@@ -87,47 +87,35 @@ void ec_enc_bits64(ec_enc *_this,ec_uint64 _fl,int _ftb){
}
void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
ec_uint32 mask;
unsigned ft;
unsigned fl;
int ftb;
_ft--;
ftb=EC_ILOG(_ft)&-!!_ft;
while(ftb>EC_UNIT_BITS){
if(ftb>EC_UNIT_BITS){
ftb-=EC_UNIT_BITS;
ft=(_ft>>ftb)+1;
fl=(unsigned)(_fl>>ftb);
ec_encode(_this,fl,fl+1,ft);
if(fl<ft-1){
ec_enc_bits(_this,_fl,ftb);
return;
}
mask=((ec_uint32)1<<ftb)-1;
_fl=_fl&mask;
_ft=_ft&mask;
ec_enc_bits(_this,_fl,ftb);
} else {
ec_encode(_this,_fl,_fl+1,_ft+1);
}
ec_encode(_this,_fl,_fl+1,_ft+1);
}
void ec_enc_uint64(ec_enc *_this,ec_uint64 _fl,ec_uint64 _ft){
ec_uint64 mask;
unsigned ft;
unsigned fl;
int ftb;
_ft--;
ftb=EC_ILOG64(_ft)&-!!_ft;
while(ftb>EC_UNIT_BITS){
if(ftb>EC_UNIT_BITS){
ftb-=EC_UNIT_BITS;
ft=(unsigned)(_ft>>ftb)+1;
fl=(unsigned)(_fl>>ftb);
ec_encode(_this,fl,fl+1,ft);
if(fl<ft-1){
ec_enc_bits64(_this,_fl,ftb);
return;
}
mask=((ec_uint64)1<<ftb)-1;
_fl=_fl&mask;
_ft=_ft&mask;
ec_enc_bits64(_this,_fl,ftb);
} else {
ec_encode(_this,_fl,_fl+1,_ft+1);
}
ec_encode(_this,_fl,_fl+1,_ft+1);
}
......@@ -203,7 +203,7 @@ static inline celt_word32_t celt_rcp(celt_word32_t x)
return VSHR32(EXTEND32(frac),i-16);
}
#define celt_div(a,b) MULT32_32_Q31(a,celt_rcp(b))
#define celt_div(a,b) MULT32_32_Q31((celt_word32_t)(a),celt_rcp(b))
#endif /* FIXED_POINT */
......
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