[xiph-commits] r12074 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Fri Nov 10 03:49:56 PST 2006


Author: jm
Date: 2006-11-10 03:49:52 -0800 (Fri, 10 Nov 2006)
New Revision: 12074

Modified:
   trunk/speex/libspeex/arch.h
   trunk/speex/libspeex/fixed_debug.h
   trunk/speex/libspeex/fixed_generic.h
   trunk/speex/libspeex/math_approx.c
   trunk/speex/libspeex/pseudofloat.h
Log:
Defined VSHR32 and using it instead of "if (shift>0)..."


Modified: trunk/speex/libspeex/arch.h
===================================================================
--- trunk/speex/libspeex/arch.h	2006-11-10 11:00:37 UTC (rev 12073)
+++ trunk/speex/libspeex/arch.h	2006-11-10 11:49:52 UTC (rev 12074)
@@ -131,6 +131,7 @@
 #define SHL32(a,shift) (a)
 #define PSHR16(a,shift) (a)
 #define PSHR32(a,shift) (a)
+#define VSHR32(a,shift) (a)
 #define SATURATE16(x,a) (x)
 #define SATURATE32(x,a) (x)
 

Modified: trunk/speex/libspeex/fixed_debug.h
===================================================================
--- trunk/speex/libspeex/fixed_debug.h	2006-11-10 11:00:37 UTC (rev 12073)
+++ trunk/speex/libspeex/fixed_debug.h	2006-11-10 11:49:52 UTC (rev 12074)
@@ -158,6 +158,8 @@
 
 #define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift))
 #define PSHR32(a,shift) (SHR32((a)+((1<<((shift))>>1)),shift))
+#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
+
 #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
 #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
 

Modified: trunk/speex/libspeex/fixed_generic.h
===================================================================
--- trunk/speex/libspeex/fixed_generic.h	2006-11-10 11:00:37 UTC (rev 12073)
+++ trunk/speex/libspeex/fixed_generic.h	2006-11-10 11:49:52 UTC (rev 12074)
@@ -48,6 +48,7 @@
 #define SHL32(a,shift) ((a) << (shift))
 #define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift))
 #define PSHR32(a,shift) (SHR32((a)+((1<<((shift))>>1)),shift))
+#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
 #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
 #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
 

Modified: trunk/speex/libspeex/math_approx.c
===================================================================
--- trunk/speex/libspeex/math_approx.c	2006-11-10 11:00:37 UTC (rev 12073)
+++ trunk/speex/libspeex/math_approx.c	2006-11-10 11:49:52 UTC (rev 12074)
@@ -111,15 +111,9 @@
    int k;
    spx_word32_t rt;
    k = spx_ilog4(x)-6;
-   if (k>0)
-      x = SHR32(x, (k<<1));
-   else
-      x = SHL32(x, (-k<<1));
+   x = VSHR32(x, (k<<1));
    rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
-   if (k>7)
-      rt <<= k-7;
-   else
-      rt >>= 7-k;
+   rt = VSHR32(rt,7-k);
    return rt;
 }
 
@@ -231,10 +225,7 @@
       return 0;
    frac = SHL16(x-SHL16(integer,11),3);
    frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
-   if (integer+2>0)
-      return SHL32(EXTEND32(frac), integer+2);
-   else
-      return SHR32(EXTEND32(frac), -integer-2);
+   return VSHR32(EXTEND32(frac), -integer-2);
 }
 
 /* Input in Q11 format, output in Q16 */

Modified: trunk/speex/libspeex/pseudofloat.h
===================================================================
--- trunk/speex/libspeex/pseudofloat.h	2006-11-10 11:00:37 UTC (rev 12073)
+++ trunk/speex/libspeex/pseudofloat.h	2006-11-10 11:49:52 UTC (rev 12074)
@@ -65,18 +65,8 @@
       spx_float_t r = {0,0};
       return r;
    }
-   while (x>32767)
-   {
-      x >>= 1;
-      /*x *= .5;*/
-      e++;
-   }
-   while (x<16383)
-   {
-      x <<= 1;
-      /*x *= 2;*/
-      e--;
-   }
+   e = spx_ilog2(ABS32(x))-14;
+   x = VSHR32(x, e);
    if (sign)
    {
       spx_float_t r;
@@ -240,43 +230,23 @@
 
 static inline spx_int32_t FLOAT_MUL32(spx_float_t a, spx_word32_t b)
 {
-   if (a.e<-15)
-      return SHR32(MULT16_32_Q15(a.m, b),-a.e-15);
-   else
-      return SHL32(MULT16_32_Q15(a.m, b),15+a.e);
+   return VSHR32(MULT16_32_Q15(a.m, b),-a.e-15);
 }
 
 static inline spx_float_t FLOAT_MUL32U(spx_word32_t a, spx_word32_t b)
 {
-   int e=0;
+   int e1, e2;
    spx_float_t r;
-   /* FIXME: Handle the sign */
-   if (a==0)
+   if (a==0 || b==0)
    {
       return FLOAT_ZERO;
    }
-   while (a>32767)
-   {
-      a >>= 1;
-      e++;
-   }
-   while (a<16384)
-   {
-      a <<= 1;
-      e--;
-   }
-   while (b>32767)
-   {
-      b >>= 1;
-      e++;
-   }
-   while (b<16384)
-   {
-      b <<= 1;
-      e--;
-   }
+   e1 = spx_ilog2(ABS32(a));
+   a = VSHR32(a, e1-14);
+   e2 = spx_ilog2(ABS32(b));
+   b = VSHR32(b, e2-14);
    r.m = MULT16_16_Q15(a,b);
-   r.e = e+15;
+   r.e = e1+e2-13;
    return r;
 }
 



More information about the commits mailing list