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 ****************************************************************************************/
33 ------------------------------------------------------------------------------
34 INPUT AND OUTPUT DEFINITIONS
37 var1 = 16 bit short signed integer (Word16) whose value falls in
38 the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
39 var2 = 16 bit short signed integer (Word16) whose value falls in
40 the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
42 Local Stores/Buffers/Pointers Needed:
45 Global Stores/Buffers/Pointers Needed:
49 var_out = shifted input w/ rounding (Word16)
51 Pointers and Buffers Modified:
54 Local Stores Modified:
57 Global Stores Modified:
60 ------------------------------------------------------------------------------
63 This function arithmetically shifts the 16 bit input var1 right var2 positions
64 with rounding. If var2 is negative, arithmetically shift var1 left by
65 -var2 with rounding. Saturate the result in case of underflows or
68 - If var2 is greater than zero :
69 if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1))))
72 shr_r(var1,var2) = shr(var1,var2)
74 shr_r(var1,var2) = add(shr(var1,var2),1)
75 - If var2 is less than or equal to zero :
76 shr_r(var1,var2) = shr(var1,var2).
78 ------------------------------------------------------------------------------
83 ------------------------------------------------------------------------------
86 [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
88 ------------------------------------------------------------------------------
91 Word16 shr_r (Word16 var1, Word16 var2)
101 var_out = shr (var1, var2);
103 multiCounter[currCounter].shr--;
108 if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
115 multiCounter[currCounter].shr_r++;
120 ------------------------------------------------------------------------------
124 /*----------------------------------------------------------------------------
126 ----------------------------------------------------------------------------*/
127 #include "basic_op.h"
129 /*----------------------------------------------------------------------------
131 ; Define module specific macros here
132 ----------------------------------------------------------------------------*/
134 /*----------------------------------------------------------------------------
136 ; Include all pre-processor statements here. Include conditional
137 ; compile variables also.
138 ----------------------------------------------------------------------------*/
140 /*----------------------------------------------------------------------------
141 ; LOCAL FUNCTION DEFINITIONS
142 ; Function Prototype declaration
143 ----------------------------------------------------------------------------*/
145 /*----------------------------------------------------------------------------
146 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
147 ; Variable declaration - defined here and used outside this module
148 ----------------------------------------------------------------------------*/
150 /*----------------------------------------------------------------------------
151 ; EXTERNAL FUNCTION REFERENCES
152 ; Declare functions defined elsewhere and referenced in this module
153 ----------------------------------------------------------------------------*/
155 /*----------------------------------------------------------------------------
156 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
157 ; Declare variables used in this module but defined elsewhere
158 ----------------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------------
162 ----------------------------------------------------------------------------*/
163 OSCL_EXPORT_REF Word16 shr_r(register Word16 var1, register Word16 var2, Flag *pOverflow)
165 /*----------------------------------------------------------------------------
166 ; Define all local variables
167 ----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------
172 ----------------------------------------------------------------------------*/
179 var_out = shr(var1, var2, pOverflow);
182 if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
189 /*----------------------------------------------------------------------------
190 ; Return nothing or data or data pointer
191 ----------------------------------------------------------------------------*/