1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2010 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Pathname: ./src/pvamrwbdecoder_basic_op.h
36 ------------------------------------------------------------------------------
39 ------------------------------------------------------------------------------
43 #ifndef PVAMRWBDECODER_BASIC_OP_H
44 #define PVAMRWBDECODER_BASIC_OP_H
47 #include "normalize_amr_wb.h"
50 #define MAX_32 (int32)0x7fffffffL
51 #define MIN_32 (int32)0x80000000L
53 #define MAX_16 (int16)+32767 /* 0x7fff */
54 #define MIN_16 (int16)-32768 /* 0x8000 */
59 /*----------------------------------------------------------------------------
60 Function Name : negate_int16
62 Negate var1 with saturation, saturate in the case where input is -32768:
63 negate(var1) = sub(0,var1).
67 16 bit short signed integer (int16) whose value falls in the
68 range : 0x8000 <= var1 <= 0x7fff.
74 16 bit short signed integer (int16) whose value falls in the
75 range : 0x8000 <= var_out <= 0x7fff.
76 ----------------------------------------------------------------------------*/
78 static inline int16 negate_int16(int16 var1)
80 return (((var1 == MIN_16) ? MAX_16 : -var1));
84 /*----------------------------------------------------------------------------
86 Function Name : shl_int16
88 Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill
89 the var2 LSB of the result. If var2 is negative, arithmetically shift
90 var1 right by -var2 with sign extension. Saturate the result in case of
91 underflows or overflows.
95 16 bit short signed integer (int16) whose value falls in the
96 range : 0x8000 <= var1 <= 0x7fff.
99 16 bit short signed integer (int16) whose value falls in the
100 range : 0x8000 <= var1 <= 0x7fff.
104 16 bit short signed integer (int16) whose value falls in the
105 range : 0x8000 <= var_out <= 0x7fff.
106 ----------------------------------------------------------------------------*/
108 static inline int16 shl_int16(int16 var1, int16 var2)
114 var2 = (-var2) & (0xf);
115 var_out = var1 >> var2;
120 var_out = var1 << var2;
121 if (var_out >> var2 != var1)
123 var_out = (var1 >> 15) ^ MAX_16;
130 /*----------------------------------------------------------------------------
132 Function Name : shl_int32
134 Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero
135 fill the var2 LSB of the result. If var2 is negative, arithmetically
136 shift L_var1 right by -var2 with sign extension. Saturate the result in
137 case of underflows or overflows.
140 L_var1 32 bit long signed integer (int32) whose value falls in the
141 range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
144 16 bit short signed integer (int16) whose value falls in the
145 range : 8000 <= var2 <= 7fff.
147 32 bit long signed integer (int32) whose value falls in the
148 range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
150 ----------------------------------------------------------------------------*/
152 static inline int32 shl_int32(int32 L_var1, int16 var2)
158 L_var_out = L_var1 << var2;
159 if (L_var_out >> var2 != L_var1)
161 L_var_out = (L_var1 >> 31) ^ MAX_32;
166 var2 = (-var2) & (0xf);
167 L_var_out = L_var1 >> var2;
174 /*----------------------------------------------------------------------------
176 Function Name : shr_int32
178 Arithmetically shift the 32 bit input L_var1 right var2 positions with
179 sign extension. If var2 is negative, arithmetically shift L_var1 left
180 by -var2 and zero fill the -var2 LSB of the result. Saturate the result
181 in case of underflows or overflows.
184 L_var1 32 bit long signed integer (int32) whose value falls in the
185 range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
188 16 bit short signed integer (int16) whose value falls in the
189 range : 8000 <= var2 <= 7fff.
191 32 bit long signed integer (int32) whose value falls in the
192 range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
194 ----------------------------------------------------------------------------*/
196 static inline int32 shr_int32(int32 L_var1, int16 var2)
202 L_var_out = L_var1 >> (var2 & 0x1f);
206 var2 = (int16)(-var2);
208 L_var_out = L_var1 << var2;
209 if (L_var_out >> var2 != L_var1)
211 L_var_out = (L_var1 >> 31) ^ MAX_32;
223 #if ((PV_CPU_ARCH_VERSION >=5) && (PV_COMPILER == EPV_ARM_GNUC))
225 #include "pvamrwbdecoder_basic_op_gcc_armv5.h"
230 #define C_EQUIVALENT // default to C_EQUIVALENT
233 #include "pvamrwbdecoder_basic_op_cequivalent.h"
238 #endif /* PVAMRWBDECODER_BASIC_OP_H */