Commit 15b9be3a authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

fixed-point: playing it safe. SHL32() now automatically casts input to 32-bit

to prevent surprises. Also, a few comments.
parent 0773fec4
......@@ -54,7 +54,7 @@
#define SHR16(a,shift) ((a) >> (shift))
#define SHL16(a,shift) ((a) << (shift))
#define SHR32(a,shift) ((a) >> (shift))
#define SHL32(a,shift) ((a) << (shift))
#define SHL32(a,shift) ((celt_word32_t)(a) << (shift))
#define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift))
#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift))
#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
......
......@@ -54,16 +54,13 @@
#include "entcode.h"
/** Integer log in base2. Undefined for zero and negative numbers */
static inline celt_int16_t celt_ilog2(celt_word32_t x)
{
return EC_ILOG(x)-1;
}
#define C0 3634
#define C1 21173
#define C2 -12627
#define C3 4204
/** Sqrt approximation (QX input, QX/2 output) */
static inline celt_word32_t celt_sqrt(celt_word32_t x)
{
int k;
......@@ -149,7 +146,7 @@ static inline celt_word16_t celt_log2(celt_word32_t x)
#define D1 11356
#define D2 3726
#define D3 1301
/* Input in Q11 format, output in Q16 */
/** Base-2 exponential approximation (2^x). (Q11 input, Q16 output) */
static inline celt_word32_t celt_exp2(celt_word16_t x)
{
int integer;
......@@ -164,6 +161,7 @@ static inline celt_word32_t celt_exp2(celt_word16_t x)
return VSHR32(EXTEND32(frac), -integer-2);
}
/** Reciprocal approximation (Q15 input, Q16 output) */
static inline celt_word32_t celt_rcp(celt_word32_t x)
{
int i, neg=0;
......
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