Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / include / l_mult.h
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  Filename: l_mult.h
32
33 ------------------------------------------------------------------------------
34  INCLUDE DESCRIPTION
35
36  This file contains all the constant definitions and prototype definitions
37  needed by the L_mult function.
38
39 ------------------------------------------------------------------------------
40 */
41
42 /*----------------------------------------------------------------------------
43 ; CONTINUE ONLY IF NOT ALREADY DEFINED
44 ----------------------------------------------------------------------------*/
45 #ifndef L_MULT_H
46 #define L_MULT_H
47
48 /*----------------------------------------------------------------------------
49 ; INCLUDES
50 ----------------------------------------------------------------------------*/
51 #include    "basicop_malloc.h"
52
53 /*--------------------------------------------------------------------------*/
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58
59     /*----------------------------------------------------------------------------
60     ; MACROS
61     ; Define module specific macros here
62     ----------------------------------------------------------------------------*/
63
64     /*----------------------------------------------------------------------------
65     ; DEFINES
66     ; Include all pre-processor statements here.
67     ----------------------------------------------------------------------------*/
68
69     /*----------------------------------------------------------------------------
70     ; EXTERNAL VARIABLES REFERENCES
71     ; Declare variables used in this module but defined elsewhere
72     ----------------------------------------------------------------------------*/
73
74     /*----------------------------------------------------------------------------
75     ; SIMPLE TYPEDEF'S
76     ----------------------------------------------------------------------------*/
77
78     /*----------------------------------------------------------------------------
79     ; ENUMERATED TYPEDEF'S
80     ----------------------------------------------------------------------------*/
81
82     /*----------------------------------------------------------------------------
83     ; STRUCTURES TYPEDEF'S
84     ----------------------------------------------------------------------------*/
85
86     /*----------------------------------------------------------------------------
87     ; GLOBAL FUNCTION DEFINITIONS
88     ; Function Prototype declaration
89     ----------------------------------------------------------------------------*/
90
91 #if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
92
93     __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
94     {
95         Word32 result;
96         Word32 product;
97
98         OSCL_UNUSED_ARG(pOverflow);
99
100         __asm
101         {
102             SMULBB product, var1, var2
103             QADD   result, product, product
104         }
105
106         return (result);
107     }
108
109 #elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
110
111     __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
112     {
113         register Word32 ra = var1;
114         register Word32 rb = var2;
115         Word32 result;
116         Word32 product;
117
118         OSCL_UNUSED_ARG(pOverflow);
119
120         asm volatile("smulbb %0, %1, %2"
121              : "=r"(product)
122                              : "r"(ra), "r"(rb)
123                             );
124
125         asm volatile("qadd %0, %1, %2"
126              : "=r"(result)
127                              : "r"(product), "r"(product)
128                             );
129
130         return(result);
131     }
132
133 #else /* C EQUIVALENT */
134
135     static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
136     {
137         register Word32 L_product;
138
139         L_product = (Word32) var1 * var2;
140
141         if (L_product != (Word32) 0x40000000L)
142         {
143             L_product <<= 1;          /* Multiply by 2 */
144         }
145         else
146         {
147             *pOverflow = 1;
148             L_product = MAX_32;
149         }
150
151         return (L_product);
152     }
153 #endif
154     /*----------------------------------------------------------------------------
155     ; END
156     ----------------------------------------------------------------------------*/
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* _L_MULT_H */
162