[xiph-commits] r12075 - trunk/speex/libspeex
jm at svn.xiph.org
jm at svn.xiph.org
Fri Nov 10 05:11:10 PST 2006
Author: jm
Date: 2006-11-10 05:11:08 -0800 (Fri, 10 Nov 2006)
New Revision: 12075
Modified:
trunk/speex/libspeex/pseudofloat.h
Log:
pseudo-float divide operators should be more robust to invalid input and
probably faster as well.
Modified: trunk/speex/libspeex/pseudofloat.h
===================================================================
--- trunk/speex/libspeex/pseudofloat.h 2006-11-10 11:49:52 UTC (rev 12074)
+++ trunk/speex/libspeex/pseudofloat.h 2006-11-10 13:11:08 UTC (rev 12075)
@@ -250,22 +250,19 @@
return r;
}
+/* Do NOT attempt to divide by a negative number */
static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b)
{
int e=0;
spx_float_t r;
- /* FIXME: Handle the sign */
if (a==0)
{
return FLOAT_ZERO;
}
- while (a<SHL32(EXTEND32(b.m),14))
+ e = spx_ilog2(ABS32(a))-spx_ilog2(b.m-1)-15;
+ a = VSHR32(a, e);
+ if (ABS32(a)>=SHL32(EXTEND32(b.m-1),15))
{
- a <<= 1;
- e--;
- }
- while (a>=SHL32(EXTEND32(b.m-1),15))
- {
a >>= 1;
e++;
}
@@ -275,40 +272,45 @@
}
+/* Do NOT attempt to divide by a negative number */
static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b)
{
- int e=0;
+ int e0=0,e=0;
spx_float_t r;
- /* FIXME: Handle the sign */
if (a==0)
{
return FLOAT_ZERO;
}
- while (b>32767)
+ if (b>32767)
{
- b >>= 1;
- e--;
+ e0 = spx_ilog2(b)-14;
+ b = VSHR32(b, e0);
+ e0 = -e0;
}
- while (a<SHL32(b,14))
+ e = spx_ilog2(ABS32(a))-spx_ilog2(b-1)-15;
+ a = VSHR32(a, e);
+ if (ABS32(a)>=SHL32(EXTEND32(b-1),15))
{
- a <<= 1;
- e--;
- }
- while (a>=SHL32(b-1,15))
- {
a >>= 1;
e++;
}
+ e += e0;
r.m = DIV32_16(a,b);
r.e = e;
return r;
}
+/* Do NOT attempt to divide by a negative number */
static inline spx_float_t FLOAT_DIVU(spx_float_t a, spx_float_t b)
{
int e=0;
spx_int32_t num;
spx_float_t r;
+ if (b.m<=0)
+ {
+ speex_warning_int("Attempted to divide by", b.m);
+ return FLOAT_ONE;
+ }
num = a.m;
a.m = ABS16(a.m);
while (a.m >= b.m)
More information about the commits
mailing list