• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #ifndef IXHEAACD_BASIC_OPS_H
21 #define IXHEAACD_BASIC_OPS_H
22 
ixheaacd_extract16h(WORD32 var)23 static PLATFORM_INLINE WORD16 ixheaacd_extract16h(WORD32 var) {
24   WORD16 var_out;
25 
26   var_out = (WORD16)(var >> 16);
27   return (var_out);
28 }
29 
ixheaacd_extract16l(WORD32 var)30 static PLATFORM_INLINE WORD16 ixheaacd_extract16l(WORD32 var) {
31   WORD16 var_out;
32 
33   var_out = (WORD16)var;
34   return (var_out);
35 }
36 
ixheaacd_deposit16h_in32(WORD16 var)37 static PLATFORM_INLINE WORD32 ixheaacd_deposit16h_in32(WORD16 var) {
38   WORD32 var_out;
39 
40   var_out = (WORD32)var << 16;
41   return (var_out);
42 }
43 
ixheaacd_deposit16l_in32(WORD16 var)44 static PLATFORM_INLINE WORD32 ixheaacd_deposit16l_in32(WORD16 var) {
45   WORD32 var_out;
46 
47   var_out = (WORD32)var;
48   return (var_out);
49 }
50 
ixheaacd_extu(UWORD32 a,WORD32 shift_left,WORD32 shift_right)51 static PLATFORM_INLINE UWORD32 ixheaacd_extu(UWORD32 a, WORD32 shift_left,
52                                              WORD32 shift_right) {
53   UWORD32 x;
54   x = (UWORD32)a << shift_left;
55   x = (UWORD32)x >> shift_right;
56 
57   return x;
58 }
59 
ixheaacd_mult32x16h_in32_shl_sat(WORD32 a,WORD32 b)60 static PLATFORM_INLINE WORD32 ixheaacd_mult32x16h_in32_shl_sat(WORD32 a,
61                                                                WORD32 b) {
62   WORD32 result;
63 
64   if (a == (WORD32)0x80000000 && b == (WORD16)0x8000) {
65     result = (WORD32)0x7fffffff;
66   } else {
67     result = ixheaacd_mult32x16in32_shl(a, ixheaacd_extract16h(b));
68   }
69 
70   return (result);
71 }
72 
ixheaacd_div32_pos_normb(WORD32 a,WORD32 b)73 static PLATFORM_INLINE WORD32 ixheaacd_div32_pos_normb(WORD32 a, WORD32 b) {
74   WORD32 quotient;
75   UWORD32 mantissa_nr = a;
76   UWORD32 mantissa_dr = b;
77 
78   LOOPINDEX i;
79 
80   if (a == b) {
81     quotient = MAX_32;
82   } else {
83     quotient = 0;
84 
85     for (i = 0; i < 32; i++) {
86       quotient = quotient << 1;
87 
88       if (mantissa_nr >= mantissa_dr) {
89         mantissa_nr = mantissa_nr - mantissa_dr;
90         quotient += 1;
91       }
92 
93       mantissa_nr = (UWORD32)mantissa_nr << 1;
94     }
95   }
96 
97   return quotient;
98 }
99 
ixheaacd_shr32_dir_sat_limit(WORD32 a,WORD b)100 static PLATFORM_INLINE WORD32 ixheaacd_shr32_dir_sat_limit(WORD32 a, WORD b) {
101   WORD32 out_val;
102 
103   if (b < 0) {
104     out_val = ixheaacd_shl32_sat(a, -b);
105   } else {
106     b = ixheaacd_min32(b, 31);
107     out_val = ixheaacd_shr32(a, b);
108   }
109 
110   return out_val;
111 }
112 
ixheaacd_shl32_dir_sat_limit(WORD32 a,WORD b)113 static PLATFORM_INLINE WORD32 ixheaacd_shl32_dir_sat_limit(WORD32 a, WORD b) {
114   WORD32 out_val;
115 
116   if (b < 0) {
117     b = -b;
118     b = ixheaacd_min32(b, 31);
119     out_val = ixheaacd_shr32(a, b);
120   } else {
121     out_val = ixheaacd_shl32_sat(a, b);
122   }
123 
124   return out_val;
125 }
126 
ixheaacd_mac32x32in64_dual(WORD32 a,WORD32 b,WORD64 c)127 static PLATFORM_INLINE WORD64 ixheaacd_mac32x32in64_dual(WORD32 a, WORD32 b,
128                                                          WORD64 c) {
129   WORD64 result;
130   WORD64 temp_result;
131 
132   temp_result = (WORD64)a * (WORD64)b;
133   result = c + (temp_result);
134   return (result);
135 }
136 
137 #endif /* IXHEAACD_BASIC_OPS_H */
138