1 /****************************************************************************** 2 * @file csky_common_tables.h 3 * @brief This file has extern declaration for common tables like 4 * Bitreverse, reciprocal etc which are used across different functions. 5 * @version V1.0 6 * @date 20. Dec 2016 7 ******************************************************************************/ 8 /* --------------------------------------------------------------------------- 9 * Copyright (C) 2016 CSKY Limited. All rights reserved. 10 * 11 * Redistribution and use of this software in source and binary forms, 12 * with or without modification, are permitted provided that the following 13 * conditions are met: 14 * * Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * * Redistributions in binary form must reproduce the above copyright notice, 17 * this list of conditions and the following disclaimer in the documentation 18 * and/or other materials provided with the distribution. 19 * * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission of CSKY Ltd. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 * THE POSSIBILITY OF SUCH DAMAGE. 34 * -------------------------------------------------------------------------- */ 35 36 #ifndef _CSKY_COMMON_TABLES_H 37 #define _CSKY_COMMON_TABLES_H 38 39 #include "csky_math.h" 40 41 extern const uint16_t cskyBitRevTable[1024]; 42 extern const q15_t cskyRecipTableQ15[64]; 43 extern const q31_t cskyRecipTableQ31[64]; 44 extern const float32_t twiddleCoef_16[32]; 45 extern const float32_t twiddleCoef_32[64]; 46 extern const float32_t twiddleCoef_64[128]; 47 extern const float32_t twiddleCoef_128[256]; 48 extern const float32_t twiddleCoef_256[512]; 49 extern const float32_t twiddleCoef_512[1024]; 50 extern const float32_t twiddleCoef_1024[2048]; 51 extern const float32_t twiddleCoef_2048[4096]; 52 extern const float32_t twiddleCoef_4096[8192]; 53 extern const q31_t twiddleCoef_16_q31[24]; 54 extern const q31_t twiddleCoef_32_q31[48]; 55 extern const q31_t twiddleCoef_64_q31[96]; 56 extern const q31_t twiddleCoef_128_q31[192]; 57 extern const q31_t twiddleCoef_256_q31[384]; 58 extern const q31_t twiddleCoef_512_q31[768]; 59 extern const q31_t twiddleCoef_1024_q31[1536]; 60 extern const q31_t twiddleCoef_2048_q31[3072]; 61 extern const q31_t twiddleCoef_4096_q31[6144]; 62 extern const q15_t twiddleCoef_16_q15[24]; 63 extern const q15_t twiddleCoef_32_q15[48]; 64 extern const q15_t twiddleCoef_64_q15[96]; 65 extern const q15_t twiddleCoef_128_q15[192]; 66 extern const q15_t twiddleCoef_256_q15[384]; 67 extern const q15_t twiddleCoef_512_q15[768]; 68 extern const q15_t twiddleCoef_1024_q15[1536]; 69 extern const q15_t twiddleCoef_2048_q15[3072]; 70 extern const q15_t twiddleCoef_4096_q15[6144]; 71 extern const float32_t twiddleCoef_rfft_32[32]; 72 extern const float32_t twiddleCoef_rfft_64[64]; 73 extern const float32_t twiddleCoef_rfft_128[128]; 74 extern const float32_t twiddleCoef_rfft_256[256]; 75 extern const float32_t twiddleCoef_rfft_512[512]; 76 extern const float32_t twiddleCoef_rfft_1024[1024]; 77 extern const float32_t twiddleCoef_rfft_2048[2048]; 78 extern const float32_t twiddleCoef_rfft_4096[4096]; 79 extern const float32_t twiddleCoef_rfft_8192[8192]; 80 81 extern const q15_t realCoefAQ15_8192[8192]; 82 extern const q31_t realCoefAQ31_8192[8192]; 83 84 /* Tables for RFFT. */ 85 extern const q15_t ALIGN4 realCoefAQ15_32[32]; 86 extern const q15_t ALIGN4 realCoefAQ15_64[64]; 87 extern const q15_t ALIGN4 realCoefAQ15_128[128]; 88 extern const q15_t ALIGN4 realCoefAQ15_256[256]; 89 extern const q15_t ALIGN4 realCoefAQ15_512[512]; 90 extern const q15_t ALIGN4 realCoefAQ15_1024[1024]; 91 extern const q15_t ALIGN4 realCoefAQ15_2048[2048]; 92 extern const q15_t ALIGN4 realCoefAQ15_4096[4096]; 93 94 extern const q31_t realCoefAQ31_32[32]; 95 extern const q31_t realCoefAQ31_64[64]; 96 extern const q31_t realCoefAQ31_128[128]; 97 extern const q31_t realCoefAQ31_256[256]; 98 extern const q31_t realCoefAQ31_512[512]; 99 extern const q31_t realCoefAQ31_1024[1024]; 100 extern const q31_t realCoefAQ31_2048[2048]; 101 extern const q31_t realCoefAQ31_4096[4096]; 102 103 extern const float32_t realCoefA[8192]; 104 extern const float32_t realCoefB[8192]; 105 106 /* Tables for DCT4 */ 107 extern const q15_t ALIGN4 WeightsQ15_128[128+2]; 108 extern const q15_t ALIGN4 WeightsQ15_512[512+2]; 109 extern const q15_t ALIGN4 WeightsQ15_2048[2048+2]; 110 extern const q15_t ALIGN4 WeightsQ15_8192[8192+2]; 111 112 extern const q15_t ALIGN4 cos_factorsQ15_128[128]; 113 extern const q15_t ALIGN4 cos_factorsQ15_512[512]; 114 extern const q15_t ALIGN4 cos_factorsQ15_2048[2048]; 115 extern const q15_t ALIGN4 cos_factorsQ15_8192[8192]; 116 117 extern const q31_t WeightsQ31_128[128+2]; 118 extern const q31_t WeightsQ31_512[512+2]; 119 extern const q31_t WeightsQ31_2048[2048+2]; 120 extern const q31_t WeightsQ31_8192[8192+2]; 121 122 extern const q31_t cos_factorsQ31_128[128]; 123 extern const q31_t cos_factorsQ31_512[512]; 124 extern const q31_t cos_factorsQ31_2048[2048]; 125 extern const q31_t cos_factorsQ31_8192[8192]; 126 127 extern const float32_t Weights_128[128+2]; 128 extern const float32_t Weights_512[512+2]; 129 extern const float32_t Weights_2048[2048+2]; 130 extern const float32_t Weights_8192[8192+2]; 131 132 extern const float32_t cos_factors_128[128]; 133 extern const float32_t cos_factors_512[512]; 134 extern const float32_t cos_factors_2048[2048]; 135 extern const float32_t cos_factors_8192[8192]; 136 137 /* floating-point bit reversal tables */ 138 #define CSKYBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20) 139 #define CSKYBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48) 140 #define CSKYBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56) 141 #define CSKYBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) 142 #define CSKYBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) 143 #define CSKYBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) 144 #define CSKYBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800) 145 #define CSKYBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808) 146 #define CSKYBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032) 147 148 extern const uint16_t cskyBitRevIndexTable16[CSKYBITREVINDEXTABLE__16_TABLE_LENGTH]; 149 extern const uint16_t cskyBitRevIndexTable32[CSKYBITREVINDEXTABLE__32_TABLE_LENGTH]; 150 extern const uint16_t cskyBitRevIndexTable64[CSKYBITREVINDEXTABLE__64_TABLE_LENGTH]; 151 extern const uint16_t cskyBitRevIndexTable128[CSKYBITREVINDEXTABLE_128_TABLE_LENGTH]; 152 extern const uint16_t cskyBitRevIndexTable256[CSKYBITREVINDEXTABLE_256_TABLE_LENGTH]; 153 extern const uint16_t cskyBitRevIndexTable512[CSKYBITREVINDEXTABLE_512_TABLE_LENGTH]; 154 extern const uint16_t cskyBitRevIndexTable1024[CSKYBITREVINDEXTABLE1024_TABLE_LENGTH]; 155 extern const uint16_t cskyBitRevIndexTable2048[CSKYBITREVINDEXTABLE2048_TABLE_LENGTH]; 156 extern const uint16_t cskyBitRevIndexTable4096[CSKYBITREVINDEXTABLE4096_TABLE_LENGTH]; 157 158 /* fixed-point bit reversal tables */ 159 #define CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12) 160 #define CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24) 161 #define CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56) 162 #define CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112) 163 #define CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240) 164 #define CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480) 165 #define CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) 166 #define CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 167 #define CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 168 169 extern const uint16_t cskyBitRevIndexTable_fixed_16[CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH]; 170 extern const uint16_t cskyBitRevIndexTable_fixed_32[CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH]; 171 extern const uint16_t cskyBitRevIndexTable_fixed_64[CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH]; 172 extern const uint16_t cskyBitRevIndexTable_fixed_128[CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH]; 173 extern const uint16_t cskyBitRevIndexTable_fixed_256[CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH]; 174 extern const uint16_t cskyBitRevIndexTable_fixed_512[CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH]; 175 extern const uint16_t cskyBitRevIndexTable_fixed_1024[CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 176 extern const uint16_t cskyBitRevIndexTable_fixed_2048[CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 177 extern const uint16_t cskyBitRevIndexTable_fixed_4096[CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 178 179 /* Tables for Fast Math Sine and Cosine */ 180 extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 181 extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; 182 extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; 183 184 /* Table for Fast math pow */ 185 extern const log2_cof1 ui; 186 extern const log2_cof2 vj; 187 extern const exp_cof1 coar; 188 extern const exp_cof2 fine; 189 190 /* Table for Fast math pow2 */ 191 extern const float64_t exp2_accuratetable[512]; 192 extern const float32_t exp2_deltatable[512]; 193 194 /* Table for Fast math pow2 */ 195 extern const mynumber Iu[182]; 196 extern const mynumber Iv[362]; 197 extern const mynumber Lu[182][2]; 198 extern const mynumber Lv[362][2]; 199 200 /* constant for Fast math */ 201 const static mynumber 202 nZERO = {{0, 0x80000000}}, /* -0.0 */ 203 INF = {{0x00000000, 0x7ff00000}}, /* INF */ 204 nINF = {{0x00000000, 0xfff00000}}, /* -INF */ 205 sqrt_2 = {{0x667f3bcc, 0x3ff6a09e}}, /* sqrt(2) */ 206 ln2a = {{0xfefa3800, 0x3fe62e42}}, /* ln(2) 43 bits */ 207 ln2b = {{0x93c76730, 0x3d2ef357}}, /* ln(2)-ln2a */ 208 bigu = {{0xfffffd2c, 0x4297ffff}}, /* 1.5*2**42 -724*2**-10 */ 209 bigv = {{0xfff8016a, 0x4207ffff}}, /* 1.5*2**33-1+362*2**-19 */ 210 t52 = {{0x00000000, 0x43300000}}, /* 2**52 */ 211 two52e = {{0x000003ff, 0x43300000}}, /* 2**52' */ 212 t256 = {{0, 0x4ff00000}}, /* 2^256 */ 213 ln_two1 = {{0xFEFA3800, 0x3FE62E42}}, /* 0.69314718055989033 */ 214 ln_two2 = {{0x93C76730, 0x3D2EF357}}, /* 5.4979230187083712e-14 */ 215 log2e = {{0x652B82FE, 0x3FF71547}}, /* 1.4426950408889634 */ 216 ep2 = {{0x000004DC, 0x3FE00000}}, /* 0.50000000000013811 */ 217 ep3 = {{0x55555A0F, 0x3FC55555}}, /* 0.16666666666670024 */ 218 three33 = {{0, 0x42180000}}, /* 25769803776 */ 219 three51 = {{0, 0x43380000}}; /* 6755399441055744 */ 220 221 const static float64_t 222 p2 = -0.5, p3 = 3.3333333333333333333e-1, p4 = -0.25, 223 q2 = -0.5, q3 = 3.3333333333331404e-01, q4 = -2.4999999999996436e-01, 224 q5 = 2.0000010500004459e-01, q6 = -1.6666678916688004e-01, 225 r3 = 3.33333333333333333372884096563030E-01, 226 r4 = -2.50000000000000000213574153875908E-01, 227 r5 = 1.99999999999683593814072199830603E-01, 228 r6 = -1.66666666666065494878165510225378E-01, 229 r7 = 1.42857517857114380606360005067609E-01, 230 r8 = -1.25000449999974370683775964001702E-01, 231 s3 = 0.333251953125000000e0, 232 ss3 = 8.138020833333333333e-05, 233 s4 = -2.500000000000000000e-01, 234 s5 = 1.999999999999960937e-01, 235 s6 = -1.666666666666592447e-01, 236 s7 = 1.428571845238194705e-01; 237 238 const static float64_t huge = 1.0e300, tiny = 1.0e-300; 239 const static float64_t err_0 = 1.000014, err_1 = 0.000016, zero = 0.0; 240 const static q31_t bigint = 0x40862002, 241 badint = 0x40876000, smallint = 0x3C8fffff; 242 const static q31_t hugeint = 0x7fffffff, infint = 0x7ff00000; 243 244 static const mynumber 245 /* polynomial I */ 246 a2 = {{0x0001aa8f, 0xbfe00000} }, /* -0.500... */ 247 a3 = {{0x55588d2e, 0x3fd55555} }, /* 0.333... */ 248 /* polynomial II */ 249 b0 = {{0x55555555, 0x3fd55555} }, /* 0.333... */ 250 b1 = {{0xffffffbb, 0xbfcfffff} }, /* -0.249... */ 251 b2 = {{0x9999992f, 0x3fc99999} }, /* 0.199... */ 252 b3 = {{0x556503fd, 0xbfc55555} }, /* -0.166... */ 253 b4 = {{0x925b3d62, 0x3fc24924} }, /* 0.142... */ 254 b5 = {{0x160472fc, 0xbfbffffe} }, /* -0.124... */ 255 b6 = {{0x25db58ac, 0x3fbc71c5} }, /* 0.111... */ 256 b7 = {{0x11a2a61c, 0xbfb9a4ac} }, /* -0.100... */ 257 b8 = {{0x0df2b591, 0x3fb75077} }, /* 0.091... */ 258 /* polynomial III */ 259 c2 = {{0x00000000, 0xbfe00000} }, /* -1/2 */ 260 c3 = {{0x55555555, 0x3fd55555} }, /* 1/3 */ 261 c4 = {{0x00000000, 0xbfd00000} }, /* -1/4 */ 262 c5 = {{0x9999999a, 0x3fc99999} }, /* 1/5 */ 263 /* polynomial IV */ 264 d2 = {{0x00000000, 0xbfe00000} }, /* -1/2 */ 265 dd2 = {{0x00000000, 0x00000000} }, /* -1/2-d2 */ 266 d3 = {{0x55555555, 0x3fd55555} }, /* 1/3 */ 267 dd3 = {{0x55555555, 0x3c755555} }, /* 1/3-d3 */ 268 d4 = {{0x00000000, 0xbfd00000} }, /* -1/4 */ 269 dd4 = {{0x00000000, 0x00000000} }, /* -1/4-d4 */ 270 d5 = {{0x9999999a, 0x3fc99999} }, /* 1/5 */ 271 dd5 = {{0x9999999a, 0xbc699999} }, /* 1/5-d5 */ 272 d6 = {{0x55555555, 0xbfc55555} }, /* -1/6 */ 273 dd6 = {{0x55555555, 0xbc655555} }, /* -1/6-d6 */ 274 d7 = {{0x92492492, 0x3fc24924} }, /* 1/7 */ 275 dd7 = {{0x92492492, 0x3c624924} }, /* 1/7-d7 */ 276 d8 = {{0x00000000, 0xbfc00000} }, /* -1/8 */ 277 dd8 = {{0x00000000, 0x00000000} }, /* -1/8-d8 */ 278 d9 = {{0x1c71c71c, 0x3fbc71c7} }, /* 1/9 */ 279 dd9 = {{0x1c71c71c, 0x3c5c71c7} }, /* 1/9-d9 */ 280 d10 = {{0x9999999a, 0xbfb99999} }, /* -1/10 */ 281 dd10 = {{0x9999999a, 0x3c599999} }, /* -1/10-d10 */ 282 d11 = {{0x745d1746, 0x3fb745d1} }, /* 1/11 */ 283 d12 = {{0x55555555, 0xbfb55555} }, /* -1/12 */ 284 d13 = {{0x13b13b14, 0x3fb3b13b} }, /* 1/13 */ 285 d14 = {{0x92492492, 0xbfb24924} }, /* -1/14 */ 286 d15 = {{0x11111111, 0x3fb11111} }, /* 1/15 */ 287 d16 = {{0x00000000, 0xbfb00000} }, /* -1/16 */ 288 d17 = {{0x1e1e1e1e, 0x3fae1e1e} }, /* 1/17 */ 289 d18 = {{0x1c71c71c, 0xbfac71c7} }, /* -1/18 */ 290 d19 = {{0xbca1af28, 0x3faaf286} }, /* 1/19 */ 291 d20 = {{0x9999999a, 0xbfa99999} }, /* -1/20 */ 292 /* constants */ 293 h1 = {{0x00000000, 0x3fd2e000} }, /* 151/2**9 */ 294 h2 = {{0x00000000, 0x3f669000} }, /* 361/2**17 */ 295 delu = {{0x00000000, 0x3f700000} }, /* 1/2**8 */ 296 delv = {{0x00000000, 0x3ef00000} }, /* 1/2**16 */ 297 e1 = {{0x00000000, 0x3bbcc868} }, /* 6.095e-21 */ 298 e2 = {{0x00000000, 0x3c1138ce} }, /* 2.334e-19 */ 299 e3 = {{0x00000000, 0x3aa1565d} }, /* 2.801e-26 */ 300 e4 = {{0x00000000, 0x39809d88} }, /* 1.024e-31 */ 301 e[4] = {{{0x00000000, 0x37da223a} }, /* 1.2e-39 */ 302 {{0x00000000, 0x35c851c4} }, /* 1.3e-49 */ 303 {{0x00000000, 0x2ab85e51} }, /* 6.8e-103 */ 304 {{0x00000000, 0x17383827} }}, /* 8.1e-197 */ 305 two54 = {{0x00000000, 0x43500000} }, /* 2**54 */ 306 u03 = {{0xeb851eb8, 0x3f9eb851} }; /* 0.03 */ 307 308 #define SQRT_2 sqrt_2.x 309 #define DEL_U delu.x 310 #define DEL_V delv.x 311 #define LN2A ln2a.x 312 #define LN2B ln2b.x 313 #define E1 e1.x 314 #define E2 e2.x 315 #define E3 e3.x 316 #define E4 e4.x 317 #define U03 u03.x 318 #define HALF 0x1.0p-1 /* 1/2 */ 319 #define MHALF (-0x1.0p-1) /* -1/2 */ 320 321 /* coeffient for log2 funtion */ 322 static const float64_t 323 ln2 = 0.69314718055994530942, 324 two54_d = 1.80143985094819840000e+16, /* 43500000 00000000 */ 325 Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ 326 Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ 327 Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ 328 Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ 329 Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ 330 Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ 331 Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ 332 333 /* coeffient for log10 function */ 334 static const float64_t 335 ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ 336 log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ 337 log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ 338 339 /* constant for log10 function */ 340 static const float64_t 341 TWO1023 = 8.988465674311579539e+307, 342 TWOM1000 = 9.3326361850321887899e-302; 343 344 #endif /* CSKY_COMMON_TABLES_H */ 345