Skip to content

Commit 5123175

Browse files
committed
Speeding up ec_tell_frac()
1 parent 58107d8 commit 5123175

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

celt/entcode.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ int ec_ilog(opus_uint32 _v){
6262
}
6363
#endif
6464

65+
#if 1
66+
/* This is a faster version of ec_tell_frac() that takes advantage
67+
of the low (1/8 bit) resolution to use just a linear function
68+
followed by a lookup to determine the exact transition thresholds. */
69+
opus_uint32 ec_tell_frac(ec_ctx *_this){
70+
static const unsigned correction[8] =
71+
{35733, 38967, 42495, 46340,
72+
50535, 55109, 60097, 65535};
73+
opus_uint32 nbits;
74+
opus_uint32 r;
75+
int l;
76+
unsigned b;
77+
nbits=_this->nbits_total<<BITRES;
78+
l=EC_ILOG(_this->rng);
79+
r=_this->rng>>(l-16);
80+
b = (r>>12)-8;
81+
b += r>correction[b];
82+
l = (l<<3)+b;
83+
return nbits-l;
84+
}
85+
#else
6586
opus_uint32 ec_tell_frac(ec_ctx *_this){
6687
opus_uint32 nbits;
6788
opus_uint32 r;
@@ -91,6 +112,7 @@ opus_uint32 ec_tell_frac(ec_ctx *_this){
91112
}
92113
return nbits-l;
93114
}
115+
#endif
94116

95117
#ifdef USE_SMALL_DIV_TABLE
96118
/* Result of 2^32/(2*i+1), except for i=0. */

0 commit comments

Comments
 (0)