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 ****************************************************************************************/
30 Pathname: ./gsm-amr/c/src/norm_l.c
32 ------------------------------------------------------------------------------
35 Description: Created separate file for the norm_l function. Sync'ed up
36 with the current template and fixed tabs.
38 Description: Updated module description to be the same as the equivalent
39 assembly file (norm_l.asm).
41 Description: Removed conditional code that updates WMOPS counter
43 Description: Made the following changes
44 1. Unrolled the search loop to make four comparison per
45 pass, using only four iterations of the loop and saving
47 2. Updated header and copyright year
49 Description: 1. Support for ARM and Linux-ARM assembly instructions.
54 ------------------------------------------------------------------------------
55 INPUT AND OUTPUT DEFINITIONS
58 L_var1 = 32 bit long signed integer (Word32) whose value falls
59 in the range : 0x8000 0000 <= var1 <= 0x7fff ffff.
61 Local Stores/Buffers/Pointers Needed:
64 Global Stores/Buffers/Pointers Needed:
68 var_out = number of left shifts need to normalize input (Word16)
70 Pointers and Buffers Modified:
73 Local Stores Modified:
76 Global Stores Modified:
79 ------------------------------------------------------------------------------
82 This function produces the number of left shifts needed to normalize the 32
83 bit variable L_var1 for positive values on the interval with minimum of
84 0x40000000 and maximum of 0x7fffffff, and for negative values on the interval
85 with minimum of 0x80000000 and maximum of 0xc0000000. Note that when L_var1
86 is equal to zero, the output var_out is set to zero.
88 ------------------------------------------------------------------------------
93 ------------------------------------------------------------------------------
96 [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
98 ------------------------------------------------------------------------------
101 Word16 norm_l (Word32 L_var1)
111 if (L_var1 == (Word32) 0xffffffffL)
121 for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
129 multiCounter[currCounter].norm_l++;
134 ------------------------------------------------------------------------------
136 When the code is written for a specific target processor the
137 the resources used should be documented below.
139 STACK USAGE: [stack count for this module] + [variable to represent
140 stack usage for each subroutine called]
142 where: [stack usage variable] = stack usage for [subroutine
143 name] (see [filename].ext)
145 DATA MEMORY USED: x words
147 PROGRAM MEMORY USED: x words
149 CLOCK CYCLES: [cycle count equation for this module] + [variable
150 used to represent cycle count for each subroutine
153 where: [cycle count variable] = cycle count for [subroutine
154 name] (see [filename].ext)
156 ------------------------------------------------------------------------------
160 /*----------------------------------------------------------------------------
162 ----------------------------------------------------------------------------*/
163 #include "basic_op.h"
165 /*----------------------------------------------------------------------------
167 ; Define module specific macros here
168 ----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------
172 ; Include all pre-processor statements here. Include conditional
173 ; compile variables also.
174 ----------------------------------------------------------------------------*/
176 /*----------------------------------------------------------------------------
177 ; LOCAL FUNCTION DEFINITIONS
178 ; Function Prototype declaration
179 ----------------------------------------------------------------------------*/
181 /*----------------------------------------------------------------------------
182 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
183 ; Variable declaration - defined here and used outside this module
184 ----------------------------------------------------------------------------*/
186 /*----------------------------------------------------------------------------
187 ; EXTERNAL FUNCTION REFERENCES
188 ; Declare functions defined elsewhere and referenced in this module
189 ----------------------------------------------------------------------------*/
191 /*----------------------------------------------------------------------------
192 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
193 ; Declare variables used in this module but defined elsewhere
194 ----------------------------------------------------------------------------*/
196 /*----------------------------------------------------------------------------
198 ----------------------------------------------------------------------------*/
199 #if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) )
200 Word16 norm_l(register Word32 L_var1)
202 /*----------------------------------------------------------------------------
203 ; Define all local variables
204 ----------------------------------------------------------------------------*/
205 register Word16 var_out = 0;
207 /*----------------------------------------------------------------------------
209 ----------------------------------------------------------------------------*/
214 Word32 y = L_var1 - (L_var1 < 0);
215 L_var1 = y ^(y >> 31);
218 while (!(0x40000000L & L_var1))
221 if ((0x20000000L & L_var1))
226 if ((0x10000000L & L_var1))
231 if ((0x08000000L & L_var1))
240 /*----------------------------------------------------------------------------
241 ; Return nothing or data or data pointer
242 ----------------------------------------------------------------------------*/