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 MSTO2I_SAT_16X16
26 ***********************************************************************************/
27
MSTo2i_Sat_16x16(const LVM_INT16 * srcM,const LVM_INT16 * srcS,LVM_INT16 * dst,LVM_INT16 n)28 void MSTo2i_Sat_16x16(const LVM_INT16 *srcM,
29 const LVM_INT16 *srcS,
30 LVM_INT16 *dst,
31 LVM_INT16 n )
32 {
33 LVM_INT32 temp,mVal,sVal;
34 LVM_INT16 ii;
35
36 for (ii = n; ii != 0; ii--)
37 {
38 mVal=(LVM_INT32)*srcM;
39 srcM++;
40
41 sVal=(LVM_INT32)*srcS;
42 srcS++;
43
44 temp = mVal + sVal;
45
46 if (temp > 0x00007FFF)
47 {
48 *dst = 0x7FFF;
49 }
50 else if (temp < -0x00008000)
51 {
52 *dst = - 0x8000;
53 }
54 else
55 {
56 *dst = (LVM_INT16)temp;
57 }
58 dst++;
59
60 temp = mVal - sVal;
61
62 if (temp > 0x00007FFF)
63 {
64 *dst = 0x7FFF;
65 }
66 else if (temp < -0x00008000)
67 {
68 *dst = - 0x8000;
69 }
70 else
71 {
72 *dst = (LVM_INT16)temp;
73 }
74 dst++;
75 }
76
77 return;
78 }
MSTo2i_Sat_Float(const LVM_FLOAT * srcM,const LVM_FLOAT * srcS,LVM_FLOAT * dst,LVM_INT16 n)79 void MSTo2i_Sat_Float(const LVM_FLOAT *srcM,
80 const LVM_FLOAT *srcS,
81 LVM_FLOAT *dst,
82 LVM_INT16 n )
83 {
84 LVM_FLOAT temp,mVal,sVal;
85 LVM_INT16 ii;
86
87 for (ii = n; ii != 0; ii--)
88 {
89 mVal = (LVM_FLOAT)*srcM;
90 srcM++;
91
92 sVal = (LVM_FLOAT)*srcS;
93 srcS++;
94
95 temp = mVal + sVal;
96
97 if (temp > 1.0f)
98 {
99 *dst = 1.0f;
100 }
101 else if (temp < -1.0f)
102 {
103 *dst = -1.0f;
104 }
105 else
106 {
107 *dst = (LVM_FLOAT)temp;
108 }
109 dst++;
110
111 temp = mVal - sVal;
112
113 if (temp > 1.0f)
114 {
115 *dst = 1.0f;
116 }
117 else if (temp < -1.0f)
118 {
119 *dst = - 1.0f;
120 }
121 else
122 {
123 *dst = (LVM_FLOAT)temp;
124 }
125 dst++;
126 }
127
128 return;
129 }
130 /**********************************************************************************/
131