Elffuss BraidHub

kikocis/ncnn public

master · 24.7 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#ifndef RISCV_USABILITY_H
16#define RISCV_USABILITY_H
17
18#if __riscv_vector
19#include <riscv_vector.h>
20#endif // __riscv_vector
21
22#if __riscv_vector
23static inline int csrr_vl()
24{
25 int a = 0;
26 asm volatile("csrr %0, vl"
27 : "=r"(a)
28 :
29 : "memory");
30 return a;
31}
32
33static inline int csrr_vtype()
34{
35 int a = 0;
36 asm volatile("csrr %0, vtype"
37 : "=r"(a)
38 :
39 : "memory");
40 return a;
41}
42
43static inline int csrr_vlenb()
44{
45 int a = 0;
46 asm volatile("csrr %0, vlenb"
47 : "=r"(a)
48 :
49 : "memory");
50 return a;
51}
52
53static inline vfloat32m8_t vle32_v_f32m8_f32m1(const float* ptr)
54{
55 const int packn = csrr_vlenb() / 4;
56 const size_t vl = vsetvl_e32m8(packn * 8);
57
58 // NOTE vloxei8_v_f32m8 gets illegal instruction on d1 --- nihui
59
60 // 128bit
61 static const uint32_t index_128bit[32] = {
62 0, 4, 8, 12,
63 0, 4, 8, 12,
64 0, 4, 8, 12,
65 0, 4, 8, 12,
66 0, 4, 8, 12,
67 0, 4, 8, 12,
68 0, 4, 8, 12,
69 0, 4, 8, 12
70 };
71
72 // 256bit
73 static const uint32_t index_256bit[64] = {
74 0, 4, 8, 12, 16, 20, 24, 28,
75 0, 4, 8, 12, 16, 20, 24, 28,
76 0, 4, 8, 12, 16, 20, 24, 28,
77 0, 4, 8, 12, 16, 20, 24, 28,
78 0, 4, 8, 12, 16, 20, 24, 28,
79 0, 4, 8, 12, 16, 20, 24, 28,
80 0, 4, 8, 12, 16, 20, 24, 28,
81 0, 4, 8, 12, 16, 20, 24, 28
82 };
83
84 const uint32_t* index = packn == 4 ? index_128bit : index_256bit;
85 vuint32m8_t bindex = vle32_v_u32m8(index, vl);
86 return vloxei32_v_f32m8(ptr, bindex, vl);
87}
88
89#if __riscv_zfh
90static inline vfloat16m8_t vle16_v_f16m8_f16m1(const __fp16* ptr)
91{
92 const int packn = csrr_vlenb() / 2;
93 const size_t vl = vsetvl_e16m8(packn * 8);
94
95 // NOTE vloxei8_v_f16m8 gets illegal instruction on d1 --- nihui
96
97 // 128bit
98 static const uint16_t index_128bit[64] = {
99 0, 2, 4, 6, 8, 10, 12, 14,
100 0, 2, 4, 6, 8, 10, 12, 14,
101 0, 2, 4, 6, 8, 10, 12, 14,
102 0, 2, 4, 6, 8, 10, 12, 14,
103 0, 2, 4, 6, 8, 10, 12, 14,
104 0, 2, 4, 6, 8, 10, 12, 14,
105 0, 2, 4, 6, 8, 10, 12, 14,
106 0, 2, 4, 6, 8, 10, 12, 14
107 };
108
109 // 256bit
110 static const uint16_t index_256bit[128] = {
111 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
112 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
113 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
114 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
115 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
116 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
117 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
118 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
119 };
120
121 const uint16_t* index = packn == 8 ? index_128bit : index_256bit;
122 vuint16m8_t bindex = vle16_v_u16m8(index, vl);
123 return vloxei16_v_f16m8(ptr, bindex, vl);
124}
125#endif // __riscv_zfh
126#endif // __riscv_vector
127
128#if __riscv_vector && __rvv_tuple
129
130// f32m1, vsseg.v
131static inline void vsseg8e32_v_f32m1(float32_t* base, vfloat32m1_t v0, vfloat32m1_t v1, vfloat32m1_t v2, vfloat32m1_t v3, vfloat32m1_t v4, vfloat32m1_t v5, vfloat32m1_t v6, vfloat32m1_t v7, size_t vl)
132{
133 vfloat32m1x8_t _tmp = vcreate_f32m1x8(v0, v1, v2, v3, v4, v5, v6, v7);
134 vsseg8e32_v_f32m1x8(base, _tmp, vl);
135}
136
137static inline void vsseg4e32_v_f32m1(float32_t* base, vfloat32m1_t v0, vfloat32m1_t v1, vfloat32m1_t v2, vfloat32m1_t v3, size_t vl)
138{
139 vfloat32m1x4_t _tmp = vcreate_f32m1x4(v0, v1, v2, v3);
140 vsseg4e32_v_f32m1x4(base, _tmp, vl);
141}
142
143static inline void vsseg2e32_v_f32m1(float32_t* base, vfloat32m1_t v0, vfloat32m1_t v1, size_t vl)
144{
145 vfloat32m1x2_t _tmp = vcreate_f32m1x2(v0, v1);
146 vsseg2e32_v_f32m1x2(base, _tmp, vl);
147}
148
149// f32m1, vssseg.v, 8/4/2
150static inline void vssseg8e32_v_f32m1(float32_t* base, ptrdiff_t bstride, vfloat32m1_t v0, vfloat32m1_t v1, vfloat32m1_t v2, vfloat32m1_t v3, vfloat32m1_t v4, vfloat32m1_t v5, vfloat32m1_t v6, vfloat32m1_t v7, size_t vl)
151{
152 vfloat32m1x8_t _tmp = vcreate_f32m1x8(v0, v1, v2, v3, v4, v5, v6, v7);
153 vssseg8e32_v_f32m1x8(base, bstride, _tmp, vl);
154}
155
156static inline void vssseg4e32_v_f32m1(float32_t* base, ptrdiff_t bstride, vfloat32m1_t v0, vfloat32m1_t v1, vfloat32m1_t v2, vfloat32m1_t v3, size_t vl)
157{
158 vfloat32m1x4_t _tmp = vcreate_f32m1x4(v0, v1, v2, v3);
159 vssseg4e32_v_f32m1x4(base, bstride, _tmp, vl);
160}
161
162static inline void vssseg2e32_v_f32m1(float32_t* base, ptrdiff_t bstride, vfloat32m1_t v0, vfloat32m1_t v1, size_t vl)
163{
164 vfloat32m1x2_t _tmp = vcreate_f32m1x2(v0, v1);
165 vssseg2e32_v_f32m1x2(base, bstride, _tmp, vl);
166}
167
168// f32m2, vsseg.v, 4/2
169static inline void vsseg4e32_v_f32m2(float32_t* base, vfloat32m2_t v0, vfloat32m2_t v1, vfloat32m2_t v2, vfloat32m2_t v3, size_t vl)
170{
171 vfloat32m2x4_t _tmp = vcreate_f32m2x4(v0, v1, v2, v3);
172 vsseg4e32_v_f32m2x4(base, _tmp, vl);
173}
174
175static inline void vsseg2e32_v_f32m2(float32_t* base, vfloat32m2_t v0, vfloat32m2_t v1, size_t vl)
176{
177 vfloat32m2x2_t _tmp = vcreate_f32m2x2(v0, v1);
178 vsseg2e32_v_f32m2x2(base, _tmp, vl);
179}
180
181// u16m1, vsseg.v, 8/4
182static inline void vsseg8e16_v_u16m1(uint16_t* base, vuint16m1_t v0, vuint16m1_t v1, vuint16m1_t v2, vuint16m1_t v3, vuint16m1_t v4, vuint16m1_t v5, vuint16m1_t v6, vuint16m1_t v7, size_t vl)
183{
184 vuint16m1x8_t _tmp = vcreate_u16m1x8(v0, v1, v2, v3, v4, v5, v6, v7);
185 vsseg8e16_v_u16m1x8(base, _tmp, vl);
186}
187
188static inline void vsseg4e16_v_u16m1(uint16_t* base, vuint16m1_t v0, vuint16m1_t v1, vuint16m1_t v2, vuint16m1_t v3, size_t vl)
189{
190 vuint16m1x4_t _tmp = vcreate_u16m1x4(v0, v1, v2, v3);
191 vsseg4e16_v_u16m1x4(base, _tmp, vl);
192}
193
194// u16m2, vsseg.v, 4/2
195static inline void vsseg4e16_v_u16m2(uint16_t* base, vuint16m2_t v0, vuint16m2_t v1, vuint16m2_t v2, vuint16m2_t v3, size_t vl)
196{
197 vuint16m2x4_t _tmp = vcreate_u16m2x4(v0, v1, v2, v3);
198 vsseg4e16_v_u16m2x4(base, _tmp, vl);
199}
200
201static inline void vsseg2e16_v_u16m2(uint16_t* base, vuint16m2_t v0, vuint16m2_t v1, size_t vl)
202{
203 vuint16m2x2_t _tmp = vcreate_u16m2x2(v0, v1);
204 vsseg2e16_v_u16m2x2(base, _tmp, vl);
205}
206
207// f32m1, vlseg.v 8/4/2
208static inline void vlseg8e32_v_f32m1(vfloat32m1_t* v0, vfloat32m1_t* v1, vfloat32m1_t* v2, vfloat32m1_t* v3, vfloat32m1_t* v4, vfloat32m1_t* v5, vfloat32m1_t* v6, vfloat32m1_t* v7, const float32_t* base, size_t vl)
209{
210 vfloat32m1x8_t _tmp = vlseg8e32_v_f32m1x8(base, vl);
211 *v0 = vget_f32m1x8_f32m1(_tmp, 0);
212 *v1 = vget_f32m1x8_f32m1(_tmp, 1);
213 *v2 = vget_f32m1x8_f32m1(_tmp, 2);
214 *v3 = vget_f32m1x8_f32m1(_tmp, 3);
215 *v4 = vget_f32m1x8_f32m1(_tmp, 4);
216 *v5 = vget_f32m1x8_f32m1(_tmp, 5);
217 *v6 = vget_f32m1x8_f32m1(_tmp, 6);
218 *v7 = vget_f32m1x8_f32m1(_tmp, 7);
219}
220
221static inline void vlseg4e32_v_f32m1(vfloat32m1_t* v0, vfloat32m1_t* v1, vfloat32m1_t* v2, vfloat32m1_t* v3, const float32_t* base, size_t vl)
222{
223 vfloat32m1x4_t _tmp = vlseg4e32_v_f32m1x4(base, vl);
224 *v0 = vget_f32m1x4_f32m1(_tmp, 0);
225 *v1 = vget_f32m1x4_f32m1(_tmp, 1);
226 *v2 = vget_f32m1x4_f32m1(_tmp, 2);
227 *v3 = vget_f32m1x4_f32m1(_tmp, 3);
228}
229
230static inline void vlseg2e32_v_f32m1(vfloat32m1_t* v0, vfloat32m1_t* v1, const float32_t* base, size_t vl)
231{
232 vfloat32m1x2_t _tmp = vlseg2e32_v_f32m1x2(base, vl);
233 *v0 = vget_f32m1x2_f32m1(_tmp, 0);
234 *v1 = vget_f32m1x2_f32m1(_tmp, 1);
235}
236
237// f32m2, vlseg.v, 4
238static inline void vlseg4e32_v_f32m2(vfloat32m2_t* v0, vfloat32m2_t* v1, vfloat32m2_t* v2, vfloat32m2_t* v3, const float32_t* base, size_t vl)
239{
240 vfloat32m2x4_t _tmp = vlseg4e32_v_f32m2x4(base, vl);
241 *v0 = vget_f32m2x4_f32m2(_tmp, 0);
242 *v1 = vget_f32m2x4_f32m2(_tmp, 1);
243 *v2 = vget_f32m2x4_f32m2(_tmp, 2);
244 *v3 = vget_f32m2x4_f32m2(_tmp, 3);
245}
246
247// f32m4, vlseg.v, 2
248static inline void vlseg2e32_v_f32m4(vfloat32m4_t* v0, vfloat32m4_t* v1, const float32_t* base, size_t vl)
249{
250 vfloat32m4x2_t _tmp = vlseg2e32_v_f32m4x2(base, vl);
251 *v0 = vget_f32m4x2_f32m4(_tmp, 0);
252 *v1 = vget_f32m4x2_f32m4(_tmp, 1);
253}
254
255// f32m4, vloxseg.v
256static inline void vloxseg2ei32_v_f32m4(vfloat32m4_t* v0, vfloat32m4_t* v1, const float32_t* base, vuint32m4_t bindex, size_t vl)
257{
258 vfloat32m4x2_t _tmp = vloxseg2ei32_v_f32m4x2(base, bindex, vl);
259 *v0 = vget_f32m4x2_f32m4(_tmp, 0);
260 *v1 = vget_f32m4x2_f32m4(_tmp, 1);
261}
262
263// u16m1, vlseg.v 8/4/2
264static inline void vlseg8e16_v_u16m1(vuint16m1_t* v0, vuint16m1_t* v1, vuint16m1_t* v2, vuint16m1_t* v3, vuint16m1_t* v4, vuint16m1_t* v5, vuint16m1_t* v6, vuint16m1_t* v7, const uint16_t* base, size_t vl)
265{
266 vuint16m1x8_t _tmp = vlseg8e16_v_u16m1x8(base, vl);
267 *v0 = vget_u16m1x8_u16m1(_tmp, 0);
268 *v1 = vget_u16m1x8_u16m1(_tmp, 1);
269 *v2 = vget_u16m1x8_u16m1(_tmp, 2);
270 *v3 = vget_u16m1x8_u16m1(_tmp, 3);
271 *v4 = vget_u16m1x8_u16m1(_tmp, 4);
272 *v5 = vget_u16m1x8_u16m1(_tmp, 5);
273 *v6 = vget_u16m1x8_u16m1(_tmp, 6);
274 *v7 = vget_u16m1x8_u16m1(_tmp, 7);
275}
276
277static inline void vlseg4e16_v_u16m1(vuint16m1_t* v0, vuint16m1_t* v1, vuint16m1_t* v2, vuint16m1_t* v3, const uint16_t* base, size_t vl)
278{
279 vuint16m1x4_t _tmp = vlseg4e16_v_u16m1x4(base, vl);
280 *v0 = vget_u16m1x4_u16m1(_tmp, 0);
281 *v1 = vget_u16m1x4_u16m1(_tmp, 1);
282 *v2 = vget_u16m1x4_u16m1(_tmp, 2);
283 *v3 = vget_u16m1x4_u16m1(_tmp, 3);
284}
285
286static inline void vlseg2e16_v_u16m1(vuint16m1_t* v0, vuint16m1_t* v1, const uint16_t* base, size_t vl)
287{
288 vuint16m1x2_t _tmp = vlseg2e16_v_u16m1x2(base, vl);
289 *v0 = vget_u16m1x2_u16m1(_tmp, 0);
290 *v1 = vget_u16m1x2_u16m1(_tmp, 1);
291}
292
293// u16m2, vlseg.v, 4
294static inline void vlseg4e16_v_u16m2(vuint16m2_t* v0, vuint16m2_t* v1, vuint16m2_t* v2, vuint16m2_t* v3, const uint16_t* base, size_t vl)
295{
296 vuint16m2x4_t _tmp = vlseg4e16_v_u16m2x4(base, vl);
297 *v0 = vget_u16m2x4_u16m2(_tmp, 0);
298 *v1 = vget_u16m2x4_u16m2(_tmp, 1);
299 *v2 = vget_u16m2x4_u16m2(_tmp, 2);
300 *v3 = vget_u16m2x4_u16m2(_tmp, 3);
301}
302
303// u16m4, vlseg.v, 2
304static inline void vlseg2e16_v_u16m4(vuint16m4_t* v0, vuint16m4_t* v1, const uint16_t* base, size_t vl)
305{
306 vuint16m4x2_t _tmp = vlseg2e16_v_u16m4x2(base, vl);
307 *v0 = vget_u16m4x2_u16m4(_tmp, 0);
308 *v1 = vget_u16m4x2_u16m4(_tmp, 1);
309}
310
311#if __riscv_zfh
312
313// f16m1, vsseg.v, 8/4/2
314static inline void vsseg8e16_v_f16m1(float16_t* base, vfloat16m1_t v0, vfloat16m1_t v1, vfloat16m1_t v2, vfloat16m1_t v3, vfloat16m1_t v4, vfloat16m1_t v5, vfloat16m1_t v6, vfloat16m1_t v7, size_t vl)
315{
316 vfloat16m1x8_t _tmp = vcreate_f16m1x8(v0, v1, v2, v3, v4, v5, v6, v7);
317 vsseg8e16_v_f16m1x8(base, _tmp, vl);
318}
319
320static inline void vsseg4e16_v_f16m1(float16_t* base, vfloat16m1_t v0, vfloat16m1_t v1, vfloat16m1_t v2, vfloat16m1_t v3, size_t vl)
321{
322 vfloat16m1x4_t _tmp = vcreate_f16m1x4(v0, v1, v2, v3);
323 vsseg4e16_v_f16m1x4(base, _tmp, vl);
324}
325
326static inline void vsseg2e16_v_f16m1(float16_t* base, vfloat16m1_t v0, vfloat16m1_t v1, size_t vl)
327{
328 vfloat16m1x2_t _tmp = vcreate_f16m1x2(v0, v1);
329 vsseg2e16_v_f16m1x2(base, _tmp, vl);
330}
331
332// f16m1, vssseg.v, 8/4/2
333static inline void vssseg8e16_v_f16m1(float16_t* base, ptrdiff_t bstride, vfloat16m1_t v0, vfloat16m1_t v1, vfloat16m1_t v2, vfloat16m1_t v3, vfloat16m1_t v4, vfloat16m1_t v5, vfloat16m1_t v6, vfloat16m1_t v7, size_t vl)
334{
335 vfloat16m1x8_t _tmp = vcreate_f16m1x8(v0, v1, v2, v3, v4, v5, v6, v7);
336 vssseg8e16_v_f16m1x8(base, bstride, _tmp, vl);
337}
338
339static inline void vssseg4e16_v_f16m1(float16_t* base, ptrdiff_t bstride, vfloat16m1_t v0, vfloat16m1_t v1, vfloat16m1_t v2, vfloat16m1_t v3, size_t vl)
340{
341 vfloat16m1x4_t _tmp = vcreate_f16m1x4(v0, v1, v2, v3);
342 vssseg4e16_v_f16m1x4(base, bstride, _tmp, vl);
343}
344
345static inline void vssseg2e16_v_f16m1(float16_t* base, ptrdiff_t bstride, vfloat16m1_t v0, vfloat16m1_t v1, size_t vl)
346{
347 vfloat16m1x2_t _tmp = vcreate_f16m1x2(v0, v1);
348 vssseg2e16_v_f16m1x2(base, bstride, _tmp, vl);
349}
350
351// f16m1, vlseg.v 8/4/2
352static inline void vlseg8e16_v_f16m1(vfloat16m1_t* v0, vfloat16m1_t* v1, vfloat16m1_t* v2, vfloat16m1_t* v3, vfloat16m1_t* v4, vfloat16m1_t* v5, vfloat16m1_t* v6, vfloat16m1_t* v7, const float16_t* base, size_t vl)
353{
354 vfloat16m1x8_t _tmp = vlseg8e16_v_f16m1x8(base, vl);
355 *v0 = vget_f16m1x8_f16m1(_tmp, 0);
356 *v1 = vget_f16m1x8_f16m1(_tmp, 1);
357 *v2 = vget_f16m1x8_f16m1(_tmp, 2);
358 *v3 = vget_f16m1x8_f16m1(_tmp, 3);
359 *v4 = vget_f16m1x8_f16m1(_tmp, 4);
360 *v5 = vget_f16m1x8_f16m1(_tmp, 5);
361 *v6 = vget_f16m1x8_f16m1(_tmp, 6);
362 *v7 = vget_f16m1x8_f16m1(_tmp, 7);
363}
364
365static inline void vlseg4e16_v_f16m1(vfloat16m1_t* v0, vfloat16m1_t* v1, vfloat16m1_t* v2, vfloat16m1_t* v3, const float16_t* base, size_t vl)
366{
367 vfloat16m1x4_t _tmp = vlseg4e16_v_f16m1x4(base, vl);
368 *v0 = vget_f16m1x4_f16m1(_tmp, 0);
369 *v1 = vget_f16m1x4_f16m1(_tmp, 1);
370 *v2 = vget_f16m1x4_f16m1(_tmp, 2);
371 *v3 = vget_f16m1x4_f16m1(_tmp, 3);
372}
373
374static inline void vlseg2e16_v_f16m1(vfloat16m1_t* v0, vfloat16m1_t* v1, const float16_t* base, size_t vl)
375{
376 vfloat16m1x2_t _tmp = vlseg2e16_v_f16m1x2(base, vl);
377 *v0 = vget_f16m1x2_f16m1(_tmp, 0);
378 *v1 = vget_f16m1x2_f16m1(_tmp, 1);
379}
380
381// f16m2, vlseg.v, 4
382static inline void vlseg4e16_v_f16m2(vfloat16m2_t* v0, vfloat16m2_t* v1, vfloat16m2_t* v2, vfloat16m2_t* v3, const float16_t* base, size_t vl)
383{
384 vfloat16m2x4_t _tmp = vlseg4e16_v_f16m2x4(base, vl);
385 *v0 = vget_f16m2x4_f16m2(_tmp, 0);
386 *v1 = vget_f16m2x4_f16m2(_tmp, 1);
387 *v2 = vget_f16m2x4_f16m2(_tmp, 2);
388 *v3 = vget_f16m2x4_f16m2(_tmp, 3);
389}
390
391// f16m4, vlseg.v, 2
392static inline void vlseg2e16_v_f16m4(vfloat16m4_t* v0, vfloat16m4_t* v1, const float16_t* base, size_t vl)
393{
394 vfloat16m4x2_t _tmp = vlseg2e16_v_f16m4x2(base, vl);
395 *v0 = vget_f16m4x2_f16m4(_tmp, 0);
396 *v1 = vget_f16m4x2_f16m4(_tmp, 1);
397}
398
399#endif // __riscv_zfh
400#endif // __riscv_vector
401
402#ifdef __riscv_vector
403
404static inline void transpose8x8_ps(vfloat32m1_t& _r0l, vfloat32m1_t& _r0h,
405 vfloat32m1_t& _r1l, vfloat32m1_t& _r1h,
406 vfloat32m1_t& _r2l, vfloat32m1_t& _r2h,
407 vfloat32m1_t& _r3l, vfloat32m1_t& _r3h,
408 vfloat32m1_t& _r4l, vfloat32m1_t& _r4h,
409 vfloat32m1_t& _r5l, vfloat32m1_t& _r5h,
410 vfloat32m1_t& _r6l, vfloat32m1_t& _r6h,
411 vfloat32m1_t& _r7l, vfloat32m1_t& _r7h, size_t vl)
412{
413 float tmp[64];
414 vsseg8e32_v_f32m1(&tmp[0], _r0l, _r1l, _r2l, _r3l, _r4l, _r5l, _r6l, _r7l, vl);
415 vsseg8e32_v_f32m1(&tmp[32], _r0h, _r1h, _r2h, _r3h, _r4h, _r5h, _r6h, _r7h, vl);
416 float* ptr = (float*)tmp;
417 _r0l = vle32_v_f32m1(ptr + 0 * 4, vl);
418 _r0h = vle32_v_f32m1(ptr + 1 * 4, vl);
419 _r1l = vle32_v_f32m1(ptr + 2 * 4, vl);
420 _r1h = vle32_v_f32m1(ptr + 3 * 4, vl);
421 _r2l = vle32_v_f32m1(ptr + 4 * 4, vl);
422 _r2h = vle32_v_f32m1(ptr + 5 * 4, vl);
423 _r3l = vle32_v_f32m1(ptr + 6 * 4, vl);
424 _r3h = vle32_v_f32m1(ptr + 7 * 4, vl);
425 _r4l = vle32_v_f32m1(ptr + 8 * 4, vl);
426 _r4h = vle32_v_f32m1(ptr + 9 * 4, vl);
427 _r5l = vle32_v_f32m1(ptr + 10 * 4, vl);
428 _r5h = vle32_v_f32m1(ptr + 11 * 4, vl);
429 _r6l = vle32_v_f32m1(ptr + 12 * 4, vl);
430 _r6h = vle32_v_f32m1(ptr + 13 * 4, vl);
431 _r7l = vle32_v_f32m1(ptr + 14 * 4, vl);
432 _r7h = vle32_v_f32m1(ptr + 15 * 4, vl);
433}
434
435static inline void transpose4x4_ps(vfloat32m1_t& _r0, vfloat32m1_t& _r1, vfloat32m1_t& _r2, vfloat32m1_t& _r3, size_t vl)
436{
437 float tmp[16];
438 vsseg4e32_v_f32m1(&tmp[0], _r0, _r1, _r2, _r3, vl);
439 float* ptr = (float*)tmp;
440 _r0 = vle32_v_f32m1(ptr + 0 * 4, vl);
441 _r1 = vle32_v_f32m1(ptr + 1 * 4, vl);
442 _r2 = vle32_v_f32m1(ptr + 2 * 4, vl);
443 _r3 = vle32_v_f32m1(ptr + 3 * 4, vl);
444}
445
446static inline void transpose8x12_ps(vfloat32m1_t& _r0l, vfloat32m1_t& _r0h,
447 vfloat32m1_t& _r1l, vfloat32m1_t& _r1h,
448 vfloat32m1_t& _r2l, vfloat32m1_t& _r2h,
449 vfloat32m1_t& _r3l, vfloat32m1_t& _r3h,
450 vfloat32m1_t& _r4l, vfloat32m1_t& _r4h,
451 vfloat32m1_t& _r5l, vfloat32m1_t& _r5h,
452 vfloat32m1_t& _r6l, vfloat32m1_t& _r6h,
453 vfloat32m1_t& _r7l, vfloat32m1_t& _r7h,
454 vfloat32m1_t& _r8l, vfloat32m1_t& _r8h,
455 vfloat32m1_t& _r9l, vfloat32m1_t& _r9h,
456 vfloat32m1_t& _ral, vfloat32m1_t& _rah,
457 vfloat32m1_t& _rbl, vfloat32m1_t& _rbh, size_t vl)
458{
459 float tmp[8][12];
460
461 vsse32_v_f32m1(&tmp[0][0], sizeof(float) * 12, _r0l, vl);
462 vsse32_v_f32m1(&tmp[4][0], sizeof(float) * 12, _r0h, vl);
463 vsse32_v_f32m1(&tmp[0][1], sizeof(float) * 12, _r1l, vl);
464 vsse32_v_f32m1(&tmp[4][1], sizeof(float) * 12, _r1h, vl);
465 vsse32_v_f32m1(&tmp[0][2], sizeof(float) * 12, _r2l, vl);
466 vsse32_v_f32m1(&tmp[4][2], sizeof(float) * 12, _r2h, vl);
467 vsse32_v_f32m1(&tmp[0][3], sizeof(float) * 12, _r3l, vl);
468 vsse32_v_f32m1(&tmp[4][3], sizeof(float) * 12, _r3h, vl);
469 vsse32_v_f32m1(&tmp[0][4], sizeof(float) * 12, _r4l, vl);
470 vsse32_v_f32m1(&tmp[4][4], sizeof(float) * 12, _r4h, vl);
471 vsse32_v_f32m1(&tmp[0][5], sizeof(float) * 12, _r5l, vl);
472 vsse32_v_f32m1(&tmp[4][5], sizeof(float) * 12, _r5h, vl);
473 vsse32_v_f32m1(&tmp[0][6], sizeof(float) * 12, _r6l, vl);
474 vsse32_v_f32m1(&tmp[4][6], sizeof(float) * 12, _r6h, vl);
475 vsse32_v_f32m1(&tmp[0][7], sizeof(float) * 12, _r7l, vl);
476 vsse32_v_f32m1(&tmp[4][7], sizeof(float) * 12, _r7h, vl);
477 vsse32_v_f32m1(&tmp[0][8], sizeof(float) * 12, _r8l, vl);
478 vsse32_v_f32m1(&tmp[4][8], sizeof(float) * 12, _r8h, vl);
479 vsse32_v_f32m1(&tmp[0][9], sizeof(float) * 12, _r9l, vl);
480 vsse32_v_f32m1(&tmp[4][9], sizeof(float) * 12, _r9h, vl);
481 vsse32_v_f32m1(&tmp[0][10], sizeof(float) * 12, _ral, vl);
482 vsse32_v_f32m1(&tmp[4][10], sizeof(float) * 12, _rah, vl);
483 vsse32_v_f32m1(&tmp[0][11], sizeof(float) * 12, _rbl, vl);
484 vsse32_v_f32m1(&tmp[4][11], sizeof(float) * 12, _rbh, vl);
485 float* ptr = (float*)tmp;
486 _r0l = vle32_v_f32m1(ptr + 0 * 4, vl);
487 _r0h = vle32_v_f32m1(ptr + 1 * 4, vl);
488 _r1l = vle32_v_f32m1(ptr + 2 * 4, vl);
489 _r1h = vle32_v_f32m1(ptr + 3 * 4, vl);
490 _r2l = vle32_v_f32m1(ptr + 4 * 4, vl);
491 _r2h = vle32_v_f32m1(ptr + 5 * 4, vl);
492 _r3l = vle32_v_f32m1(ptr + 6 * 4, vl);
493 _r3h = vle32_v_f32m1(ptr + 7 * 4, vl);
494 _r4l = vle32_v_f32m1(ptr + 8 * 4, vl);
495 _r4h = vle32_v_f32m1(ptr + 9 * 4, vl);
496 _r5l = vle32_v_f32m1(ptr + 10 * 4, vl);
497 _r5h = vle32_v_f32m1(ptr + 11 * 4, vl);
498 _r6l = vle32_v_f32m1(ptr + 12 * 4, vl);
499 _r6h = vle32_v_f32m1(ptr + 13 * 4, vl);
500 _r7l = vle32_v_f32m1(ptr + 14 * 4, vl);
501 _r7h = vle32_v_f32m1(ptr + 15 * 4, vl);
502 _r8l = vle32_v_f32m1(ptr + 16 * 4, vl);
503 _r8h = vle32_v_f32m1(ptr + 17 * 4, vl);
504 _r9l = vle32_v_f32m1(ptr + 18 * 4, vl);
505 _r9h = vle32_v_f32m1(ptr + 19 * 4, vl);
506 _ral = vle32_v_f32m1(ptr + 20 * 4, vl);
507 _rah = vle32_v_f32m1(ptr + 21 * 4, vl);
508 _rbl = vle32_v_f32m1(ptr + 22 * 4, vl);
509 _rbh = vle32_v_f32m1(ptr + 23 * 4, vl);
510}
511
512static inline void transpose12x8_ps(vfloat32m1_t& _r0l, vfloat32m1_t& _r0m, vfloat32m1_t& _r0h,
513 vfloat32m1_t& _r1l, vfloat32m1_t& _r1m, vfloat32m1_t& _r1h,
514 vfloat32m1_t& _r2l, vfloat32m1_t& _r2m, vfloat32m1_t& _r2h,
515 vfloat32m1_t& _r3l, vfloat32m1_t& _r3m, vfloat32m1_t& _r3h,
516 vfloat32m1_t& _r4l, vfloat32m1_t& _r4m, vfloat32m1_t& _r4h,
517 vfloat32m1_t& _r5l, vfloat32m1_t& _r5m, vfloat32m1_t& _r5h,
518 vfloat32m1_t& _r6l, vfloat32m1_t& _r6m, vfloat32m1_t& _r6h,
519 vfloat32m1_t& _r7l, vfloat32m1_t& _r7m, vfloat32m1_t& _r7h, size_t vl)
520{
521 float tmp[96];
522 vsseg8e32_v_f32m1(&tmp[0], _r0l, _r1l, _r2l, _r3l, _r4l, _r5l, _r6l, _r7l, vl);
523 vsseg8e32_v_f32m1(&tmp[32], _r0m, _r1m, _r2m, _r3m, _r4m, _r5m, _r6m, _r7m, vl);
524 vsseg8e32_v_f32m1(&tmp[64], _r0h, _r1h, _r2h, _r3h, _r4h, _r5h, _r6h, _r7h, vl);
525
526 float* ptr = (float*)tmp;
527 _r0l = vle32_v_f32m1(ptr + 0 * 4, vl);
528 _r0m = vle32_v_f32m1(ptr + 1 * 4, vl);
529 _r0h = vle32_v_f32m1(ptr + 2 * 4, vl);
530 _r1l = vle32_v_f32m1(ptr + 3 * 4, vl);
531 _r1m = vle32_v_f32m1(ptr + 4 * 4, vl);
532 _r1h = vle32_v_f32m1(ptr + 5 * 4, vl);
533 _r2l = vle32_v_f32m1(ptr + 6 * 4, vl);
534 _r2m = vle32_v_f32m1(ptr + 7 * 4, vl);
535 _r2h = vle32_v_f32m1(ptr + 8 * 4, vl);
536 _r3l = vle32_v_f32m1(ptr + 9 * 4, vl);
537 _r3m = vle32_v_f32m1(ptr + 10 * 4, vl);
538 _r3h = vle32_v_f32m1(ptr + 11 * 4, vl);
539 _r4l = vle32_v_f32m1(ptr + 12 * 4, vl);
540 _r4m = vle32_v_f32m1(ptr + 13 * 4, vl);
541 _r4h = vle32_v_f32m1(ptr + 14 * 4, vl);
542 _r5l = vle32_v_f32m1(ptr + 15 * 4, vl);
543 _r5m = vle32_v_f32m1(ptr + 16 * 4, vl);
544 _r5h = vle32_v_f32m1(ptr + 17 * 4, vl);
545 _r6l = vle32_v_f32m1(ptr + 18 * 4, vl);
546 _r6m = vle32_v_f32m1(ptr + 19 * 4, vl);
547 _r6h = vle32_v_f32m1(ptr + 20 * 4, vl);
548 _r7l = vle32_v_f32m1(ptr + 21 * 4, vl);
549 _r7m = vle32_v_f32m1(ptr + 22 * 4, vl);
550 _r7h = vle32_v_f32m1(ptr + 23 * 4, vl);
551}
552
553static inline void transpose4x8_ps(vfloat32m1_t& _r0, vfloat32m1_t& _r1, vfloat32m1_t& _r2, vfloat32m1_t& _r3, vfloat32m1_t& _r4, vfloat32m1_t& _r5, vfloat32m1_t& _r6, vfloat32m1_t& _r7, size_t vl)
554{
555 float tmp[32];
556 vsseg8e32_v_f32m1(&tmp[0], _r0, _r1, _r2, _r3, _r4, _r5, _r6, _r7, vl);
557
558 float* ptr = (float*)tmp;
559 _r0 = vle32_v_f32m1(ptr + 0 * 4, vl);
560 _r1 = vle32_v_f32m1(ptr + 1 * 4, vl);
561 _r2 = vle32_v_f32m1(ptr + 2 * 4, vl);
562 _r3 = vle32_v_f32m1(ptr + 3 * 4, vl);
563 _r4 = vle32_v_f32m1(ptr + 4 * 4, vl);
564 _r5 = vle32_v_f32m1(ptr + 5 * 4, vl);
565 _r6 = vle32_v_f32m1(ptr + 6 * 4, vl);
566 _r7 = vle32_v_f32m1(ptr + 7 * 4, vl);
567}
568
569static inline void transpose4x12_ps(vfloat32m1_t& _r0, vfloat32m1_t& _r1, vfloat32m1_t& _r2, vfloat32m1_t& _r3, vfloat32m1_t& _r4, vfloat32m1_t& _r5, vfloat32m1_t& _r6, vfloat32m1_t& _r7, vfloat32m1_t& _r8, vfloat32m1_t& _r9, vfloat32m1_t& _ra, vfloat32m1_t& _rb, size_t vl)
570{
571 float tmp[4][12];
572 vsse32_v_f32m1(&tmp[0][0], sizeof(float) * 12, _r0, vl);
573 vsse32_v_f32m1(&tmp[0][1], sizeof(float) * 12, _r1, vl);
574 vsse32_v_f32m1(&tmp[0][2], sizeof(float) * 12, _r2, vl);
575 vsse32_v_f32m1(&tmp[0][3], sizeof(float) * 12, _r3, vl);
576 vsse32_v_f32m1(&tmp[0][4], sizeof(float) * 12, _r4, vl);
577 vsse32_v_f32m1(&tmp[0][5], sizeof(float) * 12, _r5, vl);
578 vsse32_v_f32m1(&tmp[0][6], sizeof(float) * 12, _r6, vl);
579 vsse32_v_f32m1(&tmp[0][7], sizeof(float) * 12, _r7, vl);
580 vsse32_v_f32m1(&tmp[0][8], sizeof(float) * 12, _r8, vl);
581 vsse32_v_f32m1(&tmp[0][9], sizeof(float) * 12, _r9, vl);
582 vsse32_v_f32m1(&tmp[0][10], sizeof(float) * 12, _ra, vl);
583 vsse32_v_f32m1(&tmp[0][11], sizeof(float) * 12, _rb, vl);
584 float* ptr = (float*)tmp;
585 _r0 = vle32_v_f32m1(ptr + 0 * 4, vl);
586 _r1 = vle32_v_f32m1(ptr + 1 * 4, vl);
587 _r2 = vle32_v_f32m1(ptr + 2 * 4, vl);
588 _r3 = vle32_v_f32m1(ptr + 3 * 4, vl);
589 _r4 = vle32_v_f32m1(ptr + 4 * 4, vl);
590 _r5 = vle32_v_f32m1(ptr + 5 * 4, vl);
591 _r6 = vle32_v_f32m1(ptr + 6 * 4, vl);
592 _r7 = vle32_v_f32m1(ptr + 7 * 4, vl);
593 _r8 = vle32_v_f32m1(ptr + 8 * 4, vl);
594 _r9 = vle32_v_f32m1(ptr + 9 * 4, vl);
595 _ra = vle32_v_f32m1(ptr + 10 * 4, vl);
596 _rb = vle32_v_f32m1(ptr + 11 * 4, vl);
597}
598
599static inline void transpose8x4_ps(vfloat32m1_t& _r0l, vfloat32m1_t& _r0h,
600 vfloat32m1_t& _r1l, vfloat32m1_t& _r1h,
601 vfloat32m1_t& _r2l, vfloat32m1_t& _r2h,
602 vfloat32m1_t& _r3l, vfloat32m1_t& _r3h, size_t vl)
603{
604 float tmp[32];
605 vsseg4e32_v_f32m1(&tmp[0], _r0l, _r1l, _r2l, _r3l, vl);
606 vsseg4e32_v_f32m1(&tmp[16], _r0h, _r1h, _r2h, _r3h, vl);
607 float* ptr = (float*)tmp;
608 _r0l = vle32_v_f32m1(ptr + 0 * 4, vl);
609 _r0h = vle32_v_f32m1(ptr + 1 * 4, vl);
610 _r1l = vle32_v_f32m1(ptr + 2 * 4, vl);
611 _r1h = vle32_v_f32m1(ptr + 3 * 4, vl);
612 _r2l = vle32_v_f32m1(ptr + 4 * 4, vl);
613 _r2h = vle32_v_f32m1(ptr + 5 * 4, vl);
614 _r3l = vle32_v_f32m1(ptr + 6 * 4, vl);
615 _r3h = vle32_v_f32m1(ptr + 7 * 4, vl);
616}
617#endif
618
619#endif // RISCV_USABILITY_H