ref: d9fb8a6651ea66f18f034fc70a51cfed17d3e12f
parent: 51231750178c8a4bf87157d82fb3cd2fb93b50b2
author: Jean-Marc Valin <[email protected]>
date: Thu Jan 30 06:16:24 EST 2014
Optimizing divisions with a signed numerator
--- a/celt/bands.c
+++ b/celt/bands.c
@@ -630,7 +630,8 @@
/* The upper limit ensures that in a stereo split with itheta==16384, we'll
always have enough bits left over to code at least one pulse in the
side; otherwise it would collapse, since it doesn't get folded. */
- qb = IMIN(b-pulse_cap-(4<<BITRES), (b+N2*offset)/N2);
+ qb = celt_sudiv(b+N2*offset, N2);
+ qb = IMIN(b-pulse_cap-(4<<BITRES), qb);
qb = IMIN(8<<BITRES, qb);
@@ -1434,7 +1435,7 @@
ctx.remaining_bits = remaining_bits;
if (i <= codedBands-1)
{
- curr_balance = balance / IMIN(3, codedBands-i);
+ curr_balance = celt_sudiv(balance, IMIN(3, codedBands-i));
b = IMAX(0, IMIN(16383, IMIN(remaining_bits+1,pulses[i]+curr_balance)));
} else {
b = 0;
--- a/celt/entcode.h
+++ b/celt/entcode.h
@@ -137,4 +137,16 @@
#endif
}
+static OPUS_INLINE opus_int32 celt_sudiv(opus_int32 n, opus_int32 d) {
+ celt_assert(d>0);
+#ifdef USE_SMALL_DIV_TABLE
+ if (n<0)
+ return -(opus_int32)celt_udiv(-n, d);
+ else
+ return celt_udiv(n, d);
+#else
+ return n/d;
+#endif
+}
+
#endif