media/libopus/celt/_kiss_fft_guts.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial