shithub: opus

Download patch

ref: 98c86c7885791ee1e2508ebf878a5e94f16a70ae
parent: 9ce7fbc4217ac13ef3c5d2543d3269c95d366323
author: Jean-Marc Valin <[email protected]>
date: Thu Mar 27 04:40:45 EDT 2008

Trying to clean up celt_ilog2() vs. EC_ILOG a bit.

--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -39,6 +39,7 @@
 
 #include <stdlib.h>
 #include "cwrs.h"
+#include "mathops.h"
 
 /* Knowing ncwrs() for a fixed number of pulses m and for all vector sizes n,
    compute ncwrs() for m+1, for all n. Could also be used when m and n are
@@ -373,7 +374,7 @@
    
    pulse2comb(N, K, comb, signs, _y);
    /* Simple heuristic to figure out whether it fits in 32 bits */
-   if((N+4)*(K+4)<250 || EC_ILOG(N)*K<31)
+   if((N+4)*(K+4)<250 || (celt_ilog2(N)+1)*K<31)
    {
       celt_uint32_t bound, id;
       id = icwrs(N, K, comb, signs, &bound);
@@ -395,7 +396,7 @@
    ALLOC(comb, K, int);
    ALLOC(signs, K, int);
    /* Simple heuristic to figure out whether it fits in 32 bits */
-   if((N+4)*(K+4)<250 || EC_ILOG(N)*K<31)
+   if((N+4)*(K+4)<250 || (celt_ilog2(N)+1)*K<31)
    {
       cwrsi(N, K, ec_dec_uint(dec, ncwrs(N, K)), comb, signs);
       comb2pulse(N, K, _y, comb, signs);
--- a/libcelt/ecintrin.h
+++ b/libcelt/ecintrin.h
@@ -70,6 +70,9 @@
   The majority of the time we can never pass it zero.
   When we need to, it can be special cased.*/
 # define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x))
+#elif defined(ENABLE_TI_DSPLIB)
+#include "dsplib.h"
+#define EC_ILOG(x) (31 - _lnorm(x))
 #else
 # define EC_ILOG(_x) (ec_ilog(_x))
 #endif
--- a/libcelt/mathops.h
+++ b/libcelt/mathops.h
@@ -36,7 +36,17 @@
 #define MATHOPS_H
 
 #include "arch.h"
+#include "entcode.h"
 
+#ifndef OVERRIDE_CELT_ILOG2
+/** Integer log in base2. Undefined for zero and negative numbers */
+static inline celt_int16_t celt_ilog2(celt_word32_t x)
+{
+   celt_assert2(x>0, "celt_ilog2() only defined for strictly positive numbers");
+   return EC_ILOG(x)-1;
+}
+#endif
+
 #ifndef OVERRIDE_FIND_MAX16
 static inline int find_max16(celt_word16_t *x, int len)
 {
@@ -89,18 +99,8 @@
 
 #ifdef FIXED_POINT
 
-#include "entcode.h"
 #include "os_support.h"
 
-#ifndef OVERRIDE_CELT_ILOG2
-/** Integer log in base2. Undefined for zero and negative numbers */
-static inline celt_int16_t celt_ilog2(celt_word32_t x)
-{
-   celt_assert2(x>0, "celt_ilog2() only defined for strictly positive numbers");
-   return EC_ILOG(x)-1;
-}
-#endif
-
 #ifndef OVERRIDE_CELT_MAXABS16
 static inline celt_word16_t celt_maxabs16(celt_word16_t *x, int len)
 {
@@ -115,7 +115,7 @@
 /** Integer log in base2. Defined for zero, but not for negative numbers */
 static inline celt_int16_t celt_zlog2(celt_word32_t x)
 {
-   return EC_ILOG(x)-1;
+   return x <= 0 ? 0 : celt_ilog2(x);
 }
 
 /** Reciprocal sqrt approximation (Q30 input, Q0 output or equivalent) */
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -138,7 +138,7 @@
       int q2;
       celt_word16_t offset = (error[i]+QCONST16(.5f,8))*frac[i];
       /* FIXME: Instead of giving up without warning, we should degrade everything gracefully */
-      if (ec_enc_tell(enc, 0) - bits +EC_ILOG(frac[i])> budget)
+      if (ec_enc_tell(enc, 0) - bits + celt_ilog2(frac[i]) >= budget)
          break;
 #ifdef FIXED_POINT
       /* Has to be without rounding */
@@ -196,7 +196,7 @@
    {
       int q2;
       celt_word16_t offset;
-      if (ec_dec_tell(dec, 0) - bits +EC_ILOG(frac[i])> budget)
+      if (ec_dec_tell(dec, 0) - bits + celt_ilog2(frac[i]) >= budget)
          break;
       q2 = ec_dec_uint(dec, frac[i]);
       offset = EXTRACT16(celt_div(SHL16(q2,8)+QCONST16(.5,8),frac[i])-QCONST16(.5f,8));
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -52,7 +52,7 @@
 #endif
    SAVE_STACK;
 #ifdef FIXED_POINT
-   yshift = 14-EC_ILOG(K);
+   yshift = 13-celt_ilog2(K);
 #endif
    ALLOC(y, N, celt_norm_t);
 
@@ -104,7 +104,7 @@
    SAVE_STACK;
 
 #ifdef FIXED_POINT
-   yshift = 14-EC_ILOG(K);
+   yshift = 13-celt_ilog2(K);
 #endif
 
    ALLOC(y, N, celt_norm_t);