Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / include / mpy_32.h
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2010 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: mpy_32.h
32
33 ------------------------------------------------------------------------------
34  INCLUDE DESCRIPTION
35
36  This file contains all the constant definitions and prototype definitions
37  needed by the Mpy_32 function.
38
39 ------------------------------------------------------------------------------
40 */
41
42 /*----------------------------------------------------------------------------
43 ; CONTINUE ONLY IF NOT ALREADY DEFINED
44 ----------------------------------------------------------------------------*/
45 #ifndef MPY_32_H
46 #define MPY_32_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     /*----------------------------------------------------------------------------
66     ; DEFINES
67     ; Include all pre-processor statements here.
68     ----------------------------------------------------------------------------*/
69
70     /*----------------------------------------------------------------------------
71     ; EXTERNAL VARIABLES REFERENCES
72     ; Declare variables used in this module but defined elsewhere
73     ----------------------------------------------------------------------------*/
74
75     /*----------------------------------------------------------------------------
76     ; SIMPLE TYPEDEF'S
77     ----------------------------------------------------------------------------*/
78
79     /*----------------------------------------------------------------------------
80     ; ENUMERATED TYPEDEF'S
81     ----------------------------------------------------------------------------*/
82
83     /*----------------------------------------------------------------------------
84     ; STRUCTURES TYPEDEF'S
85     ----------------------------------------------------------------------------*/
86
87     /*----------------------------------------------------------------------------
88     ; GLOBAL FUNCTION DEFINITIONS
89     ; Function Prototype declaration
90     ----------------------------------------------------------------------------*/
91 #if   ((PV_CPU_ARCH_VERSION >=5) && (PV_COMPILER == EPV_ARM_GNUC))/* Instructions for ARM-linux cross-compiler*/
92
93     static inline Word32 Mpy_32(Word16 L_var1_hi,
94     Word16 L_var1_lo,
95     Word16 L_var2_hi,
96     Word16 L_var2_lo,
97     Flag   *pOverflow)
98     {
99         register Word32 product32;
100         register Word32 L_sum;
101         register Word32 L_product, result;
102         register Word32 ra = L_var1_hi;
103         register Word32 rb = L_var1_lo;
104         register Word32 rc = L_var2_hi;
105         register Word32 rd = L_var2_lo;
106
107
108
109         OSCL_UNUSED_ARG(pOverflow);
110
111         asm volatile("smulbb %0, %1, %2"
112              : "=r"(L_product)
113                              : "r"(ra), "r"(rc)
114                             );
115         asm volatile("mov %0, #0"
116              : "=r"(result)
117                     );
118
119         asm volatile("qdadd %0, %1, %2"
120              : "=r"(L_sum)
121                              : "r"(result), "r"(L_product)
122                             );
123
124         asm volatile("smulbb %0, %1, %2"
125              : "=r"(product32)
126                              : "r"(ra), "r"(rd)
127                             );
128
129         asm volatile("mov %0, %1, ASR #15"
130              : "=r"(ra)
131                              : "r"(product32)
132                             );
133         asm volatile("qdadd %0, %1, %2"
134              : "=r"(L_product)
135                              : "r"(L_sum), "r"(ra)
136                             );
137
138         asm volatile("smulbb %0, %1, %2"
139              : "=r"(product32)
140                              : "r"(rb), "r"(rc)
141                             );
142
143         asm volatile("mov %0, %1, ASR #15"
144              : "=r"(rb)
145                              : "r"(product32)
146                             );
147
148         asm volatile("qdadd %0, %1, %2"
149              : "=r"(L_sum)
150                              : "r"(L_product), "r"(rb)
151                             );
152
153         return (L_sum);
154     }
155
156 #else /* C_EQUIVALENT */
157
158     __inline Word32 Mpy_32(Word16 L_var1_hi,
159                            Word16 L_var1_lo,
160                            Word16 L_var2_hi,
161                            Word16 L_var2_lo,
162                            Flag   *pOverflow)
163     {
164         Word32 L_product;
165         Word32 L_sum;
166         Word32 product32;
167
168         OSCL_UNUSED_ARG(pOverflow);
169         L_product = (Word32) L_var1_hi * L_var2_hi;
170
171         if (L_product != (Word32) 0x40000000L)
172         {
173             L_product <<= 1;
174         }
175         else
176         {
177             L_product = MAX_32;
178         }
179
180         /* result = mult (L_var1_hi, L_var2_lo, pOverflow); */
181         product32 = ((Word32) L_var1_hi * L_var2_lo) >> 15;
182
183         /* L_product = L_mac (L_product, result, 1, pOverflow); */
184         L_sum = L_product + (product32 << 1);
185
186         if ((L_product ^ product32) > 0)
187         {
188             if ((L_sum ^ L_product) < 0)
189             {
190                 L_sum = (L_product < 0) ? MIN_32 : MAX_32;
191             }
192         }
193
194         L_product = L_sum;
195
196         /* result = mult (L_var1_lo, L_var2_hi, pOverflow); */
197         product32 = ((Word32) L_var1_lo * L_var2_hi) >> 15;
198
199         /* L_product = L_mac (L_product, result, 1, pOverflow); */
200         L_sum = L_product + (product32 << 1);
201
202         if ((L_product ^ product32) > 0)
203         {
204             if ((L_sum ^ L_product) < 0)
205             {
206                 L_sum = (L_product < 0) ? MIN_32 : MAX_32;
207             }
208         }
209
210         /*----------------------------------------------------------------------------
211         ; Return nothing or data or data pointer
212         ----------------------------------------------------------------------------*/
213         return (L_sum);
214     }
215
216 #endif
217     /*----------------------------------------------------------------------------
218     ; END
219     ----------------------------------------------------------------------------*/
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif /* _MPY_32_H_ */