Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 1 | /*********************************************************************** |
| 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
| 3 | Redistribution and use in source and binary forms, with or without |
Jean-Marc Valin | ae00e60 | 2012-04-20 16:31:04 -0400 | [diff] [blame] | 4 | modification, are permitted provided that the following conditions |
| 5 | are met: |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 6 | - Redistributions of source code must retain the above copyright notice, |
| 7 | this list of conditions and the following disclaimer. |
| 8 | - Redistributions in binary form must reproduce the above copyright |
| 9 | notice, this list of conditions and the following disclaimer in the |
| 10 | documentation and/or other materials provided with the distribution. |
Ralph Giles | f2446c2 | 2013-09-16 14:40:04 -0700 | [diff] [blame] | 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the |
Jean-Marc Valin | ae00e60 | 2012-04-20 16:31:04 -0400 | [diff] [blame] | 12 | names of specific contributors, may be used to endorse or promote |
| 13 | products derived from this software without specific prior written |
| 14 | permission. |
Timothy B. Terriberry | 80ad383 | 2013-05-19 18:00:39 -0700 | [diff] [blame] | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Jean-Marc Valin | ae00e60 | 2012-04-20 16:31:04 -0400 | [diff] [blame] | 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | POSSIBILITY OF SUCH DAMAGE. |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 26 | ***********************************************************************/ |
| 27 | |
Ralph Giles | 120800f | 2011-11-25 13:02:00 -0800 | [diff] [blame] | 28 | #ifndef SIGPROCFIX_API_MACROCOUNT_H |
| 29 | #define SIGPROCFIX_API_MACROCOUNT_H |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 32 | #ifdef silk_MACRO_COUNT |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 33 | #define varDefine opus_int64 ops_count = 0; |
| 34 | |
| 35 | extern opus_int64 ops_count; |
| 36 | |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 37 | static OPUS_INLINE opus_int64 silk_SaveCount(){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 38 | return(ops_count); |
| 39 | } |
| 40 | |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 41 | static OPUS_INLINE opus_int64 silk_SaveResetCount(){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 42 | opus_int64 ret; |
| 43 | |
| 44 | ret = ops_count; |
| 45 | ops_count = 0; |
| 46 | return(ret); |
| 47 | } |
| 48 | |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 49 | static OPUS_INLINE silk_PrintCount(){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 50 | printf("ops_count = %d \n ", (opus_int32)ops_count); |
| 51 | } |
| 52 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 53 | #undef silk_MUL |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 54 | static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 55 | opus_int32 ret; |
| 56 | ops_count += 4; |
| 57 | ret = a32 * b32; |
| 58 | return ret; |
| 59 | } |
| 60 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 61 | #undef silk_MUL_uint |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 62 | static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 63 | opus_uint32 ret; |
| 64 | ops_count += 4; |
| 65 | ret = a32 * b32; |
| 66 | return ret; |
| 67 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 68 | #undef silk_MLA |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 69 | static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 70 | opus_int32 ret; |
| 71 | ops_count += 4; |
| 72 | ret = a32 + b32 * c32; |
| 73 | return ret; |
| 74 | } |
| 75 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 76 | #undef silk_MLA_uint |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 77 | static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 78 | opus_uint32 ret; |
| 79 | ops_count += 4; |
| 80 | ret = a32 + b32 * c32; |
| 81 | return ret; |
| 82 | } |
| 83 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 84 | #undef silk_SMULWB |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 85 | static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 86 | opus_int32 ret; |
| 87 | ops_count += 5; |
| 88 | ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16); |
| 89 | return ret; |
| 90 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 91 | #undef silk_SMLAWB |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 92 | static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 93 | opus_int32 ret; |
| 94 | ops_count += 5; |
| 95 | ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16))); |
| 96 | return ret; |
| 97 | } |
| 98 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 99 | #undef silk_SMULWT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 100 | static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 101 | opus_int32 ret; |
| 102 | ops_count += 4; |
| 103 | ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16); |
| 104 | return ret; |
| 105 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 106 | #undef silk_SMLAWT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 107 | static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 108 | opus_int32 ret; |
| 109 | ops_count += 4; |
| 110 | ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16)); |
| 111 | return ret; |
| 112 | } |
| 113 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 114 | #undef silk_SMULBB |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 115 | static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 116 | opus_int32 ret; |
| 117 | ops_count += 1; |
| 118 | ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32); |
| 119 | return ret; |
| 120 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 121 | #undef silk_SMLABB |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 122 | static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 123 | opus_int32 ret; |
| 124 | ops_count += 1; |
| 125 | ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32); |
| 126 | return ret; |
| 127 | } |
| 128 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 129 | #undef silk_SMULBT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 130 | static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 131 | opus_int32 ret; |
| 132 | ops_count += 4; |
| 133 | ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16); |
| 134 | return ret; |
| 135 | } |
| 136 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 137 | #undef silk_SMLABT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 138 | static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 139 | opus_int32 ret; |
| 140 | ops_count += 1; |
| 141 | ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16); |
| 142 | return ret; |
| 143 | } |
| 144 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 145 | #undef silk_SMULTT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 146 | static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 147 | opus_int32 ret; |
| 148 | ops_count += 1; |
| 149 | ret = (a32 >> 16) * (b32 >> 16); |
| 150 | return ret; |
| 151 | } |
| 152 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 153 | #undef silk_SMLATT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 154 | static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 155 | opus_int32 ret; |
| 156 | ops_count += 1; |
| 157 | ret = a32 + (b32 >> 16) * (c32 >> 16); |
| 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 162 | /* multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)*/ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 163 | #undef silk_MLA_ovflw |
| 164 | #define silk_MLA_ovflw silk_MLA |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 165 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 166 | #undef silk_SMLABB_ovflw |
| 167 | #define silk_SMLABB_ovflw silk_SMLABB |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 168 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 169 | #undef silk_SMLABT_ovflw |
| 170 | #define silk_SMLABT_ovflw silk_SMLABT |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 171 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 172 | #undef silk_SMLATT_ovflw |
| 173 | #define silk_SMLATT_ovflw silk_SMLATT |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 174 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 175 | #undef silk_SMLAWB_ovflw |
| 176 | #define silk_SMLAWB_ovflw silk_SMLAWB |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 177 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 178 | #undef silk_SMLAWT_ovflw |
| 179 | #define silk_SMLAWT_ovflw silk_SMLAWT |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 180 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 181 | #undef silk_SMULL |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 182 | static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 183 | opus_int64 ret; |
| 184 | ops_count += 8; |
| 185 | ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32)); |
| 186 | return ret; |
| 187 | } |
| 188 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 189 | #undef silk_SMLAL |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 190 | static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 191 | opus_int64 ret; |
| 192 | ops_count += 8; |
| 193 | ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32)); |
| 194 | return ret; |
| 195 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 196 | #undef silk_SMLALBB |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 197 | static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 198 | opus_int64 ret; |
| 199 | ops_count += 4; |
| 200 | ret = a64 + ((opus_int64)(b16) * /*(opus_int64)*/(c16)); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | #undef SigProcFIX_CLZ16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 205 | static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 206 | { |
| 207 | opus_int32 out32 = 0; |
| 208 | ops_count += 10; |
| 209 | if( in16 == 0 ) { |
| 210 | return 16; |
| 211 | } |
| 212 | /* test nibbles */ |
| 213 | if( in16 & 0xFF00 ) { |
| 214 | if( in16 & 0xF000 ) { |
| 215 | in16 >>= 12; |
| 216 | } else { |
| 217 | out32 += 4; |
| 218 | in16 >>= 8; |
| 219 | } |
| 220 | } else { |
| 221 | if( in16 & 0xFFF0 ) { |
| 222 | out32 += 8; |
| 223 | in16 >>= 4; |
| 224 | } else { |
| 225 | out32 += 12; |
| 226 | } |
| 227 | } |
| 228 | /* test bits and return */ |
| 229 | if( in16 & 0xC ) { |
| 230 | if( in16 & 0x8 ) |
| 231 | return out32 + 0; |
| 232 | else |
| 233 | return out32 + 1; |
| 234 | } else { |
| 235 | if( in16 & 0xE ) |
| 236 | return out32 + 2; |
| 237 | else |
| 238 | return out32 + 3; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | #undef SigProcFIX_CLZ32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 243 | static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 244 | { |
| 245 | /* test highest 16 bits and convert to opus_int16 */ |
| 246 | ops_count += 2; |
| 247 | if( in32 & 0xFFFF0000 ) { |
| 248 | return SigProcFIX_CLZ16((opus_int16)(in32 >> 16)); |
| 249 | } else { |
| 250 | return SigProcFIX_CLZ16((opus_int16)in32) + 16; |
| 251 | } |
| 252 | } |
| 253 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 254 | #undef silk_DIV32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 255 | static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 256 | ops_count += 64; |
| 257 | return a32 / b32; |
| 258 | } |
| 259 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 260 | #undef silk_DIV32_16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 261 | static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 262 | ops_count += 32; |
| 263 | return a32 / b32; |
| 264 | } |
| 265 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 266 | #undef silk_SAT8 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 267 | static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 268 | opus_int8 tmp; |
| 269 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 270 | tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \ |
| 271 | ((a) < silk_int8_MIN ? silk_int8_MIN : (a))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 272 | return(tmp); |
| 273 | } |
| 274 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 275 | #undef silk_SAT16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 276 | static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 277 | opus_int16 tmp; |
| 278 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 279 | tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \ |
| 280 | ((a) < silk_int16_MIN ? silk_int16_MIN : (a))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 281 | return(tmp); |
| 282 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 283 | #undef silk_SAT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 284 | static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 285 | opus_int32 tmp; |
| 286 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 287 | tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \ |
| 288 | ((a) < silk_int32_MIN ? silk_int32_MIN : (a))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 289 | return(tmp); |
| 290 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 291 | #undef silk_POS_SAT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 292 | static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 293 | opus_int32 tmp; |
| 294 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 295 | tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a)); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 296 | return(tmp); |
| 297 | } |
| 298 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 299 | #undef silk_ADD_POS_SAT8 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 300 | static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 301 | opus_int8 tmp; |
| 302 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 303 | tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 304 | return(tmp); |
| 305 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 306 | #undef silk_ADD_POS_SAT16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 307 | static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 308 | opus_int16 tmp; |
| 309 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 310 | tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 311 | return(tmp); |
| 312 | } |
| 313 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 314 | #undef silk_ADD_POS_SAT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 315 | static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 316 | opus_int32 tmp; |
| 317 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 318 | tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 319 | return(tmp); |
| 320 | } |
| 321 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 322 | #undef silk_ADD_POS_SAT64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 323 | static OPUS_INLINE opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 324 | opus_int64 tmp; |
| 325 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 326 | tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b))); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 327 | return(tmp); |
| 328 | } |
| 329 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 330 | #undef silk_LSHIFT8 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 331 | static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 332 | opus_int8 ret; |
| 333 | ops_count += 1; |
| 334 | ret = a << shift; |
| 335 | return ret; |
| 336 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 337 | #undef silk_LSHIFT16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 338 | static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 339 | opus_int16 ret; |
| 340 | ops_count += 1; |
| 341 | ret = a << shift; |
| 342 | return ret; |
| 343 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 344 | #undef silk_LSHIFT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 345 | static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 346 | opus_int32 ret; |
| 347 | ops_count += 1; |
| 348 | ret = a << shift; |
| 349 | return ret; |
| 350 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 351 | #undef silk_LSHIFT64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 352 | static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 353 | ops_count += 1; |
| 354 | return a << shift; |
| 355 | } |
| 356 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 357 | #undef silk_LSHIFT_ovflw |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 358 | static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 359 | ops_count += 1; |
| 360 | return a << shift; |
| 361 | } |
| 362 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 363 | #undef silk_LSHIFT_uint |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 364 | static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 365 | opus_uint32 ret; |
| 366 | ops_count += 1; |
| 367 | ret = a << shift; |
| 368 | return ret; |
| 369 | } |
| 370 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 371 | #undef silk_RSHIFT8 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 372 | static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 373 | ops_count += 1; |
| 374 | return a >> shift; |
| 375 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 376 | #undef silk_RSHIFT16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 377 | static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 378 | ops_count += 1; |
| 379 | return a >> shift; |
| 380 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 381 | #undef silk_RSHIFT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 382 | static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 383 | ops_count += 1; |
| 384 | return a >> shift; |
| 385 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 386 | #undef silk_RSHIFT64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 387 | static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 388 | ops_count += 1; |
| 389 | return a >> shift; |
| 390 | } |
| 391 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 392 | #undef silk_RSHIFT_uint |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 393 | static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 394 | ops_count += 1; |
| 395 | return a >> shift; |
| 396 | } |
| 397 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 398 | #undef silk_ADD_LSHIFT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 399 | static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 400 | opus_int32 ret; |
| 401 | ops_count += 1; |
| 402 | ret = a + (b << shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 403 | return ret; /* shift >= 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 404 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 405 | #undef silk_ADD_LSHIFT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 406 | static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 407 | opus_int32 ret; |
| 408 | ops_count += 1; |
| 409 | ret = a + (b << shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 410 | return ret; /* shift >= 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 411 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 412 | #undef silk_ADD_LSHIFT_uint |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 413 | static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 414 | opus_uint32 ret; |
| 415 | ops_count += 1; |
| 416 | ret = a + (b << shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 417 | return ret; /* shift >= 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 418 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 419 | #undef silk_ADD_RSHIFT |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 420 | static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 421 | opus_int32 ret; |
| 422 | ops_count += 1; |
| 423 | ret = a + (b >> shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 424 | return ret; /* shift > 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 425 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 426 | #undef silk_ADD_RSHIFT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 427 | static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 428 | opus_int32 ret; |
| 429 | ops_count += 1; |
| 430 | ret = a + (b >> shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 431 | return ret; /* shift > 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 432 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 433 | #undef silk_ADD_RSHIFT_uint |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 434 | static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 435 | opus_uint32 ret; |
| 436 | ops_count += 1; |
| 437 | ret = a + (b >> shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 438 | return ret; /* shift > 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 439 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 440 | #undef silk_SUB_LSHIFT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 441 | static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 442 | opus_int32 ret; |
| 443 | ops_count += 1; |
| 444 | ret = a - (b << shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 445 | return ret; /* shift >= 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 446 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 447 | #undef silk_SUB_RSHIFT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 448 | static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 449 | opus_int32 ret; |
| 450 | ops_count += 1; |
| 451 | ret = a - (b >> shift); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 452 | return ret; /* shift > 0*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 453 | } |
| 454 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 455 | #undef silk_RSHIFT_ROUND |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 456 | static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 457 | opus_int32 ret; |
| 458 | ops_count += 3; |
| 459 | ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; |
| 460 | return ret; |
| 461 | } |
| 462 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 463 | #undef silk_RSHIFT_ROUND64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 464 | static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 465 | opus_int64 ret; |
| 466 | ops_count += 6; |
| 467 | ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; |
| 468 | return ret; |
| 469 | } |
| 470 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 471 | #undef silk_abs_int64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 472 | static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 473 | ops_count += 1; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 474 | return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 475 | } |
| 476 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 477 | #undef silk_abs_int32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 478 | static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 479 | ops_count += 1; |
Gregory Maxwell | e052947 | 2012-05-23 01:52:39 -0400 | [diff] [blame] | 480 | return silk_abs(a); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 484 | #undef silk_min |
| 485 | static silk_min(a, b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 486 | ops_count += 1; |
| 487 | return (((a) < (b)) ? (a) : (b)); |
| 488 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 489 | #undef silk_max |
| 490 | static silk_max(a, b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 491 | ops_count += 1; |
| 492 | return (((a) > (b)) ? (a) : (b)); |
| 493 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 494 | #undef silk_sign |
| 495 | static silk_sign(a){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 496 | ops_count += 1; |
| 497 | return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )); |
| 498 | } |
| 499 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 500 | #undef silk_ADD16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 501 | static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 502 | opus_int16 ret; |
| 503 | ops_count += 1; |
| 504 | ret = a + b; |
| 505 | return ret; |
| 506 | } |
| 507 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 508 | #undef silk_ADD32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 509 | static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 510 | opus_int32 ret; |
| 511 | ops_count += 1; |
| 512 | ret = a + b; |
| 513 | return ret; |
| 514 | } |
| 515 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 516 | #undef silk_ADD64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 517 | static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 518 | opus_int64 ret; |
| 519 | ops_count += 2; |
| 520 | ret = a + b; |
| 521 | return ret; |
| 522 | } |
| 523 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 524 | #undef silk_SUB16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 525 | static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 526 | opus_int16 ret; |
| 527 | ops_count += 1; |
| 528 | ret = a - b; |
| 529 | return ret; |
| 530 | } |
| 531 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 532 | #undef silk_SUB32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 533 | static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 534 | opus_int32 ret; |
| 535 | ops_count += 1; |
| 536 | ret = a - b; |
| 537 | return ret; |
| 538 | } |
| 539 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 540 | #undef silk_SUB64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 541 | static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 542 | opus_int64 ret; |
| 543 | ops_count += 2; |
| 544 | ret = a - b; |
| 545 | return ret; |
| 546 | } |
| 547 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 548 | #undef silk_ADD_SAT16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 549 | static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) { |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 550 | opus_int16 res; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 551 | /* Nb will be counted in AKP_add32 and silk_SAT16*/ |
| 552 | res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 553 | return res; |
| 554 | } |
| 555 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 556 | #undef silk_ADD_SAT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 557 | static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 558 | opus_int32 res; |
| 559 | ops_count += 1; |
| 560 | res = ((((a32) + (b32)) & 0x80000000) == 0 ? \ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 561 | ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \ |
| 562 | ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 563 | return res; |
| 564 | } |
| 565 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 566 | #undef silk_ADD_SAT64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 567 | static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) { |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 568 | opus_int64 res; |
| 569 | ops_count += 1; |
| 570 | res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 571 | ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \ |
| 572 | ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 573 | return res; |
| 574 | } |
| 575 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 576 | #undef silk_SUB_SAT16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 577 | static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) { |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 578 | opus_int16 res; |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 579 | silk_assert(0); |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 580 | /* Nb will be counted in sub-macros*/ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 581 | res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 582 | return res; |
| 583 | } |
| 584 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 585 | #undef silk_SUB_SAT32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 586 | static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) { |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 587 | opus_int32 res; |
| 588 | ops_count += 1; |
| 589 | res = ((((a32)-(b32)) & 0x80000000) == 0 ? \ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 590 | (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \ |
| 591 | ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 592 | return res; |
| 593 | } |
| 594 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 595 | #undef silk_SUB_SAT64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 596 | static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) { |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 597 | opus_int64 res; |
| 598 | ops_count += 1; |
| 599 | res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 600 | (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \ |
| 601 | ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 602 | |
| 603 | return res; |
| 604 | } |
| 605 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 606 | #undef silk_SMULWW |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 607 | static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 608 | opus_int32 ret; |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 609 | /* Nb will be counted in sub-macros*/ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 610 | ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 611 | return ret; |
| 612 | } |
| 613 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 614 | #undef silk_SMLAWW |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 615 | static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 616 | opus_int32 ret; |
Jean-Marc Valin | ccaa6d2 | 2011-08-28 02:09:55 -0400 | [diff] [blame] | 617 | /* Nb will be counted in sub-macros*/ |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 618 | ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16)); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 619 | return ret; |
| 620 | } |
| 621 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 622 | #undef silk_min_int |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 623 | static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 624 | { |
| 625 | ops_count += 1; |
| 626 | return (((a) < (b)) ? (a) : (b)); |
| 627 | } |
| 628 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 629 | #undef silk_min_16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 630 | static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 631 | { |
| 632 | ops_count += 1; |
| 633 | return (((a) < (b)) ? (a) : (b)); |
| 634 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 635 | #undef silk_min_32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 636 | static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 637 | { |
| 638 | ops_count += 1; |
| 639 | return (((a) < (b)) ? (a) : (b)); |
| 640 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 641 | #undef silk_min_64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 642 | static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 643 | { |
| 644 | ops_count += 1; |
| 645 | return (((a) < (b)) ? (a) : (b)); |
| 646 | } |
| 647 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 648 | /* silk_min() versions with typecast in the function call */ |
| 649 | #undef silk_max_int |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 650 | static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 651 | { |
| 652 | ops_count += 1; |
| 653 | return (((a) > (b)) ? (a) : (b)); |
| 654 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 655 | #undef silk_max_16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 656 | static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 657 | { |
| 658 | ops_count += 1; |
| 659 | return (((a) > (b)) ? (a) : (b)); |
| 660 | } |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 661 | #undef silk_max_32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 662 | static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 663 | { |
| 664 | ops_count += 1; |
| 665 | return (((a) > (b)) ? (a) : (b)); |
| 666 | } |
| 667 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 668 | #undef silk_max_64 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 669 | static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 670 | { |
| 671 | ops_count += 1; |
| 672 | return (((a) > (b)) ? (a) : (b)); |
| 673 | } |
| 674 | |
| 675 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 676 | #undef silk_LIMIT_int |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 677 | static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 678 | { |
| 679 | opus_int ret; |
| 680 | ops_count += 6; |
| 681 | |
| 682 | ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ |
| 683 | : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); |
| 684 | |
| 685 | return(ret); |
| 686 | } |
| 687 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 688 | #undef silk_LIMIT_16 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 689 | static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 690 | { |
| 691 | opus_int16 ret; |
| 692 | ops_count += 6; |
| 693 | |
| 694 | ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ |
| 695 | : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); |
| 696 | |
| 697 | return(ret); |
| 698 | } |
| 699 | |
| 700 | |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 701 | #undef silk_LIMIT_32 |
Gregory Maxwell | 7830cf1 | 2013-10-17 15:56:52 -0700 | [diff] [blame] | 702 | static OPUS_INLINE opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2) |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 703 | { |
| 704 | opus_int32 ret; |
| 705 | ops_count += 6; |
| 706 | |
| 707 | ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ |
| 708 | : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); |
| 709 | return(ret); |
| 710 | } |
| 711 | |
| 712 | #else |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 713 | #define varDefine |
Jean-Marc Valin | fb3a437 | 2011-09-16 00:58:26 -0700 | [diff] [blame] | 714 | #define silk_SaveCount() |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 715 | |
| 716 | #endif |
| 717 | #endif |
| 718 | |