| OLD | NEW |
| 1 /* Copyright (c) 2002-2008 Jean-Marc Valin | 1 /* Copyright (c) 2002-2008 Jean-Marc Valin |
| 2 Copyright (c) 2007-2008 CSIRO | 2 Copyright (c) 2007-2008 CSIRO |
| 3 Copyright (c) 2007-2009 Xiph.Org Foundation | 3 Copyright (c) 2007-2009 Xiph.Org Foundation |
| 4 Written by Jean-Marc Valin */ | 4 Written by Jean-Marc Valin */ |
| 5 /** | 5 /** |
| 6 @file mathops.h | 6 @file mathops.h |
| 7 @brief Various math functions | 7 @brief Various math functions |
| 8 */ | 8 */ |
| 9 /* | 9 /* |
| 10 Redistribution and use in source and binary forms, with or without | 10 Redistribution and use in source and binary forms, with or without |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 /** Sqrt approximation (QX input, QX/2 output) */ | 117 /** Sqrt approximation (QX input, QX/2 output) */ |
| 118 opus_val32 celt_sqrt(opus_val32 x) | 118 opus_val32 celt_sqrt(opus_val32 x) |
| 119 { | 119 { |
| 120 int k; | 120 int k; |
| 121 opus_val16 n; | 121 opus_val16 n; |
| 122 opus_val32 rt; | 122 opus_val32 rt; |
| 123 static const opus_val16 C[5] = {23175, 11561, -3011, 1699, -664}; | 123 static const opus_val16 C[5] = {23175, 11561, -3011, 1699, -664}; |
| 124 if (x==0) | 124 if (x==0) |
| 125 return 0; | 125 return 0; |
| 126 else if (x>=1073741824) |
| 127 return 32767; |
| 126 k = (celt_ilog2(x)>>1)-7; | 128 k = (celt_ilog2(x)>>1)-7; |
| 127 x = VSHR32(x, 2*k); | 129 x = VSHR32(x, 2*k); |
| 128 n = x-32768; | 130 n = x-32768; |
| 129 rt = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], | 131 rt = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], |
| 130 MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, (C[4]))))))))); | 132 MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, (C[4]))))))))); |
| 131 rt = VSHR32(rt,7-k); | 133 rt = VSHR32(rt,7-k); |
| 132 return rt; | 134 return rt; |
| 133 } | 135 } |
| 134 | 136 |
| 135 #define L1 32767 | 137 #define L1 32767 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 neatly compensates for truncation error in the rest of the process. */ | 199 neatly compensates for truncation error in the rest of the process. */ |
| 198 r = SUB16(r, ADD16(1, MULT16_16_Q15(r, | 200 r = SUB16(r, ADD16(1, MULT16_16_Q15(r, |
| 199 ADD16(MULT16_16_Q15(r, n), ADD16(r, -32768))))); | 201 ADD16(MULT16_16_Q15(r, n), ADD16(r, -32768))))); |
| 200 /* r is now the Q15 solution to 2/(n+1), with a maximum relative error | 202 /* r is now the Q15 solution to 2/(n+1), with a maximum relative error |
| 201 of 7.05346E-5, a (relative) RMSE of 2.14418E-5, and a peak absolute | 203 of 7.05346E-5, a (relative) RMSE of 2.14418E-5, and a peak absolute |
| 202 error of 1.24665/32768. */ | 204 error of 1.24665/32768. */ |
| 203 return VSHR32(EXTEND32(r),i-16); | 205 return VSHR32(EXTEND32(r),i-16); |
| 204 } | 206 } |
| 205 | 207 |
| 206 #endif | 208 #endif |
| OLD | NEW |