1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 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 (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
31 Filename: basic_op_arm_gcc_v5.h
33 ------------------------------------------------------------------------------
36 This file includes all the GCC-ARM V5 basicop.c functions.
38 ------------------------------------------------------------------------------
41 /*----------------------------------------------------------------------------
42 ; CONTINUE ONLY IF NOT ALREADY DEFINED
43 ----------------------------------------------------------------------------*/
44 #ifndef BASIC_OP_ARM_GCC_V5_H
45 #define BASIC_OP_ARM_GCC_V5_H
47 /*----------------------------------------------------------------------------
49 ----------------------------------------------------------------------------*/
50 #include "basicop_malloc.h"
52 /*--------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
61 ; Define module specific macros here
62 ----------------------------------------------------------------------------*/
64 /*----------------------------------------------------------------------------
66 ; Include all pre-processor statements here.
67 ----------------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------------
70 ; EXTERNAL VARIABLES REFERENCES
71 ; Declare variables used in this module but defined elsewhere
72 ----------------------------------------------------------------------------*/
74 /*----------------------------------------------------------------------------
76 ----------------------------------------------------------------------------*/
78 /*----------------------------------------------------------------------------
79 ; ENUMERATED TYPEDEF'S
80 ----------------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------------
83 ; STRUCTURES TYPEDEF'S
84 ----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------
87 ; GLOBAL FUNCTION DEFINITIONS
88 ; Function Prototype declaration
89 ----------------------------------------------------------------------------*/
94 ------------------------------------------------------------------------------
96 ------------------------------------------------------------------------------
97 INPUT AND OUTPUT DEFINITIONS
100 L_var1 = 32 bit long signed integer (Word32) whose value falls
101 in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
103 L_var2 = 32 bit long signed integer (Word32) whose value falls
104 in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
106 pOverflow = pointer to overflow (Flag)
109 pOverflow -> 1 if the 32 bit add operation resulted in overflow
112 L_sum = 32-bit sum of L_var1 and L_var2 (Word32)
115 static inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
117 register Word32 ra = L_var1;
118 register Word32 rb = L_var2;
121 OSCL_UNUSED_ARG(pOverflow);
123 __asm__ volatile("qadd %0, %1, %2"
132 ------------------------------------------------------------------------------
134 ------------------------------------------------------------------------------
135 INPUT AND OUTPUT DEFINITIONS
138 L_var1 = 32 bit long signed integer (Word32) whose value falls
139 in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
141 L_var2 = 32 bit long signed integer (Word32) whose value falls
142 in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
144 pOverflow = pointer to overflow (Flag)
147 pOverflow -> 1 if the 32 bit add operation resulted in overflow
150 L_diff = 32-bit difference of L_var1 and L_var2 (Word32)
152 static inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
154 register Word32 ra = L_var1;
155 register Word32 rb = L_var2;
158 OSCL_UNUSED_ARG(pOverflow);
160 __asm__ volatile("qsub %0, %1, %2"
170 ------------------------------------------------------------------------------
172 ------------------------------------------------------------------------------
173 INPUT AND OUTPUT DEFINITIONS
176 L_var3 = 32 bit long signed integer (Word32) whose value falls
177 in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
178 var1 = 16 bit short signed integer (Word16) whose value falls in
179 the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
180 var2 = 16 bit short signed integer (Word16) whose value falls in
181 the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
183 pOverflow = pointer to overflow (Flag)
186 pOverflow -> 1 if the 32 bit add operation resulted in overflow
189 result = 32-bit result of L_var3 + (var1 * var2)(Word32)
191 static inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
193 register Word32 ra = L_var3;
194 register Word32 rb = var1;
195 register Word32 rc = var2;
198 OSCL_UNUSED_ARG(pOverflow);
200 __asm__ volatile("smulbb %0, %1, %2"
205 __asm__ volatile("qdadd %0, %1, %2"
207 : "r"(ra), "r"(result)
214 ------------------------------------------------------------------------------
215 FUNCTION NAME: L_mult
216 ------------------------------------------------------------------------------
217 INPUT AND OUTPUT DEFINITIONS
220 L_var1 = 16 bit short signed integer (Word16) whose value falls in
221 the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
223 L_var2 = 16 bit short signed integer (Word16) whose value falls in
224 the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
226 pOverflow = pointer to overflow (Flag)
229 pOverflow -> 1 if the 32 bit add operation resulted in overflow
232 L_product = 32-bit product of L_var1 and L_var2 (Word32)
235 static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
237 register Word32 ra = var1;
238 register Word32 rb = var2;
242 OSCL_UNUSED_ARG(pOverflow);
244 __asm__ volatile("smulbb %0, %1, %2"
249 __asm__ volatile("qadd %0, %1, %2"
251 : "r"(product), "r"(product)
258 ------------------------------------------------------------------------------
260 ------------------------------------------------------------------------------
261 INPUT AND OUTPUT DEFINITIONS
264 L_var3 = 32 bit long signed integer (Word32) whose value falls
265 in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
267 var1 = 16 bit short signed integer (Word16) whose value falls in
268 the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
269 var2 = 16 bit short signed integer (Word16) whose value falls in
270 the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
272 pOverflow = pointer to overflow (Flag)
275 pOverflow -> 1 if the 32 bit operation resulted in overflow
278 result = 32-bit result of L_var3 - (var1 * var2)
280 static inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
282 register Word32 ra = L_var3;
283 register Word32 rb = var1;
284 register Word32 rc = var2;
288 OSCL_UNUSED_ARG(pOverflow);
290 __asm__ volatile("smulbb %0, %1, %2"
295 __asm__ volatile("qdsub %0, %1, %2"
297 : "r"(ra), "r"(product)
304 ------------------------------------------------------------------------------
305 FUNCTION NAME: Mpy_32
306 ------------------------------------------------------------------------------
307 INPUT AND OUTPUT DEFINITIONS
310 L_var1_hi = most significant word of first input (Word16).
311 L_var1_lo = least significant word of first input (Word16).
312 L_var2_hi = most significant word of second input (Word16).
313 L_var2_lo = least significant word of second input (Word16).
315 pOverflow = pointer to overflow (Flag)
318 pOverflow -> 1 if the 32 bit multiply operation resulted in overflow
321 L_product = 32-bit product of L_var1 and L_var2 (Word32)
323 static inline Word32 Mpy_32(Word16 L_var1_hi,
329 register Word32 product32;
330 register Word32 L_sum;
331 register Word32 L_product, result;
332 register Word32 ra = L_var1_hi;
333 register Word32 rb = L_var1_lo;
334 register Word32 rc = L_var2_hi;
335 register Word32 rd = L_var2_lo;
339 OSCL_UNUSED_ARG(pOverflow);
341 __asm__ volatile("smulbb %0, %1, %2"
345 __asm__ volatile("mov %0, #0"
349 __asm__ volatile("qdadd %0, %1, %2"
351 : "r"(result), "r"(L_product)
354 __asm__ volatile("smulbb %0, %1, %2"
359 __asm__ volatile("mov %0, %1, ASR #15"
363 __asm__ volatile("qdadd %0, %1, %2"
365 : "r"(L_sum), "r"(ra)
368 __asm__ volatile("smulbb %0, %1, %2"
373 __asm__ volatile("mov %0, %1, ASR #15"
378 __asm__ volatile("qdadd %0, %1, %2"
380 : "r"(L_product), "r"(rb)
389 ------------------------------------------------------------------------------
390 FUNCTION NAME: Mpy_32_16
391 ------------------------------------------------------------------------------
392 INPUT AND OUTPUT DEFINITIONS
395 L_var1_hi = most significant 16 bits of 32-bit input (Word16).
396 L_var1_lo = least significant 16 bits of 32-bit input (Word16).
397 var2 = 16-bit signed integer (Word16).
399 pOverflow = pointer to overflow (Flag)
402 pOverflow -> 1 if the 32 bit product operation resulted in overflow
405 product = 32-bit product of the 32-bit L_var1 and 16-bit var1 (Word32)
407 static inline Word32 Mpy_32_16(Word16 L_var1_hi,
413 register Word32 ra = L_var1_hi;
414 register Word32 rb = L_var1_lo;
415 register Word32 rc = var2;
416 Word32 result, L_product;
418 OSCL_UNUSED_ARG(pOverflow);
420 __asm__ volatile("smulbb %0, %1, %2"
424 __asm__ volatile("mov %0, #0"
428 __asm__ volatile("qdadd %0, %1, %2"
430 : "r"(result), "r"(L_product)
433 __asm__ volatile("smulbb %0, %1, %2"
438 __asm__ volatile("mov %0, %1, ASR #15"
442 __asm__ volatile("qdadd %0, %1, %2"
444 : "r"(L_product), "r"(ra)
451 ------------------------------------------------------------------------------
453 ------------------------------------------------------------------------------
454 INPUT AND OUTPUT DEFINITIONS
457 var1 = 16 bit short signed integer (Word16) whose value falls in
458 the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
460 var2 = 16 bit short signed integer (Word16) whose value falls in
461 the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
463 pOverflow = pointer to overflow (Flag)
466 pOverflow -> 1 if the add operation resulted in overflow
469 product = 16-bit limited product of var1 and var2 (Word16)
471 static inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
473 register Word32 ra = var1;
474 register Word32 rb = var2;
478 OSCL_UNUSED_ARG(pOverflow);
486 "qadd %0, %1, %2\n\t"
487 "mov %0, %0, asr #16"
489 : "r"(temp), "r"(temp)
492 return ((Word16) product);
495 static inline Word32 amrnb_fxp_mac_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
497 register Word32 ra = L_var1;
498 register Word32 rb = L_var2;
499 register Word32 rc = L_var3;
502 __asm__ volatile("smlabb %0, %1, %2, %3"
504 : "r"(ra), "r"(rb), "r"(rc)
509 static inline Word32 amrnb_fxp_msu_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
511 register Word32 ra = L_var1;
512 register Word32 rb = L_var2;
513 register Word32 rc = L_var3;
516 __asm__ volatile("rsb %0, %1, #0"
521 __asm__ volatile("smlabb %0, %1, %2, %3"
523 : "r"(ra), "r"(rb), "r"(rc)
528 /*----------------------------------------------------------------------------
530 ----------------------------------------------------------------------------*/
535 #endif /* BASIC_OP_ARM_GCC_V5_H */