Debian Codegraph @

kernels/sifive_x280/1/bli_copyv_sifive_x280_asm.c

raw symbols SCIP
1 /*
2
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
6
7 Copyright (C) 2023, SiFive, Inc.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 - Neither the name(s) of the copyright holder(s) nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 */
34
35 #include "blis.h"
36 #include <math.h>
37 #include <riscv_vector.h>
38 #include <stdbool.h>
39 #include <stddef.h>
40
41 #define FLT_SIZE 4
42 #define VLE "vle32.v "
43 #define VLSE "vlse32.v "
44 #define VSE "vse32.v "
45 #define VSSE "vsse32.v "
46
47 void bli_scopyv_sifive_x280_asm(conj_t conjx, dim_t n, const void * restrict x_, inc_t incx,
48 void * restrict y_, inc_t incy, const cntx_t *cntx) {
49 (void)conjx;
50 (void)cntx;
51 const float* restrict x = x_;
52 float* restrict y = y_;
53 if (n <= 0)
54 return;
55
56 incx *= FLT_SIZE;
57 incy *= FLT_SIZE;
58 size_t avl = n;
59 while (avl) {
60 size_t vl;
61 __asm__ volatile("vsetvli %0, %1, e%2, m8, ta, ma"
62 : "=r"(vl)
63 : "r"(avl), "i"(8 * FLT_SIZE));
64 if (incx == FLT_SIZE)
65 __asm__(VLE "v0, (%0)" : : "r"(x));
66 else
67 __asm__(VLSE "v0, (%0), %1" : : "r"(x), "r"(incx));
68
69 if (incy == FLT_SIZE)
70 __asm__(VSE "v0, (%0)" : : "r"(y));
71 else
72 __asm__(VSSE "v0, (%0), %1" : : "r"(y), "r"(incy));
73
74 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
75 __asm__("add %0, %0, %1" : "+r"(y) : "r"(vl * incy));
76 avl -= vl;
77 }
78 return;
79 }
80
81 #undef FLT_SIZE
82 #undef VLE
83 #undef VLSE
84 #undef VSE
85 #undef VSSE
86
87 #define FLT_SIZE 8
88 #define VLE "vle64.v "
89 #define VLSE "vlse64.v "
90 #define VSE "vse64.v "
91 #define VSSE "vsse64.v "
92
93 void bli_dcopyv_sifive_x280_asm(conj_t conjx, dim_t n, const void * restrict x_, inc_t incx,
94 void * restrict y_, inc_t incy, const cntx_t *cntx) {
95 (void)conjx;
96 (void)cntx;
97 const double* restrict x = x_;
98 double* restrict y = y_;
99 if (n <= 0)
100 return;
101
102 incx *= FLT_SIZE;
103 incy *= FLT_SIZE;
104 size_t avl = n;
105 while (avl) {
106 size_t vl;
107 __asm__ volatile("vsetvli %0, %1, e%2, m8, ta, ma"
108 : "=r"(vl)
109 : "r"(avl), "i"(8 * FLT_SIZE));
110 if (incx == FLT_SIZE)
111 __asm__(VLE "v0, (%0)" : : "r"(x));
112 else
113 __asm__(VLSE "v0, (%0), %1" : : "r"(x), "r"(incx));
114
115 if (incy == FLT_SIZE)
116 __asm__(VSE "v0, (%0)" : : "r"(y));
117 else
118 __asm__(VSSE "v0, (%0), %1" : : "r"(y), "r"(incy));
119
120 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
121 __asm__("add %0, %0, %1" : "+r"(y) : "r"(vl * incy));
122 avl -= vl;
123 }
124 return;
125 }
126
127 #undef FLT_SIZE
128 #undef VLE
129 #undef VLSE
130 #undef VSE
131 #undef VSSE
132
133 #define FLT_SIZE 4
134 #define VLE "vle64.v "
135 #define VLSE "vlse64.v "
136 #define VSE "vse64.v "
137 #define VSSE "vsse64.v "
138 #define VLSEG2 "vlseg2e32.v "
139 #define VLSSEG2 "vlsseg2e32.v "
140 #define VSSEG2 "vsseg2e32.v "
141 #define VSSSEG2 "vssseg2e32.v "
142
143 void bli_ccopyv_sifive_x280_asm(conj_t conjx, dim_t n, const void * restrict x_, inc_t incx,
144 void * restrict y_, inc_t incy, const cntx_t *cntx) {
145 (void)cntx;
146 const scomplex* restrict x = x_;
147 scomplex* restrict y = y_;
148 if (n <= 0)
149 return;
150
151 incx *= 2 * FLT_SIZE;
152 incy *= 2 * FLT_SIZE;
153 if (conjx == BLIS_NO_CONJUGATE) {
154 size_t avl = n;
155 while (avl) {
156 size_t vl;
157 __asm__ volatile("vsetvli %0, %1, e%2, m8, ta, ma"
158 : "=r"(vl)
159 : "r"(avl), "i"(8 * 2 * FLT_SIZE));
160 if (incx == 2 * FLT_SIZE)
161 __asm__(VLE "v0, (%0)" : : "r"(x));
162 else
163 __asm__(VLSE "v0, (%0), %1" : : "r"(x), "r"(incx));
164
165 if (incy == 2 * FLT_SIZE)
166 __asm__(VSE "v0, (%0)" : : "r"(y));
167 else
168 __asm__(VSSE "v0, (%0), %1" : : "r"(y), "r"(incy));
169
170 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
171 __asm__("add %0, %0, %1" : "+r"(y) : "r"(vl * incy));
172 avl -= vl;
173 }
174 } else {
175 size_t avl = n;
176 while (avl) {
177 size_t vl;
178 __asm__ volatile("vsetvli %0, %1, e%2, m4, ta, ma"
179 : "=r"(vl)
180 : "r"(avl), "i"(8 * FLT_SIZE));
181 if (incx == 2 * FLT_SIZE)
182 __asm__(VLSEG2 "v0, (%0)" : : "r"(x));
183 else
184 __asm__(VLSSEG2 "v0, (%0), %1" : : "r"(x), "r"(incx));
185
186 __asm__("vfneg.v v4, v4");
187
188 if (incy == 2 * FLT_SIZE)
189 __asm__(VSSEG2 "v0, (%0)" : : "r"(y));
190 else
191 __asm__(VSSSEG2 "v0, (%0), %1" : : "r"(y), "r"(incy));
192
193 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
194 __asm__("add %0, %0, %1" : "+r"(y) : "r"(vl * incy));
195 avl -= vl;
196 }
197 }
198 return;
199 }
200
201 #undef FLT_SIZE
202 #undef VLE
203 #undef VLSE
204 #undef VSE
205 #undef VSSE
206 #undef VLSEG2
207 #undef VLSSEG2
208 #undef VSSEG2
209 #undef VSSSEG2
210
211 #define FLT_SIZE 8
212 #define SH_ADD "sh3add "
213 #define VLE "vle64.v "
214 #define VLSE "vlse64.v "
215 #define VSE "vse64.v "
216 #define VSSE "vsse64.v "
217 #define VLSEG2 "vlseg2e64.v "
218 #define VLSSEG2 "vlsseg2e64.v "
219 #define VSSEG2 "vsseg2e64.v "
220 #define VSSSEG2 "vssseg2e64.v "
221
222 void bli_zcopyv_sifive_x280_asm(conj_t conjx, dim_t n, const void * restrict x_, inc_t incx,
223 void * restrict y_, inc_t incy, const cntx_t *cntx) {
224 (void)cntx;
225 const dcomplex* restrict x = x_;
226 dcomplex* restrict y = y_;
227 if (n <= 0)
228 return;
229
230 incx *= 2 * FLT_SIZE;
231 incy *= 2 * FLT_SIZE;
232 if (conjx == BLIS_NO_CONJUGATE && incx == 2 * FLT_SIZE &&
233 incy == 2 * FLT_SIZE) {
234 size_t avl = 2 * n;
235 while (avl) {
236 size_t vl;
237 __asm__ volatile("vsetvli %0, %1, e%2, m8, ta, ma"
238 : "=r"(vl)
239 : "r"(avl), "i"(8 * FLT_SIZE));
240 __asm__(VLE "v0, (%0)" : : "r"(x));
241 __asm__(VSE "v0, (%0)" : : "r"(y));
242 __asm__(SH_ADD "%0, %1, %0" : "+r"(x) : "r"(vl));
243 __asm__(SH_ADD "%0, %1, %0" : "+r"(y) : "r"(vl));
244 avl -= vl;
245 }
246 } else {
247 size_t avl = n;
248 while (avl) {
249 size_t vl;
250 __asm__ volatile("vsetvli %0, %1, e%2, m4, ta, ma"
251 : "=r"(vl)
252 : "r"(avl), "i"(8 * FLT_SIZE));
253 if (incx == 2 * FLT_SIZE)
254 __asm__(VLSEG2 "v0, (%0)" : : "r"(x));
255 else
256 __asm__(VLSSEG2 "v0, (%0), %1" : : "r"(x), "r"(incx));
257
258 if (conjx == BLIS_CONJUGATE)
259 __asm__("vfneg.v v4, v4");
260
261 if (incy == 2 * FLT_SIZE)
262 __asm__(VSSEG2 "v0, (%0)" : : "r"(y));
263 else
264 __asm__(VSSSEG2 "v0, (%0), %1" : : "r"(y), "r"(incy));
265
266 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
267 __asm__("add %0, %0, %1" : "+r"(y) : "r"(vl * incy));
268 avl -= vl;
269 }
270 }
271 return;
272 }