FreeCalypso > hg > gsm-codec-lib
comparison libgsmefr/basic_op.h @ 350:9b05bbc23b8a
libgsmefr inline: make shift count guards 100% robust
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 Apr 2024 05:34:54 +0000 |
parents | ed8762eea8a1 |
children |
comparison
equal
deleted
inserted
replaced
349:ed8762eea8a1 | 350:9b05bbc23b8a |
---|---|
2 * This version of basic_op.h for GSM-EFR codec has been created at | 2 * This version of basic_op.h for GSM-EFR codec has been created at |
3 * Themyscira Wireless with the aim of performance improvement. | 3 * Themyscira Wireless with the aim of performance improvement. |
4 * The original version contained only function declarations, | 4 * The original version contained only function declarations, |
5 * resulting in a function call for every elementary operation; | 5 * resulting in a function call for every elementary operation; |
6 * the present version implements most of these operations as inline | 6 * the present version implements most of these operations as inline |
7 * functions. (Further update: for extra speed-up, the some inline | 7 * functions. (Further update: for extra speed-up, some inline |
8 * function implementations have been lifted from PacketVideo AMR | 8 * function implementations have been lifted from PacketVideo AMR |
9 * version, aka libopencore-amrnb.) | 9 * version, aka libopencore-amrnb.) |
10 * | 10 * |
11 * Elimination of Overflow flag: examination of EFR code reveals that | 11 * Elimination of Overflow flag: examination of EFR code reveals that |
12 * both Carry and Overflow flags are accessed outside of basicop2.c | 12 * both Carry and Overflow flags are accessed outside of basicop2.c |
204 static inline Word16 shl (Word16 var1, Word16 var2) | 204 static inline Word16 shl (Word16 var1, Word16 var2) |
205 { | 205 { |
206 Word16 var_out; | 206 Word16 var_out; |
207 | 207 |
208 if (unlikely(var2 < 0)) { | 208 if (unlikely(var2 < 0)) { |
209 if (unlikely(var2 < -15)) | |
210 var2 = -15; | |
209 var2 = -var2; | 211 var2 = -var2; |
210 if (unlikely(var2 > 15)) | |
211 var2 = 15; | |
212 var_out = var1 >> var2; | 212 var_out = var1 >> var2; |
213 } else { | 213 } else { |
214 if (unlikely(var2 > 15)) | 214 if (unlikely(var2 > 15)) |
215 var2 = 15; | 215 var2 = 15; |
216 var_out = var1 << var2; | 216 var_out = var1 << var2; |
260 static inline Word16 shr (Word16 var1, Word16 var2) | 260 static inline Word16 shr (Word16 var1, Word16 var2) |
261 { | 261 { |
262 Word16 var_out; | 262 Word16 var_out; |
263 | 263 |
264 if (unlikely(var2 < 0)) { | 264 if (unlikely(var2 < 0)) { |
265 if (unlikely(var2 < -15)) | |
266 var2 = -15; | |
265 var2 = -var2; | 267 var2 = -var2; |
266 if (unlikely(var2 > 15)) | |
267 var2 = 15; | |
268 var_out = var1 << var2; | 268 var_out = var1 << var2; |
269 if (unlikely(var_out >> var2 != var1)) | 269 if (unlikely(var_out >> var2 != var1)) |
270 { | 270 { |
271 var_out = (var1 >> 15) ^ MAX_16; | 271 var_out = (var1 >> 15) ^ MAX_16; |
272 } | 272 } |
798 static inline Word32 L_shl (Word32 L_var1, Word16 var2) | 798 static inline Word32 L_shl (Word32 L_var1, Word16 var2) |
799 { | 799 { |
800 Word32 L_var_out; | 800 Word32 L_var_out; |
801 | 801 |
802 if (unlikely(var2 < 0)) { | 802 if (unlikely(var2 < 0)) { |
803 if (unlikely(var2 < -31)) | |
804 var2 = -31; | |
803 var2 = -var2; | 805 var2 = -var2; |
804 if (unlikely(var2 > 31)) | |
805 var2 = 31; | |
806 L_var_out = L_var1 >> var2; | 806 L_var_out = L_var1 >> var2; |
807 } else { | 807 } else { |
808 if (unlikely(var2 > 31)) | 808 if (unlikely(var2 > 31)) |
809 var2 = 31; | 809 var2 = 31; |
810 L_var_out = L_var1 << var2; | 810 L_var_out = L_var1 << var2; |
851 static inline Word32 L_shr (Word32 L_var1, Word16 var2) | 851 static inline Word32 L_shr (Word32 L_var1, Word16 var2) |
852 { | 852 { |
853 Word32 L_var_out; | 853 Word32 L_var_out; |
854 | 854 |
855 if (unlikely(var2 < 0)) { | 855 if (unlikely(var2 < 0)) { |
856 if (unlikely(var2 < -31)) | |
857 var2 = -31; | |
856 var2 = -var2; | 858 var2 = -var2; |
857 if (unlikely(var2 > 31)) | |
858 var2 = 31; | |
859 L_var_out = L_var1 << var2; | 859 L_var_out = L_var1 << var2; |
860 if (unlikely(L_var_out >> var2 != L_var1)) | 860 if (unlikely(L_var_out >> var2 != L_var1)) |
861 L_var_out = (L_var1 >> 31) ^ MAX_32; | 861 L_var_out = (L_var1 >> 31) ^ MAX_32; |
862 } else { | 862 } else { |
863 if (unlikely(var2 > 31)) | 863 if (unlikely(var2 > 31)) |