Commit 98c86c78 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

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

parent 9ce7fbc4
......@@ -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 @@ void encode_pulses(int *_y, int N, int K, ec_enc *enc)
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 @@ void decode_pulses(int *_y, int N, int K, ec_dec *dec)
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);
......
......@@ -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
......
......@@ -36,6 +36,16 @@
#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 @@ static inline int find_max32(celt_word32_t *x, int len)
#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 @@ static inline celt_word16_t celt_maxabs16(celt_word16_t *x, int len)
/** 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) */
......
......@@ -138,7 +138,7 @@ static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word1
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 @@ static void unquant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_wor
{
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));
......
......@@ -52,7 +52,7 @@ static void mix_pitch_and_residual(int * restrict iy, celt_norm_t * restrict X,
#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 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *
SAVE_STACK;
#ifdef FIXED_POINT
yshift = 14-EC_ILOG(K);
yshift = 13-celt_ilog2(K);
#endif
ALLOC(y, N, celt_norm_t);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment