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