tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

_kiss_fft_guts.h (6200B)


      1 /*Copyright (c) 2003-2004, Mark Borgerding
      2 
      3  All rights reserved.
      4 
      5  Redistribution and use in source and binary forms, with or without
      6   modification, are permitted provided that the following conditions are met:
      7 
      8    * Redistributions of source code must retain the above copyright notice,
      9       this list of conditions and the following disclaimer.
     10    * Redistributions in binary form must reproduce the above copyright notice,
     11       this list of conditions and the following disclaimer in the
     12       documentation and/or other materials provided with the distribution.
     13 
     14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     15  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     17  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     18  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     19  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     20  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     21  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     22  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     23  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     24  POSSIBILITY OF SUCH DAMAGE.*/
     25 
     26 #ifndef KISS_FFT_GUTS_H
     27 #define KISS_FFT_GUTS_H
     28 
     29 #define MIN(a,b) ((a)<(b) ? (a):(b))
     30 #define MAX(a,b) ((a)>(b) ? (a):(b))
     31 
     32 /* kiss_fft.h
     33   defines kiss_fft_scalar as either short or a float type
     34   and defines
     35   typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
     36 #include "kiss_fft.h"
     37 
     38 /*
     39  Explanation of macros dealing with complex math:
     40 
     41   C_MUL(m,a,b)         : m = a*b
     42   C_FIXDIV( c , div )  : if a fixed point impl., c /= div. noop otherwise
     43   C_SUB( res, a,b)     : res = a - b
     44   C_SUBFROM( res , a)  : res -= a
     45   C_ADDTO( res , a)    : res += a
     46 * */
     47 #ifdef FIXED_POINT
     48 #include "arch.h"
     49 
     50 
     51 #define SAMP_MAX 2147483647
     52 #define TWID_MAX 32767
     53 #define TRIG_UPSCALE 1
     54 
     55 #define SAMP_MIN -SAMP_MAX
     56 
     57 #ifdef ENABLE_QEXT
     58 #   define S_MUL(a,b) MULT32_32_P31(b, a)
     59 #   define S_MUL2(a,b) MULT32_32_P31(b, a)
     60 #else
     61 #   define S_MUL(a,b) MULT16_32_Q15(b, a)
     62 #   define S_MUL2(a,b) MULT16_32_Q16(b, a)
     63 #endif
     64 
     65 #   define C_MUL(m,a,b) \
     66      do{ (m).r = SUB32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \
     67          (m).i = ADD32_ovflw(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0)
     68 
     69 #   define C_MULC(m,a,b) \
     70      do{ (m).r = ADD32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \
     71          (m).i = SUB32_ovflw(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0)
     72 
     73 #   define C_MULBYSCALAR( c, s ) \
     74      do{ (c).r =  S_MUL( (c).r , s ) ;\
     75          (c).i =  S_MUL( (c).i , s ) ; }while(0)
     76 
     77 #   define DIVSCALAR(x,k) \
     78        (x) = S_MUL(  x, (TWID_MAX-((k)>>1))/(k)+1 )
     79 
     80 #   define C_FIXDIV(c,div) \
     81        do {    DIVSCALAR( (c).r , div);  \
     82                DIVSCALAR( (c).i  , div); }while (0)
     83 
     84 #define  C_ADD( res, a,b)\
     85    do {(res).r=ADD32_ovflw((a).r,(b).r);  (res).i=ADD32_ovflw((a).i,(b).i); \
     86    }while(0)
     87 #define  C_SUB( res, a,b)\
     88    do {(res).r=SUB32_ovflw((a).r,(b).r);  (res).i=SUB32_ovflw((a).i,(b).i); \
     89    }while(0)
     90 #define C_ADDTO( res , a)\
     91    do {(res).r = ADD32_ovflw((res).r, (a).r);  (res).i = ADD32_ovflw((res).i,(a).i);\
     92    }while(0)
     93 
     94 #define C_SUBFROM( res , a)\
     95    do {(res).r = ADD32_ovflw((res).r,(a).r);  (res).i = SUB32_ovflw((res).i,(a).i); \
     96    }while(0)
     97 
     98 #if defined(OPUS_ARM_INLINE_ASM)
     99 #include "arm/kiss_fft_armv4.h"
    100 #endif
    101 
    102 #if defined(OPUS_ARM_INLINE_EDSP)
    103 #include "arm/kiss_fft_armv5e.h"
    104 #endif
    105 #if defined(__mips)
    106 #include "mips/kiss_fft_mipsr1.h"
    107 #endif
    108 
    109 #else  /* not FIXED_POINT*/
    110 
    111 #   define S_MUL(a,b) ( (a)*(b) )
    112 #   define S_MUL2(a,b) ( (a)*(b) )
    113 #define C_MUL(m,a,b) \
    114    do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
    115        (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
    116 #define C_MULC(m,a,b) \
    117    do{ (m).r = (a).r*(b).r + (a).i*(b).i;\
    118        (m).i = (a).i*(b).r - (a).r*(b).i; }while(0)
    119 
    120 #define C_MUL4(m,a,b) C_MUL(m,a,b)
    121 
    122 #   define C_FIXDIV(c,div) /* NOOP */
    123 #   define C_MULBYSCALAR( c, s ) \
    124    do{ (c).r *= (s);\
    125        (c).i *= (s); }while(0)
    126 #endif
    127 
    128 #ifndef CHECK_OVERFLOW_OP
    129 #  define CHECK_OVERFLOW_OP(a,op,b) /* noop */
    130 #endif
    131 
    132 #ifndef C_ADD
    133 #define  C_ADD( res, a,b)\
    134    do { \
    135            CHECK_OVERFLOW_OP((a).r,+,(b).r)\
    136            CHECK_OVERFLOW_OP((a).i,+,(b).i)\
    137            (res).r=(a).r+(b).r;  (res).i=(a).i+(b).i; \
    138    }while(0)
    139 #define  C_SUB( res, a,b)\
    140    do { \
    141            CHECK_OVERFLOW_OP((a).r,-,(b).r)\
    142            CHECK_OVERFLOW_OP((a).i,-,(b).i)\
    143            (res).r=(a).r-(b).r;  (res).i=(a).i-(b).i; \
    144    }while(0)
    145 #define C_ADDTO( res , a)\
    146    do { \
    147            CHECK_OVERFLOW_OP((res).r,+,(a).r)\
    148            CHECK_OVERFLOW_OP((res).i,+,(a).i)\
    149            (res).r += (a).r;  (res).i += (a).i;\
    150    }while(0)
    151 
    152 #define C_SUBFROM( res , a)\
    153    do {\
    154            CHECK_OVERFLOW_OP((res).r,-,(a).r)\
    155            CHECK_OVERFLOW_OP((res).i,-,(a).i)\
    156            (res).r -= (a).r;  (res).i -= (a).i; \
    157    }while(0)
    158 #endif /* C_ADD defined */
    159 
    160 #ifdef FIXED_POINT
    161 /*#  define KISS_FFT_COS(phase)  TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase))))
    162 #  define KISS_FFT_SIN(phase)  TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/
    163 #  define KISS_FFT_COS(phase)  floor(.5+TWID_MAX*cos (phase))
    164 #  define KISS_FFT_SIN(phase)  floor(.5+TWID_MAX*sin (phase))
    165 #  define HALF_OF(x) ((x)>>1)
    166 #elif defined(USE_SIMD)
    167 #  define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) )
    168 #  define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) )
    169 #  define HALF_OF(x) ((x)*_mm_set1_ps(.5f))
    170 #else
    171 #  define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
    172 #  define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
    173 #  define HALF_OF(x) ((x)*.5f)
    174 #endif
    175 
    176 #define  kf_cexp(x,phase) \
    177        do{ \
    178                (x)->r = KISS_FFT_COS(phase);\
    179                (x)->i = KISS_FFT_SIN(phase);\
    180        }while(0)
    181 
    182 #define  kf_cexp2(x,phase) \
    183   do{ \
    184      (x)->r = TRIG_UPSCALE*celt_cos_norm((phase));\
    185      (x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\
    186 }while(0)
    187 
    188 #endif /* KISS_FFT_GUTS_H */