tizen 2.3.1 release
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / norm_l.cpp
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  Filename: norm_l.cpp
31
32 ------------------------------------------------------------------------------
33  INPUT AND OUTPUT DEFINITIONS
34
35  Inputs:
36     L_var1 = 32 bit long signed integer (Word32) whose value falls
37              in the range : 0x8000 0000 <= var1 <= 0x7fff ffff.
38
39  Local Stores/Buffers/Pointers Needed:
40     None
41
42  Global Stores/Buffers/Pointers Needed:
43     None
44
45  Outputs:
46     var_out = number of left shifts need to normalize input (Word16)
47
48  Pointers and Buffers Modified:
49     None
50
51  Local Stores Modified:
52     None
53
54  Global Stores Modified:
55     None
56
57 ------------------------------------------------------------------------------
58  FUNCTION DESCRIPTION
59
60  This function produces the number of left shifts needed to normalize the 32
61  bit variable L_var1 for positive values on the interval with minimum of
62  0x40000000 and maximum of 0x7fffffff, and for negative values on the interval
63  with minimum of 0x80000000 and maximum of 0xc0000000. Note that when L_var1
64  is equal to zero, the output var_out is set to zero.
65
66 ------------------------------------------------------------------------------
67  REQUIREMENTS
68
69  None
70
71 ------------------------------------------------------------------------------
72  REFERENCES
73
74  [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
75
76 ------------------------------------------------------------------------------
77  PSEUDO-CODE
78
79 Word16 norm_l (Word32 L_var1)
80 {
81     Word16 var_out;
82
83     if (L_var1 == 0)
84     {
85         var_out = 0;
86     }
87     else
88     {
89         if (L_var1 == (Word32) 0xffffffffL)
90         {
91             var_out = 31;
92         }
93         else
94         {
95             if (L_var1 < 0)
96             {
97                 L_var1 = ~L_var1;
98             }
99             for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
100             {
101                 L_var1 <<= 1;
102             }
103         }
104     }
105
106 #if (WMOPS)
107     multiCounter[currCounter].norm_l++;
108 #endif
109     return (var_out);
110 }
111
112 ------------------------------------------------------------------------------
113 */
114
115
116 /*----------------------------------------------------------------------------
117 ; INCLUDES
118 ----------------------------------------------------------------------------*/
119 #include    "basic_op.h"
120
121 /*----------------------------------------------------------------------------
122 ; MACROS
123 ; Define module specific macros here
124 ----------------------------------------------------------------------------*/
125
126 /*----------------------------------------------------------------------------
127 ; DEFINES
128 ; Include all pre-processor statements here. Include conditional
129 ; compile variables also.
130 ----------------------------------------------------------------------------*/
131
132 /*----------------------------------------------------------------------------
133 ; LOCAL FUNCTION DEFINITIONS
134 ; Function Prototype declaration
135 ----------------------------------------------------------------------------*/
136
137 /*----------------------------------------------------------------------------
138 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
139 ; Variable declaration - defined here and used outside this module
140 ----------------------------------------------------------------------------*/
141
142 /*----------------------------------------------------------------------------
143 ; EXTERNAL FUNCTION REFERENCES
144 ; Declare functions defined elsewhere and referenced in this module
145 ----------------------------------------------------------------------------*/
146
147 /*----------------------------------------------------------------------------
148 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
149 ; Declare variables used in this module but defined elsewhere
150 ----------------------------------------------------------------------------*/
151
152 /*----------------------------------------------------------------------------
153 ; FUNCTION CODE
154 ----------------------------------------------------------------------------*/
155 #if !((PV_CPU_ARCH_VERSION >=5) && ((PV_COMPILER == EPV_ARM_GNUC) || (PV_COMPILER == EPV_ARM_RVCT)))
156 OSCL_EXPORT_REF Word16 norm_l(register Word32 L_var1)
157 {
158     /*----------------------------------------------------------------------------
159     ; Define all local variables
160     ----------------------------------------------------------------------------*/
161     register Word16 var_out = 0;
162
163     /*----------------------------------------------------------------------------
164     ; Function body here
165     ----------------------------------------------------------------------------*/
166
167     if (L_var1)
168     {
169
170         Word32 y = L_var1 - (L_var1 < 0);
171         L_var1 = y ^(y >> 31);
172
173
174         while (!(0x40000000L & L_var1))
175         {
176             var_out++;
177             if ((0x20000000L & L_var1))
178             {
179                 break;
180             }
181             var_out++;
182             if ((0x10000000L & L_var1))
183             {
184                 break;
185             }
186             var_out++;
187             if ((0x08000000L & L_var1))
188             {
189                 break;
190             }
191             var_out++;
192             L_var1 <<= 4;
193         }
194     }
195
196     /*----------------------------------------------------------------------------
197     ; Return nothing or data or data pointer
198     ----------------------------------------------------------------------------*/
199
200
201     return (var_out);
202 }
203 #endif