Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / include / l_mult.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: 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 #if   ((PV_CPU_ARCH_VERSION >=5) && (PV_COMPILER == EPV_ARM_GNUC))/* Instructions for ARM-linux cross-compiler*/
91
92     __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
93     {
94         register Word32 ra = var1;
95         register Word32 rb = var2;
96         Word32 result;
97         Word32 product;
98
99         OSCL_UNUSED_ARG(pOverflow);
100
101         asm volatile("smulbb %0, %1, %2"
102              : "=r"(product)
103                              : "r"(ra), "r"(rb)
104                             );
105
106         asm volatile("qadd %0, %1, %2"
107              : "=r"(result)
108                              : "r"(product), "r"(product)
109                             );
110
111         return(result);
112     }
113
114 #else /* C EQUIVALENT */
115
116     static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
117     {
118         register Word32 L_product;
119
120         L_product = (Word32) var1 * var2;
121
122         if (L_product != (Word32) 0x40000000L)
123         {
124             L_product <<= 1;          /* Multiply by 2 */
125         }
126         else
127         {
128             *pOverflow = 1;
129             L_product = MAX_32;
130         }
131
132         return (L_product);
133     }
134 #endif
135     /*----------------------------------------------------------------------------
136     ; END
137     ----------------------------------------------------------------------------*/
138 #ifdef __cplusplus
139 }
140 #endif
141
142 #endif /* _L_MULT_H */
143