Commit 4c7f0a5f authored by jm's avatar jm

Merging Trimedia support contributed by Hong Zhiqian (incomplete for now)


git-svn-id: http://svn.xiph.org/trunk/speex@12764 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent 57656c5f
################# REMOVE warnings on trimedia compiler ##############################
################# Not critical to compilation ##############################
1. Change the following statements to remove warning for constant expression
(i) mdf.c [if(0) --> #if 0]
(ii) ltp.c [if(1) --> #if 1]
(iii) preprocess.c [if(1) --> #if 1]
(iv) sb_celp.c [if (SPEEX_SET_VBR_MAX_BITRATE<1) --> #if (SPEEX_SET_VBR_MAX_BITRATE<1)]
2. add REMARK_ON macro to remove warning on not reference variable
-- uses (void)<variable> to remove warning on not referenced variable
-- #define REMARK_ON
-- (void)<variable>
-- #endif
-- search for REMARK_ON on the following files
(i) jitter.c
(ii) lsp.c
(iii) ltp.c
(iv) mdf.c
(v) filters.c
(vi) filterbank.c
(vii) cb_search.c
(viii) vq.c
(ix) vbr.c
(x) stereo.c
(xi) speex_callbacks.c
(xii) preprocess.c
3. commented out the following in pseudofloat.h for unused variable
//static const spx_float_t FLOAT_HALF = {16384,-15};
4. commented out unused variable in nb_celp.c
//spx_word16_t *sp; ***unused variable***
//sp=out+offset; ***unused variable***
//int submode; ***unused variable***
// ***unused variable***
// advance = submode = speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);
advance = speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);
// ***unused variable***
//advance = submode = speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);
advance = speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);
// spx_word16_t *exc; ***unused variable***
// exc=st->exc+offset; ***unused variable***
5. commented out unused variable in vbr.c
//int va; ***unused variable***
//va = 0; ***unused variable***
//va = 1; ***unused variable***
6. added HAVE_CONFIG into medfilter.c
################# Patches for trimedia compiler ##############################
################# Critical to compilation ##############################
-- change the following in modes.c and speex.h as compiler does not support const * const...
(i) modes.c
#ifdef __TCS__
const SpeexMode * speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
#else
const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
#endif
(ii) speex.h
#ifdef __TCS__
extern const SpeexMode * speex_mode_list[SPEEX_NB_MODES];
#else
extern const SpeexMode * const speex_mode_list[SPEEX_NB_MODES];
#endif
-- added the #elif defined (TM_ASM) to the following files for optimized codes
(1) arch.h
(2) cb_search.c
(3) fftwrap.c
(4) filterbank.c
(5) filters.c
(6) kiss_fft.c
(7) kiss_fftr.c
(8) lpc.c
(9) lsp.c
(10) ltp.c
(11) mdf.c
(12) misc.c
(13) preprocess.c
(14) quant_lsp.c
(15) vq.c
-- reorder macro definations in quant_lsp.c
#ifdef FIXED_POINT
#define LSP_LINEAR(i) (SHL16(i+1,11))
#define LSP_LINEAR_HIGH(i) (ADD16(MULT16_16_16(i,2560),6144))
#define LSP_DIV_256(x) (SHL16((spx_word16_t)x, 5))
#define LSP_DIV_512(x) (SHL16((spx_word16_t)x, 4))
#define LSP_DIV_1024(x) (SHL16((spx_word16_t)x, 3))
#define LSP_PI 25736
#else
#define LSP_LINEAR(i) (.25*(i)+.25)
#define LSP_LINEAR_HIGH(i) (.3125*(i)+.75)
#define LSP_SCALE 256.
#define LSP_DIV_256(x) (0.0039062*(x))
#define LSP_DIV_512(x) (0.0019531*(x))
#define LSP_DIV_1024(x) (0.00097656*(x))
#define LSP_PI M_PI
#endif
#ifdef BFIN_ASM
#include "quant_lsp_bfin.h"
#elif defined (TM_ASM)
#include "quant_lsp_tm.h"
#endif
-- added macro PREPROCESS_MDF_FLOAT to allow using of floating point
-- in mdf and preprocess while keeping fixed point in encoder/decoder
-- This is due to the fact that preprocess/mdf run faster on floating
-- point on trimedia
-- added the following 3 lines to the files below
#ifdef PREPROCESS_MDF_FLOAT
#undef FIXED_POINT
#endif
(1) mdf.c
(2) preprocess.c
(3) filterbank.c
(4) fftwrap.c
(5) kiss_fft.c
(6) kiss_fftr.c
-- created a new USE_COMPACT_KISS_FFT for fftwrap.c and shifted defination
-- to config file so that user configure the usage of fft on config.h
-- TOEXPLORE:is it possible to share table between mdf/preprocess?
-- Introducing this macro made the following changes in C code
-- New macro to facilitate integration
(grouping real/complex for dc and nyquist frequency seems to require a large
amount of memory for mdf, therefore did not made the changes for that)
(1) modify preprocess.c on init and destroy
(2) modify mdf.c on init and destroy
(3) shifted power_spectrum to fftwrap.c to share optimised code between
preprocess.c and mdf.c
################# NOTES ##############################
(1) fixed point encoding/decoding is tested on narrowband
- some of the QX fractions are packed together to
(frac1 * a + frac2 * a) >> X (should be more accurate in rounding)
instead of
((frac1 * a) >> X) + ((frac2 * a) >> X)
will cause some different between optimized and unoptimized code.
tried decoding/encoding optimized code on some audio files retains
the clearity of the word
- wideband/ultrawideband is not heavily tested yet
(2) optimized fixed point code requires memory alignment
- used config to debug on functions where memory is not align
(3) floating point optimization for preprocess/mdf is tested
fixed point is not tested yet (except fft/filterbank)
Note (1) also applies to sround in fft for fixed point
some optimization is provided for fixed point as it requires lesser
memory compared to floating point.
(4) unroll configurations provided to reduce code size if required
(5) use profile options only if compiler profiling fails to work
(6) can't include the makefile as it is close proprietary
################# TODO:For Trimedia ##############################
(1) Possible add TSSA wrapper for codec but don't think this can be open source.
(2) Optimizations for fixed point in mdf/preprocess
################# Added Files ##############################
- _kiss_fft_guts_tm.h
- cb_search_tm.h
- fftwrap_tm.h
- filterbank_tm.h
- filters_tm.h
- fixed_tm.h
- kiss_fft_tm.h
- kiss_fftr_tm.h
- lpc_tm.h
- lsp_tm.h
- ltp_tm.h
- mdf_tm.h
- misc_tm.h
- preprocess_tm.h
- profile_tm.h
- quant_lsp_tm.h
- vq_tm.h
- config.h
- speex_config_types.h
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file _kiss_fft_guts_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _KISS_FFT_GUTS_TM_
#define _KISS_FFT_GUTS_TM_
#ifdef TM_ASM
#include <ops/custom_defs.h>
#ifdef FIXED_POINT
#undef sround
#define sround(x) sex16(((x) + (1<<(FRACBITS-1)) ) >> FRACBITS)
#undef MIN
#undef MAX
#define MIN(a,b) imin(a,b)
#define MAX(a,b) imax(a,b)
#define TM_MUL(res,a,b) \
{ register int a0, a1, b0, b1; \
\
a0 = sex16((a)); \
a1 = asri(16,(a)); \
b0 = sex16((b)); \
b1 = asri(16,(b)); \
(res)= pack16lsb( \
sround(ifir16((a),funshift2((b),(b)))), \
sround(a0*b0-a1*b1)); \
} \
#define TM_ADD(res,a,b) \
{ (res)=dspidualadd((a),(b)); \
} \
#define TM_SUB(res,a,b) \
{ (res)=dspidualsub((a),(b)); \
} \
#define TM_SHR(res,a,shift) \
{ (res)=dualasr((a),(shift)); \
} \
#define TM_DIV(res,c,frac) \
{ register int c1, c0; \
\
c1 = asri(16,(c)); \
c0 = sex16((c)); \
(res) = pack16lsb(sround(c1 * (32767/(frac))), sround(c0 * (32767/(frac))));\
} \
#define TM_NEGMSB(res, a) \
{ (res) = pack16lsb((ineg(asri(16,(a)))), (a)); \
} \
#else
#undef MIN
#undef MAX
#define MIN(a,b) fmin(a,b)
#define MAX(a,b) fmax(a,b)
#endif
#endif
#undef CHECKBUF
#define CHECKBUF(buf,nbuf,n) \
{ \
if ( nbuf < (size_t)(n) ) { \
speex_free(buf); \
buf = (kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx)*(n)); \
nbuf = (size_t)(n); \
} \
} \
#undef C_ADD
#define C_ADD( res, a,b) \
{ \
CHECK_OVERFLOW_OP((a).r,+,(b).r) \
CHECK_OVERFLOW_OP((a).i,+,(b).i) \
(res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
} \
#undef C_SUB
#define C_SUB( res, a,b) \
{ \
CHECK_OVERFLOW_OP((a).r,-,(b).r) \
CHECK_OVERFLOW_OP((a).i,-,(b).i) \
(res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
} \
#undef C_ADDTO
#define C_ADDTO( res , a) \
{ \
CHECK_OVERFLOW_OP((res).r,+,(a).r) \
CHECK_OVERFLOW_OP((res).i,+,(a).i) \
(res).r += (a).r; (res).i += (a).i; \
} \
#undef C_SUBFROM
#define C_SUBFROM( res, a) \
{ \
CHECK_OVERFLOW_OP((res).r,-,(a).r) \
CHECK_OVERFLOW_OP((res).i,-,(a).i) \
(res).r -= (a).r; (res).i -= (a).i; \
} \
#undef kf_cexp
#define kf_cexp(x,phase) \
{ (x)->r = KISS_FFT_COS(phase); \
(x)->i = KISS_FFT_SIN(phase); } \
#undef kf_cexp2
#define kf_cexp2(x,phase) \
{ (x)->r = spx_cos_norm((phase)); \
(x)->i = spx_cos_norm((phase)-32768); } \
#ifdef FIXED_POINT
#undef C_MUL
#define C_MUL(m,a,b) \
{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
(m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); } \
#undef C_FIXDIV
#define C_FIXDIV(c,div) \
{ DIVSCALAR( (c).r , div); \
DIVSCALAR( (c).i , div); } \
#undef C_MULBYSCALAR
#define C_MULBYSCALAR( c, s ) \
{ (c).r = sround( smul( (c).r , s ) ) ; \
(c).i = sround( smul( (c).i , s ) ) ; } \
#else
#undef C_MUL
#define C_MUL(m,a,b) \
{ (m).r = (a).r*(b).r - (a).i*(b).i; \
(m).i = (a).r*(b).i + (a).i*(b).r; } \
#undef C_MULBYSCALAR
#define C_MULBYSCALAR( c, s ) \
{ (c).r *= (s); \
(c).i *= (s); } \
#endif
#endif
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file cb_search_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK
static void compute_weighted_codebook(
const signed char * restrict shape_cb,
const Int16 * restrict r,
Int16 * restrict resp,
Int16 * restrict resp2,
Int32 * restrict E,
int shape_cb_size, int subvect_size, char *stack)
{
register int i, j;
register int quadsize;
TMDEBUG_ALIGNMEM(r);
TMDEBUG_ALIGNMEM(resp);
TMDEBUG_ALIGNMEM(resp2);
COMPUTEWEIGHTEDCODEBOOK_START();
quadsize = subvect_size << 2;
for ( i=0 ; i<shape_cb_size ; i+=4 )
{ register int e0, e1, e2, e3;
e0 = e1 = e2 = e3 = 0;
for( j=0 ; j<subvect_size ; ++j )
{
register int k, rr;
register int resj0, resj1, resj2, resj3;
resj0 = resj1 = resj2 = resj3 = 0;
for ( k=0 ; k<=j ; ++k )
{ rr = r[j-k];
resj0 += shape_cb[k] * rr;
resj1 += shape_cb[k+subvect_size] * rr;
resj2 += shape_cb[k+2*subvect_size] * rr;
resj3 += shape_cb[k+3*subvect_size] * rr;
}
resj0 >>= 13;
resj1 >>= 13;
resj2 >>= 13;
resj3 >>= 13;
e0 += resj0 * resj0;
e1 += resj1 * resj1;
e2 += resj2 * resj2;
e3 += resj3 * resj3;
resp[j] = resj0;
resp[j+subvect_size] = resj1;
resp[j+2*subvect_size] = resj2;
resp[j+3*subvect_size] = resj3;
}
E[i] = e0;
E[i+1] = e1;
E[i+2] = e2;
E[i+3] = e3;
resp += quadsize;
shape_cb += quadsize;
}
#ifndef REMARK_ON
(void)resp2;
(void)stack;
#endif
COMPUTEWEIGHTEDCODEBOOK_STOP();
}
#define OVERRIDE_TARGET_UPDATE
static inline void target_update(Int16 * restrict t, Int16 g, Int16 * restrict r, int len)
{
register int n;
register int gr1, gr2, t1, t2, r1, r2;
register int quadsize;
TARGETUPDATE_START();
quadsize = len & 0xFFFFFFFC;
for ( n=0; n<quadsize ; n+=4 )
{ gr1 = pack16lsb(PSHR32((g * r[n]),13) , PSHR32((g * r[n+1]),13));
gr2 = pack16lsb(PSHR32((g * r[n+2]),13), PSHR32((g * r[n+3]),13));
t1 = pack16lsb(t[n], t[n+1]);
t2 = pack16lsb(t[n+2],t[n+3]);
r1 = dspidualsub(t1, gr1);
r2 = dspidualsub(t2, gr2);
t[n] = asri(16,r1);
t[n+1] = sex16(r1);
t[n+2] = asri(16,r2);
t[n+3] = sex16(r2);
}
for ( n=quadsize ; n<len ; ++n )
{ t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13));
}
TARGETUPDATE_STOP();
}
#endif
#ifndef _CONFIG_H_
#define _CONFIG_H_
#define USE_COMPACT_KISS_FFT
//#define USE_KISS_FFT
#ifdef WIN32
//#define FIXED_POINT
#define inline __inline
#define restrict
#elif defined (__TCS__)
#define FIXED_POINT
#define PREPROCESS_MDF_FLOAT
#define TM_ASM
#define TM_DEBUGMEM_ALIGNNMENT 1
#define TM_PROFILE 1
#define TM_PROFILE_FIRMEM16 0
#define TM_PROFILE_IIRMEM16 0
#define TM_PROFILE_FILTERMEM16 0
#define TM_PROFILE_VQNBEST 0
#define TM_PROFILE_VQNBESTSIGN 0
#define TM_PROFILE_COMPUTEQUANTWEIGHTS 0
#define TM_PROFILE_LSPQUANT 0
#define TM_PROFILE_LSPWEIGHTQUANT 0
#define TM_PROFILE_LSPENFORCEMARGIN 0
#define TM_PROFILE_LSPTOLPC 0
#define TM_PROFILE_INNERPROD 0
#define TM_PROFILE_PITCHXCORR 0
#define TM_PROFILE_LSP_INTERPOLATE 0
#define TM_PROFILE_CHEBPOLYEVA 0
#define TM_PROFILE_COMPUTEWEIGHTEDCODEBOOK 0
#define TM_PROFILE_TARGETUPDATE 0
#define TM_PROFILE_SPXAUTOCORR 0
#define TM_PROFILE_COMPUTEPITCHERROR 0
#define TM_PROFILE_COMPUTERMS16 0
#define TM_PROFILE_NORMALIZE16 0
#define TM_PROFILE_BWLPC 0
#define TM_PROFILE_HIGHPASS 0
#define TM_PROFILE_SIGNALMUL 0
#define TM_PROFILE_SIGNALDIV 0
#define TM_PROFILE_COMPUTEIMPULSERESPONSE 0
#define TM_PROFILE_PITCHGAINSEARCH3TAPVQ 0
#define TM_PROFILE_OPENLOOPNBESTPITCH 0
#define TM_PROFILE_PREPROCESSANALYSIS 0
#define TM_PROFILE_UPDATENOISEPROB 0
#define TM_PROFILE_COMPUTEGAINFLOOR 0
#define TM_PROFILE_FILTERDCNOTCH16 0
#define TM_PROFILE_MDFINNERPROD 0
#define TM_PROFILE_SPECTRALMULACCUM 0
#define TM_PROFILE_WEIGHTEDSPECTRALMULCONJ 0
#define TM_PROFILE_MDFADJUSTPROP 0
#define TM_PROFILE_SPEEXECHOGETRESIDUAL 0
#define TM_PROFILE_MAXIMIZERANGE 0
#define TM_PROFILE_RENORMRANGE 0
#define TM_PROFILE_POWERSPECTRUM 0
#define TM_PROFILE_QMFSYNTH 0
#define TM_PROFILE_QMFDECOMP 0
#define TM_PROFILE_FILTERBANKCOMPUTEBANK32 0
#define TM_PROFILE_FILTERBANKCOMPUTEPSD16 0
#define TM_UNROLL 1
#define TM_UNROLL_FILTER 1
#define TM_UNROLL_IIR 1
#define TM_UNROLL_FIR 1
#define TM_UNROLL_HIGHPASS 1
#define TM_UNROLL_SIGNALMUL 1
#define TM_UNROLL_SIGNALDIV 1
#define TM_UNROLL_VQNBEST 1
#define TM_UNROLL_VQSIGNNBEST 1
#define TM_UNROLL__SPXAUTOCORR 1
#define TM_UNROLL_COMPUTERMS16 1
#define TM_UNROLL_COMPUTEIMPULSERESPONSE 1
#define TM_UNROLL_QMFSYNTH 1
#define TM_UNROLL_PITCHGAINSEARCH3TAPVQ 1
#define TM_UNROLL_OPENLOOPNBESTPITCH 1
#define TM_UNROLL_FILTERBANKCOMPUTEBANK32 1
#define TM_UNROLL_FILTERBANKCOMPUTEPSD16 1
#define TM_UNROLL_SPEEXPREPROCESSRUN 1
#define TM_UNROLL_PREPROCESSANALYSIS 1
#define TM_UNROLL_UPDATENOISEPROB 1
#define TM_UNROLL_COMPUTEGAINFLOOR 1
#define TM_UNROLL_SPEEXECHOGETRESIDUAL 1
#define TM_UNROLL_SPEEXECHOCANCELLATION 1
#define TM_UNROLL_FILTERDCNOTCH16 1
#define TM_UNROLL_MDFINNERPRODUCT 1
#define TM_UNROLL_SPECTRALMULACCUM 1
#define TM_UNROLL_MDFADJUSTPROP 1
#endif
#endif
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file fftwrap_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_MAXIMIZE_RANGE
static int maximize_range(Int16 *in, Int16 *out, int bound, int len)
{
register int max_val=0;
register int shift=0;
register int i, j;
TMDEBUG_ALIGNMEM(in);
TMDEBUG_ALIGNMEM(out);
MAXIMIZERANGE_START();
len >>= 1;
for ( i=0 ; i<len ; i+=4 )
{
register int x10, x32, x54, x76;
x10 = ld32x(in,i);
x32 = ld32x(in,i+1);
x54 = ld32x(in,i+2);
x76 = ld32x(in,i+3);
x10 = dspidualabs(x10);
x32 = dspidualabs(x32);
x54 = dspidualabs(x54);
x76 = dspidualabs(x76);
x10 = imax(sex16(x10), asri(16,x10));
x32 = imax(sex16(x32), asri(16,x32));
x54 = imax(sex16(x54), asri(16,x54));
x76 = imax(sex16(x76), asri(16,x76));
max_val = imax(max_val,x10);
max_val = imax(max_val,x32);
max_val = imax(max_val,x54);
max_val = imax(max_val,x76);
}
while ( max_val <= (bound>>1) && max_val != 0 )
{ max_val <<= 1;
shift++;
}
if ( shift != 0 )
{
for ( i=0,j=0 ; i<len ; i+=4,j+=16 )
{
register int x10, x32, x54, x76;
x10 = ld32x(in,i);
x32 = ld32x(in,i+1);
x54 = ld32x(in,i+2);
x76 = ld32x(in,i+3);
x10 = dualasl(x10, shift);
x32 = dualasl(x32, shift);
x54 = dualasl(x54, shift);
x76 = dualasl(x76, shift);
st32d(j,out,x10);
st32d(j+4,out,x32);
st32d(j+8,out,x54);
st32d(j+12,out,x76);
}
}
MAXIMIZERANGE_STOP();
return shift;
}
#define OVERRIDE_RENORM_RANGE
static void renorm_range(Int16 *in, Int16 *out, int shift, int len)
{
register int i, j, s, l;
TMDEBUG_ALIGNMEM(in);
TMDEBUG_ALIGNMEM(out);
RENORMRANGE_START();
s = (1<<((shift))>>1);
s = pack16lsb(s,s);
len >>= 1;
l = len & (int)0xFFFFFFFE;
for ( i=0,j=0 ; i<l; i+=2,j+=8 )
{
register int x10, x32;
x10 = ld32x(in,i);
x32 = ld32x(in,i+1);
x10 = dspidualadd(x10, s);