OLD | NEW |
1 /* Copyright (C) 2007-2009 Xiph.Org Foundation | 1 /* Copyright (C) 2007-2009 Xiph.Org Foundation |
2 Copyright (C) 2003-2008 Jean-Marc Valin | 2 Copyright (C) 2003-2008 Jean-Marc Valin |
3 Copyright (C) 2007-2008 CSIRO */ | 3 Copyright (C) 2007-2008 CSIRO */ |
4 /** | 4 /** |
5 @file fixed_generic.h | 5 @file fixed_generic.h |
6 @brief Generic fixed-point operations | 6 @brief Generic fixed-point operations |
7 */ | 7 */ |
8 /* | 8 /* |
9 Redistribution and use in source and binary forms, with or without | 9 Redistribution and use in source and binary forms, with or without |
10 modification, are permitted provided that the following conditions | 10 modification, are permitted provided that the following conditions |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 /** "RAW" macros, should not be used outside of this header file */ | 97 /** "RAW" macros, should not be used outside of this header file */ |
98 #define SHR(a,shift) ((a) >> (shift)) | 98 #define SHR(a,shift) ((a) >> (shift)) |
99 #define SHL(a,shift) SHL32(a,shift) | 99 #define SHL(a,shift) SHL32(a,shift) |
100 #define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) | 100 #define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) |
101 #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) | 101 #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) |
102 | 102 |
103 #define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x))) | 103 #define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x))) |
104 | 104 |
105 /** Shift by a and round-to-neareast 32-bit value. Result is a 16-bit value */ | 105 /** Shift by a and round-to-neareast 32-bit value. Result is a 16-bit value */ |
106 #define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a)))) | 106 #define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a)))) |
| 107 /** Shift by a and round-to-neareast 32-bit value. Result is a saturated 16-bit
value */ |
| 108 #define SROUND16(x,a) EXTRACT16(SATURATE(PSHR32(x,a), 32767)); |
| 109 |
107 /** Divide by two */ | 110 /** Divide by two */ |
108 #define HALF16(x) (SHR16(x,1)) | 111 #define HALF16(x) (SHR16(x,1)) |
109 #define HALF32(x) (SHR32(x,1)) | 112 #define HALF32(x) (SHR32(x,1)) |
110 | 113 |
111 /** Add two 16-bit values */ | 114 /** Add two 16-bit values */ |
112 #define ADD16(a,b) ((opus_val16)((opus_val16)(a)+(opus_val16)(b))) | 115 #define ADD16(a,b) ((opus_val16)((opus_val16)(a)+(opus_val16)(b))) |
113 /** Subtract two 16-bit values */ | 116 /** Subtract two 16-bit values */ |
114 #define SUB16(a,b) ((opus_val16)(a)-(opus_val16)(b)) | 117 #define SUB16(a,b) ((opus_val16)(a)-(opus_val16)(b)) |
115 /** Add two 32-bit values */ | 118 /** Add two 32-bit values */ |
116 #define ADD32(a,b) ((opus_val32)(a)+(opus_val32)(b)) | 119 #define ADD32(a,b) ((opus_val32)(a)+(opus_val32)(b)) |
117 /** Subtract two 32-bit values */ | 120 /** Subtract two 32-bit values */ |
118 #define SUB32(a,b) ((opus_val32)(a)-(opus_val32)(b)) | 121 #define SUB32(a,b) ((opus_val32)(a)-(opus_val32)(b)) |
119 | 122 |
| 123 /** Add two 32-bit values, ignore any overflows */ |
| 124 #define ADD32_ovflw(a,b) ((opus_val32)((opus_uint32)(a)+(opus_uint32)(b))) |
| 125 /** Subtract two 32-bit values, ignore any overflows */ |
| 126 #define SUB32_ovflw(a,b) ((opus_val32)((opus_uint32)(a)-(opus_uint32)(b))) |
| 127 /* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */ |
| 128 /** Negate 32-bit value, ignore any overflows */ |
| 129 #define NEG32_ovflw(a) ((opus_val32)(0-(opus_uint32)(a))) |
| 130 |
120 /** 16x16 multiplication where the result fits in 16 bits */ | 131 /** 16x16 multiplication where the result fits in 16 bits */ |
121 #define MULT16_16_16(a,b) ((((opus_val16)(a))*((opus_val16)(b)))) | 132 #define MULT16_16_16(a,b) ((((opus_val16)(a))*((opus_val16)(b)))) |
122 | 133 |
123 /* (opus_val32)(opus_val16) gives TI compiler a hint that it's 16x16->32 multipl
y */ | 134 /* (opus_val32)(opus_val16) gives TI compiler a hint that it's 16x16->32 multipl
y */ |
124 /** 16x16 multiplication where the result fits in 32 bits */ | 135 /** 16x16 multiplication where the result fits in 32 bits */ |
125 #define MULT16_16(a,b) (((opus_val32)(opus_val16)(a))*((opus_val32)(opus_val
16)(b))) | 136 #define MULT16_16(a,b) (((opus_val32)(opus_val16)(a))*((opus_val32)(opus_val
16)(b))) |
126 | 137 |
127 /** 16x16 multiply-add where the result fits in 32 bits */ | 138 /** 16x16 multiply-add where the result fits in 32 bits */ |
128 #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) | 139 #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) |
129 /** 16x32 multiply, followed by a 15-bit shift right and 32-bit add. | 140 /** 16x32 multiply, followed by a 15-bit shift right and 32-bit add. |
(...skipping 28 matching lines...) Expand all Loading... |
158 static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x) | 169 static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x) |
159 { | 170 { |
160 x = PSHR32(x, SIG_SHIFT); | 171 x = PSHR32(x, SIG_SHIFT); |
161 x = MAX32(x, -32768); | 172 x = MAX32(x, -32768); |
162 x = MIN32(x, 32767); | 173 x = MIN32(x, 32767); |
163 return EXTRACT16(x); | 174 return EXTRACT16(x); |
164 } | 175 } |
165 #define SIG2WORD16(x) (SIG2WORD16_generic(x)) | 176 #define SIG2WORD16(x) (SIG2WORD16_generic(x)) |
166 | 177 |
167 #endif | 178 #endif |
OLD | NEW |