First public contribution.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 //#include "liboil_wsd_solutions.h"
34 #include "liboil/liboilfunction.h"
35 #include "liboil/simdpack/simdpack.h"
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)())
43 OIL_DEFINE_CLASS (abs_f32_f32, "float *dest, int dstr, float *src, int sstr, int n");
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");
54 //static void abs_test (OilFunctionClass *klass, OilFunctionImpl *impl);
56 #define ABS(x) ((x)>0 ? (x) : -(x))
61 * @dest: destination array
62 * @dstr: stride of destination elements
64 * @sstr: stride of source elements
65 * @n: number of elements in arrays
67 * Calculates the absolute value of each element in the source array
68 * and writes it into the destination array.
71 abs_u8_s8_ref (uint8_t *dest, int dstr, int8_t *src, int sstr, int n)
77 x = OIL_GET(src, i*sstr, int8_t);
79 OIL_GET(dest, i*dstr, uint8_t) = x;
82 OIL_DEFINE_IMPL_REF (abs_u8_s8_ref, abs_u8_s8);
86 OilFunctionImpl* __oil_function_impl_abs_u8_s8_ref()
88 return &_oil_function_impl_abs_u8_s8_ref;
93 * @dest: destination array
94 * @dstr: stride of destination elements
96 * @sstr: stride of source elements
97 * @n: number of elements in arrays
99 * Calculates the absolute value of each element in the source array
100 * and writes it into the destination array.
103 abs_u16_s16_ref (uint16_t *dest, int dstr, int16_t *src, int sstr, int n)
108 for (i=0; i<n; i++) {
109 x = OIL_GET(src, i*sstr, int16_t);
111 OIL_GET(dest, i*dstr, uint16_t) = x;
114 OIL_DEFINE_IMPL_REF (abs_u16_s16_ref, abs_u16_s16);
118 * @dest: destination array
119 * @dstr: stride of destination elements
121 * @sstr: stride of source elements
122 * @n: number of elements in arrays
124 * Calculates the absolute value of each element in the source array
125 * and writes it into the destination array.
128 abs_u32_s32_ref (uint32_t *dest, int dstr, int32_t *src, int sstr, int n)
133 for (i=0; i<n; i++) {
134 x = OIL_GET(src, i*sstr, int32_t);
136 OIL_GET(dest, i*dstr, uint32_t) = x;
139 OIL_DEFINE_IMPL_REF (abs_u32_s32_ref, abs_u32_s32);
143 * @dest: destination array
144 * @dstr: stride of destination elements
146 * @sstr: stride of source elements
147 * @n: number of elements in arrays
149 * Calculates the absolute value of each element in the source array
150 * and writes it into the destination array.
153 abs_f32_f32_ref (float *dest, int dstr, float *src, int sstr, int n)
157 for (i=0; i<n; i++) {
158 OIL_GET(dest, i*dstr, float) = fabs(OIL_GET(src, i*sstr, float));
162 OIL_DEFINE_IMPL_REF (abs_f32_f32_ref, abs_f32_f32);
167 OilFunctionImpl* __oil_function_impl_abs_f32_f32_ref() {
168 return &_oil_function_impl_abs_f32_f32_ref;
175 * @dest: destination array
176 * @dstr: stride of destination elements
178 * @sstr: stride of source elements
179 * @n: number of elements in arrays
181 * Calculates the absolute value of each element in the source array
182 * and writes it into the destination array.
185 abs_f64_f64_ref (double *dest, int dstr, double *src, int sstr, int n)
189 for (i=0; i<n; i++) {
190 OIL_GET(dest, i*dstr, double) = fabs(OIL_GET(src, i*sstr, double));
194 OIL_DEFINE_IMPL_REF (abs_f64_f64_ref, abs_f64_f64);
199 OilFunctionClass* __oil_function_class_abs_f32_f32() {
200 return &_oil_function_class_abs_f32_f32;
206 OilFunctionClass* __oil_function_class_abs_u8_s8() {
207 return &_oil_function_class_abs_u8_s8;
213 OilFunctionClass* __oil_function_class_abs_u16_s16() {
214 return &_oil_function_class_abs_u16_s16;
220 OilFunctionClass* __oil_function_class_abs_u32_s32() {
221 return &_oil_function_class_abs_u32_s32;
227 OilFunctionClass* __oil_function_class_abs_f64_f64() {
228 return &_oil_function_class_abs_f64_f64;
234 OilFunctionImpl* __oil_function_impl_abs_u16_s16_ref() {
235 return &_oil_function_impl_abs_u16_s16_ref;
241 OilFunctionImpl* __oil_function_impl_abs_u32_s32_ref() {
242 return &_oil_function_impl_abs_u32_s32_ref;
248 OilFunctionImpl* __oil_function_impl_abs_f64_f64_ref() {
249 return &_oil_function_impl_abs_f64_f64_ref;
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;
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;
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;
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;
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;