fix build error
[platform/upstream/openblas.git] / kernel / mips / sasum_msa.c
1 /*******************************************************************************
2 Copyright (c) 2016, The OpenBLAS Project
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 3. Neither the name of the OpenBLAS project nor the names of
14 its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *******************************************************************************/
27
28 #include "common.h"
29 #include <math.h>
30 #include "macros_msa.h"
31
32 #define AND_VEC_W(in)   ((v4f32) ((v4i32) in & and_vec))
33
34 FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
35 {
36     BLASLONG i = 0;
37     FLOAT data0, data1, sumf = 0.0;
38     v4f32 src0, src1, src2, src3, src4, src5, src6, src7;
39     v4f32 src8, src9, src10, src11, src12, src13, src14, src15;
40     v4f32 sum_abs0 = {0, 0, 0, 0};
41     v4f32 sum_abs1 = {0, 0, 0, 0};
42     v4f32 sum_abs2 = {0, 0, 0, 0};
43     v4f32 sum_abs3 = {0, 0, 0, 0};
44     v4f32 zero_v = {0, 0, 0, 0};
45     v4i32 and_vec = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
46
47     if (n <= 0 || inc_x <= 0) return (sumf);
48
49     if (1 == inc_x)
50     {
51         if (n > 63)
52         {
53             FLOAT *x_pref;
54             BLASLONG pref_offset;
55
56             pref_offset = (BLASLONG)x & (L1_DATA_LINESIZE - 1);
57             if (pref_offset > 0)
58             {
59                 pref_offset = L1_DATA_LINESIZE - pref_offset;
60                 pref_offset = pref_offset / sizeof(FLOAT);
61             }
62             x_pref = x + pref_offset + 128 + 32;
63
64             LD_SP8_INC(x, 4, src0, src1, src2, src3, src4, src5, src6, src7);
65             for (i = 0; i < (n >> 6) - 1; i++)
66             {
67                 PREF_OFFSET(x_pref, 0);
68                 PREF_OFFSET(x_pref, 32);
69                 PREF_OFFSET(x_pref, 64);
70                 PREF_OFFSET(x_pref, 96);
71                 PREF_OFFSET(x_pref, 128);
72                 PREF_OFFSET(x_pref, 160);
73                 PREF_OFFSET(x_pref, 192);
74                 PREF_OFFSET(x_pref, 224);
75                 x_pref += 64;
76
77                 LD_SP8_INC(x, 4, src8, src9, src10, src11, src12, src13, src14, src15);
78
79                 sum_abs0 += AND_VEC_W(src0);
80                 sum_abs1 += AND_VEC_W(src1);
81                 sum_abs2 += AND_VEC_W(src2);
82                 sum_abs3 += AND_VEC_W(src3);
83                 sum_abs0 += AND_VEC_W(src4);
84                 sum_abs1 += AND_VEC_W(src5);
85                 sum_abs2 += AND_VEC_W(src6);
86                 sum_abs3 += AND_VEC_W(src7);
87
88                 LD_SP8_INC(x, 4, src0, src1, src2, src3, src4, src5, src6, src7);
89
90                 sum_abs0 += AND_VEC_W(src8);
91                 sum_abs1 += AND_VEC_W(src9);
92                 sum_abs2 += AND_VEC_W(src10);
93                 sum_abs3 += AND_VEC_W(src11);
94                 sum_abs0 += AND_VEC_W(src12);
95                 sum_abs1 += AND_VEC_W(src13);
96                 sum_abs2 += AND_VEC_W(src14);
97                 sum_abs3 += AND_VEC_W(src15);
98             }
99
100             LD_SP8_INC(x, 4, src8, src9, src10, src11, src12, src13, src14, src15);
101
102             sum_abs0 += AND_VEC_W(src0);
103             sum_abs1 += AND_VEC_W(src1);
104             sum_abs2 += AND_VEC_W(src2);
105             sum_abs3 += AND_VEC_W(src3);
106             sum_abs0 += AND_VEC_W(src4);
107             sum_abs1 += AND_VEC_W(src5);
108             sum_abs2 += AND_VEC_W(src6);
109             sum_abs3 += AND_VEC_W(src7);
110             sum_abs0 += AND_VEC_W(src8);
111             sum_abs1 += AND_VEC_W(src9);
112             sum_abs2 += AND_VEC_W(src10);
113             sum_abs3 += AND_VEC_W(src11);
114             sum_abs0 += AND_VEC_W(src12);
115             sum_abs1 += AND_VEC_W(src13);
116             sum_abs2 += AND_VEC_W(src14);
117             sum_abs3 += AND_VEC_W(src15);
118         }
119
120         if (n & 63)
121         {
122             if (n & 32)
123             {
124                 LD_SP8_INC(x, 4, src0, src1, src2, src3, src4, src5, src6, src7);
125
126                 sum_abs0 += AND_VEC_W(src0);
127                 sum_abs1 += AND_VEC_W(src1);
128                 sum_abs2 += AND_VEC_W(src2);
129                 sum_abs3 += AND_VEC_W(src3);
130                 sum_abs0 += AND_VEC_W(src4);
131                 sum_abs1 += AND_VEC_W(src5);
132                 sum_abs2 += AND_VEC_W(src6);
133                 sum_abs3 += AND_VEC_W(src7);
134             }
135
136             if (n & 16)
137             {
138                 LD_SP4_INC(x, 4, src0, src1, src2, src3);
139
140                 sum_abs0 += AND_VEC_W(src0);
141                 sum_abs1 += AND_VEC_W(src1);
142                 sum_abs2 += AND_VEC_W(src2);
143                 sum_abs3 += AND_VEC_W(src3);
144             }
145
146             if (n & 8)
147             {
148                 LD_SP2_INC(x, 4, src0, src1);
149
150                 sum_abs0 += AND_VEC_W(src0);
151                 sum_abs1 += AND_VEC_W(src1);
152             }
153
154             if (n & 4)
155             {
156                 src0 = LD_SP(x); x += 4;
157
158                 sum_abs0 += AND_VEC_W(src0);
159             }
160
161             if (n & 2)
162             {
163                 sumf += fabsf(*x);
164                 sumf += fabsf(*(x + 1));
165                 x += 2;
166             }
167
168             if (n & 1)
169             {
170                 sumf += fabsf(*x);
171             }
172         }
173
174         sum_abs0 += sum_abs1 + sum_abs2 + sum_abs3;
175
176         sumf += sum_abs0[0];
177         sumf += sum_abs0[1];
178         sumf += sum_abs0[2];
179         sumf += sum_abs0[3];
180     }
181     else
182     {
183         for (i = (n >> 4); i--;)
184         {
185             src0 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
186             x += inc_x;
187             src0 = (v4f32) __msa_insert_w((v4i32) src0, 1, *((int *) x));
188             x += inc_x;
189             src0 = (v4f32) __msa_insert_w((v4i32) src0, 2, *((int *) x));
190             x += inc_x;
191             src0 = (v4f32) __msa_insert_w((v4i32) src0, 3, *((int *) x));
192             x += inc_x;
193             src1 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
194             x += inc_x;
195             src1 = (v4f32) __msa_insert_w((v4i32) src1, 1, *((int *) x));
196             x += inc_x;
197             src1 = (v4f32) __msa_insert_w((v4i32) src1, 2, *((int *) x));
198             x += inc_x;
199             src1 = (v4f32) __msa_insert_w((v4i32) src1, 3, *((int *) x));
200             x += inc_x;
201             src2 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
202             x += inc_x;
203             src2 = (v4f32) __msa_insert_w((v4i32) src2, 1, *((int *) x));
204             x += inc_x;
205             src2 = (v4f32) __msa_insert_w((v4i32) src2, 2, *((int *) x));
206             x += inc_x;
207             src2 = (v4f32) __msa_insert_w((v4i32) src2, 3, *((int *) x));
208             x += inc_x;
209             src3 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
210             x += inc_x;
211             src3 = (v4f32) __msa_insert_w((v4i32) src3, 1, *((int *) x));
212             x += inc_x;
213             src3 = (v4f32) __msa_insert_w((v4i32) src3, 2, *((int *) x));
214             x += inc_x;
215             src3 = (v4f32) __msa_insert_w((v4i32) src3, 3, *((int *) x));
216             x += inc_x;
217
218             sum_abs0 += AND_VEC_W(src0);
219             sum_abs1 += AND_VEC_W(src1);
220             sum_abs2 += AND_VEC_W(src2);
221             sum_abs3 += AND_VEC_W(src3);
222         }
223
224         if (n & 15)
225         {
226             if (n & 8)
227             {
228                 src0 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
229                 x += inc_x;
230                 src0 = (v4f32) __msa_insert_w((v4i32) src0, 1, *((int *) x));
231                 x += inc_x;
232                 src0 = (v4f32) __msa_insert_w((v4i32) src0, 2, *((int *) x));
233                 x += inc_x;
234                 src0 = (v4f32) __msa_insert_w((v4i32) src0, 3, *((int *) x));
235                 x += inc_x;
236                 src1 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
237                 x += inc_x;
238                 src1 = (v4f32) __msa_insert_w((v4i32) src1, 1, *((int *) x));
239                 x += inc_x;
240                 src1 = (v4f32) __msa_insert_w((v4i32) src1, 2, *((int *) x));
241                 x += inc_x;
242                 src1 = (v4f32) __msa_insert_w((v4i32) src1, 3, *((int *) x));
243                 x += inc_x;
244
245                 sum_abs0 += AND_VEC_W(src0);
246                 sum_abs1 += AND_VEC_W(src1);
247             }
248
249             if (n & 4)
250             {
251                 src0 = (v4f32) __msa_insert_w((v4i32) zero_v, 0, *((int *) x));
252                 x += inc_x;
253                 src0 = (v4f32) __msa_insert_w((v4i32) src0, 1, *((int *) x));
254                 x += inc_x;
255                 src0 = (v4f32) __msa_insert_w((v4i32) src0, 2, *((int *) x));
256                 x += inc_x;
257                 src0 = (v4f32) __msa_insert_w((v4i32) src0, 3, *((int *) x));
258                 x += inc_x;
259
260                 sum_abs0 += AND_VEC_W(src0);
261             }
262
263             if (n & 2)
264             {
265                 data0 = fabsf(*x); x += inc_x;
266                 data1 = fabsf(*x); x += inc_x;
267
268                 sumf += data0;
269                 sumf += data1;
270             }
271
272             if (n & 1)
273             {
274                 sumf += fabsf(*x);
275             }
276         }
277
278         sum_abs0 += sum_abs1 + sum_abs2 + sum_abs3;
279
280         sumf += sum_abs0[0];
281         sumf += sum_abs0[1];
282         sumf += sum_abs0[2];
283         sumf += sum_abs0[3];
284     }
285
286     return (sumf);
287 }