• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20 
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24 
25 (C) 2004, 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 ****************************************************************************************/
29 /*
30 
31  Pathname: ./include/basic_op.h
32 
33 ------------------------------------------------------------------------------
34  REVISION HISTORY
35 
36  Description: Revised basic_op.h since the basicop2.c functions were split
37           up into separate source and header files. This function was
38           retained because there are legacy GSM AMR C functions that still
39           include this file. This file now includes the various basicop2
40           functions' header files instead of defining the function
41           prototypes.
42 
43  Description: Including header files with platform specific inline assembly
44               instructions.
45 
46  Who:                       Date:
47  Description:
48 
49 ------------------------------------------------------------------------------
50  INCLUDE DESCRIPTION
51 
52  This file includes all the basicop2.c functions' header files.
53 
54 ------------------------------------------------------------------------------
55 */
56 
57 /*----------------------------------------------------------------------------
58 ; CONTINUE ONLY IF NOT ALREADY DEFINED
59 ----------------------------------------------------------------------------*/
60 #ifndef BASIC_OP_H
61 #define BASIC_OP_H
62 
63 /*----------------------------------------------------------------------------
64 ; INCLUDES
65 ----------------------------------------------------------------------------*/
66 #include    "basicop_malloc.h"
67 
68 #if defined(PV_ARM_V5)
69 #include "basic_op_arm_v5.h"
70 
71 #elif defined(PV_ARM_GCC_V5)
72 #include "basic_op_arm_gcc_v5.h"
73 
74 #else
75 #include "basic_op_c_equivalent.h"
76 
77 #endif
78 
79 
80 
81 #include    "add.h"
82 #include    "div_s.h"
83 #include    "div_32.h"
84 #include    "extract_h.h"
85 #include    "extract_l.h"
86 #include    "l_deposit_h.h"
87 #include    "l_deposit_l.h"
88 #include    "l_shr_r.h"
89 #include    "mult_r.h"
90 #include    "norm_l.h"
91 #include    "norm_s.h"
92 #include    "round.h"
93 #include    "shr_r.h"
94 #include    "sub.h"
95 #include    "shr.h"
96 #include    "l_abs.h"
97 #include    "l_negate.h"
98 #include    "l_extract.h"
99 #include    "l_abs.h"
100 /*--------------------------------------------------------------------------*/
101 #ifdef __cplusplus
102 extern "C"
103 {
104 #endif
105 
106     /*----------------------------------------------------------------------------
107     ; MACROS
108     ; Define module specific macros here
109     ----------------------------------------------------------------------------*/
110 
111     /*----------------------------------------------------------------------------
112     ; DEFINES
113     ; Include all pre-processor statements here.
114     ----------------------------------------------------------------------------*/
115 
116     /*----------------------------------------------------------------------------
117     ; EXTERNAL VARIABLES REFERENCES
118     ; Declare variables used in this module but defined elsewhere
119     ----------------------------------------------------------------------------*/
120 
121     /*----------------------------------------------------------------------------
122     ; SIMPLE TYPEDEF'S
123     ----------------------------------------------------------------------------*/
124 
125     /*----------------------------------------------------------------------------
126     ; ENUMERATED TYPEDEF'S
127     ----------------------------------------------------------------------------*/
128 
129     /*----------------------------------------------------------------------------
130     ; STRUCTURES TYPEDEF'S
131     ----------------------------------------------------------------------------*/
132 
133     /*----------------------------------------------------------------------------
134     ; GLOBAL FUNCTION DEFINITIONS
135     ; Function Prototype declaration
136     ----------------------------------------------------------------------------*/
137     /*
138     ------------------------------------------------------------------------------
139      FUNCTION NAME: mac_32
140     ------------------------------------------------------------------------------
141      INPUT AND OUTPUT DEFINITIONS
142 
143      Inputs:
144         L_var3 = 32 bit long signed integer (Word32) whose value falls
145                  in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
146         L_var1_hi = 16 bit short signed integer (Word16) whose value falls in
147                the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
148         L_var1_lo = 16 bit short signed integer (Word16) whose value falls in
149                the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
150         L_var2_hi = 16 bit short signed integer (Word16) whose value falls in
151                the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
152         L_var2_lo = 16 bit short signed integer (Word16) whose value falls in
153                the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
154 
155         pOverflow = pointer to overflow (Flag)
156 
157      Outputs:
158         pOverflow -> 1 if the 32 bit mac operation resulted in overflow
159 
160      Returns:
161         L_var3 = 32-bit result of L_var3 + (L_var1 * L_var2)(Word32)
162 
163     */
Mac_32(Word32 L_var3,Word16 L_var1_hi,Word16 L_var1_lo,Word16 L_var2_hi,Word16 L_var2_lo,Flag * pOverflow)164     static inline Word32 Mac_32(Word32 L_var3,
165     Word16 L_var1_hi,
166     Word16 L_var1_lo,
167     Word16 L_var2_hi,
168     Word16 L_var2_lo,
169     Flag *pOverflow)
170     {
171         Word16  product;
172 
173         L_var3 = L_mac(L_var3, L_var1_hi, L_var2_hi, pOverflow);
174 
175         product = mult(L_var1_hi, L_var2_lo, pOverflow);
176         L_var3 = L_mac(L_var3, product, 1, pOverflow);
177 
178         product = mult(L_var1_lo, L_var2_hi, pOverflow);
179         L_var3 = L_mac(L_var3, product, 1, pOverflow);
180 
181         return (L_var3);
182     }
183 
184     /*
185     ------------------------------------------------------------------------------
186      FUNCTION NAME: mac_32_16
187     ------------------------------------------------------------------------------
188      INPUT AND OUTPUT DEFINITIONS
189 
190      Inputs:
191         L_var3 = 32 bit long signed integer (Word32) whose value falls
192                  in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
193         L_var1_hi = 16 bit short signed integer (Word16) whose value falls in
194                the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
195         L_var1_lo = 16 bit short signed integer (Word16) whose value falls in
196                the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
197         var2= 16 bit short signed integer (Word16) whose value falls in
198                the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
199         pOverflow = pointer to overflow (Flag)
200 
201      Outputs:
202         pOverflow -> 1 if the 32 bit mac operation resulted in overflow
203 
204      Returns:
205         L_var3 = 32-bit result of L_var3 + (L_var1 * var2)(Word32)
206     */
207 
Mac_32_16(Word32 L_var3,Word16 L_var1_hi,Word16 L_var1_lo,Word16 var2,Flag * pOverflow)208     static inline Word32 Mac_32_16(Word32 L_var3,
209                                    Word16 L_var1_hi,
210                                    Word16 L_var1_lo,
211                                    Word16 var2,
212                                    Flag  *pOverflow)
213     {
214         Word16  product;
215 
216         L_var3 = L_mac(L_var3, L_var1_hi, var2, pOverflow);
217 
218         product = mult(L_var1_lo, var2, pOverflow);
219         L_var3 = L_mac(L_var3, product, 1, pOverflow);
220 
221         return (L_var3);
222     }
223 
224 
225     /*----------------------------------------------------------------------------
226          Function Name : negate
227 
228          Negate var1 with saturation, saturate in the case where input is -32768:
229                       negate(var1) = sub(0,var1).
230 
231          Inputs :
232           var1
233                    16 bit short signed integer (Word16) whose value falls in the
234                    range : 0x8000 <= var1 <= 0x7fff.
235 
236          Outputs :
237           none
238 
239          Return Value :
240                    16 bit short signed integer (Word16) whose value falls in the
241                    range : 0x8000 <= var_out <= 0x7fff.
242      ----------------------------------------------------------------------------*/
243 
negate(Word16 var1)244     static inline Word16 negate(Word16 var1)
245     {
246         return (((var1 == MIN_16) ? MAX_16 : -var1));
247     }
248 
249     /*----------------------------------------------------------------------------
250 
251          Function Name : shl
252 
253          Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill
254          the var2 LSB of the result. If var2 is negative, arithmetically shift
255          var1 right by -var2 with sign extension. Saturate the result in case of
256          underflows or overflows.
257 
258          Inputs :
259           var1
260                    16 bit short signed integer (Word16) whose value falls in the
261                    range : 0x8000 <= var1 <= 0x7fff.
262 
263           var2
264                    16 bit short signed integer (Word16) whose value falls in the
265                    range : 0x8000 <= var1 <= 0x7fff.
266 
267           pOverflow : pointer to overflow (Flag)
268 
269          Return Value :
270           var_out
271                    16 bit short signed integer (Word16) whose value falls in the
272                    range : 0x8000 <= var_out <= 0x7fff.
273      ----------------------------------------------------------------------------*/
274 
shl(Word16 var1,Word16 var2,Flag * pOverflow)275     static inline Word16 shl(Word16 var1, Word16 var2, Flag *pOverflow)
276     {
277         Word16 var_out = 0;
278 
279         OSCL_UNUSED_ARG(pOverflow);
280 
281         if (var2 < 0)
282         {
283             var2 = -var2;
284             if (var2 < 15)
285             {
286                 var_out = var1 >> var2;
287             }
288 
289         }
290         else
291         {
292             var_out = var1 << var2;
293             if (var_out >> var2 != var1)
294             {
295                 var_out = (var1 >> 15) ^ MAX_16;
296             }
297         }
298         return (var_out);
299     }
300 
301 
302     /*----------------------------------------------------------------------------
303 
304          Function Name : L_shl
305 
306          Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero
307          fill the var2 LSB of the result. If var2 is negative, arithmetically
308          shift L_var1 right by -var2 with sign extension. Saturate the result in
309          case of underflows or overflows.
310 
311          Inputs :
312           L_var1   32 bit long signed integer (Word32) whose value falls in the
313                    range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
314 
315           var2
316                    16 bit short signed integer (Word16) whose value falls in the
317                    range :  8000 <= var2 <= 7fff.
318 
319           pOverflow : pointer to overflow (Flag)
320 
321          Return Value :
322                    32 bit long signed integer (Word32) whose value falls in the
323                    range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
324 
325      ----------------------------------------------------------------------------*/
326 
L_shl(Word32 L_var1,Word16 var2,Flag * pOverflow)327     static inline Word32 L_shl(Word32 L_var1, Word16 var2, Flag *pOverflow)
328     {
329         Word32 L_var_out = 0;
330 
331         OSCL_UNUSED_ARG(pOverflow);
332 
333         if (var2 > 0)
334         {
335             L_var_out = L_var1 << var2;
336             if (L_var_out >> var2 != L_var1)
337             {
338                 L_var_out = (L_var1 >> 31) ^ MAX_32;
339             }
340         }
341         else
342         {
343             var2 = -var2;
344             if (var2 < 31)
345             {
346                 L_var_out = L_var1 >> var2;
347             }
348 
349         }
350 
351         return (L_var_out);
352     }
353 
354 
355     /*----------------------------------------------------------------------------
356 
357          Function Name : L_shr
358 
359          Arithmetically shift the 32 bit input L_var1 right var2 positions with
360          sign extension. If var2 is negative, arithmetically shift L_var1 left
361          by -var2 and zero fill the -var2 LSB of the result. Saturate the result
362          in case of underflows or overflows.
363 
364          Inputs :
365           L_var1   32 bit long signed integer (Word32) whose value falls in the
366                    range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
367 
368           var2
369                    16 bit short signed integer (Word16) whose value falls in the
370                    range :  8000 <= var2 <= 7fff.
371 
372           pOverflow : pointer to overflow (Flag)
373 
374          Return Value :
375                    32 bit long signed integer (Word32) whose value falls in the
376                    range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
377 
378      ----------------------------------------------------------------------------*/
379 
L_shr(Word32 L_var1,Word16 var2,Flag * pOverflow)380     static inline Word32 L_shr(Word32 L_var1, Word16 var2, Flag *pOverflow)
381     {
382         Word32 L_var_out = 0;
383 
384         OSCL_UNUSED_ARG(pOverflow);
385 
386         if (var2 > 0)
387         {
388             if (var2 < 31)
389             {
390                 L_var_out = L_var1 >> var2;
391             }
392         }
393         else
394         {
395             var2 = -var2;
396 
397             L_var_out = L_var1 << (var2) ;
398             if ((L_var_out >> (var2)) != L_var1)
399             {
400                 L_var_out = (L_var1 >> 31) ^ MAX_32;
401             }
402 
403         }
404 
405         return (L_var_out);
406     }
407 
408     /*----------------------------------------------------------------------------
409 
410          Function Name : abs_s
411 
412           Absolute value of var1; abs_s(-32768) = 32767.
413 
414          Inputs :
415           var1
416                    16 bit short signed integer (Word16) whose value falls in the
417                    range : 0x8000 <= var1 <= 0x7fff.
418 
419           pOverflow : pointer to overflow (Flag)
420 
421          Outputs :
422           none
423 
424          Return Value :
425                    16 bit short signed integer (Word16) whose value falls in the
426                    range : 0x0000 <= var_out <= 0x7fff.
427 
428      ----------------------------------------------------------------------------*/
429 
abs_s(Word16 var1)430     static inline Word16 abs_s(Word16 var1)
431     {
432 
433         Word16 y = var1 - (var1 < 0);
434         y = y ^(y >> 15);
435         return (y);
436 
437     }
438     /*----------------------------------------------------------------------------
439     ; END
440     ----------------------------------------------------------------------------*/
441 #ifdef __cplusplus
442 }
443 #endif
444 
445 
446 #endif /* BASIC_OP_H */
447 
448 
449