Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: third_party/openmax_dl/dl/src/armCOMM.c

Issue 12317152: Add openmax dl routines for review. MUST NOT BE LANDED (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 *
10 * This file was originally licensed as follows. It has been
11 * relicensed with permission from the copyright holders.
12 */
13
14 /**
15 *
16 * File Name: armCOMM.c
17 * OpenMAX DL: v1.0.2
18 * Revision: 10586
19 * Date: Wednesday, March 5, 2008
20 *
21 * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
22 *
23 *
24 *
25 * Defines Common APIs used across OpenMAX API's
26 */
27
28 #include "omxtypes.h"
29 #include "armCOMM.h"
30
31 /***********************************************************************/
32 /* Miscellaneous Arithmetic operations */
33
34 /**
35 * Function: armRoundFloatToS16
36 *
37 * Description:
38 * Converts a double precision value into a short int after rounding
39 *
40 * Parameters:
41 * [in] Value Float value to be converted
42 *
43 * Return Value:
44 * [out] converted value in OMX_S16 format
45 *
46 */
47
48 OMX_S16 armRoundFloatToS16 (OMX_F64 Value)
49 {
50 if (Value > 0)
51 {
52 return (OMX_S16)(Value + .5);
53 }
54 else
55 {
56 return (OMX_S16)(Value - .5);
57 }
58 }
59
60 /**
61 * Function: armRoundFloatToS32
62 *
63 * Description:
64 * Converts a double precision value into a int after rounding
65 *
66 * Parameters:
67 * [in] Value Float value to be converted
68 *
69 * Return Value:
70 * [out] converted value in OMX_S32 format
71 *
72 */
73
74 OMX_S32 armRoundFloatToS32 (OMX_F64 Value)
75 {
76 if (Value > 0)
77 {
78 return (OMX_S32)(Value + .5);
79 }
80 else
81 {
82 return (OMX_S32)(Value - .5);
83 }
84 }
85 /**
86 * Function: armSatRoundFloatToS16
87 *
88 * Description:
89 * Converts a double precision value into a short int after rounding and saturat ion
90 *
91 * Parameters:
92 * [in] Value Float value to be converted
93 *
94 * Return Value:
95 * [out] converted value in OMX_S16 format
96 *
97 */
98
99 OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value)
100 {
101 if (Value > 0)
102 {
103 Value += 0.5;
104
105 if(Value > (OMX_S16)OMX_MAX_S16 )
106 {
107 return (OMX_S16)OMX_MAX_S16;
108 }
109 else
110 {
111 return (OMX_S16)Value;
112 }
113 }
114 else
115 {
116 Value -= 0.5;
117
118 if(Value < (OMX_S16)OMX_MIN_S16 )
119 {
120 return (OMX_S16)OMX_MIN_S16;
121 }
122 else
123 {
124 return (OMX_S16)Value;
125 }
126 }
127 }
128
129 /**
130 * Function: armSatRoundFloatToS32
131 *
132 * Description:
133 * Converts a double precision value into a int after rounding and saturation
134 *
135 * Parameters:
136 * [in] Value Float value to be converted
137 *
138 * Return Value:
139 * [out] converted value in OMX_S32 format
140 *
141 */
142
143 OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value)
144 {
145 if (Value > 0)
146 {
147 Value += 0.5;
148
149 if(Value > (OMX_S32)OMX_MAX_S32 )
150 {
151 return (OMX_S32)OMX_MAX_S32;
152 }
153 else
154 {
155 return (OMX_S32)Value;
156 }
157 }
158 else
159 {
160 Value -= 0.5;
161
162 if(Value < (OMX_S32)OMX_MIN_S32 )
163 {
164 return (OMX_S32)OMX_MIN_S32;
165 }
166 else
167 {
168 return (OMX_S32)Value;
169 }
170 }
171 }
172
173 /**
174 * Function: armSatRoundFloatToU16
175 *
176 * Description:
177 * Converts a double precision value into a unsigned short int after rounding an d saturation
178 *
179 * Parameters:
180 * [in] Value Float value to be converted
181 *
182 * Return Value:
183 * [out] converted value in OMX_U16 format
184 *
185 */
186
187 OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value)
188 {
189 Value += 0.5;
190
191 if(Value > (OMX_U16)OMX_MAX_U16 )
192 {
193 return (OMX_U16)OMX_MAX_U16;
194 }
195 else
196 {
197 return (OMX_U16)Value;
198 }
199 }
200
201 /**
202 * Function: armSatRoundFloatToU32
203 *
204 * Description:
205 * Converts a double precision value into a unsigned int after rounding and satu ration
206 *
207 * Parameters:
208 * [in] Value Float value to be converted
209 *
210 * Return Value:
211 * [out] converted value in OMX_U32 format
212 *
213 */
214
215 OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value)
216 {
217 Value += 0.5;
218
219 if(Value > (OMX_U32)OMX_MAX_U32 )
220 {
221 return (OMX_U32)OMX_MAX_U32;
222 }
223 else
224 {
225 return (OMX_U32)Value;
226 }
227 }
228
229 /**
230 * Function: armRoundFloatToS64
231 *
232 * Description:
233 * Converts a double precision value into a 64 bit int after rounding
234 *
235 * Parameters:
236 * [in] Value Float value to be converted
237 *
238 * Return Value:
239 * [out] converted value in OMX_S64 format
240 *
241 */
242
243 OMX_S64 armRoundFloatToS64 (OMX_F64 Value)
244 {
245 if (Value > 0)
246 {
247 return (OMX_S64)(Value + .5);
248 }
249 else
250 {
251 return (OMX_S64)(Value - .5);
252 }
253 }
254
255 /**
256 * Function: armSignCheck
257 *
258 * Description:
259 * Checks the sign of a variable:
260 * returns 1 if it is Positive
261 * returns 0 if it is 0
262 * returns -1 if it is Negative
263 *
264 * Remarks:
265 *
266 * Parameters:
267 * [in] var Variable to be checked
268 *
269 * Return Value:
270 * OMX_INT -- returns 1 if it is Positive
271 * returns 0 if it is 0
272 * returns -1 if it is Negative
273 */
274
275 OMX_INT armSignCheck (
276 OMX_S16 var
277 )
278
279 {
280 OMX_INT Sign;
281
282 if (var < 0)
283 {
284 Sign = -1;
285 }
286 else if ( var > 0)
287 {
288 Sign = 1;
289 }
290 else
291 {
292 Sign = 0;
293 }
294
295 return Sign;
296 }
297
298 /**
299 * Function: armClip
300 *
301 * Description: Clips the input between MAX and MIN value
302 *
303 *
304 * Remarks:
305 *
306 * Parameters:
307 * [in] Min lower bound
308 * [in] Max upper bound
309 * [in] src variable to the clipped
310 *
311 * Return Value:
312 * OMX_S32 -- returns clipped value
313 */
314
315 OMX_S32 armClip (
316 OMX_INT min,
317 OMX_INT max,
318 OMX_S32 src
319 )
320
321 {
322 if (src > max)
323 {
324 src = max;
325 }
326 else if (src < min)
327 {
328 src = min;
329 }
330
331 return src;
332 }
333
334 /**
335 * Function: armClip_F32
336 *
337 * Description: Clips the input between MAX and MIN value
338 *
339 *
340 * Remarks:
341 *
342 * Parameters:
343 * [in] Min lower bound
344 * [in] Max upper bound
345 * [in] src variable to the clipped
346 *
347 * Return Value:
348 * OMX_F32 -- returns clipped value
349 */
350
351 OMX_F32 armClip_F32 (
352 OMX_F32 min,
353 OMX_F32 max,
354 OMX_F32 src
355 )
356
357 {
358 if (src > max)
359 {
360 src = max;
361 }
362 else if (src < min)
363 {
364 src = min;
365 }
366
367 return src;
368 }
369
370 /**
371 * Function: armShiftSat_F32
372 *
373 * Description: Divides a float value by 2^shift and
374 * saturates it for unsigned value range for satBits.
375 * Second parameter is like "shifting" the corresponding
376 * integer value. Takes care of rounding while clipping the final
377 * value.
378 *
379 * Parameters:
380 * [in] v Number to be operated upon
381 * [in] shift Divides the input "v" by "2^shift"
382 * [in] satBits Final range is [0, 2^satBits)
383 *
384 * Return Value:
385 * OMX_S32 -- returns "shifted" saturated value
386 */
387
388 OMX_U32 armShiftSat_F32(OMX_F32 v, OMX_INT shift, OMX_INT satBits)
389 {
390 OMX_U32 allOnes = (OMX_U32)(-1);
391 OMX_U32 maxV = allOnes >> (32-satBits);
392 OMX_F32 vShifted, vRounded, shiftDiv = (OMX_F32)(1 << shift);
393 OMX_U32 vInt;
394 OMX_U32 vIntSat;
395
396 if(v <= 0)
397 return 0;
398
399 vShifted = v / shiftDiv;
400 vRounded = (OMX_F32)(vShifted + 0.5);
401 vInt = (OMX_U32)vRounded;
402 vIntSat = vInt;
403 if(vIntSat > maxV)
404 vIntSat = maxV;
405 return vIntSat;
406 }
407
408 /**
409 * Functions: armSwapElem
410 *
411 * Description:
412 * These function swaps two elements at the specified pointer locations.
413 * The size of each element could be anything as specified by <elemSize>
414 *
415 * Return Value:
416 * OMXResult -- Error status from the function
417 */
418 OMXResult armSwapElem(
419 OMX_U8 *pBuf1,
420 OMX_U8 *pBuf2,
421 OMX_INT elemSize
422 )
423 {
424 OMX_INT i;
425 OMX_U8 temp;
426 armRetArgErrIf(!pBuf1 || !pBuf2, OMX_Sts_BadArgErr);
427
428 for(i = 0; i < elemSize; i++)
429 {
430 temp = *(pBuf1 + i);
431 *(pBuf1 + i) = *(pBuf2 + i);
432 *(pBuf2 + i) = temp;
433 }
434 return OMX_Sts_NoErr;
435 }
436
437 /**
438 * Function: armMedianOf3
439 *
440 * Description: Finds the median of three numbers
441 *
442 * Remarks:
443 *
444 * Parameters:
445 * [in] fEntry First entry
446 * [in] sEntry second entry
447 * [in] tEntry Third entry
448 *
449 * Return Value:
450 * OMX_S32 -- returns the median value
451 */
452
453 OMX_S32 armMedianOf3 (
454 OMX_S32 fEntry,
455 OMX_S32 sEntry,
456 OMX_S32 tEntry
457 )
458 {
459 OMX_S32 a, b, c;
460
461 a = armMin (fEntry, sEntry);
462 b = armMax (fEntry, sEntry);
463 c = armMin (b, tEntry);
464 return (armMax (a, c));
465 }
466
467 /**
468 * Function: armLogSize
469 *
470 * Description: Finds the size of a positive value and returns the same
471 *
472 * Remarks:
473 *
474 * Parameters:
475 * [in] value Positive value
476 *
477 * Return Value:
478 * OMX_U8 -- Returns the minimum number of bits required to represent the po sitive value.
479 This is the smallest k>=0 such that that value is less than (1< <k).
480 */
481
482 OMX_U8 armLogSize (
483 OMX_U16 value
484 )
485 {
486 OMX_U8 i;
487 for ( i = 0; value > 0; value = value >> 1)
488 {
489 i++;
490 }
491 return i;
492 }
493
494 /***********************************************************************/
495 /* Saturating Arithmetic operations */
496
497 /**
498 * Function :armSatAdd_S32()
499 *
500 * Description :
501 * Returns the result of saturated addition of the two inputs Value1, Value2
502 *
503 * Parametrs:
504 * [in] Value1 First Operand
505 * [in] Value2 Second Operand
506 *
507 * Return:
508 * [out] Result of operation
509 *
510 *
511 **/
512
513 OMX_S32 armSatAdd_S32(OMX_S32 Value1,OMX_S32 Value2)
514 {
515 OMX_S32 Result;
516
517 Result = Value1 + Value2;
518
519 if( (Value1^Value2) >= 0)
520 {
521 /*Same sign*/
522 if( (Result^Value1) >= 0)
523 {
524 /*Result has not saturated*/
525 return Result;
526 }
527 else
528 {
529 if(Value1 >= 0)
530 {
531 /*Result has saturated in positive side*/
532 return OMX_MAX_S32;
533 }
534 else
535 {
536 /*Result has saturated in negative side*/
537 return OMX_MIN_S32;
538 }
539
540 }
541
542 }
543 else
544 {
545 return Result;
546 }
547
548 }
549
550 /**
551 * Function :armSatAdd_S64()
552 *
553 * Description :
554 * Returns the result of saturated addition of the two inputs Value1, Value2
555 *
556 * Parametrs:
557 * [in] Value1 First Operand
558 * [in] Value2 Second Operand
559 *
560 * Return:
561 * [out] Result of operation
562 *
563 *
564 **/
565
566 OMX_S64 armSatAdd_S64(OMX_S64 Value1,OMX_S64 Value2)
567 {
568 OMX_S64 Result;
569
570 Result = Value1 + Value2;
571
572 if( (Value1^Value2) >= 0)
573 {
574 /*Same sign*/
575 if( (Result^Value1) >= 0)
576 {
577 /*Result has not saturated*/
578 return Result;
579 }
580 else
581 {
582 if(Value1 >= 0)
583 {
584 /*Result has saturated in positive side*/
585 Result = OMX_MAX_S64;
586 return Result;
587 }
588 else
589 {
590 /*Result has saturated in negative side*/
591 return OMX_MIN_S64;
592 }
593
594 }
595
596 }
597 else
598 {
599 return Result;
600 }
601
602 }
603
604 /** Function :armSatSub_S32()
605 *
606 * Description :
607 * Returns the result of saturated substraction of the two inputs Value1, Va lue2
608 *
609 * Parametrs:
610 * [in] Value1 First Operand
611 * [in] Value2 Second Operand
612 *
613 * Return:
614 * [out] Result of operation
615 *
616 **/
617
618 OMX_S32 armSatSub_S32(OMX_S32 Value1,OMX_S32 Value2)
619 {
620 OMX_S32 Result;
621
622 Result = Value1 - Value2;
623
624 if( (Value1^Value2) < 0)
625 {
626 /*Opposite sign*/
627 if( (Result^Value1) >= 0)
628 {
629 /*Result has not saturated*/
630 return Result;
631 }
632 else
633 {
634 if(Value1 >= 0)
635 {
636 /*Result has saturated in positive side*/
637 return OMX_MAX_S32;
638 }
639 else
640 {
641 /*Result has saturated in negative side*/
642 return OMX_MIN_S32;
643 }
644
645 }
646
647 }
648 else
649 {
650 return Result;
651 }
652
653 }
654
655 /**
656 * Function :armSatMac_S32()
657 *
658 * Description :
659 * Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
660 * accumulation with Mac
661 *
662 * Parametrs:
663 * [in] Value1 First Operand
664 * [in] Value2 Second Operand
665 * [in] Mac Accumulator
666 *
667 * Return:
668 * [out] Result of operation
669 **/
670
671 OMX_S32 armSatMac_S32(OMX_S32 Mac,OMX_S16 Value1,OMX_S16 Value2)
672 {
673 OMX_S32 Result;
674
675 Result = (OMX_S32)(Value1*Value2);
676 Result = armSatAdd_S32( Mac , Result );
677
678 return Result;
679 }
680
681 /**
682 * Function :armSatMac_S16S32_S32
683 *
684 * Description :
685 * Returns the result of saturated MAC operation of the three inputs delayElem , filTap , mac
686 *
687 * mac = mac + Saturate_in_32Bits(delayElem * filTap)
688 *
689 * Parametrs:
690 * [in] delayElem First 32 bit Operand
691 * [in] filTap Second 16 bit Operand
692 * [in] mac Result of MAC operation
693 *
694 * Return:
695 * [out] mac Result of operation
696 *
697 **/
698
699 OMX_S32 armSatMac_S16S32_S32(OMX_S32 mac, OMX_S32 delayElem, OMX_S16 filTap )
700 {
701
702 OMX_S32 result;
703
704 result = armSatMulS16S32_S32(filTap,delayElem);
705
706 if ( result > OMX_MAX_S16 )
707 {
708 result = OMX_MAX_S32;
709 }
710 else if( result < OMX_MIN_S16 )
711 {
712 result = OMX_MIN_S32;
713 }
714 else
715 {
716 result = delayElem * filTap;
717 }
718
719 mac = armSatAdd_S32(mac,result);
720
721 return mac;
722 }
723
724
725 /**
726 * Function :armSatRoundRightShift_S32_S16
727 *
728 * Description :
729 * Returns the result of rounded right shift operation of input by the scalefa ctor
730 *
731 * output = Saturate_in_16Bits( ( Right/LeftShift( (Round(input) , shift ) )
732 *
733 * Parametrs:
734 * [in] input The input to be operated on
735 * [in] shift The shift number
736 *
737 * Return:
738 * [out] Result of operation
739 *
740 **/
741
742
743 OMX_S16 armSatRoundRightShift_S32_S16(OMX_S32 input, OMX_INT shift)
744 {
745 input = armSatRoundLeftShift_S32(input,-shift);
746
747 if ( input > OMX_MAX_S16 )
748 {
749 return (OMX_S16)OMX_MAX_S16;
750 }
751 else if (input < OMX_MIN_S16)
752 {
753 return (OMX_S16)OMX_MIN_S16;
754 }
755 else
756 {
757 return (OMX_S16)input;
758 }
759
760 }
761
762 /**
763 * Function :armSatRoundLeftShift_S32()
764 *
765 * Description :
766 * Returns the result of saturating left-shift operation on input
767 * Or rounded Right shift if the input Shift is negative.
768 *
769 * Parametrs:
770 * [in] Value Operand
771 * [in] Shift Operand for shift operation
772 *
773 * Return:
774 * [out] Result of operation
775 *
776 **/
777
778 OMX_S32 armSatRoundLeftShift_S32(OMX_S32 Value, OMX_INT Shift)
779 {
780 OMX_INT i;
781
782 if (Shift < 0)
783 {
784 Shift = -Shift;
785 Value = armSatAdd_S32(Value, (1 << (Shift - 1)));
786 Value = Value >> Shift;
787 }
788 else
789 {
790 for (i = 0; i < Shift; i++)
791 {
792 Value = armSatAdd_S32(Value, Value);
793 }
794 }
795 return Value;
796 }
797
798 /**
799 * Function :armSatRoundLeftShift_S64()
800 *
801 * Description :
802 * Returns the result of saturating left-shift operation on input
803 * Or rounded Right shift if the input Shift is negative.
804 *
805 * Parametrs:
806 * [in] Value Operand
807 * [in] shift Operand for shift operation
808 *
809 * Return:
810 * [out] Result of operation
811 *
812 **/
813
814 OMX_S64 armSatRoundLeftShift_S64(OMX_S64 Value, OMX_INT Shift)
815 {
816 OMX_INT i;
817
818 if (Shift < 0)
819 {
820 Shift = -Shift;
821 Value = armSatAdd_S64(Value, ((OMX_S64)1 << (Shift - 1)));
822 Value = Value >> Shift;
823 }
824 else
825 {
826 for (i = 0; i < Shift; i++)
827 {
828 Value = armSatAdd_S64(Value, Value);
829 }
830 }
831 return Value;
832 }
833
834 /**
835 * Function :armSatMulS16S32_S32()
836 *
837 * Description :
838 * Returns the result of a S16 data type multiplied with an S32 data type
839 * in a S32 container
840 *
841 * Parametrs:
842 * [in] input1 Operand 1
843 * [in] input2 Operand 2
844 *
845 * Return:
846 * [out] Result of operation
847 *
848 **/
849
850
851 OMX_S32 armSatMulS16S32_S32(OMX_S16 input1,OMX_S32 input2)
852 {
853 OMX_S16 hi2,lo1;
854 OMX_U16 lo2;
855
856 OMX_S32 temp1,temp2;
857 OMX_S32 result;
858
859 lo1 = input1;
860
861 hi2 = ( input2 >> 16 );
862 lo2 = ( (OMX_U32)( input2 << 16 ) >> 16 );
863
864 temp1 = hi2 * lo1;
865 temp2 = ( lo2* lo1 ) >> 16;
866
867 result = armSatAdd_S32(temp1,temp2);
868
869 return result;
870 }
871
872 /**
873 * Function :armSatMulS32S32_S32()
874 *
875 * Description :
876 * Returns the result of a S32 data type multiplied with an S32 data type
877 * in a S32 container
878 *
879 * Parametrs:
880 * [in] input1 Operand 1
881 * [in] input2 Operand 2
882 *
883 * Return:
884 * [out] Result of operation
885 *
886 **/
887
888 OMX_S32 armSatMulS32S32_S32(OMX_S32 input1,OMX_S32 input2)
889 {
890 OMX_S16 hi1,hi2;
891 OMX_U16 lo1,lo2;
892
893 OMX_S32 temp1,temp2,temp3;
894 OMX_S32 result;
895
896 hi1 = ( input1 >> 16 );
897 lo1 = ( (OMX_U32)( input1 << 16 ) >> 16 );
898
899 hi2 = ( input2 >> 16 );
900 lo2 = ( (OMX_U32)( input2 << 16 ) >> 16 );
901
902 temp1 = hi1 * hi2;
903 temp2 = ( hi1* lo2 ) >> 16;
904 temp3 = ( hi2* lo1 ) >> 16;
905
906 result = armSatAdd_S32(temp1,temp2);
907 result = armSatAdd_S32(result,temp3);
908
909 return result;
910 }
911
912 /**
913 * Function :armIntDivAwayFromZero()
914 *
915 * Description : Integer division with rounding to the nearest integer.
916 * Half-integer values are rounded away from zero
917 * unless otherwise specified. For example 3//2 is rounded
918 * to 2, and -3//2 is rounded to -2.
919 *
920 * Parametrs:
921 * [in] Num Operand 1
922 * [in] Deno Operand 2
923 *
924 * Return:
925 * [out] Result of operation input1//input2
926 *
927 **/
928
929 OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno)
930 {
931 OMX_F64 result;
932
933 result = ((OMX_F64)Num)/((OMX_F64)Deno);
934
935 if (result >= 0)
936 {
937 result += 0.5;
938 }
939 else
940 {
941 result -= 0.5;
942 }
943
944 return (OMX_S32)(result);
945 }
946
947
948 /*End of File*/
949
OLDNEW
« third_party/openmax_dl/dl/api/armCOMM.h ('K') | « third_party/openmax_dl/dl/sp/src/test/test_util.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698