ref: 9a7539fcf3de10de06e165e1abeb13905df6fa50
parent: 4dc0b3970568ff4cd484954333d3f800d8e4eeec
author: Gregory Maxwell <[email protected]>
date: Mon Aug 15 07:35:39 EDT 2011
Remove two branches from bitexact_cos(). These cases were actually unreachable due the maximum and minimum values being special cases in the caller plus the limits of the maximum itheta precision. The testcases are also updated to only test the reachable range.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -53,12 +53,10 @@
opus_int32 tmp;
opus_int16 x2;
tmp = (4096+((opus_int32)(x)*(x)))>>13;
- if (tmp > 32767)
- tmp = 32767;
+ celt_assert(tmp<=32767);
x2 = tmp;
x2 = (32767-x2) + FRAC_MUL16(x2, (-7651 + FRAC_MUL16(x2, (8277 + FRAC_MUL16(-626, x2)))));
- if (x2 > 32766)
- x2 = 32766;
+ celt_assert(x2<=32766);
return 1+x2;
}
--- a/libcelt/tests/mathops-test.c
+++ b/libcelt/tests/mathops-test.c
@@ -68,7 +68,7 @@
opus_int32 min_d,max_d,last,chk;
chk=max_d=0;
last=min_d=32767;
- for(i=0;i<16385;i++)
+ for(i=64;i<=16320;i++)
{
opus_int32 d;
opus_int32 q=bitexact_cos(i);
@@ -78,8 +78,8 @@
if (d<min_d)min_d=d;
last = q;
}
- if ((chk!=91017006)||(max_d!=5)||(min_d!=0)||(bitexact_cos(0)!=32767)||
- (bitexact_cos(16384)!=1)||(bitexact_cos(8192)!=23171))
+ if ((chk!=89408644)||(max_d!=5)||(min_d!=0)||(bitexact_cos(64)!=32767)||
+ (bitexact_cos(16320)!=200)||(bitexact_cos(8192)!=23171))
{
fprintf (stderr, "bitexact_cos failed\n");
ret = 1;
@@ -91,8 +91,8 @@
int i,fail;
opus_int32 min_d,max_d,last,chk;
fail=chk=max_d=0;
- last=min_d=30690;
- for(i=0;i<8193;i++)
+ last=min_d=15059;
+ for(i=64;i<8193;i++)
{
opus_int32 d;
opus_int32 mid=bitexact_cos(i);
@@ -106,8 +106,8 @@
if (d<min_d)min_d=d;
last = q;
}
- if ((chk!=16578548)||(max_d!=3219)||(min_d!=-2)||fail||
- (bitexact_log2tan(32767,1)!=30690)||(bitexact_log2tan(30274,12540)!=2611)||
+ if ((chk!=15821257)||(max_d!=61)||(min_d!=-2)||fail||
+ (bitexact_log2tan(32767,200)!=15059)||(bitexact_log2tan(30274,12540)!=2611)||
(bitexact_log2tan(23171,23171)!=0))
{
fprintf (stderr, "bitexact_log2tan failed\n");