fix build error
[platform/upstream/openblas.git] / kernel / mips / sdot_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 "macros_msa.h"
30
31 #if defined(DSDOT)
32 double CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
33 #else
34 FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
35 #endif
36 {
37     BLASLONG i = 0;
38     double dot = 0.0;
39     FLOAT x0, x1, x2, x3, y0, y1, y2, y3;
40     v4f32 vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7;
41     v4f32 vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7;
42     v4f32 dot0 = {0, 0, 0, 0};
43     v4f32 dot1 = {0, 0, 0, 0};
44     v4f32 dot2 = {0, 0, 0, 0};
45     v4f32 dot3 = {0, 0, 0, 0};
46
47     if (n < 1) return (dot);
48
49     if ((1 == inc_x) && (1 == inc_y))
50     {
51         FLOAT *x_pref, *y_pref;
52         BLASLONG pref_offset;
53
54         pref_offset = (BLASLONG)x & (L1_DATA_LINESIZE - 1);
55         if (pref_offset > 0)
56         {
57             pref_offset = L1_DATA_LINESIZE - pref_offset;
58             pref_offset = pref_offset / sizeof(FLOAT);
59         }
60         x_pref = x + pref_offset + 64;
61
62         pref_offset = (BLASLONG)y & (L1_DATA_LINESIZE - 1);
63         if (pref_offset > 0)
64         {
65             pref_offset = L1_DATA_LINESIZE - pref_offset;
66             pref_offset = pref_offset / sizeof(FLOAT);
67         }
68         y_pref = y + pref_offset + 64;
69
70         for (i = (n >> 5); i--;)
71         {
72             LD_SP8_INC(x, 4, vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7);
73             LD_SP8_INC(y, 4, vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7);
74
75             PREF_OFFSET(x_pref, 0);
76             PREF_OFFSET(x_pref, 32);
77             PREF_OFFSET(x_pref, 64);
78             PREF_OFFSET(x_pref, 96);
79             PREF_OFFSET(y_pref, 0);
80             PREF_OFFSET(y_pref, 32);
81             PREF_OFFSET(y_pref, 64);
82             PREF_OFFSET(y_pref, 96);
83             x_pref += 32;
84             y_pref += 32;
85
86             dot0 += (vy0 * vx0);
87             dot1 += (vy1 * vx1);
88             dot2 += (vy2 * vx2);
89             dot3 += (vy3 * vx3);
90             dot0 += (vy4 * vx4);
91             dot1 += (vy5 * vx5);
92             dot2 += (vy6 * vx6);
93             dot3 += (vy7 * vx7);
94         }
95
96         if (n & 31)
97         {
98             if (n & 16)
99             {
100                 LD_SP4_INC(x, 4, vx0, vx1, vx2, vx3);
101                 LD_SP4_INC(y, 4, vy0, vy1, vy2, vy3);
102
103                 dot0 += (vy0 * vx0);
104                 dot1 += (vy1 * vx1);
105                 dot2 += (vy2 * vx2);
106                 dot3 += (vy3 * vx3);
107             }
108
109             if (n & 8)
110             {
111                 LD_SP2_INC(x, 4, vx0, vx1);
112                 LD_SP2_INC(y, 4, vy0, vy1);
113
114                 dot0 += (vy0 * vx0);
115                 dot1 += (vy1 * vx1);
116             }
117
118             if (n & 4)
119             {
120                 vx0 = LD_SP(x); x += 4;
121                 vy0 = LD_SP(y); y += 4;
122
123                 dot0 += (vy0 * vx0);
124             }
125
126             if (n & 2)
127             {
128                 LD_GP2_INC(x, 1, x0, x1);
129                 LD_GP2_INC(y, 1, y0, y1);
130
131                 dot += (y0 * x0);
132                 dot += (y1 * x1);
133             }
134
135             if (n & 1)
136             {
137                 x0 = *x;
138                 y0 = *y;
139
140                 dot += (y0 * x0);
141             }
142         }
143
144         dot0 += dot1 + dot2 + dot3;
145
146         dot += dot0[0];
147         dot += dot0[1];
148         dot += dot0[2];
149         dot += dot0[3];
150     }
151     else
152     {
153         for (i = (n >> 2); i--;)
154         {
155             LD_GP4_INC(x, inc_x, x0, x1, x2, x3);
156             LD_GP4_INC(y, inc_y, y0, y1, y2, y3);
157
158             dot += (y0 * x0);
159             dot += (y1 * x1);
160             dot += (y2 * x2);
161             dot += (y3 * x3);
162         }
163
164         if (n & 2)
165         {
166             LD_GP2_INC(x, inc_x, x0, x1);
167             LD_GP2_INC(y, inc_y, y0, y1);
168
169             dot += (y0 * x0);
170             dot += (y1 * x1);
171         }
172
173         if (n & 1)
174         {
175             x0 = *x;
176             y0 = *y;
177
178             dot += (y0 * x0);
179         }
180     }
181
182     return (dot);
183 }