Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*
34 : ===========================================================================
35 : File: ENH40.H v.2.3 - 30.Nov.2009
36 : ===========================================================================
37 :
38 : ITU-T STL BASIC OPERATORS
39 :
40 : 40-BIT ARITHMETIC OPERATORS
41 :
42 : History:
43 : 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control
44 : operators for the ITU-T Standard Tool Library as
45 : described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
46 : TD 11 document and subsequent discussions on the
47 : wp3audio@yahoogroups.com email reflector.
48 : March 06 v2.1 Changed to improve portability.
49 :
50 : ============================================================================
51 : */
52 :
53 :
54 : #ifndef _ENH40_H
55 : #define _ENH40_H
56 :
57 : #include "stl.h"
58 :
59 : #if defined( BASOP_NOGLOB ) || defined( _MSC_VER )
60 : #define MAX_40 ( 0x0000007fffffffff )
61 : #define MIN_40 ( 0xffffff8000000000 )
62 : #endif
63 :
64 : #define L40_OVERFLOW_OCCURED( L40_var1 ) ( Overflow = 1, exit( 1 ), L40_var1 )
65 : #define L40_UNDERFLOW_OCCURED( L40_var1 ) ( Overflow = 1, exit( 2 ), L40_var1 )
66 :
67 : /*****************************************************************************
68 : *
69 : * Prototypes for enhanced 40 bit arithmetic operators
70 : *
71 : *****************************************************************************/
72 : Word40 L40_shr( Word40 L40_var1, Word16 var2 );
73 : Word40 L40_shr_r( Word40 L40_var1, Word16 var2 );
74 : Word40 L40_shl( Word40 L40_var1, Word16 var2 );
75 : Word40 L40_shl_r( Word40 L40_var1, Word16 var2 );
76 :
77 : static __inline Word40 L40_mult( Word16 var1, Word16 var2 );
78 :
79 : static __inline Word40 L40_mac( Word40 L40_var1, Word16 var1, Word16 var2 );
80 : static __inline Word16 mac_r40( Word40 L40_var1, Word16 var1, Word16 var2 );
81 :
82 : static __inline Word40 L40_msu( Word40 L40_var1, Word16 var1, Word16 var2 );
83 : static __inline Word16 msu_r40( Word40 L40_var1, Word16 var1, Word16 var2 );
84 :
85 :
86 : void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l );
87 : void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l );
88 :
89 :
90 : Word40 L40_lshl( Word40 L40_var1, Word16 var2 );
91 : Word40 L40_lshr( Word40 L40_var1, Word16 var2 );
92 :
93 : static __inline Word40 L40_set( Word40 L40_var1 );
94 : static __inline UWord16 Extract40_H( Word40 L40_var1 );
95 : static __inline UWord16 Extract40_L( Word40 L40_var1 );
96 : static __inline UWord32 L_Extract40( Word40 L40_var1 );
97 :
98 : static __inline Word40 L40_deposit_h( Word16 var1 );
99 : static __inline Word40 L40_deposit_l( Word16 var1 );
100 : static __inline Word40 L40_deposit32( Word32 L_var1 );
101 :
102 : static __inline Word40 L40_round( Word40 L40_var1 );
103 : static __inline Word16 round40( Word40 L40_var1 );
104 :
105 :
106 : Word40 L40_add( Word40 L40_var1, Word40 L40_var2 );
107 : Word40 L40_sub( Word40 L40_var1, Word40 L40_var2 );
108 : Word40 L40_abs( Word40 L40_var1 );
109 : Word40 L40_negate( Word40 L40_var1 );
110 : Word40 L40_max( Word40 L40_var1, Word40 L40_var2 );
111 : Word40 L40_min( Word40 L40_var1, Word40 L40_var2 );
112 : Word32 L_saturate40( Word40 L40_var1 );
113 : Word16 norm_L40( Word40 L40_var1 );
114 : #ifdef BASOP_NOGLOB
115 : /*
116 : * Overflowing operators
117 : */
118 : Word40 L40_shl_o( Word40 L40_var1, Word16 var2, Flag *Overflow );
119 : Word40 L40_add_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow );
120 : Word40 L40_sub_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow );
121 : Word32 L_saturate40_o( Word40 L40_var1, Flag *Overflow );
122 : #endif /* BASOP_NOGLOB */
123 : /*#ifdef _MSC_VER*/
124 0 : static __inline Word40 L40_set( Word40 L40_var1 )
125 : {
126 : Word40 L40_var_out;
127 :
128 : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
129 : L40_var_out = L40_var1 & 0x000000ffffffffff;
130 :
131 : if ( L40_var1 & 0x8000000000 )
132 : L40_var_out = L40_var_out | 0xffffff0000000000;
133 : #else
134 0 : L40_var_out = L40_var1 & 0x000000ffffffffffLL;
135 :
136 0 : if ( L40_var1 & 0x8000000000LL )
137 0 : L40_var_out = L40_var_out | 0xffffff0000000000LL;
138 : #endif
139 :
140 : #ifdef WMOPS
141 : multiCounter[currCounter].L40_set++;
142 : #endif
143 :
144 0 : return ( L40_var_out );
145 : }
146 : /*#endif*/ /* ifdef _MSC_VER */
147 :
148 :
149 : static __inline UWord16 Extract40_H( Word40 L40_var1 )
150 : {
151 : UWord16 var_out;
152 :
153 : var_out = (UWord16) ( L40_var1 >> 16 );
154 :
155 : #ifdef WMOPS
156 : multiCounter[currCounter].Extract40_H++;
157 : #endif
158 :
159 : return ( var_out );
160 : }
161 :
162 :
163 239057676 : static __inline UWord16 Extract40_L( Word40 L40_var1 )
164 : {
165 : UWord16 var_out;
166 :
167 239057676 : var_out = (UWord16) ( L40_var1 );
168 :
169 : #ifdef WMOPS
170 : multiCounter[currCounter].Extract40_L++;
171 : #endif
172 :
173 239057676 : return ( var_out );
174 : }
175 :
176 :
177 246136485 : static __inline UWord32 L_Extract40( Word40 L40_var1 )
178 : {
179 : UWord32 L_var_out;
180 :
181 246136485 : L_var_out = (UWord32) L40_var1;
182 :
183 : #ifdef WMOPS
184 : multiCounter[currCounter].L_Extract40++;
185 : #endif
186 :
187 246136485 : return ( L_var_out );
188 : }
189 :
190 :
191 : static __inline Word40 L40_deposit_h( Word16 var1 )
192 : {
193 : Word40 L40_var_out;
194 :
195 : L40_var_out = ( (Word40) var1 ) << 16;
196 :
197 : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
198 : if ( var1 & 0x8000 )
199 : {
200 : L40_var_out = L40_set( L40_var_out | 0xff00000000 );
201 :
202 : #ifdef WMOPS
203 : multiCounter[currCounter].L40_set--;
204 : #endif
205 : }
206 : #else
207 : if ( var1 & 0x8000 )
208 : {
209 : L40_var_out = L40_set( L40_var_out | 0xff00000000LL );
210 :
211 : #ifdef WMOPS
212 : multiCounter[currCounter].L40_set--;
213 : #endif
214 : }
215 : #endif
216 :
217 : #ifdef WMOPS
218 : multiCounter[currCounter].L40_deposit_h++;
219 : #endif
220 :
221 : return ( L40_var_out );
222 : }
223 :
224 :
225 : static __inline Word40 L40_deposit_l( Word16 var1 )
226 : {
227 : Word40 L40_var_out;
228 :
229 : L40_var_out = var1;
230 :
231 : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
232 : if ( var1 & 0x8000 )
233 : {
234 : L40_var_out = L40_set( L40_var_out | 0xffffff0000 );
235 :
236 : #ifdef WMOPS
237 : multiCounter[currCounter].L40_set--;
238 : #endif
239 : }
240 : #else
241 : if ( var1 & 0x8000 )
242 : {
243 : L40_var_out = L40_set( L40_var_out | 0xffffff0000LL );
244 :
245 : #ifdef WMOPS
246 : multiCounter[currCounter].L40_set--;
247 : #endif
248 : }
249 : #endif
250 :
251 : #ifdef WMOPS
252 : multiCounter[currCounter].L40_deposit_l++;
253 : #endif
254 :
255 : return ( L40_var_out );
256 : }
257 :
258 :
259 : static __inline Word40 L40_deposit32( Word32 L_var1 )
260 : {
261 : Word40 L40_var_out;
262 :
263 : L40_var_out = (Word40) L_var1;
264 :
265 : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
266 : if ( L_var1 & 0x80000000 )
267 : {
268 : L40_var_out = L40_set( L40_var_out | 0xff00000000 );
269 :
270 : #ifdef WMOPS
271 : multiCounter[currCounter].L40_set--;
272 : #endif
273 : }
274 : #else
275 : if ( L_var1 & 0x80000000 )
276 : {
277 : L40_var_out = L40_set( L40_var_out | 0xff00000000LL );
278 :
279 : #ifdef WMOPS
280 : multiCounter[currCounter].L40_set--;
281 : #endif
282 : }
283 : #endif
284 :
285 : #ifdef WMOPS
286 : multiCounter[currCounter].L40_deposit32++;
287 : #endif
288 :
289 : return ( L40_var_out );
290 : }
291 :
292 :
293 : static __inline Word40 L40_round( Word40 L40_var1 )
294 : {
295 : Word40 L40_var_out;
296 : Word40 L40_constant;
297 :
298 : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
299 : L40_constant = L40_set( 0xffffff0000 );
300 : #else
301 : L40_constant = L40_set( 0xffffff0000LL );
302 : #endif
303 :
304 : L40_var_out = L40_add( 0x8000, L40_var1 );
305 : L40_var_out = L40_var_out & L40_constant;
306 :
307 : #ifdef WMOPS
308 : multiCounter[currCounter].L40_set--;
309 : multiCounter[currCounter].L40_add--;
310 : multiCounter[currCounter].L40_round++;
311 : #endif
312 :
313 : return ( L40_var_out );
314 : }
315 :
316 :
317 : static __inline Word16 round40( Word40 L40_var1 )
318 : {
319 : Word16 var_out;
320 :
321 : var_out = extract_h( L_saturate40( L40_round( L40_var1 ) ) );
322 :
323 : #ifdef WMOPS
324 : multiCounter[currCounter].L40_round--;
325 : multiCounter[currCounter].L_saturate40--;
326 : multiCounter[currCounter].extract_h--;
327 : multiCounter[currCounter].round40++;
328 : #endif
329 :
330 : return ( var_out );
331 : }
332 :
333 :
334 241417279 : static __inline Word40 L40_mult( Word16 var1, Word16 var2 )
335 : {
336 : Word32 L_var_out;
337 : Word40 L40_var_out;
338 :
339 241417279 : L_var_out = (Word32) var1 * (Word32) var2;
340 241417279 : L40_var_out = (Word40) L_var_out;
341 :
342 : /* Below line can not overflow, so we can use << instead of L40_shl. */
343 241417279 : L40_var_out = L40_var_out << 1;
344 :
345 : #ifdef WMOPS
346 : multiCounter[currCounter].L40_mult++;
347 : #endif
348 :
349 241417279 : return ( L40_var_out );
350 : }
351 :
352 :
353 241417279 : static __inline Word40 L40_mac( Word40 L40_var1, Word16 var2, Word16 var3 )
354 : {
355 : Word40 L40_var_out;
356 :
357 241417279 : L40_var_out = L40_mult( var2, var3 );
358 241417279 : L40_var_out = L40_add( L40_var1, L40_var_out );
359 :
360 : #ifdef WMOPS
361 : multiCounter[currCounter].L40_mac++;
362 : #endif
363 :
364 241417279 : return ( L40_var_out );
365 : }
366 :
367 :
368 : static __inline Word16 mac_r40( Word40 L40_var1, Word16 var2, Word16 var3 )
369 : {
370 : Word40 L40_var_out;
371 : Word16 var_out;
372 :
373 : L40_var_out = L40_mac( L40_var1, var2, var3 );
374 : var_out = round40( L40_var_out );
375 :
376 :
377 : return ( var_out );
378 : }
379 :
380 :
381 : static __inline Word40 L40_msu( Word40 L40_var1, Word16 var2, Word16 var3 )
382 : {
383 : Word40 L40_var_out;
384 :
385 : L40_var_out = L40_mult( var2, var3 );
386 : L40_var_out = L40_sub( L40_var1, L40_var_out );
387 :
388 :
389 : return ( L40_var_out );
390 : }
391 :
392 :
393 : static __inline Word16 msu_r40( Word40 L40_var1, Word16 var2, Word16 var3 )
394 : {
395 : Word40 L40_var_out;
396 : Word16 var_out;
397 :
398 : L40_var_out = L40_msu( L40_var1, var2, var3 );
399 : var_out = round40( L40_var_out );
400 :
401 :
402 : return ( var_out );
403 : }
404 :
405 :
406 : #endif /*_ENH40_H*/
407 :
408 :
409 : /* end of file */
|