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 ****************************************************************************************/
35 /*----------------------------------------------------------------------------
37 ----------------------------------------------------------------------------*/
40 /*----------------------------------------------------------------------------
42 ; [Define module specific macros here]
43 ----------------------------------------------------------------------------*/
45 /*----------------------------------------------------------------------------
47 ; [Include all pre-processor statements here. Include conditional
48 ; compile variables also.]
49 ----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------
52 ; LOCAL FUNCTION DEFINITIONS
53 ; [List function prototypes here]
54 ----------------------------------------------------------------------------*/
56 /*----------------------------------------------------------------------------
57 ; LOCAL VARIABLE DEFINITIONS
58 ; [Variable declaration - defined here and used outside this module]
59 ----------------------------------------------------------------------------*/
63 ------------------------------------------------------------------------------
64 FUNCTION NAME: L_shr_r
65 ------------------------------------------------------------------------------
66 INPUT AND OUTPUT DEFINITIONS
69 L_var1 = 32 bit long signed integer (Word32 ) whose value falls
70 in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
71 var2 = 16 bit short signed integer (Word16) whose value falls in
72 the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
74 pOverflow = pointer to overflow (Flag)
77 pOverflow -> 1 if the 32 bit shift operation resulted in overflow
80 result = Shifted result w/ rounding (Word32)
82 Global Variables Used:
85 Local Variables Needed:
88 ------------------------------------------------------------------------------
91 This function arithmetically shifts the 32 bit input L_var1 right var2
92 positions with rounding. If var2 is negative, the function
93 arithmetically shifts L_var1 left by -var2 and zero fills the -var2 LSB of
94 the result. The result is saturated in case of underflows or overflows, i.e.,
96 - If var2 is greater than zero :
97 if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))
100 L_shr_r(L_var1,var2) = L_shr(L_var1,var2)
102 L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1)
103 - If var2 is less than or equal to zero :
104 L_shr_r(L_var1,var2) = L_shr(L_var1,var2).
106 ------------------------------------------------------------------------------
111 ------------------------------------------------------------------------------
114 [1] L_shr_r() function in basic_op2.c, UMTS GSM AMR speech codec, R99 -
115 Version 3.2.0, March 2, 2001
117 ------------------------------------------------------------------------------
120 Word32 L_shr_r (Word32 L_var1, Word16 var2)
124 * The reference ETSI code uses a global flag for Overflow. In the actual
125 * implementation a pointer to Overflow flag is passed in as a parameter to the
134 L_var_out = L_shr (L_var1, var2);
136 multiCounter[currCounter].L_shr--;
140 if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
147 multiCounter[currCounter].L_shr_r++;
152 ------------------------------------------------------------------------------
154 [State any special notes, constraints or cautions for users of this function]
156 ------------------------------------------------------------------------------
159 /*----------------------------------------------------------------------------
161 ----------------------------------------------------------------------------*/
162 OSCL_EXPORT_REF Word32 L_shr_r(register Word32 L_var1, register Word16 var2, Flag *pOverflow)
172 result = L_shr(L_var1, var2, pOverflow);
176 if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)