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 ****************************************************************************************/
32 ------------------------------------------------------------------------------
33 INPUT AND OUTPUT DEFINITIONS
36 var1 = 16 bit signed integer (Word16) whose value falls in
37 the range : 0x0000 <= var1 <= 0x7fff.
38 var2 = 16 bit signed integer (Word16) whose value falls in
39 the range : 0x0000 <= var1 <= 0x7fff.
41 Local Stores/Buffers/Pointers Needed:
44 Global Stores/Buffers/Pointers Needed:
48 var_out = quotient of var1 divided by var2 (Word16)
50 Pointers and Buffers Modified:
53 Local Stores Modified:
56 Global Stores Modified:
59 ------------------------------------------------------------------------------
62 This function produces a result which is the fractional integer division of
63 var1 by var2; var1 and var2 must be positive and var2 must be greater or equal
64 to var1; the result is positive (leading bit equal to 0) and truncated to 16
65 bits. If var1 = var2 then div(var1,var2) = 32767.
67 ------------------------------------------------------------------------------
72 ------------------------------------------------------------------------------
75 [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
77 ------------------------------------------------------------------------------
80 Word16 div_s (Word16 var1, Word16 var2)
86 Word16 abort_flag = 0;
88 if ((var1 > var2) || (var1 < 0))
90 printf ("Division Error var1=%d var2=%d\n", var1, var2);
94 if ((var1 != 0) && (abort_flag == 0))
102 L_num = (Word32) var1;
103 L_denom = (Word32) var2;
105 for (iteration = 15; iteration > 0; iteration--)
110 if (L_num >= L_denom)
120 multiCounter[currCounter].div_s++;
125 ------------------------------------------------------------------------------
129 /*----------------------------------------------------------------------------
131 ----------------------------------------------------------------------------*/
132 #include "basic_op.h"
134 /*----------------------------------------------------------------------------
136 ; Define module specific macros here
137 ----------------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------------
141 ; Include all pre-processor statements here. Include conditional
142 ; compile variables also.
143 ----------------------------------------------------------------------------*/
145 /*----------------------------------------------------------------------------
146 ; LOCAL FUNCTION DEFINITIONS
147 ; Function Prototype declaration
148 ----------------------------------------------------------------------------*/
150 /*----------------------------------------------------------------------------
151 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
152 ; Variable declaration - defined here and used outside this module
153 ----------------------------------------------------------------------------*/
155 /*----------------------------------------------------------------------------
156 ; EXTERNAL FUNCTION REFERENCES
157 ; Declare functions defined elsewhere and referenced in this module
158 ----------------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------------
161 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
162 ; Declare variables used in this module but defined elsewhere
163 ----------------------------------------------------------------------------*/
165 /*----------------------------------------------------------------------------
167 ----------------------------------------------------------------------------*/
168 OSCL_EXPORT_REF Word16 div_s(register Word16 var1, register Word16 var2)
170 /*----------------------------------------------------------------------------
171 ; Define all local variables
172 ----------------------------------------------------------------------------*/
174 register Word16 iteration;
180 /*----------------------------------------------------------------------------
182 ----------------------------------------------------------------------------*/
183 if ((var1 > var2) || (var1 < 0))
185 return 0; // used to exit(0);
192 L_num = (Word32) var1;
193 L_denom = (Word32) var2;
194 L_denom_by_2 = (L_denom << 1);
195 L_denom_by_4 = (L_denom << 2);
196 for (iteration = 5; iteration > 0; iteration--)
201 if (L_num >= L_denom_by_4)
203 L_num -= L_denom_by_4;
207 if (L_num >= L_denom_by_2)
209 L_num -= L_denom_by_2;
213 if (L_num >= (L_denom))
228 multiCounter[currCounter].div_s++;
231 /*----------------------------------------------------------------------------
232 ; Return nothing or data or data pointer
233 ----------------------------------------------------------------------------*/