Debian Codegraph @

kernels/sifive_x280/1/bli_invertv_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 FLT_LOAD "flw "
43 #define VLE "vle32.v "
44 #define VLSE "vlse32.v "
45 #define VSE "vse32.v "
46 #define VSSE "vsse32.v "
47
48 void bli_sinvertv_sifive_x280_asm(dim_t n, void * restrict x_, inc_t incx,
49 const cntx_t *cntx) {
50 (void)cntx;
51 float* restrict x = x_;
52 if (n <= 0)
53 return;
54
55 float one = 1.f;
56 __asm__(FLT_LOAD "f0, (%0)" : : "r"(&one));
57 incx *= 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 __asm__("vfrdiv.vf v0, v0, f0");
67 __asm__(VSE "v0, (%0)" : : "r"(x));
68 } else {
69 __asm__(VLSE "v0, (%0), %1" : : "r"(x), "r"(incx));
70 __asm__("vfrdiv.vf v0, v0, f0");
71 __asm__(VSSE "v0, (%0), %1" : : "r"(x), "r"(incx));
72 }
73 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
74 avl -= vl;
75 }
76 return;
77 }
78
79 #undef FLT_SIZE
80 #undef FLT_LOAD
81 #undef VLE
82 #undef VLSE
83 #undef VSE
84 #undef VSSE
85
86 #define FLT_SIZE 8
87 #define FLT_LOAD "fld "
88 #define VLE "vle64.v "
89 #define VLSE "vlse64.v "
90 #define VSE "vse64.v "
91 #define VSSE "vsse64.v "
92
93 void bli_dinvertv_sifive_x280_asm(dim_t n, void * restrict x_, inc_t incx,
94 const cntx_t *cntx) {
95 (void)cntx;
96 double* restrict x = x_;
97 if (n <= 0)
98 return;
99
100 double one = 1.;
101 __asm__(FLT_LOAD "f0, (%0)" : : "r"(&one));
102 incx *= FLT_SIZE;
103 size_t avl = n;
104 while (avl) {
105 size_t vl;
106 __asm__ volatile("vsetvli %0, %1, e%2, m8, ta, ma"
107 : "=r"(vl)
108 : "r"(avl), "i"(8 * FLT_SIZE));
109 if (incx == FLT_SIZE) {
110 __asm__(VLE "v0, (%0)" : : "r"(x));
111 __asm__("vfrdiv.vf v0, v0, f0");
112 __asm__(VSE "v0, (%0)" : : "r"(x));
113 } else {
114 __asm__(VLSE "v0, (%0), %1" : : "r"(x), "r"(incx));
115 __asm__("vfrdiv.vf v0, v0, f0");
116 __asm__(VSSE "v0, (%0), %1" : : "r"(x), "r"(incx));
117 }
118 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
119 avl -= vl;
120 }
121 return;
122 }
123
124 #undef FLT_SIZE
125 #undef FLT_LOAD
126 #undef VLE
127 #undef VLSE
128 #undef VSE
129 #undef VSSE
130
131 #define FLT_SIZE 4
132 #define VLSEG2 "vlseg2e32.v "
133 #define VLSSEG2 "vlsseg2e32.v "
134 #define VSSEG2 "vsseg2e32.v "
135 #define VSSSEG2 "vssseg2e32.v "
136
137 void bli_cinvertv_sifive_x280_asm(dim_t n, void * restrict x_, inc_t incx,
138 const cntx_t *cntx) {
139 (void)cntx;
140 scomplex* restrict x = x_;
141 if (n <= 0)
142 return;
143
144 incx *= 2 * FLT_SIZE;
145 size_t avl = n;
146 while (avl) {
147 size_t vl;
148 __asm__ volatile("vsetvli %0, %1, e%2, m4, ta, ma"
149 : "=r"(vl)
150 : "r"(avl), "i"(8 * FLT_SIZE));
151 if (incx == 2 * FLT_SIZE) {
152 __asm__(VLSEG2 "v0, (%0)" : : "r"(x));
153 __asm__("vfneg.v v4, v4");
154 __asm__("vfmul.vv v8, v0, v0");
155 __asm__("vfmacc.vv v8, v4, v4");
156 __asm__("vfdiv.vv v0, v0, v8");
157 __asm__("vfdiv.vv v4, v4, v8");
158 __asm__(VSSEG2 "v0, (%0)" : : "r"(x));
159 } else {
160 __asm__(VLSSEG2 "v0, (%0), %1" : : "r"(x), "r"(incx));
161 __asm__("vfneg.v v4, v4");
162 __asm__("vfmul.vv v8, v0, v0");
163 __asm__("vfmacc.vv v8, v4, v4");
164 __asm__("vfdiv.vv v0, v0, v8");
165 __asm__("vfdiv.vv v4, v4, v8");
166 __asm__(VSSSEG2 "v0, (%0), %1" : : "r"(x), "r"(incx));
167 }
168 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
169 avl -= vl;
170 }
171 return;
172 }
173
174 #undef FLT_SIZE
175 #undef VLSEG2
176 #undef VLSSEG2
177 #undef VSSEG2
178 #undef VSSSEG2
179
180 #define FLT_SIZE 8
181 #define VLSEG2 "vlseg2e64.v "
182 #define VLSSEG2 "vlsseg2e64.v "
183 #define VSSEG2 "vsseg2e64.v "
184 #define VSSSEG2 "vssseg2e64.v "
185
186 void bli_zinvertv_sifive_x280_asm(dim_t n, void * restrict x_, inc_t incx,
187 const cntx_t *cntx) {
188 (void)cntx;
189 dcomplex* restrict x = x_;
190 if (n <= 0)
191 return;
192
193 incx *= 2 * FLT_SIZE;
194 size_t avl = n;
195 while (avl) {
196 size_t vl;
197 __asm__ volatile("vsetvli %0, %1, e%2, m4, ta, ma"
198 : "=r"(vl)
199 : "r"(avl), "i"(8 * FLT_SIZE));
200 if (incx == 2 * FLT_SIZE) {
201 __asm__(VLSEG2 "v0, (%0)" : : "r"(x));
202 __asm__("vfneg.v v4, v4");
203 __asm__("vfmul.vv v8, v0, v0");
204 __asm__("vfmacc.vv v8, v4, v4");
205 __asm__("vfdiv.vv v0, v0, v8");
206 __asm__("vfdiv.vv v4, v4, v8");
207 __asm__(VSSEG2 "v0, (%0)" : : "r"(x));
208 } else {
209 __asm__(VLSSEG2 "v0, (%0), %1" : : "r"(x), "r"(incx));
210 __asm__("vfneg.v v4, v4");
211 __asm__("vfmul.vv v8, v0, v0");
212 __asm__("vfmacc.vv v8, v4, v4");
213 __asm__("vfdiv.vv v0, v0, v8");
214 __asm__("vfdiv.vv v4, v4, v8");
215 __asm__(VSSSEG2 "v0, (%0), %1" : : "r"(x), "r"(incx));
216 }
217 __asm__("add %0, %0, %1" : "+r"(x) : "r"(vl * incx));
218 avl -= vl;
219 }
220 return;
221 }