|
1 /* |
|
2 * LIBOIL - Library of Optimized Inner Loops |
|
3 * Copyright (c) 2003 David A. Schleef <ds@schleef.org> |
|
4 * All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions |
|
8 * are met: |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * |
|
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
25 * POSSIBILITY OF SUCH DAMAGE. |
|
26 */ |
|
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
28 |
|
29 #ifdef HAVE_CONFIG_H |
|
30 #include "config.h" |
|
31 #endif |
|
32 |
|
33 //#include "liboil_wsd_solutions.h" |
|
34 #include "liboil/liboilfunction.h" |
|
35 #include "liboil/simdpack/simdpack.h" |
|
36 #include <math.h> |
|
37 |
|
38 /* |
|
39 #if EMULATOR |
|
40 GET_GLOBAL_VAR_FROM_TLS(_class,abs_f32_f32,OilFunctionClass) |
|
41 #define _oil_function_class_abs_f32_f32 (*GET_OIL_WSD_VAR_NAME(_class,abs_f32_f32,g)()) |
|
42 #else |
|
43 OIL_DEFINE_CLASS (abs_f32_f32, "float *dest, int dstr, float *src, int sstr, int n"); |
|
44 #endif |
|
45 */ |
|
46 |
|
47 OIL_DEFINE_CLASS (abs_u8_s8, "uint8_t *dest, int dstr, int8_t *src, int sstr, int n"); |
|
48 OIL_DEFINE_CLASS (abs_u16_s16, "uint16_t *dest, int dstr, int16_t *src, int sstr, int n"); |
|
49 OIL_DEFINE_CLASS (abs_u32_s32, "uint32_t *dest, int dstr, int32_t *src, int sstr, int n"); |
|
50 OIL_DEFINE_CLASS (abs_f32_f32, "float *dest, int dstr, float *src, int sstr, int n"); |
|
51 OIL_DEFINE_CLASS (abs_f64_f64, "double *dest, int dstr, double *src, int sstr, int n"); |
|
52 |
|
53 |
|
54 //static void abs_test (OilFunctionClass *klass, OilFunctionImpl *impl); |
|
55 |
|
56 #define ABS(x) ((x)>0 ? (x) : -(x)) |
|
57 |
|
58 |
|
59 /** |
|
60 * oil_abs_u8_s8: |
|
61 * @dest: destination array |
|
62 * @dstr: stride of destination elements |
|
63 * @src: source array |
|
64 * @sstr: stride of source elements |
|
65 * @n: number of elements in arrays |
|
66 * |
|
67 * Calculates the absolute value of each element in the source array |
|
68 * and writes it into the destination array. |
|
69 */ |
|
70 static void |
|
71 abs_u8_s8_ref (uint8_t *dest, int dstr, int8_t *src, int sstr, int n) |
|
72 { |
|
73 int i; |
|
74 int x; |
|
75 |
|
76 for (i=0; i<n; i++) { |
|
77 x = OIL_GET(src, i*sstr, int8_t); |
|
78 x = ABS(x); |
|
79 OIL_GET(dest, i*dstr, uint8_t) = x; |
|
80 } |
|
81 } |
|
82 OIL_DEFINE_IMPL_REF (abs_u8_s8_ref, abs_u8_s8); |
|
83 |
|
84 #ifdef __SYMBIAN32__ |
|
85 |
|
86 OilFunctionImpl* __oil_function_impl_abs_u8_s8_ref() |
|
87 { |
|
88 return &_oil_function_impl_abs_u8_s8_ref; |
|
89 } |
|
90 #endif |
|
91 /** |
|
92 * oil_abs_u16_s16: |
|
93 * @dest: destination array |
|
94 * @dstr: stride of destination elements |
|
95 * @src: source array |
|
96 * @sstr: stride of source elements |
|
97 * @n: number of elements in arrays |
|
98 * |
|
99 * Calculates the absolute value of each element in the source array |
|
100 * and writes it into the destination array. |
|
101 */ |
|
102 static void |
|
103 abs_u16_s16_ref (uint16_t *dest, int dstr, int16_t *src, int sstr, int n) |
|
104 { |
|
105 int i; |
|
106 int x; |
|
107 |
|
108 for (i=0; i<n; i++) { |
|
109 x = OIL_GET(src, i*sstr, int16_t); |
|
110 x = ABS(x); |
|
111 OIL_GET(dest, i*dstr, uint16_t) = x; |
|
112 } |
|
113 } |
|
114 OIL_DEFINE_IMPL_REF (abs_u16_s16_ref, abs_u16_s16); |
|
115 |
|
116 /** |
|
117 * oil_abs_u32_s32: |
|
118 * @dest: destination array |
|
119 * @dstr: stride of destination elements |
|
120 * @src: source array |
|
121 * @sstr: stride of source elements |
|
122 * @n: number of elements in arrays |
|
123 * |
|
124 * Calculates the absolute value of each element in the source array |
|
125 * and writes it into the destination array. |
|
126 */ |
|
127 static void |
|
128 abs_u32_s32_ref (uint32_t *dest, int dstr, int32_t *src, int sstr, int n) |
|
129 { |
|
130 int i; |
|
131 int x; |
|
132 |
|
133 for (i=0; i<n; i++) { |
|
134 x = OIL_GET(src, i*sstr, int32_t); |
|
135 x = ABS(x); |
|
136 OIL_GET(dest, i*dstr, uint32_t) = x; |
|
137 } |
|
138 } |
|
139 OIL_DEFINE_IMPL_REF (abs_u32_s32_ref, abs_u32_s32); |
|
140 |
|
141 /** |
|
142 * oil_abs_f32_f32: |
|
143 * @dest: destination array |
|
144 * @dstr: stride of destination elements |
|
145 * @src: source array |
|
146 * @sstr: stride of source elements |
|
147 * @n: number of elements in arrays |
|
148 * |
|
149 * Calculates the absolute value of each element in the source array |
|
150 * and writes it into the destination array. |
|
151 */ |
|
152 static void |
|
153 abs_f32_f32_ref (float *dest, int dstr, float *src, int sstr, int n) |
|
154 { |
|
155 int i; |
|
156 |
|
157 for (i=0; i<n; i++) { |
|
158 OIL_GET(dest, i*dstr, float) = fabs(OIL_GET(src, i*sstr, float)); |
|
159 } |
|
160 } |
|
161 |
|
162 OIL_DEFINE_IMPL_REF (abs_f32_f32_ref, abs_f32_f32); |
|
163 |
|
164 |
|
165 #ifdef __SYMBIAN32__ |
|
166 |
|
167 OilFunctionImpl* __oil_function_impl_abs_f32_f32_ref() { |
|
168 return &_oil_function_impl_abs_f32_f32_ref; |
|
169 } |
|
170 #endif |
|
171 |
|
172 |
|
173 /** |
|
174 * oil_abs_f64_f64: |
|
175 * @dest: destination array |
|
176 * @dstr: stride of destination elements |
|
177 * @src: source array |
|
178 * @sstr: stride of source elements |
|
179 * @n: number of elements in arrays |
|
180 * |
|
181 * Calculates the absolute value of each element in the source array |
|
182 * and writes it into the destination array. |
|
183 */ |
|
184 static void |
|
185 abs_f64_f64_ref (double *dest, int dstr, double *src, int sstr, int n) |
|
186 { |
|
187 int i; |
|
188 |
|
189 for (i=0; i<n; i++) { |
|
190 OIL_GET(dest, i*dstr, double) = fabs(OIL_GET(src, i*sstr, double)); |
|
191 } |
|
192 } |
|
193 |
|
194 OIL_DEFINE_IMPL_REF (abs_f64_f64_ref, abs_f64_f64); |
|
195 |
|
196 |
|
197 #ifdef __SYMBIAN32__ |
|
198 |
|
199 OilFunctionClass* __oil_function_class_abs_f32_f32() { |
|
200 return &_oil_function_class_abs_f32_f32; |
|
201 } |
|
202 #endif |
|
203 |
|
204 #ifdef __SYMBIAN32__ |
|
205 |
|
206 OilFunctionClass* __oil_function_class_abs_u8_s8() { |
|
207 return &_oil_function_class_abs_u8_s8; |
|
208 } |
|
209 #endif |
|
210 |
|
211 #ifdef __SYMBIAN32__ |
|
212 |
|
213 OilFunctionClass* __oil_function_class_abs_u16_s16() { |
|
214 return &_oil_function_class_abs_u16_s16; |
|
215 } |
|
216 #endif |
|
217 |
|
218 #ifdef __SYMBIAN32__ |
|
219 |
|
220 OilFunctionClass* __oil_function_class_abs_u32_s32() { |
|
221 return &_oil_function_class_abs_u32_s32; |
|
222 } |
|
223 #endif |
|
224 |
|
225 #ifdef __SYMBIAN32__ |
|
226 |
|
227 OilFunctionClass* __oil_function_class_abs_f64_f64() { |
|
228 return &_oil_function_class_abs_f64_f64; |
|
229 } |
|
230 #endif |
|
231 |
|
232 #ifdef __SYMBIAN32__ |
|
233 |
|
234 OilFunctionImpl* __oil_function_impl_abs_u16_s16_ref() { |
|
235 return &_oil_function_impl_abs_u16_s16_ref; |
|
236 } |
|
237 #endif |
|
238 |
|
239 #ifdef __SYMBIAN32__ |
|
240 |
|
241 OilFunctionImpl* __oil_function_impl_abs_u32_s32_ref() { |
|
242 return &_oil_function_impl_abs_u32_s32_ref; |
|
243 } |
|
244 #endif |
|
245 |
|
246 #ifdef __SYMBIAN32__ |
|
247 |
|
248 OilFunctionImpl* __oil_function_impl_abs_f64_f64_ref() { |
|
249 return &_oil_function_impl_abs_f64_f64_ref; |
|
250 } |
|
251 #endif |
|
252 |
|
253 |
|
254 |
|
255 #ifdef __SYMBIAN32__ |
|
256 |
|
257 EXPORT_C void** _oil_function_class_ptr_abs_f32_f32 () { |
|
258 oil_function_class_ptr_abs_f32_f32 = __oil_function_class_abs_f32_f32(); |
|
259 return &oil_function_class_ptr_abs_f32_f32->func; |
|
260 } |
|
261 #endif |
|
262 |
|
263 #ifdef __SYMBIAN32__ |
|
264 |
|
265 EXPORT_C void** _oil_function_class_ptr_abs_u8_s8 () { |
|
266 oil_function_class_ptr_abs_u8_s8 = __oil_function_class_abs_u8_s8(); |
|
267 return &oil_function_class_ptr_abs_u8_s8->func; |
|
268 } |
|
269 #endif |
|
270 |
|
271 #ifdef __SYMBIAN32__ |
|
272 |
|
273 EXPORT_C void** _oil_function_class_ptr_abs_u16_s16 () { |
|
274 oil_function_class_ptr_abs_u16_s16 = __oil_function_class_abs_u16_s16(); |
|
275 return &oil_function_class_ptr_abs_u16_s16->func; |
|
276 } |
|
277 #endif |
|
278 |
|
279 #ifdef __SYMBIAN32__ |
|
280 |
|
281 EXPORT_C void** _oil_function_class_ptr_abs_u32_s32 () { |
|
282 oil_function_class_ptr_abs_u32_s32 = __oil_function_class_abs_u32_s32(); |
|
283 return &oil_function_class_ptr_abs_u32_s32->func; |
|
284 } |
|
285 #endif |
|
286 |
|
287 #ifdef __SYMBIAN32__ |
|
288 |
|
289 EXPORT_C void** _oil_function_class_ptr_abs_f64_f64 () { |
|
290 oil_function_class_ptr_abs_f64_f64 = __oil_function_class_abs_f64_f64(); |
|
291 return &oil_function_class_ptr_abs_f64_f64->func; |
|
292 } |
|
293 #endif |
|
294 |