|
1 /* |
|
2 * LIBOIL - Library of Optimized Inner Loops |
|
3 * Copyright (c) 2003,2004 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/liboilfunction.h> |
|
34 #include "liboil/simdpack/simdpack.h" |
|
35 #include <math.h> |
|
36 |
|
37 static void |
|
38 squaresum_f64_i10_simple(double *dest, double *src, int n) |
|
39 { |
|
40 double sum2 = 0; |
|
41 int i; |
|
42 |
|
43 for(i=0;i<n;i++){ |
|
44 sum2 += src[i]*src[i]; |
|
45 } |
|
46 |
|
47 *dest = sum2; |
|
48 } |
|
49 OIL_DEFINE_IMPL (squaresum_f64_i10_simple, squaresum_f64); |
|
50 |
|
51 #if 0 |
|
52 #include <multsum_f64.h> |
|
53 static void |
|
54 squaresum_f64_i10_multsum(double *dest, double *src, int n) |
|
55 { |
|
56 multsum_f64(dest,src,src,n); |
|
57 } |
|
58 #endif |
|
59 |
|
60 static void |
|
61 squaresum_f64_i10_unroll4a(double *dest, double *src, int n) |
|
62 { |
|
63 double sum1 = 0; |
|
64 double sum2 = 0; |
|
65 double sum3 = 0; |
|
66 double sum4 = 0; |
|
67 |
|
68 while(n&0x3){ |
|
69 sum1 += *src * *src; |
|
70 src++; |
|
71 n--; |
|
72 } |
|
73 while(n>0){ |
|
74 sum1 += *src * *src; |
|
75 src++; |
|
76 sum2 += *src * *src; |
|
77 src++; |
|
78 sum3 += *src * *src; |
|
79 src++; |
|
80 sum4 += *src * *src; |
|
81 src++; |
|
82 n-=4; |
|
83 } |
|
84 |
|
85 *dest = sum1 + sum2 + sum3 + sum4; |
|
86 } |
|
87 OIL_DEFINE_IMPL (squaresum_f64_i10_unroll4a, squaresum_f64); |
|
88 |
|
89 static void |
|
90 squaresum_f64_i10_unroll4(double *dest, double *src, int n) |
|
91 { |
|
92 double sum1 = 0; |
|
93 double sum2 = 0; |
|
94 double sum3 = 0; |
|
95 double sum4 = 0; |
|
96 int i; |
|
97 |
|
98 while(n&0x3){ |
|
99 sum1 += src[0]*src[0]; |
|
100 src++; |
|
101 n--; |
|
102 } |
|
103 for(i=0;i<n;i+=4){ |
|
104 sum1 += src[i]*src[i]; |
|
105 sum2 += src[i+1]*src[i+1]; |
|
106 sum3 += src[i+2]*src[i+2]; |
|
107 sum4 += src[i+3]*src[i+3]; |
|
108 } |
|
109 |
|
110 *dest = sum1 + sum2 + sum3 + sum4; |
|
111 } |
|
112 OIL_DEFINE_IMPL (squaresum_f64_i10_unroll4, squaresum_f64); |
|
113 |
|
114 static void |
|
115 squaresum_f64_i10_unroll8(double *dest, double *src, int n) |
|
116 { |
|
117 double sum1 = 0; |
|
118 double sum2 = 0; |
|
119 double sum3 = 0; |
|
120 double sum4 = 0; |
|
121 double sum5 = 0; |
|
122 double sum6 = 0; |
|
123 double sum7 = 0; |
|
124 double sum8 = 0; |
|
125 int i; |
|
126 |
|
127 while(n&0x7){ |
|
128 sum1 += src[0]*src[0]; |
|
129 src++; |
|
130 n--; |
|
131 } |
|
132 for(i=0;i<n;i+=8){ |
|
133 sum1 += src[i]*src[i]; |
|
134 sum2 += src[i+1]*src[i+1]; |
|
135 sum3 += src[i+2]*src[i+2]; |
|
136 sum4 += src[i+3]*src[i+3]; |
|
137 sum5 += src[i+4]*src[i+4]; |
|
138 sum6 += src[i+5]*src[i+5]; |
|
139 sum7 += src[i+6]*src[i+6]; |
|
140 sum8 += src[i+7]*src[i+7]; |
|
141 } |
|
142 |
|
143 *dest = sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8; |
|
144 } |
|
145 OIL_DEFINE_IMPL (squaresum_f64_i10_unroll8, squaresum_f64); |
|
146 |
|
147 |
|
148 |
|
149 #ifdef __SYMBIAN32__ |
|
150 |
|
151 OilFunctionImpl* __oil_function_impl_squaresum_f64_i10_simple() { |
|
152 return &_oil_function_impl_squaresum_f64_i10_simple; |
|
153 } |
|
154 #endif |
|
155 |
|
156 #ifdef __SYMBIAN32__ |
|
157 |
|
158 OilFunctionImpl* __oil_function_impl_squaresum_f64_i10_unroll4a() { |
|
159 return &_oil_function_impl_squaresum_f64_i10_unroll4a; |
|
160 } |
|
161 #endif |
|
162 |
|
163 #ifdef __SYMBIAN32__ |
|
164 |
|
165 OilFunctionImpl* __oil_function_impl_squaresum_f64_i10_unroll4() { |
|
166 return &_oil_function_impl_squaresum_f64_i10_unroll4; |
|
167 } |
|
168 #endif |
|
169 |
|
170 #ifdef __SYMBIAN32__ |
|
171 |
|
172 OilFunctionImpl* __oil_function_impl_squaresum_f64_i10_unroll8() { |
|
173 return &_oil_function_impl_squaresum_f64_i10_unroll8; |
|
174 } |
|
175 #endif |
|
176 |