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 
21 /*****************************************************************************/
22 /*                                                                           */
23 /*  file name        : ia_basic_ops40.h                                      */
24 /*                                                                           */
25 /*  description      : this file has all basic operations, which have        */
26 /*                     40 bit intermediate operations                        */
27 /*                                                                           */
28 /*  list of functions: 1. norm40                                             */
29 /*                     2. add32_shr40                                        */
30 /*                     3. sub32_shr40                                        */
31 /*                     4. mult32x16in32_shl                                  */
32 /*                     5. mult32x16in32                                      */
33 /*                     6. mult32x16in32_shl_sat                              */
34 /*                     7. mult32_shl                                         */
35 /*                     8. mult32                                             */
36 /*                     9. mult32_shl_sat                                     */
37 /*                     10.mac32x16in32                                       */
38 /*                     11.mac32x16in32_shl                                   */
39 /*                     12.mac32x16in32_shl_sat                               */
40 /*                     13.mac32                                              */
41 /*                     14.mac32_shl                                          */
42 /*                     15.mac32_shl_sat                                      */
43 /*                     16.msu32x16in32                                       */
44 /*                     17.msu32x16in32_shl                                   */
45 /*                     18.msu32x16in32_shl_sat                               */
46 /*                     19.msu32                                              */
47 /*                     20.msu32_shl                                          */
48 /*                     21.msu32_shl_sat                                      */
49 /*                     22.mac3216_arr40                                      */
50 /*                     23.mac32_arr40                                        */
51 /*                     24.mac16_arr40                                        */
52 /*                     25.add32_arr40                                        */
53 /*                                                                           */
54 /*  issues / problems: none                                                  */
55 /*                                                                           */
56 /*  revision history :                                                       */
57 /*                                                                           */
58 /*        DD MM YYYY       author                changes                     */
59 /*        06 12 2002       ashok M/chetan K      created                     */
60 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
61 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
62 /*                                                                           */
63 /*****************************************************************************/
64 
65 #ifndef __IA_BASIC_OPS40_H__
66 #define __IA_BASIC_OPS40_H__
67 
68 /*****************************************************************************/
69 /* file includes                                                             */
70 /*  ia_type_def.h                                                            */
71 /*  ia_basic_ops32.h                                                         */
72 /*****************************************************************************/
73 
74 /*****************************************************************************/
75 /*                                                                           */
76 /*  function name : norm40                                                   */
77 /*                                                                           */
78 /*  description   : normalize input to 32 bits, return denormalizing info    */
79 /*                  static function                                          */
80 /*                                                                           */
81 /*  inputs        : WORD40  *in                                              */
82 /*                                                                           */
83 /*  globals       : none                                                     */
84 /*                                                                           */
85 /*  processing    : if input above 32_bits then only the upper 8 bits        */
86 /*                  normalized to fit in 32_bits else normal 32_bit norming  */
87 /*                                                                           */
88 /*  outputs       : normalized 32 bit value                                  */
89 /*                                                                           */
90 /*  returns       : WORD16 exponent                                          */
91 /*                                                                           */
92 /*  assumptions   : if supplied input is 0 the result returned is 31         */
93 /*                                                                           */
94 /*  issues        : none                                                     */
95 /*                                                                           */
96 /*  revision history :                                                       */
97 /*                                                                           */
98 /*        DD MM YYYY       author                changes                     */
99 /*        06 12 2002       ashok M/chetan K      created                     */
100 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
101 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
102 /*                                                                           */
103 /*****************************************************************************/
104 
norm40(WORD40 * in)105 static PLATFORM_INLINE WORD16 norm40(WORD40 *in)
106 {
107     WORD16 expo;
108     WORD32 tempo;
109     WORD40 cmp_val = (WORD40)-2147483648.0;
110 
111     if(0 == (*in))
112         return 31;
113 
114     if(((*in) <= 0x7fffffff) && ((WORD40)(*in) >= cmp_val))
115     {
116         tempo = (WORD32)(*in);
117         expo = norm32(tempo);
118         *in = tempo << expo;
119 
120         return (expo);
121     }
122 
123     tempo = (WORD32)((*in) >> 31);
124     expo = 31 - (norm32(tempo));
125     *in = (*in) >> expo;
126 
127     return (-expo);
128 }
129 
130 /*****************************************************************************/
131 /*                                                                           */
132 /*  function name : add32_shr40                                              */
133 /*                                                                           */
134 /*  description   : adds two numbers and right shifts once                   */
135 /*                                                                           */
136 /*  inputs        : WORD32 a, WORD32 b                                       */
137 /*                                                                           */
138 /*  outputs       : none                                                     */
139 /*                                                                           */
140 /*  globals       : none                                                     */
141 /*                                                                           */
142 /*  processing    : add and right shift                                      */
143 /*                                                                           */
144 /*  returns       : WORD32 sum                                               */
145 /*                                                                           */
146 /*  issues        : none                                                     */
147 /*                                                                           */
148 /*  revision history :                                                       */
149 /*                                                                           */
150 /*        DD MM YYYY       author                changes                     */
151 /*        06 12 2002       ashok M/chetan K      created                     */
152 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
153 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
154 /*                                                                           */
155 /*****************************************************************************/
156 
add32_shr40(WORD32 a,WORD32 b)157 static PLATFORM_INLINE WORD32 add32_shr40(WORD32 a, WORD32 b)
158 {
159     WORD40 sum;
160 
161     sum = (WORD40)a + (WORD40)b;
162     sum = sum >> 1;
163 
164     return ((WORD32)sum);
165 }
166 
167 /*****************************************************************************/
168 /*                                                                           */
169 /*  function name : sub32_shr40                                              */
170 /*                                                                           */
171 /*  description   : subtracts and right shifts once                          */
172 /*                                                                           */
173 /*  inputs        : WORD32 a, WORD32 b                                       */
174 /*                                                                           */
175 /*  outputs       : none                                                     */
176 /*                                                                           */
177 /*  globals       : none                                                     */
178 /*                                                                           */
179 /*  processing    : substract and right shift                                */
180 /*                                                                           */
181 /*  returns       : WORD32 sum                                               */
182 /*                                                                           */
183 /*  issues        : none                                                     */
184 /*                                                                           */
185 /*  revision history :                                                       */
186 /*                                                                           */
187 /*        DD MM YYYY       author                changes                     */
188 /*        06 12 2002       ashok M/chetan K      created                     */
189 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
190 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
191 /*                                                                           */
192 /*****************************************************************************/
193 
sub32_shr40(WORD32 a,WORD32 b)194 static PLATFORM_INLINE WORD32 sub32_shr40(WORD32 a, WORD32 b)
195 {
196     WORD40 sum;
197 
198     sum = (WORD40)a - (WORD40)b;
199     sum = sum >> 1;
200 
201     return ((WORD32)sum);
202 }
203 
204 /*****************************************************************************/
205 /*                                                                           */
206 /*  function name : mult32x16in32_shl                                        */
207 /*                                                                           */
208 /*  description   : multiply WORD32 with WORD16 return bits 46 to 15         */
209 /*                  doesnt take care of saturation                           */
210 /*                                                                           */
211 /*  inputs        : WORD32 a, WORD16 b                                       */
212 /*                                                                           */
213 /*  outputs       : none                                                     */
214 /*                                                                           */
215 /*  globals       : none                                                     */
216 /*                                                                           */
217 /*  processing    : multiply and right shift by 15                           */
218 /*                                                                           */
219 /*  returns       : WORD32 result                                            */
220 /*                                                                           */
221 /*  issues        : none                                                     */
222 /*                                                                           */
223 /*  revision history :                                                       */
224 /*                                                                           */
225 /*        DD MM YYYY       author                changes                     */
226 /*        06 12 2002       ashok M/chetan K      created                     */
227 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
228 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
229 /*                                                                           */
230 /*****************************************************************************/
231 
mult32x16in32_shl(WORD32 a,WORD16 b)232 static PLATFORM_INLINE WORD32 mult32x16in32_shl(WORD32 a, WORD16 b)
233 {
234     WORD32 result;
235     LWORD64 temp_result;
236 
237     temp_result = (LWORD64)a * (LWORD64)b;
238 
239     result = (WORD32)((temp_result + 16384) >> 15);
240 
241     return (result);
242 }
243 
244 /*****************************************************************************/
245 /*                                                                           */
246 /*  function name : mult32x16in32                                            */
247 /*                                                                           */
248 /*  description   : multiply WORD32 with WORD16 return bits 47 to 16         */
249 /*                                                                           */
250 /*  inputs        : WORD32 a, WORD16 b                                       */
251 /*                                                                           */
252 /*  outputs       : none                                                     */
253 /*                                                                           */
254 /*  globals       : none                                                     */
255 /*                                                                           */
256 /*  processing    : multiply and right shift by 16                           */
257 /*                                                                           */
258 /*  returns       : WORD32 result                                            */
259 /*                                                                           */
260 /*  issues        : none                                                     */
261 /*                                                                           */
262 /*  revision history :                                                       */
263 /*                                                                           */
264 /*        DD MM YYYY       author                changes                     */
265 /*        06 12 2002       ashok M/chetan K      created                     */
266 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
267 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
268 /*                                                                           */
269 /*****************************************************************************/
270 
mult32x16in32(WORD32 a,WORD16 b)271 static PLATFORM_INLINE WORD32 mult32x16in32(WORD32 a, WORD16 b)
272 {
273     WORD32 result;
274     LWORD64 temp_result;
275 
276     temp_result = (LWORD64)a * (LWORD64)b;
277 
278     result = (WORD32)((temp_result + 16384) >> 16);
279 
280     return (result);
281 }
282 
283 /*****************************************************************************/
284 /*                                                                           */
285 /*  function name : mult32x16in32_shl_sat                                    */
286 /*                                                                           */
287 /*  description   : multiply WORD32 with WORD16 return bits 46 to 15         */
288 /*                  take care of saturation (MIN32 x MIN16 = MAX32)          */
289 /*                                                                           */
290 /*  inputs        : WORD32 a, WORD16 b                                       */
291 /*                                                                           */
292 /*  outputs       : none                                                     */
293 /*                                                                           */
294 /*  globals       : none                                                     */
295 /*                                                                           */
296 /*  processing    : if input mi_ns return MAX32 else                         */
297 /*                  multiply and right shift by 15                           */
298 /*                                                                           */
299 /*  returns       : WORD32 result                                            */
300 /*                                                                           */
301 /*  issues        : none                                                     */
302 /*                                                                           */
303 /*  revision history :                                                       */
304 /*                                                                           */
305 /*        DD MM YYYY       author                changes                     */
306 /*        06 12 2002       ashok M/chetan K      created                     */
307 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
308 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
309 /*                                                                           */
310 /*****************************************************************************/
311 
mult32x16in32_shl_sat(WORD32 a,WORD16 b)312 static PLATFORM_INLINE WORD32 mult32x16in32_shl_sat(WORD32 a, WORD16 b)
313 {
314     WORD32 result;
315 
316     if(a == (WORD32)0x80000000 && b == (WORD16)0x8000)
317     {
318         result = (WORD32)0x7fffffff;
319     }
320     else
321     {
322         result = mult32x16in32_shl(a, b);
323     }
324 
325     return (result);
326 }
327 
328 /*****************************************************************************/
329 /*                                                                           */
330 /*  function name : mult32_shl                                               */
331 /*                                                                           */
332 /*  description   : multiply WORD32 with WORD32 return bits 62 to 31         */
333 /*                  doesnt take care of saturation                           */
334 /*                                                                           */
335 /*  inputs        : WORD32 a, WORD32 b                                       */
336 /*                                                                           */
337 /*  outputs       : none                                                     */
338 /*                                                                           */
339 /*  globals       : none                                                     */
340 /*                                                                           */
341 /*  processing    : multiply and right shift by 31                           */
342 /*                                                                           */
343 /*  returns       : WORD32 result                                            */
344 /*                                                                           */
345 /*  issues        : none                                                     */
346 /*                                                                           */
347 /*  revision history :                                                       */
348 /*                                                                           */
349 /*        DD MM YYYY       author                changes                     */
350 /*        06 12 2002       ashok M/chetan K      created                     */
351 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
352 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
353 /*                                                                           */
354 /*****************************************************************************/
355 
mult32_shl(WORD32 a,WORD32 b)356 static PLATFORM_INLINE WORD32 mult32_shl(WORD32 a, WORD32 b)
357 {
358     WORD32 result;
359     LWORD64 temp_result;
360 
361     temp_result = (LWORD64)a * (LWORD64)b;
362     result = (WORD32)(temp_result >> 31);
363 
364     return (result);
365 }
366 
367 /*****************************************************************************/
368 /*                                                                           */
369 /*  function name : mult32                                                   */
370 /*                                                                           */
371 /*  description   : multiply WORD32 with WORD32 return bits 63 to 32         */
372 /*                                                                           */
373 /*  inputs        : WORD32 a, WORD16 b                                       */
374 /*                                                                           */
375 /*  outputs       : none                                                     */
376 /*                                                                           */
377 /*  globals       : none                                                     */
378 /*                                                                           */
379 /*  processing    : multiply and right shift by 32                           */
380 /*                                                                           */
381 /*  returns       : WORD32 result                                            */
382 /*                                                                           */
383 /*  issues        : none                                                     */
384 /*                                                                           */
385 /*  revision history :                                                       */
386 /*                                                                           */
387 /*        DD MM YYYY       author                changes                     */
388 /*        06 12 2002       ashok M/chetan K      created                     */
389 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
390 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
391 /*                                                                           */
392 /*****************************************************************************/
393 
mult32(WORD32 a,WORD32 b)394 static PLATFORM_INLINE WORD32 mult32(WORD32 a, WORD32 b)
395 {
396     WORD32 result;
397     LWORD64 temp_result;
398 
399     temp_result = (LWORD64)a * (LWORD64)b;
400     result = (WORD32)(temp_result >> 32);
401 
402     return (result);
403 }
404 
405 /*****************************************************************************/
406 /*                                                                           */
407 /*  function name : mult32_shl_sat                                           */
408 /*                                                                           */
409 /*  description   : multiply WORD32 with WORD32 return bits 62 to 31         */
410 /*                  take care of saturation (MIN32 x MIN32 = MAX32)          */
411 /*                                                                           */
412 /*  inputs        : WORD32 a, WORD32 b                                       */
413 /*                                                                           */
414 /*  outputs       : none                                                     */
415 /*                                                                           */
416 /*  globals       : none                                                     */
417 /*                                                                           */
418 /*  processing    : if input mi_ns return MAX32 else                         */
419 /*                  multiply and right shift by 31                           */
420 /*                                                                           */
421 /*  returns       : WORD32 result                                            */
422 /*                                                                           */
423 /*  issues        : none                                                     */
424 /*                                                                           */
425 /*  revision history :                                                       */
426 /*                                                                           */
427 /*        DD MM YYYY       author                changes                     */
428 /*        06 12 2002       ashok M/chetan K      created                     */
429 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
430 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
431 /*                                                                           */
432 /*****************************************************************************/
433 
434 #define MPYHIRC(x, y)                                                                              \
435     (((int)((short)(x >> 16) * (unsigned short)(y & 0x0000FFFF) + 0x4000) >> 15) +                 \
436      ((int)((short)(x >> 16) * (short)((y) >> 16)) << 1))
437 
438 #define MPYLUHS(x, y) ((int)((unsigned short)(x & 0x0000FFFF) * (short)(y >> 16)))
439 
mult32_shl_sat(WORD32 a,WORD32 b)440 static PLATFORM_INLINE WORD32 mult32_shl_sat(WORD32 a, WORD32 b)
441 {
442     WORD32 high;
443 
444     high = (MPYHIRC(a, b) + (MPYLUHS(a, b) >> 15));
445 
446     return high;
447 }
448 
449 /*****************************************************************************/
450 /*                                                                           */
451 /*  function name : mac32x16in32                                             */
452 /*                                                                           */
453 /*  description   : multiply WORD32 with WORD16 add bits 47 to 16 to acc     */
454 /*                                                                           */
455 /*  inputs        : WORD32 a, WORD32 b, WORD16 c                             */
456 /*                                                                           */
457 /*  outputs       : none                                                     */
458 /*                                                                           */
459 /*  globals       : none                                                     */
460 /*                                                                           */
461 /*  processing    : multiply, right shift by 16 & add to acc                 */
462 /*                                                                           */
463 /*  returns       : WORD32 accumulated result                                */
464 /*                                                                           */
465 /*  issues        : none                                                     */
466 /*                                                                           */
467 /*  revision history :                                                       */
468 /*                                                                           */
469 /*        DD MM YYYY       author                changes                     */
470 /*        06 12 2002       ashok M/chetan K      created                     */
471 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
472 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
473 /*                                                                           */
474 /*****************************************************************************/
475 
mac32x16in32(WORD32 a,WORD32 b,WORD16 c)476 static PLATFORM_INLINE WORD32 mac32x16in32(WORD32 a, WORD32 b, WORD16 c)
477 {
478     WORD32 result;
479 
480     result = a + mult32x16in32(b, c);
481 
482     return (result);
483 }
484 
485 /*****************************************************************************/
486 /*                                                                           */
487 /*  function name : mac32x16in32_shl                                         */
488 /*                                                                           */
489 /*  description   : multiply WORD32 with WORD16 add bits 46 to 15 to acc     */
490 /*                  doesnt take care of saturation                           */
491 /*                                                                           */
492 /*  inputs        : WORD32 a, WORD32 b, WORD16 c                             */
493 /*                                                                           */
494 /*  outputs       : none                                                     */
495 /*                                                                           */
496 /*  globals       : none                                                     */
497 /*                                                                           */
498 /*  processing    : multiply, right shift by 15 & add to acc                 */
499 /*                                                                           */
500 /*  returns       : WORD32 accumulated result                                */
501 /*                                                                           */
502 /*  issues        : none                                                     */
503 /*                                                                           */
504 /*  revision history :                                                       */
505 /*                                                                           */
506 /*        DD MM YYYY       author                changes                     */
507 /*        06 12 2002       ashok M/chetan K      created                     */
508 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
509 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
510 /*                                                                           */
511 /*****************************************************************************/
512 
mac32x16in32_shl(WORD32 a,WORD32 b,WORD16 c)513 static PLATFORM_INLINE WORD32 mac32x16in32_shl(WORD32 a, WORD32 b, WORD16 c)
514 {
515     WORD32 result;
516 
517     result = a + mult32x16in32_shl(b, c);
518 
519     return (result);
520 }
521 
522 /*****************************************************************************/
523 /*                                                                           */
524 /*  function name : mac32x16in32_shl_sat                                     */
525 /*                                                                           */
526 /*  description   : multiply WORD32 with WORD16 add bits 46 to 15 to acc     */
527 /*                  takes care of saturation in multiply and addition        */
528 /*                                                                           */
529 /*  inputs        : WORD32 a, WORD32 b, WORD16 c                             */
530 /*                                                                           */
531 /*  outputs       : none                                                     */
532 /*                                                                           */
533 /*  globals       : none                                                     */
534 /*                                                                           */
535 /*  processing    : if input mi_ns add MAX32 else multiply,                  */
536 /*                  right shift by 15 & add to acc with saturation           */
537 /*                                                                           */
538 /*  returns       : WORD32 accumulated result                                */
539 /*                                                                           */
540 /*  issues        : none                                                     */
541 /*                                                                           */
542 /*  revision history :                                                       */
543 /*                                                                           */
544 /*        DD MM YYYY       author                changes                     */
545 /*        06 12 2002       ashok M/chetan K      created                     */
546 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
547 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
548 /*                                                                           */
549 /*****************************************************************************/
550 
mac32x16in32_shl_sat(WORD32 a,WORD32 b,WORD16 c)551 static PLATFORM_INLINE WORD32 mac32x16in32_shl_sat(WORD32 a, WORD32 b, WORD16 c)
552 {
553     return (add32_sat(a, mult32x16in32_shl_sat(b, c)));
554 }
555 
556 /*****************************************************************************/
557 /*                                                                           */
558 /*  function name : mac32                                                    */
559 /*                                                                           */
560 /*  description   : multiply WORD32 with WORD32 add bits 63 to 32 to acc     */
561 /*                                                                           */
562 /*  inputs        : WORD32 a, WORD32 b, WORD32 c                             */
563 /*                                                                           */
564 /*  outputs       : none                                                     */
565 /*                                                                           */
566 /*  globals       : none                                                     */
567 /*                                                                           */
568 /*  processing    : multiply, right shift by 32 & add to acc                 */
569 /*                                                                           */
570 /*  returns       : WORD32 accumulated result                                */
571 /*                                                                           */
572 /*  issues        : none                                                     */
573 /*                                                                           */
574 /*  revision history :                                                       */
575 /*                                                                           */
576 /*        DD MM YYYY       author                changes                     */
577 /*        06 12 2002       ashok M/chetan K      created                     */
578 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
579 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
580 /*                                                                           */
581 /*****************************************************************************/
582 
mac32(WORD32 a,WORD32 b,WORD32 c)583 static PLATFORM_INLINE WORD32 mac32(WORD32 a, WORD32 b, WORD32 c)
584 {
585     WORD32 result;
586 
587     result = a + mult32(b, c);
588 
589     return (result);
590 }
591 
592 /*****************************************************************************/
593 /*                                                                           */
594 /*  function name : mac32_shl                                                 */
595 /*                                                                           */
596 /*  description   : multiply WORD32 with WORD32 add bits 62 to 31 to acc     */
597 /*                  doesnt take care of saturation                           */
598 /*                                                                           */
599 /*  inputs        : WORD32 a, WORD32 b, WORD32 c                             */
600 /*                                                                           */
601 /*  outputs       : none                                                     */
602 /*                                                                           */
603 /*  globals       : none                                                     */
604 /*                                                                           */
605 /*  processing    : multiply, right shift by 31 & add to acc                 */
606 /*                                                                           */
607 /*  returns       : WORD32 accumulated result                                */
608 /*                                                                           */
609 /*  issues        : none                                                     */
610 /*                                                                           */
611 /*  revision history :                                                       */
612 /*                                                                           */
613 /*        DD MM YYYY       author                changes                     */
614 /*        06 12 2002       ashok M/chetan K      created                     */
615 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
616 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
617 /*                                                                           */
618 /*****************************************************************************/
619 
mac32_shl(WORD32 a,WORD32 b,WORD32 c)620 static PLATFORM_INLINE WORD32 mac32_shl(WORD32 a, WORD32 b, WORD32 c)
621 {
622     WORD32 result;
623 
624     result = a + mult32_shl(b, c);
625 
626     return (result);
627 }
628 
629 /*****************************************************************************/
630 /*                                                                           */
631 /*  function name : mac32_shl_sat                                              */
632 /*                                                                           */
633 /*  description   : multiply WORD32 with WORD32 add bits 62 to 31 to acc     */
634 /*                  takes care of saturation in multiply and addition        */
635 /*                                                                           */
636 /*  inputs        : WORD32 a, WORD32 b, WORD32 c                             */
637 /*                                                                           */
638 /*  outputs       : none                                                     */
639 /*                                                                           */
640 /*  globals       : none                                                     */
641 /*                                                                           */
642 /*  processing    : if input mi_ns add MAX32 else multiply,                   */
643 /*                  right shift by 31 & add to acc with saturation           */
644 /*                                                                           */
645 /*  returns       : WORD32 accumulated result                                */
646 /*                                                                           */
647 /*  issues        : none                                                     */
648 /*                                                                           */
649 /*  revision history :                                                       */
650 /*                                                                           */
651 /*        DD MM YYYY       author                changes                     */
652 /*        06 12 2002       ashok M/chetan K      created                     */
653 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
654 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
655 /*                                                                           */
656 /*****************************************************************************/
657 
mac32_shl_sat(WORD32 a,WORD32 b,WORD32 c)658 static PLATFORM_INLINE WORD32 mac32_shl_sat(WORD32 a, WORD32 b, WORD32 c)
659 {
660     return (add32_sat(a, mult32_shl_sat(b, c)));
661 }
662 
663 /*****************************************************************************/
664 /*                                                                           */
665 /*  function name : msu32x16in32                                             */
666 /*                                                                           */
667 /*  description   : multiply WORD32 with WORD16 sub bits 47 to 16 from acc   */
668 /*                                                                           */
669 /*  inputs        : WORD32 a, WORD32 b, WORD16 c                             */
670 /*                                                                           */
671 /*  outputs       : none                                                     */
672 /*                                                                           */
673 /*  globals       : none                                                     */
674 /*                                                                           */
675 /*  processing    : multiply, right shift by 16 & sub from acc               */
676 /*                                                                           */
677 /*  returns       : WORD32 accumulated result                                */
678 /*                                                                           */
679 /*  issues        : none                                                     */
680 /*                                                                           */
681 /*  revision history :                                                       */
682 /*                                                                           */
683 /*        DD MM YYYY       author                changes                     */
684 /*        06 12 2002       ashok M/chetan K      created                     */
685 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
686 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
687 /*                                                                           */
688 /*****************************************************************************/
689 
msu32x16in32(WORD32 a,WORD32 b,WORD16 c)690 static PLATFORM_INLINE WORD32 msu32x16in32(WORD32 a, WORD32 b, WORD16 c)
691 {
692     WORD32 result;
693 
694     result = a - mult32x16in32(b, c);
695 
696     return (result);
697 }
698 
699 /*****************************************************************************/
700 /*                                                                           */
701 /*  function name : msu32x16in32_shl                                          */
702 /*                                                                           */
703 /*  description   : multiply WORD32 with WORD16 sub bits 46 to 15 from acc   */
704 /*                  doesnt take care of saturation                           */
705 /*                                                                           */
706 /*  inputs        : WORD32 a, WORD32 b, WORD16 c                             */
707 /*                                                                           */
708 /*  outputs       : none                                                     */
709 /*                                                                           */
710 /*  globals       : none                                                     */
711 /*                                                                           */
712 /*  processing    : multiply, right shift by 15 & sub from acc               */
713 /*                                                                           */
714 /*  returns       : WORD32 accumulated result                                */
715 /*                                                                           */
716 /*  issues        : none                                                     */
717 /*                                                                           */
718 /*  revision history :                                                       */
719 /*                                                                           */
720 /*        DD MM YYYY       author                changes                     */
721 /*        06 12 2002       ashok M/chetan K      created                     */
722 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
723 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
724 /*                                                                           */
725 /*****************************************************************************/
726 
msu32x16in32_shl(WORD32 a,WORD32 b,WORD16 c)727 static PLATFORM_INLINE WORD32 msu32x16in32_shl(WORD32 a, WORD32 b, WORD16 c)
728 {
729     WORD32 result;
730 
731     result = a - mult32x16in32_shl(b, c);
732 
733     return (result);
734 }
735 
736 /*****************************************************************************/
737 /*                                                                           */
738 /*  function name : msu32x16in32_shl_sat                                     */
739 /*                                                                           */
740 /*  description   : multiply WORD32 with WORD16 sub bits 46 to 15 from acc   */
741 /*                  takes care of saturation in multiply and addition        */
742 /*                                                                           */
743 /*  inputs        : WORD32 a, WORD32 b, WORD16 c                             */
744 /*                                                                           */
745 /*  outputs       : none                                                     */
746 /*                                                                           */
747 /*  globals       : none                                                     */
748 /*                                                                           */
749 /*  processing    : if input mi_ns sub MAX32 else multiply,                  */
750 /*                  right shift by 15 & sub from acc with saturation         */
751 /*                                                                           */
752 /*  returns       : WORD32 accumulated result                                */
753 /*                                                                           */
754 /*  issues        : none                                                     */
755 /*                                                                           */
756 /*  revision history :                                                       */
757 /*                                                                           */
758 /*        DD MM YYYY       author                changes                     */
759 /*        06 12 2002       ashok M/chetan K      created                     */
760 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
761 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
762 /*                                                                           */
763 /*****************************************************************************/
764 
msu32x16in32_shl_sat(WORD32 a,WORD32 b,WORD16 c)765 static PLATFORM_INLINE WORD32 msu32x16in32_shl_sat(WORD32 a, WORD32 b, WORD16 c)
766 {
767     return (sub32_sat(a, mult32x16in32_shl_sat(b, c)));
768 }
769 
770 /*****************************************************************************/
771 /*                                                                           */
772 /*  function name : msu32                                                    */
773 /*                                                                           */
774 /*  description   : multiply WORD32 with WORD32 sub bits 63 to 32 from acc   */
775 /*                                                                           */
776 /*  inputs        : WORD32 a, WORD32 b, WORD32 c                             */
777 /*                                                                           */
778 /*  outputs       : none                                                     */
779 /*                                                                           */
780 /*  globals       : none                                                     */
781 /*                                                                           */
782 /*  processing    : multiply, right shift by 32 & sub from acc               */
783 /*                                                                           */
784 /*  returns       : WORD32 accumulated result                                */
785 /*                                                                           */
786 /*  issues        : none                                                     */
787 /*                                                                           */
788 /*  revision history :                                                       */
789 /*                                                                           */
790 /*        DD MM YYYY       author                changes                     */
791 /*        06 12 2002       ashok M/chetan K      created                     */
792 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
793 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
794 /*                                                                           */
795 /*****************************************************************************/
796 
msu32(WORD32 a,WORD32 b,WORD32 c)797 static PLATFORM_INLINE WORD32 msu32(WORD32 a, WORD32 b, WORD32 c)
798 {
799     WORD32 result;
800 
801     result = a - mult32(b, c);
802 
803     return (result);
804 }
805 
806 /*****************************************************************************/
807 /*                                                                           */
808 /*  function name : msu32_shl                                                */
809 /*                                                                           */
810 /*  description   : multiply WORD32 with WORD32 sub bits 62 to 31 from acc   */
811 /*                  doesnt take care of saturation                           */
812 /*                                                                           */
813 /*  inputs        : WORD32 a, WORD32 b, WORD32 c                             */
814 /*                                                                           */
815 /*  outputs       : none                                                     */
816 /*                                                                           */
817 /*  globals       : none                                                     */
818 /*                                                                           */
819 /*  processing    : multiply, right shift by 31 & sub from acc               */
820 /*                                                                           */
821 /*  returns       : WORD32 accumulated result                                */
822 /*                                                                           */
823 /*  issues        : none                                                     */
824 /*                                                                           */
825 /*  revision history :                                                       */
826 /*                                                                           */
827 /*        DD MM YYYY       author                changes                     */
828 /*        06 12 2002       ashok M/chetan K      created                     */
829 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
830 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
831 /*                                                                           */
832 /*****************************************************************************/
833 
msu32_shl(WORD32 a,WORD32 b,WORD32 c)834 static PLATFORM_INLINE WORD32 msu32_shl(WORD32 a, WORD32 b, WORD32 c)
835 {
836     WORD32 result;
837 
838     result = a - mult32_shl(b, c);
839 
840     return (result);
841 }
842 
843 /*****************************************************************************/
844 /*                                                                           */
845 /*  function name : msu32_shl_sat                                            */
846 /*                                                                           */
847 /*  description   : multiply WORD32 with WORD32 sub bits 62 to 31 from acc   */
848 /*                  takes care of saturation in multiply and addition        */
849 /*                                                                           */
850 /*  inputs        : WORD32 a, WORD32 b, WORD32 c                             */
851 /*                                                                           */
852 /*  outputs       : none                                                     */
853 /*                                                                           */
854 /*  globals       : none                                                     */
855 /*                                                                           */
856 /*  processing    : if input mi_ns sub MAX32 else multiply,                  */
857 /*                  right shift by 31 & sub from acc with saturation         */
858 /*                                                                           */
859 /*  returns       : WORD32 accumulated result                                */
860 /*                                                                           */
861 /*  issues        : none                                                     */
862 /*                                                                           */
863 /*  revision history :                                                       */
864 /*                                                                           */
865 /*        DD MM YYYY       author                changes                     */
866 /*        06 12 2002       ashok M/chetan K      created                     */
867 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
868 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
869 /*                                                                           */
870 /*****************************************************************************/
871 
msu32_shl_sat(WORD32 a,WORD32 b,WORD32 c)872 static PLATFORM_INLINE WORD32 msu32_shl_sat(WORD32 a, WORD32 b, WORD32 c)
873 {
874     return (sub32_sat(a, mult32_shl_sat(b, c)));
875 }
876 
877 /*****************************************************************************/
878 /*                                                                           */
879 /*  function name : mac3216_arr40                                            */
880 /*                                                                           */
881 /*  description   : returns normalized 32 bit accumulated result and         */
882 /*                  denormalizing info                                       */
883 /*                                                                           */
884 /*  inputs        : WORD32 x[], WORD16 y[], LOOPINDEX length                 */
885 /*                                                                           */
886 /*  outputs       : WORD16 *q_val                                            */
887 /*                                                                           */
888 /*  globals       : none                                                     */
889 /*                                                                           */
890 /*  processing    : multiply and accumalate in WORD40 finally normalize      */
891 /*                                                                           */
892 /*  returns       : WORD32 accumulated result                                */
893 /*                                                                           */
894 /*  assumptions   : length < 256 for strict definition of WORD40             */
895 /*                                                                           */
896 /*  issues        : none                                                     */
897 /*                                                                           */
898 /*  revision history :                                                       */
899 /*                                                                           */
900 /*        DD MM YYYY       author                changes                     */
901 /*        06 12 2002       ashok M/chetan K      created                     */
902 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
903 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
904 /*                                                                           */
905 /*****************************************************************************/
906 
mac3216_arr40(WORD32 * x,WORD16 * y,LOOPINDEX length,WORD16 * q_val)907 static PLATFORM_INLINE WORD32 mac3216_arr40(WORD32 *x, WORD16 *y, LOOPINDEX length, WORD16 *q_val)
908 {
909     LOOPINDEX i;
910     WORD40 sum = 0;
911 
912     for(i = 0; i < length; i++)
913     {
914         sum += (WORD40)(mult32x16in32(x[i], y[i]));
915     }
916 
917     *q_val = norm40(&sum);
918 
919     return (WORD32)sum;
920 }
921 
922 /*****************************************************************************/
923 /*                                                                           */
924 /*  function name : mac32_arr40                                              */
925 /*                                                                           */
926 /*  description   : returns normalized 32 bit accumulated result and         */
927 /*                  denormalizing info                                       */
928 /*                                                                           */
929 /*  inputs        : WORD32 x[], WORD32 y[], LOOPINDEX length                 */
930 /*                                                                           */
931 /*  outputs       : WORD16 *q_val                                            */
932 /*                                                                           */
933 /*  globals       : none                                                     */
934 /*                                                                           */
935 /*  processing    : multiply and accumalate in WORD40 finally normalize      */
936 /*                                                                           */
937 /*  returns       : WORD32 accumulated result                                */
938 /*                                                                           */
939 /*  assumptions   : length < 256 for strict definition of WORD40             */
940 /*                                                                           */
941 /*  issues        : none                                                     */
942 /*                                                                           */
943 /*  revision history :                                                       */
944 /*                                                                           */
945 /*        DD MM YYYY       author                changes                     */
946 /*        06 12 2002       ashok M/chetan K      created                     */
947 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
948 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
949 /*                                                                           */
950 /*****************************************************************************/
951 
mac32_arr40(WORD32 * x,WORD32 * y,LOOPINDEX length,WORD16 * q_val)952 static PLATFORM_INLINE WORD32 mac32_arr40(WORD32 *x, WORD32 *y, LOOPINDEX length, WORD16 *q_val)
953 {
954     LOOPINDEX i;
955     WORD40 sum = 0;
956 
957     for(i = 0; i < length; i++)
958     {
959         sum += (WORD40)(mult32(x[i], y[i]));
960     }
961 
962     *q_val = norm40(&sum);
963 
964     return ((WORD32)sum);
965 }
966 
967 /*****************************************************************************/
968 /*                                                                           */
969 /*  function name : mac16_arr40                                              */
970 /*                                                                           */
971 /*  description   : returns normalized 32 bit accumulated result and         */
972 /*                  denormalizing info                                       */
973 /*                                                                           */
974 /*  inputs        : WORD16 x[], WORD16 y[], LOOPINDEX length                 */
975 /*                                                                           */
976 /*  outputs       : WORD16 *q_val                                            */
977 /*                                                                           */
978 /*  globals       : none                                                     */
979 /*                                                                           */
980 /*  processing    : multiply and accumalate in WORD40 finally normalize      */
981 /*                                                                           */
982 /*  returns       : WORD32 accumulated result                                */
983 /*                                                                           */
984 /*  assumptions   : length < 256 for strict definition of WORD40             */
985 /*                                                                           */
986 /*  issues        : none                                                     */
987 /*                                                                           */
988 /*  revision history :                                                       */
989 /*                                                                           */
990 /*        DD MM YYYY       author                changes                     */
991 /*        06 12 2002       ashok M/chetan K      created                     */
992 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
993 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
994 /*                                                                           */
995 /*****************************************************************************/
996 
mac16_arr40(WORD16 * x,WORD16 * y,LOOPINDEX length,WORD16 * q_val)997 static PLATFORM_INLINE WORD32 mac16_arr40(WORD16 *x, WORD16 *y, LOOPINDEX length, WORD16 *q_val)
998 {
999     LOOPINDEX i;
1000     WORD40 sum = 0;
1001 
1002     for(i = 0; i < length; i++)
1003     {
1004         sum += (WORD40)((WORD32)x[i] * (WORD32)y[i]);
1005     }
1006 
1007     *q_val = norm40(&sum);
1008 
1009     return ((WORD32)sum);
1010 }
1011 
1012 /*****************************************************************************/
1013 /*                                                                           */
1014 /*  function name : add32_arr40                                              */
1015 /*                                                                           */
1016 /*  description   : returns normalized 32 bit accumulated result and         */
1017 /*                  denormalizing info                                       */
1018 /*                                                                           */
1019 /*  inputs        : WORD32 x[], LOOPINDEX length                             */
1020 /*                                                                           */
1021 /*  outputs       : WORD16 *q_val                                            */
1022 /*                                                                           */
1023 /*  globals       : none                                                     */
1024 /*                                                                           */
1025 /*  processing    : accumalate in WORD40 finally normalize                   */
1026 /*                                                                           */
1027 /*  returns       : WORD32 accumulated result                                */
1028 /*                                                                           */
1029 /*  assumptions   : length < 256 for strict definition of WORD40             */
1030 /*                                                                           */
1031 /*  issues        : none                                                     */
1032 /*                                                                           */
1033 /*  revision history :                                                       */
1034 /*                                                                           */
1035 /*        DD MM YYYY       author                changes                     */
1036 /*        06 12 2002       ashok M/chetan K      created                     */
1037 /*        21 11 2003       raghavendra K R       modified(bug fixes)         */
1038 /*        15 11 2004       tejaswi/vishal        modified(bug fixes/cleanup) */
1039 /*                                                                           */
1040 /*****************************************************************************/
1041 
add32_arr40(WORD32 * in_arr,LOOPINDEX length,WORD16 * q_val)1042 static PLATFORM_INLINE WORD32 add32_arr40(WORD32 *in_arr, LOOPINDEX length, WORD16 *q_val)
1043 {
1044     LOOPINDEX i;
1045     WORD40 sum = 0;
1046 
1047     for(i = 0; i < length; i++)
1048     {
1049         sum += (WORD40)in_arr[i];
1050     }
1051 
1052     *q_val = norm40(&sum);
1053 
1054     return ((WORD32)sum);
1055 }
1056 
1057 #endif /* __IA_BASIC_OPS40_H__ */
1058