10c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
20c1bc742181ded4930842b46e9507372f0b1b963James Dong *
30c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  armCOMM.c
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong *
110c1bc742181ded4930842b46e9507372f0b1b963James Dong *
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * Defines Common APIs used across OpenMAX API's
130c1bc742181ded4930842b46e9507372f0b1b963James Dong */
140c1bc742181ded4930842b46e9507372f0b1b963James Dong
150c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
160c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
170c1bc742181ded4930842b46e9507372f0b1b963James Dong
180c1bc742181ded4930842b46e9507372f0b1b963James Dong/***********************************************************************/
190c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* Miscellaneous Arithmetic operations */
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armRoundFloatToS16
230c1bc742181ded4930842b46e9507372f0b1b963James Dong *
240c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
250c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a short int after rounding
260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
280c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
290c1bc742181ded4930842b46e9507372f0b1b963James Dong *
300c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
310c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_S16 format
320c1bc742181ded4930842b46e9507372f0b1b963James Dong *
330c1bc742181ded4930842b46e9507372f0b1b963James Dong */
340c1bc742181ded4930842b46e9507372f0b1b963James Dong
350c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S16 armRoundFloatToS16 (OMX_F64 Value)
360c1bc742181ded4930842b46e9507372f0b1b963James Dong{
370c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Value > 0)
380c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
390c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S16)(Value + .5);
400c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
410c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
420c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
430c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S16)(Value - .5);
440c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
450c1bc742181ded4930842b46e9507372f0b1b963James Dong}
460c1bc742181ded4930842b46e9507372f0b1b963James Dong
470c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
480c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armRoundFloatToS32
490c1bc742181ded4930842b46e9507372f0b1b963James Dong *
500c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
510c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a int after rounding
520c1bc742181ded4930842b46e9507372f0b1b963James Dong *
530c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
540c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
550c1bc742181ded4930842b46e9507372f0b1b963James Dong *
560c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
570c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_S32 format
580c1bc742181ded4930842b46e9507372f0b1b963James Dong *
590c1bc742181ded4930842b46e9507372f0b1b963James Dong */
600c1bc742181ded4930842b46e9507372f0b1b963James Dong
610c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armRoundFloatToS32 (OMX_F64 Value)
620c1bc742181ded4930842b46e9507372f0b1b963James Dong{
630c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Value > 0)
640c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
650c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S32)(Value + .5);
660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
670c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
690c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S32)(Value - .5);
700c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
710c1bc742181ded4930842b46e9507372f0b1b963James Dong}
720c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
730c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armSatRoundFloatToS16
740c1bc742181ded4930842b46e9507372f0b1b963James Dong *
750c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
760c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a short int after rounding and saturation
770c1bc742181ded4930842b46e9507372f0b1b963James Dong *
780c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
790c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
800c1bc742181ded4930842b46e9507372f0b1b963James Dong *
810c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
820c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_S16 format
830c1bc742181ded4930842b46e9507372f0b1b963James Dong *
840c1bc742181ded4930842b46e9507372f0b1b963James Dong */
850c1bc742181ded4930842b46e9507372f0b1b963James Dong
860c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S16 armSatRoundFloatToS16 (OMX_F64 Value)
870c1bc742181ded4930842b46e9507372f0b1b963James Dong{
880c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Value > 0)
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
900c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value += 0.5;
910c1bc742181ded4930842b46e9507372f0b1b963James Dong
920c1bc742181ded4930842b46e9507372f0b1b963James Dong        if(Value > (OMX_S16)OMX_MAX_S16 )
930c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
940c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S16)OMX_MAX_S16;
950c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
960c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
970c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
980c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S16)Value;
990c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value -= 0.5;
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong        if(Value < (OMX_S16)OMX_MIN_S16 )
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S16)OMX_MIN_S16;
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S16)Value;
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armSatRoundFloatToS32
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a int after rounding and saturation
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_S32 format
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong */
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong
1300c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatRoundFloatToS32 (OMX_F64 Value)
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Value > 0)
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value += 0.5;
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong        if(Value > (OMX_S32)OMX_MAX_S32 )
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S32)OMX_MAX_S32;
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S32)Value;
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value -= 0.5;
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong        if(Value < (OMX_S32)OMX_MIN_S32 )
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S32)OMX_MIN_S32;
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong            return (OMX_S32)Value;
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armSatRoundFloatToU16
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a unsigned short int after rounding and saturation
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_U16 format
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong */
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong
1740c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U16 armSatRoundFloatToU16 (OMX_F64 Value)
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong    Value += 0.5;
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong    if(Value > (OMX_U16)OMX_MAX_U16 )
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_U16)OMX_MAX_U16;
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_U16)Value;
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armSatRoundFloatToU32
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a unsigned int after rounding and saturation
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_U32 format
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong */
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong
2020c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U32 armSatRoundFloatToU32 (OMX_F64 Value)
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong    Value += 0.5;
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong    if(Value > (OMX_U32)OMX_MAX_U32 )
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_U32)OMX_MAX_U32;
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_U32)Value;
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armRoundFloatToS64
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong * Converts a double precision value into a 64 bit int after rounding
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]  Value                 Float value to be converted
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] converted value in OMX_S64 format
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong */
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong
2300c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S64 armRoundFloatToS64 (OMX_F64 Value)
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Value > 0)
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S64)(Value + .5);
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S64)(Value - .5);
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armSignCheck
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong * Checks the sign of a variable:
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong * returns 1 if it is Positive
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong * returns 0 if it is 0
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong * returns -1 if it is Negative
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	    var     Variable to be checked
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_INT --   returns 1 if it is Positive
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong *              returns 0 if it is 0
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong *              returns -1 if it is Negative
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong */
2610c1bc742181ded4930842b46e9507372f0b1b963James Dong
2620c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_INT armSignCheck (
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S16 var
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong)
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT Sign;
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (var < 0)
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong        Sign = -1;
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if ( var > 0)
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong        Sign = 1;
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong        Sign = 0;
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong    return Sign;
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armClip
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: Clips the input between MAX and MIN value
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Min     lower bound
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Max     upper bound
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] src     variable to the clipped
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_S32 --   returns clipped value
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong */
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong
3020c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armClip (
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT min,
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT max,
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 src
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong)
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (src > max)
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong        src = max;
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (src < min)
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong        src = min;
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong    return src;
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armClip_F32
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: Clips the input between MAX and MIN value
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Min     lower bound
3310c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Max     upper bound
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] src     variable to the clipped
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_F32 --   returns clipped value
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong */
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong
3380c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_F32 armClip_F32 (
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_F32 min,
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_F32 max,
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_F32 src
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong)
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (src > max)
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong        src = max;
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (src < min)
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong        src = min;
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong    return src;
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armShiftSat_F32
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3600c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: Divides a float value by 2^shift and
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong * saturates it for unsigned value range for satBits.
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong * Second parameter is like "shifting" the corresponding
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong * integer value. Takes care of rounding while clipping the final
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong * value.
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3660c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] v          Number to be operated upon
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] shift      Divides the input "v" by "2^shift"
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] satBits    Final range is [0, 2^satBits)
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
3720c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_S32 --   returns "shifted" saturated value
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong */
3740c1bc742181ded4930842b46e9507372f0b1b963James Dong
3750c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U32 armShiftSat_F32(OMX_F32 v, OMX_INT shift, OMX_INT satBits)
3760c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3770c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32 allOnes = (OMX_U32)(-1);
3780c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32 maxV = allOnes >> (32-satBits);
3790c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_F32 vShifted, vRounded, shiftDiv = (OMX_F32)(1 << shift);
3800c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32 vInt;
3810c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32 vIntSat;
3820c1bc742181ded4930842b46e9507372f0b1b963James Dong
3830c1bc742181ded4930842b46e9507372f0b1b963James Dong    if(v <= 0)
3840c1bc742181ded4930842b46e9507372f0b1b963James Dong        return 0;
3850c1bc742181ded4930842b46e9507372f0b1b963James Dong
3860c1bc742181ded4930842b46e9507372f0b1b963James Dong    vShifted = v / shiftDiv;
3870c1bc742181ded4930842b46e9507372f0b1b963James Dong    vRounded = (OMX_F32)(vShifted + 0.5);
3880c1bc742181ded4930842b46e9507372f0b1b963James Dong    vInt = (OMX_U32)vRounded;
3890c1bc742181ded4930842b46e9507372f0b1b963James Dong    vIntSat = vInt;
3900c1bc742181ded4930842b46e9507372f0b1b963James Dong    if(vIntSat > maxV)
3910c1bc742181ded4930842b46e9507372f0b1b963James Dong        vIntSat = maxV;
3920c1bc742181ded4930842b46e9507372f0b1b963James Dong    return vIntSat;
3930c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3940c1bc742181ded4930842b46e9507372f0b1b963James Dong
3950c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
3960c1bc742181ded4930842b46e9507372f0b1b963James Dong * Functions: armSwapElem
3970c1bc742181ded4930842b46e9507372f0b1b963James Dong *
3980c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
3990c1bc742181ded4930842b46e9507372f0b1b963James Dong * These function swaps two elements at the specified pointer locations.
4000c1bc742181ded4930842b46e9507372f0b1b963James Dong * The size of each element could be anything as specified by <elemSize>
4010c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4020c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
4030c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMXResult -- Error status from the function
4040c1bc742181ded4930842b46e9507372f0b1b963James Dong */
4050c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult armSwapElem(
4060c1bc742181ded4930842b46e9507372f0b1b963James Dong        OMX_U8 *pBuf1,
4070c1bc742181ded4930842b46e9507372f0b1b963James Dong        OMX_U8 *pBuf2,
4080c1bc742181ded4930842b46e9507372f0b1b963James Dong        OMX_INT elemSize
4090c1bc742181ded4930842b46e9507372f0b1b963James Dong       )
4100c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4110c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT i;
4120c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8 temp;
4130c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(!pBuf1 || !pBuf2, OMX_Sts_BadArgErr);
4140c1bc742181ded4930842b46e9507372f0b1b963James Dong
4150c1bc742181ded4930842b46e9507372f0b1b963James Dong    for(i = 0; i < elemSize; i++)
4160c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4170c1bc742181ded4930842b46e9507372f0b1b963James Dong        temp = *(pBuf1 + i);
4180c1bc742181ded4930842b46e9507372f0b1b963James Dong        *(pBuf1 + i) = *(pBuf2 + i);
4190c1bc742181ded4930842b46e9507372f0b1b963James Dong        *(pBuf2 + i) = temp;
4200c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4210c1bc742181ded4930842b46e9507372f0b1b963James Dong    return OMX_Sts_NoErr;
4220c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4230c1bc742181ded4930842b46e9507372f0b1b963James Dong
4240c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
4250c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armMedianOf3
4260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: Finds the median of three numbers
4280c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4290c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
4300c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4310c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
4320c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] fEntry     First entry
4330c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] sEntry     second entry
4340c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] tEntry     Third entry
4350c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4360c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
4370c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_S32 --   returns the median value
4380c1bc742181ded4930842b46e9507372f0b1b963James Dong */
4390c1bc742181ded4930842b46e9507372f0b1b963James Dong
4400c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armMedianOf3 (
4410c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 fEntry,
4420c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 sEntry,
4430c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 tEntry
4440c1bc742181ded4930842b46e9507372f0b1b963James Dong)
4450c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4460c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 a, b, c;
4470c1bc742181ded4930842b46e9507372f0b1b963James Dong
4480c1bc742181ded4930842b46e9507372f0b1b963James Dong    a = armMin (fEntry, sEntry);
4490c1bc742181ded4930842b46e9507372f0b1b963James Dong    b = armMax (fEntry, sEntry);
4500c1bc742181ded4930842b46e9507372f0b1b963James Dong    c = armMin (b, tEntry);
4510c1bc742181ded4930842b46e9507372f0b1b963James Dong    return (armMax (a, c));
4520c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4530c1bc742181ded4930842b46e9507372f0b1b963James Dong
4540c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
4550c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armLogSize
4560c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4570c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: Finds the size of a positive value and returns the same
4580c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4590c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
4600c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4610c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
4620c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] value    Positive value
4630c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4640c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
4650c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_U8 --     Returns the minimum number of bits required to represent the positive value.
4660c1bc742181ded4930842b46e9507372f0b1b963James Dong                 This is the smallest k>=0 such that that value is less than (1<<k).
4670c1bc742181ded4930842b46e9507372f0b1b963James Dong */
4680c1bc742181ded4930842b46e9507372f0b1b963James Dong
4690c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U8 armLogSize (
4700c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U16 value
4710c1bc742181ded4930842b46e9507372f0b1b963James Dong)
4720c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4730c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8 i;
4740c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( i = 0; value > 0; value = value >> 1)
4750c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4760c1bc742181ded4930842b46e9507372f0b1b963James Dong        i++;
4770c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4780c1bc742181ded4930842b46e9507372f0b1b963James Dong    return i;
4790c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4800c1bc742181ded4930842b46e9507372f0b1b963James Dong
4810c1bc742181ded4930842b46e9507372f0b1b963James Dong/***********************************************************************/
4820c1bc742181ded4930842b46e9507372f0b1b963James Dong                /* Saturating Arithmetic operations */
4830c1bc742181ded4930842b46e9507372f0b1b963James Dong
4840c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
4850c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatAdd_S32()
4860c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4870c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
4880c1bc742181ded4930842b46e9507372f0b1b963James Dong *   Returns the result of saturated addition of the two inputs Value1, Value2
4890c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4900c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
4910c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value1       First Operand
4920c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value2       Second Operand
4930c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4940c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
4950c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
4960c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4970c1bc742181ded4930842b46e9507372f0b1b963James Dong *
4980c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
4990c1bc742181ded4930842b46e9507372f0b1b963James Dong
5000c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatAdd_S32(OMX_S32 Value1,OMX_S32 Value2)
5010c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5020c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 Result;
5030c1bc742181ded4930842b46e9507372f0b1b963James Dong
5040c1bc742181ded4930842b46e9507372f0b1b963James Dong    Result = Value1 + Value2;
5050c1bc742181ded4930842b46e9507372f0b1b963James Dong
5060c1bc742181ded4930842b46e9507372f0b1b963James Dong    if( (Value1^Value2) >= 0)
5070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5080c1bc742181ded4930842b46e9507372f0b1b963James Dong        /*Same sign*/
5090c1bc742181ded4930842b46e9507372f0b1b963James Dong        if( (Result^Value1) >= 0)
5100c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
5110c1bc742181ded4930842b46e9507372f0b1b963James Dong            /*Result has not saturated*/
5120c1bc742181ded4930842b46e9507372f0b1b963James Dong            return Result;
5130c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
5140c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
5150c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
5160c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(Value1 >= 0)
5170c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
5180c1bc742181ded4930842b46e9507372f0b1b963James Dong                /*Result has saturated in positive side*/
5190c1bc742181ded4930842b46e9507372f0b1b963James Dong                return OMX_MAX_S32;
5200c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
5210c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
5220c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
5230c1bc742181ded4930842b46e9507372f0b1b963James Dong                /*Result has saturated in negative side*/
5240c1bc742181ded4930842b46e9507372f0b1b963James Dong                return OMX_MIN_S32;
5250c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
5260c1bc742181ded4930842b46e9507372f0b1b963James Dong
5270c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
5280c1bc742181ded4930842b46e9507372f0b1b963James Dong
5290c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5300c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
5310c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5320c1bc742181ded4930842b46e9507372f0b1b963James Dong        return Result;
5330c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5340c1bc742181ded4930842b46e9507372f0b1b963James Dong
5350c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5360c1bc742181ded4930842b46e9507372f0b1b963James Dong
5370c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
5380c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatAdd_S64()
5390c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5400c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
5410c1bc742181ded4930842b46e9507372f0b1b963James Dong *   Returns the result of saturated addition of the two inputs Value1, Value2
5420c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5430c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
5440c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value1       First Operand
5450c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value2       Second Operand
5460c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5470c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
5480c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
5490c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5500c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5510c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
5520c1bc742181ded4930842b46e9507372f0b1b963James Dong
5530c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S64 armSatAdd_S64(OMX_S64 Value1,OMX_S64 Value2)
5540c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5550c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S64 Result;
5560c1bc742181ded4930842b46e9507372f0b1b963James Dong
5570c1bc742181ded4930842b46e9507372f0b1b963James Dong    Result = Value1 + Value2;
5580c1bc742181ded4930842b46e9507372f0b1b963James Dong
5590c1bc742181ded4930842b46e9507372f0b1b963James Dong    if( (Value1^Value2) >= 0)
5600c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5610c1bc742181ded4930842b46e9507372f0b1b963James Dong        /*Same sign*/
5620c1bc742181ded4930842b46e9507372f0b1b963James Dong        if( (Result^Value1) >= 0)
5630c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
5640c1bc742181ded4930842b46e9507372f0b1b963James Dong            /*Result has not saturated*/
5650c1bc742181ded4930842b46e9507372f0b1b963James Dong            return Result;
5660c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
5670c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
5680c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
5690c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(Value1 >= 0)
5700c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
5710c1bc742181ded4930842b46e9507372f0b1b963James Dong                /*Result has saturated in positive side*/
5720c1bc742181ded4930842b46e9507372f0b1b963James Dong                Result = OMX_MAX_S64;
5730c1bc742181ded4930842b46e9507372f0b1b963James Dong                return Result;
5740c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
5750c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
5760c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
5770c1bc742181ded4930842b46e9507372f0b1b963James Dong                /*Result has saturated in negative side*/
5780c1bc742181ded4930842b46e9507372f0b1b963James Dong                return OMX_MIN_S64;
5790c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
5800c1bc742181ded4930842b46e9507372f0b1b963James Dong
5810c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
5820c1bc742181ded4930842b46e9507372f0b1b963James Dong
5830c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5840c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
5850c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5860c1bc742181ded4930842b46e9507372f0b1b963James Dong        return Result;
5870c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5880c1bc742181ded4930842b46e9507372f0b1b963James Dong
5890c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5900c1bc742181ded4930842b46e9507372f0b1b963James Dong
5910c1bc742181ded4930842b46e9507372f0b1b963James Dong/** Function :armSatSub_S32()
5920c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5930c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
5940c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Returns the result of saturated substraction of the two inputs Value1, Value2
5950c1bc742181ded4930842b46e9507372f0b1b963James Dong *
5960c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
5970c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value1       First Operand
5980c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value2       Second Operand
5990c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6000c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
6010c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
6020c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6030c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
6040c1bc742181ded4930842b46e9507372f0b1b963James Dong
6050c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatSub_S32(OMX_S32 Value1,OMX_S32 Value2)
6060c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6070c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 Result;
6080c1bc742181ded4930842b46e9507372f0b1b963James Dong
6090c1bc742181ded4930842b46e9507372f0b1b963James Dong    Result = Value1 - Value2;
6100c1bc742181ded4930842b46e9507372f0b1b963James Dong
6110c1bc742181ded4930842b46e9507372f0b1b963James Dong    if( (Value1^Value2) < 0)
6120c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6130c1bc742181ded4930842b46e9507372f0b1b963James Dong        /*Opposite sign*/
6140c1bc742181ded4930842b46e9507372f0b1b963James Dong        if( (Result^Value1) >= 0)
6150c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6160c1bc742181ded4930842b46e9507372f0b1b963James Dong            /*Result has not saturated*/
6170c1bc742181ded4930842b46e9507372f0b1b963James Dong            return Result;
6180c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
6190c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
6200c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6210c1bc742181ded4930842b46e9507372f0b1b963James Dong            if(Value1 >= 0)
6220c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
6230c1bc742181ded4930842b46e9507372f0b1b963James Dong                /*Result has saturated in positive side*/
6240c1bc742181ded4930842b46e9507372f0b1b963James Dong                return OMX_MAX_S32;
6250c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
6260c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
6270c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
6280c1bc742181ded4930842b46e9507372f0b1b963James Dong                /*Result has saturated in negative side*/
6290c1bc742181ded4930842b46e9507372f0b1b963James Dong                return OMX_MIN_S32;
6300c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
6310c1bc742181ded4930842b46e9507372f0b1b963James Dong
6320c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
6330c1bc742181ded4930842b46e9507372f0b1b963James Dong
6340c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6350c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
6360c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6370c1bc742181ded4930842b46e9507372f0b1b963James Dong        return Result;
6380c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6390c1bc742181ded4930842b46e9507372f0b1b963James Dong
6400c1bc742181ded4930842b46e9507372f0b1b963James Dong}
6410c1bc742181ded4930842b46e9507372f0b1b963James Dong
6420c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
6430c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatMac_S32()
6440c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
6460c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
6470c1bc742181ded4930842b46e9507372f0b1b963James Dong *     accumulation with Mac
6480c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6490c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
6500c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value1       First Operand
6510c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value2       Second Operand
6520c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Mac          Accumulator
6530c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6540c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
6550c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
6560c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
6570c1bc742181ded4930842b46e9507372f0b1b963James Dong
6580c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatMac_S32(OMX_S32 Mac,OMX_S16 Value1,OMX_S16 Value2)
6590c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6600c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 Result;
6610c1bc742181ded4930842b46e9507372f0b1b963James Dong
6620c1bc742181ded4930842b46e9507372f0b1b963James Dong    Result = (OMX_S32)(Value1*Value2);
6630c1bc742181ded4930842b46e9507372f0b1b963James Dong    Result = armSatAdd_S32( Mac , Result );
6640c1bc742181ded4930842b46e9507372f0b1b963James Dong
6650c1bc742181ded4930842b46e9507372f0b1b963James Dong    return Result;
6660c1bc742181ded4930842b46e9507372f0b1b963James Dong}
6670c1bc742181ded4930842b46e9507372f0b1b963James Dong
6680c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
6690c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatMac_S16S32_S32
6700c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6710c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
6720c1bc742181ded4930842b46e9507372f0b1b963James Dong *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
6730c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6740c1bc742181ded4930842b46e9507372f0b1b963James Dong *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
6750c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6760c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
6770c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] delayElem    First 32 bit Operand
6780c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] filTap       Second 16 bit Operand
6790c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] mac          Result of MAC operation
6800c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6810c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
6820c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]  mac        Result of operation
6830c1bc742181ded4930842b46e9507372f0b1b963James Dong *
6840c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
6850c1bc742181ded4930842b46e9507372f0b1b963James Dong
6860c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatMac_S16S32_S32(OMX_S32 mac, OMX_S32 delayElem, OMX_S16 filTap )
6870c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6880c1bc742181ded4930842b46e9507372f0b1b963James Dong
6890c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 result;
6900c1bc742181ded4930842b46e9507372f0b1b963James Dong
6910c1bc742181ded4930842b46e9507372f0b1b963James Dong    result = armSatMulS16S32_S32(filTap,delayElem);
6920c1bc742181ded4930842b46e9507372f0b1b963James Dong
6930c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( result > OMX_MAX_S16 )
6940c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6950c1bc742181ded4930842b46e9507372f0b1b963James Dong        result = OMX_MAX_S32;
6960c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6970c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if( result < OMX_MIN_S16 )
6980c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6990c1bc742181ded4930842b46e9507372f0b1b963James Dong        result = OMX_MIN_S32;
7000c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7010c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
7020c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7030c1bc742181ded4930842b46e9507372f0b1b963James Dong        result = delayElem * filTap;
7040c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7050c1bc742181ded4930842b46e9507372f0b1b963James Dong
7060c1bc742181ded4930842b46e9507372f0b1b963James Dong    mac = armSatAdd_S32(mac,result);
7070c1bc742181ded4930842b46e9507372f0b1b963James Dong
7080c1bc742181ded4930842b46e9507372f0b1b963James Dong    return mac;
7090c1bc742181ded4930842b46e9507372f0b1b963James Dong}
7100c1bc742181ded4930842b46e9507372f0b1b963James Dong
7110c1bc742181ded4930842b46e9507372f0b1b963James Dong
7120c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
7130c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatRoundRightShift_S32_S16
7140c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7150c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
7160c1bc742181ded4930842b46e9507372f0b1b963James Dong *   Returns the result of rounded right shift operation of input by the scalefactor
7170c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7180c1bc742181ded4930842b46e9507372f0b1b963James Dong *   output = Saturate_in_16Bits( ( Right/LeftShift( (Round(input) , shift ) )
7190c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7200c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
7210c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] input       The input to be operated on
7220c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] shift The shift number
7230c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7240c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
7250c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]            Result of operation
7260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7270c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
7280c1bc742181ded4930842b46e9507372f0b1b963James Dong
7290c1bc742181ded4930842b46e9507372f0b1b963James Dong
7300c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S16 armSatRoundRightShift_S32_S16(OMX_S32 input, OMX_INT shift)
7310c1bc742181ded4930842b46e9507372f0b1b963James Dong{
7320c1bc742181ded4930842b46e9507372f0b1b963James Dong    input = armSatRoundLeftShift_S32(input,-shift);
7330c1bc742181ded4930842b46e9507372f0b1b963James Dong
7340c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( input > OMX_MAX_S16 )
7350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7360c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S16)OMX_MAX_S16;
7370c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7380c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (input < OMX_MIN_S16)
7390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7400c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (OMX_S16)OMX_MIN_S16;
7410c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7420c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
7430c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7440c1bc742181ded4930842b46e9507372f0b1b963James Dong       return (OMX_S16)input;
7450c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7460c1bc742181ded4930842b46e9507372f0b1b963James Dong
7470c1bc742181ded4930842b46e9507372f0b1b963James Dong}
7480c1bc742181ded4930842b46e9507372f0b1b963James Dong
7490c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
7500c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatRoundLeftShift_S32()
7510c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7520c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
7530c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Returns the result of saturating left-shift operation on input
7540c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Or rounded Right shift if the input Shift is negative.
7550c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7560c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
7570c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value        Operand
7580c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Shift        Operand for shift operation
7590c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7600c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
7610c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
7620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7630c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
7640c1bc742181ded4930842b46e9507372f0b1b963James Dong
7650c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatRoundLeftShift_S32(OMX_S32 Value, OMX_INT Shift)
7660c1bc742181ded4930842b46e9507372f0b1b963James Dong{
7670c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT i;
7680c1bc742181ded4930842b46e9507372f0b1b963James Dong
7690c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Shift < 0)
7700c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7710c1bc742181ded4930842b46e9507372f0b1b963James Dong        Shift = -Shift;
7720c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value = armSatAdd_S32(Value, (1 << (Shift - 1)));
7730c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value = Value >> Shift;
7740c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7750c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
7760c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7770c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 0; i < Shift; i++)
7780c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7790c1bc742181ded4930842b46e9507372f0b1b963James Dong            Value = armSatAdd_S32(Value, Value);
7800c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7810c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7820c1bc742181ded4930842b46e9507372f0b1b963James Dong    return Value;
7830c1bc742181ded4930842b46e9507372f0b1b963James Dong}
7840c1bc742181ded4930842b46e9507372f0b1b963James Dong
7850c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
7860c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatRoundLeftShift_S64()
7870c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7880c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
7890c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Returns the result of saturating left-shift operation on input
7900c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Or rounded Right shift if the input Shift is negative.
7910c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7920c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
7930c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Value        Operand
7940c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] shift        Operand for shift operation
7950c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7960c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
7970c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
7980c1bc742181ded4930842b46e9507372f0b1b963James Dong *
7990c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
8000c1bc742181ded4930842b46e9507372f0b1b963James Dong
8010c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S64 armSatRoundLeftShift_S64(OMX_S64 Value, OMX_INT Shift)
8020c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8030c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT i;
8040c1bc742181ded4930842b46e9507372f0b1b963James Dong
8050c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Shift < 0)
8060c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8070c1bc742181ded4930842b46e9507372f0b1b963James Dong        Shift = -Shift;
8080c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value = armSatAdd_S64(Value, ((OMX_S64)1 << (Shift - 1)));
8090c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value = Value >> Shift;
8100c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8110c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
8120c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8130c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 0; i < Shift; i++)
8140c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
8150c1bc742181ded4930842b46e9507372f0b1b963James Dong            Value = armSatAdd_S64(Value, Value);
8160c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8170c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8180c1bc742181ded4930842b46e9507372f0b1b963James Dong    return Value;
8190c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8200c1bc742181ded4930842b46e9507372f0b1b963James Dong
8210c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
8220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatMulS16S32_S32()
8230c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8240c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
8250c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Returns the result of a S16 data type multiplied with an S32 data type
8260c1bc742181ded4930842b46e9507372f0b1b963James Dong *     in a S32 container
8270c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8280c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
8290c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] input1       Operand 1
8300c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] input2       Operand 2
8310c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8320c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
8330c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
8340c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8350c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
8360c1bc742181ded4930842b46e9507372f0b1b963James Dong
8370c1bc742181ded4930842b46e9507372f0b1b963James Dong
8380c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatMulS16S32_S32(OMX_S16 input1,OMX_S32 input2)
8390c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8400c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S16 hi2,lo1;
8410c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U16 lo2;
8420c1bc742181ded4930842b46e9507372f0b1b963James Dong
8430c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 temp1,temp2;
8440c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 result;
8450c1bc742181ded4930842b46e9507372f0b1b963James Dong
8460c1bc742181ded4930842b46e9507372f0b1b963James Dong    lo1  = input1;
8470c1bc742181ded4930842b46e9507372f0b1b963James Dong
8480c1bc742181ded4930842b46e9507372f0b1b963James Dong    hi2  = ( input2 >>  16 );
8490c1bc742181ded4930842b46e9507372f0b1b963James Dong    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
8500c1bc742181ded4930842b46e9507372f0b1b963James Dong
8510c1bc742181ded4930842b46e9507372f0b1b963James Dong    temp1 = hi2 * lo1;
8520c1bc742181ded4930842b46e9507372f0b1b963James Dong    temp2 = ( lo2* lo1 ) >> 16;
8530c1bc742181ded4930842b46e9507372f0b1b963James Dong
8540c1bc742181ded4930842b46e9507372f0b1b963James Dong    result =  armSatAdd_S32(temp1,temp2);
8550c1bc742181ded4930842b46e9507372f0b1b963James Dong
8560c1bc742181ded4930842b46e9507372f0b1b963James Dong    return result;
8570c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8580c1bc742181ded4930842b46e9507372f0b1b963James Dong
8590c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
8600c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armSatMulS32S32_S32()
8610c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8620c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description :
8630c1bc742181ded4930842b46e9507372f0b1b963James Dong *     Returns the result of a S32 data type multiplied with an S32 data type
8640c1bc742181ded4930842b46e9507372f0b1b963James Dong *     in a S32 container
8650c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8660c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
8670c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] input1       Operand 1
8680c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] input2       Operand 2
8690c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8700c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
8710c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation
8720c1bc742181ded4930842b46e9507372f0b1b963James Dong *
8730c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
8740c1bc742181ded4930842b46e9507372f0b1b963James Dong
8750c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armSatMulS32S32_S32(OMX_S32 input1,OMX_S32 input2)
8760c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8770c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S16 hi1,hi2;
8780c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U16 lo1,lo2;
8790c1bc742181ded4930842b46e9507372f0b1b963James Dong
8800c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 temp1,temp2,temp3;
8810c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 result;
8820c1bc742181ded4930842b46e9507372f0b1b963James Dong
8830c1bc742181ded4930842b46e9507372f0b1b963James Dong    hi1  = ( input1 >>  16 );
8840c1bc742181ded4930842b46e9507372f0b1b963James Dong    lo1  = ( (OMX_U32)( input1 << 16 ) >> 16 );
8850c1bc742181ded4930842b46e9507372f0b1b963James Dong
8860c1bc742181ded4930842b46e9507372f0b1b963James Dong    hi2  = ( input2 >>  16 );
8870c1bc742181ded4930842b46e9507372f0b1b963James Dong    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
8880c1bc742181ded4930842b46e9507372f0b1b963James Dong
8890c1bc742181ded4930842b46e9507372f0b1b963James Dong    temp1 =   hi1 * hi2;
8900c1bc742181ded4930842b46e9507372f0b1b963James Dong    temp2 = ( hi1* lo2 ) >> 16;
8910c1bc742181ded4930842b46e9507372f0b1b963James Dong    temp3 = ( hi2* lo1 ) >> 16;
8920c1bc742181ded4930842b46e9507372f0b1b963James Dong
8930c1bc742181ded4930842b46e9507372f0b1b963James Dong    result = armSatAdd_S32(temp1,temp2);
8940c1bc742181ded4930842b46e9507372f0b1b963James Dong    result = armSatAdd_S32(result,temp3);
8950c1bc742181ded4930842b46e9507372f0b1b963James Dong
8960c1bc742181ded4930842b46e9507372f0b1b963James Dong    return result;
8970c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8980c1bc742181ded4930842b46e9507372f0b1b963James Dong
8990c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
9000c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function :armIntDivAwayFromZero()
9010c1bc742181ded4930842b46e9507372f0b1b963James Dong *
9020c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description : Integer division with rounding to the nearest integer.
9030c1bc742181ded4930842b46e9507372f0b1b963James Dong *               Half-integer values are rounded away from zero
9040c1bc742181ded4930842b46e9507372f0b1b963James Dong *               unless otherwise specified. For example 3//2 is rounded
9050c1bc742181ded4930842b46e9507372f0b1b963James Dong *               to 2, and -3//2 is rounded to -2.
9060c1bc742181ded4930842b46e9507372f0b1b963James Dong *
9070c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parametrs:
9080c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Num        Operand 1
9090c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Deno       Operand 2
9100c1bc742181ded4930842b46e9507372f0b1b963James Dong *
9110c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return:
9120c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]             Result of operation input1//input2
9130c1bc742181ded4930842b46e9507372f0b1b963James Dong *
9140c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
9150c1bc742181ded4930842b46e9507372f0b1b963James Dong
9160c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno)
9170c1bc742181ded4930842b46e9507372f0b1b963James Dong{
9180c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_F64 result;
9190c1bc742181ded4930842b46e9507372f0b1b963James Dong
9200c1bc742181ded4930842b46e9507372f0b1b963James Dong    result = ((OMX_F64)Num)/((OMX_F64)Deno);
9210c1bc742181ded4930842b46e9507372f0b1b963James Dong
9220c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (result >= 0)
9230c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9240c1bc742181ded4930842b46e9507372f0b1b963James Dong        result += 0.5;
9250c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9260c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
9270c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9280c1bc742181ded4930842b46e9507372f0b1b963James Dong        result -= 0.5;
9290c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9300c1bc742181ded4930842b46e9507372f0b1b963James Dong
9310c1bc742181ded4930842b46e9507372f0b1b963James Dong    return (OMX_S32)(result);
9320c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9330c1bc742181ded4930842b46e9507372f0b1b963James Dong
9340c1bc742181ded4930842b46e9507372f0b1b963James Dong
9350c1bc742181ded4930842b46e9507372f0b1b963James Dong/*End of File*/
9360c1bc742181ded4930842b46e9507372f0b1b963James Dong
937