1/* 2 * Copyright (C) 2004-2010 NXP Software 3 * Copyright (C) 2010 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/********************************************************************************** 19 INCLUDE FILES 20***********************************************************************************/ 21 22#include "VectorArithmetic.h" 23 24/********************************************************************************** 25 FUNCTION Shift_Sat_v32xv32 26***********************************************************************************/ 27#ifdef BUILD_FLOAT 28void Shift_Sat_Float (const LVM_INT16 val, 29 const LVM_FLOAT *src, 30 LVM_FLOAT *dst, 31 LVM_INT16 n) 32{ 33 LVM_FLOAT temp; 34 LVM_INT32 ii,ij; 35 LVM_INT16 RShift; 36 37 if(val > 0) 38 { 39 for (ii = n; ii != 0; ii--) 40 { 41 temp = (LVM_FLOAT)*src; 42 src++; 43 for(ij = 0; ij < val; ij++) 44 { 45 temp = temp * 2; 46 } 47 48 if(temp > 1.0) 49 temp = 1.0; 50 if(temp < -1.0) 51 temp = -1.0; 52 53 *dst = (LVM_FLOAT)temp; 54 dst++; 55 } 56 } 57 else if(val < 0) 58 { 59 RShift=(LVM_INT16)(-val); 60 61 for (ii = n; ii != 0; ii--) 62 { 63 temp = (LVM_FLOAT)*src; 64 src++; 65 for(ij = 0; ij < RShift; ij++) 66 { 67 temp = temp / 2; 68 } 69 *dst = (LVM_FLOAT)temp; 70 dst++; 71 } 72 } 73 else 74 { 75 if(src != dst) 76 { 77 Copy_Float(src, dst, n); 78 } 79 } 80 return; 81} 82#else 83void Shift_Sat_v32xv32 (const LVM_INT16 val, 84 const LVM_INT32 *src, 85 LVM_INT32 *dst, 86 LVM_INT16 n) 87{ 88 LVM_INT32 ii; 89 LVM_INT16 RShift; 90 91 if(val>0) 92 { 93 LVM_INT32 a,b; 94 95 for (ii = n; ii != 0; ii--) 96 { 97 a=*src; 98 src++; 99 100 b=(a<<val); 101 102 if( (b>>val) != a ) /* if overflow occured, right shift will show difference*/ 103 { 104 if(a<0) 105 { 106 b=0x80000000l; 107 } 108 else 109 { 110 b=0x7FFFFFFFl; 111 } 112 } 113 114 *dst = b; 115 dst++; 116 } 117 } 118 else if(val<0) 119 { 120 RShift=(LVM_INT16)(-val); 121 for (ii = n; ii != 0; ii--) 122 { 123 *dst = (*src >> RShift); 124 dst++; 125 src++; 126 } 127 } 128 else 129 { 130 if(src!=dst) 131 { 132 Copy_16((LVM_INT16 *)src,(LVM_INT16 *)dst,(LVM_INT16)(n<<1)); 133 } 134 } 135 return; 136} 137#endif 138/**********************************************************************************/ 139