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