Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SVE/PacketMath.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2020, Arm Limited and Contributors
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_PACKET_MATH_SVE_H
11#define EIGEN_PACKET_MATH_SVE_H
12
13// IWYU pragma: private
14#include "../../InternalHeaderCheck.h"
15
16namespace Eigen {
17namespace internal {
18#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
19#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
20#endif
21
22#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
23#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
24#endif
25
26#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
27
28template <typename Scalar, int SVEVectorLength>
29struct sve_packet_size_selector {
30 enum { size = SVEVectorLength / (sizeof(Scalar) * CHAR_BIT) };
31};
32
33/********************************* int32 **************************************/
34typedef svint32_t PacketXi __attribute__((arm_sve_vector_bits(EIGEN_ARM64_SVE_VL)));
35
36template <>
37struct packet_traits<numext::int32_t> : default_packet_traits {
38 typedef PacketXi type;
39 typedef PacketXi half; // Half not implemented yet
40 enum {
41 Vectorizable = 1,
42 AlignedOnScalar = 1,
43 size = sve_packet_size_selector<numext::int32_t, EIGEN_ARM64_SVE_VL>::size,
44
45 HasAdd = 1,
46 HasSub = 1,
47 HasShift = 1,
48 HasMul = 1,
49 HasNegate = 1,
50 HasAbs = 1,
51 HasArg = 0,
52 HasAbs2 = 1,
53 HasMin = 1,
54 HasMax = 1,
55 HasConj = 1,
56 HasSetLinear = 0,
57 HasBlend = 0,
58 HasReduxp = 0 // Not implemented in SVE
59 };
60};
61
62template <>
63struct unpacket_traits<PacketXi> {
64 typedef numext::int32_t type;
65 typedef PacketXi half; // Half not yet implemented
66 enum {
67 size = sve_packet_size_selector<numext::int32_t, EIGEN_ARM64_SVE_VL>::size,
68 alignment = Aligned64,
69 vectorizable = true,
70 masked_load_available = false,
71 masked_store_available = false
72 };
73};
74
75template <>
76EIGEN_STRONG_INLINE void prefetch<numext::int32_t>(const numext::int32_t* addr) {
77 svprfw(svptrue_b32(), addr, SV_PLDL1KEEP);
78}
79
80template <>
81EIGEN_STRONG_INLINE PacketXi pset1<PacketXi>(const numext::int32_t& from) {
82 return svdup_n_s32(from);
83}
84
85template <>
86EIGEN_STRONG_INLINE PacketXi plset<PacketXi>(const numext::int32_t& a) {
87 numext::int32_t c[packet_traits<numext::int32_t>::size];
88 for (int i = 0; i < packet_traits<numext::int32_t>::size; i++) c[i] = i;
89 return svadd_s32_z(svptrue_b32(), pset1<PacketXi>(a), svld1_s32(svptrue_b32(), c));
90}
91
92template <>
93EIGEN_STRONG_INLINE PacketXi padd<PacketXi>(const PacketXi& a, const PacketXi& b) {
94 return svadd_s32_z(svptrue_b32(), a, b);
95}
96
97template <>
98EIGEN_STRONG_INLINE PacketXi psub<PacketXi>(const PacketXi& a, const PacketXi& b) {
99 return svsub_s32_z(svptrue_b32(), a, b);
100}
101
102template <>
103EIGEN_STRONG_INLINE PacketXi pnegate(const PacketXi& a) {
104 return svneg_s32_z(svptrue_b32(), a);
105}
106
107template <>
108EIGEN_STRONG_INLINE PacketXi pconj(const PacketXi& a) {
109 return a;
110}
111
112template <>
113EIGEN_STRONG_INLINE PacketXi pmul<PacketXi>(const PacketXi& a, const PacketXi& b) {
114 return svmul_s32_z(svptrue_b32(), a, b);
115}
116
117template <>
118EIGEN_STRONG_INLINE PacketXi pdiv<PacketXi>(const PacketXi& a, const PacketXi& b) {
119 return svdiv_s32_z(svptrue_b32(), a, b);
120}
121
122template <>
123EIGEN_STRONG_INLINE PacketXi pmadd(const PacketXi& a, const PacketXi& b, const PacketXi& c) {
124 return svmla_s32_z(svptrue_b32(), c, a, b);
125}
126
127template <>
128EIGEN_STRONG_INLINE PacketXi pmin<PacketXi>(const PacketXi& a, const PacketXi& b) {
129 return svmin_s32_z(svptrue_b32(), a, b);
130}
131
132template <>
133EIGEN_STRONG_INLINE PacketXi pmax<PacketXi>(const PacketXi& a, const PacketXi& b) {
134 return svmax_s32_z(svptrue_b32(), a, b);
135}
136
137template <>
138EIGEN_STRONG_INLINE PacketXi pcmp_le<PacketXi>(const PacketXi& a, const PacketXi& b) {
139 return svdup_n_s32_z(svcmple_s32(svptrue_b32(), a, b), 0xffffffffu);
140}
141
142template <>
143EIGEN_STRONG_INLINE PacketXi pcmp_lt<PacketXi>(const PacketXi& a, const PacketXi& b) {
144 return svdup_n_s32_z(svcmplt_s32(svptrue_b32(), a, b), 0xffffffffu);
145}
146
147template <>
148EIGEN_STRONG_INLINE PacketXi pcmp_eq<PacketXi>(const PacketXi& a, const PacketXi& b) {
149 return svdup_n_s32_z(svcmpeq_s32(svptrue_b32(), a, b), 0xffffffffu);
150}
151
152template <>
153EIGEN_STRONG_INLINE PacketXi ptrue<PacketXi>(const PacketXi& /*a*/) {
154 return svdup_n_s32_z(svptrue_b32(), 0xffffffffu);
155}
156
157template <>
158EIGEN_STRONG_INLINE PacketXi pzero<PacketXi>(const PacketXi& /*a*/) {
159 return svdup_n_s32_z(svptrue_b32(), 0);
160}
161
162template <>
163EIGEN_STRONG_INLINE PacketXi pand<PacketXi>(const PacketXi& a, const PacketXi& b) {
164 return svand_s32_z(svptrue_b32(), a, b);
165}
166
167template <>
168EIGEN_STRONG_INLINE PacketXi por<PacketXi>(const PacketXi& a, const PacketXi& b) {
169 return svorr_s32_z(svptrue_b32(), a, b);
170}
171
172template <>
173EIGEN_STRONG_INLINE PacketXi pxor<PacketXi>(const PacketXi& a, const PacketXi& b) {
174 return sveor_s32_z(svptrue_b32(), a, b);
175}
176
177template <>
178EIGEN_STRONG_INLINE PacketXi pandnot<PacketXi>(const PacketXi& a, const PacketXi& b) {
179 return svbic_s32_z(svptrue_b32(), a, b);
180}
181
182template <int N>
183EIGEN_STRONG_INLINE PacketXi parithmetic_shift_right(PacketXi a) {
184 return svasrd_n_s32_z(svptrue_b32(), a, N);
185}
186
187template <int N>
188EIGEN_STRONG_INLINE PacketXi plogical_shift_right(PacketXi a) {
189 return svreinterpret_s32_u32(svlsr_n_u32_z(svptrue_b32(), svreinterpret_u32_s32(a), N));
190}
191
192template <int N>
193EIGEN_STRONG_INLINE PacketXi plogical_shift_left(PacketXi a) {
194 return svlsl_n_s32_z(svptrue_b32(), a, N);
195}
196
197template <>
198EIGEN_STRONG_INLINE PacketXi pload<PacketXi>(const numext::int32_t* from) {
199 EIGEN_DEBUG_ALIGNED_LOAD return svld1_s32(svptrue_b32(), from);
200}
201
202template <>
203EIGEN_STRONG_INLINE PacketXi ploadu<PacketXi>(const numext::int32_t* from) {
204 EIGEN_DEBUG_UNALIGNED_LOAD return svld1_s32(svptrue_b32(), from);
205}
206
207template <>
208EIGEN_STRONG_INLINE PacketXi ploaddup<PacketXi>(const numext::int32_t* from) {
209 svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
210 indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
211 return svld1_gather_u32index_s32(svptrue_b32(), from, indices);
212}
213
214template <>
215EIGEN_STRONG_INLINE PacketXi ploadquad<PacketXi>(const numext::int32_t* from) {
216 svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
217 indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
218 indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a0, a0, a1, a1, a1, a1, ...}
219 return svld1_gather_u32index_s32(svptrue_b32(), from, indices);
220}
221
222template <>
223EIGEN_STRONG_INLINE void pstore<numext::int32_t>(numext::int32_t* to, const PacketXi& from) {
224 EIGEN_DEBUG_ALIGNED_STORE svst1_s32(svptrue_b32(), to, from);
225}
226
227template <>
228EIGEN_STRONG_INLINE void pstoreu<numext::int32_t>(numext::int32_t* to, const PacketXi& from) {
229 EIGEN_DEBUG_UNALIGNED_STORE svst1_s32(svptrue_b32(), to, from);
230}
231
232template <>
233EIGEN_DEVICE_FUNC inline PacketXi pgather<numext::int32_t, PacketXi>(const numext::int32_t* from, Index stride) {
234 // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
235 svint32_t indices = svindex_s32(0, stride);
236 return svld1_gather_s32index_s32(svptrue_b32(), from, indices);
237}
238
239template <>
240EIGEN_DEVICE_FUNC inline void pscatter<numext::int32_t, PacketXi>(numext::int32_t* to, const PacketXi& from,
241 Index stride) {
242 // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
243 svint32_t indices = svindex_s32(0, stride);
244 svst1_scatter_s32index_s32(svptrue_b32(), to, indices, from);
245}
246
247template <>
248EIGEN_STRONG_INLINE numext::int32_t pfirst<PacketXi>(const PacketXi& a) {
249 // svlasta returns the first element if all predicate bits are 0
250 return svlasta_s32(svpfalse_b(), a);
251}
252
253template <>
254EIGEN_STRONG_INLINE PacketXi preverse(const PacketXi& a) {
255 return svrev_s32(a);
256}
257
258template <>
259EIGEN_STRONG_INLINE PacketXi pabs(const PacketXi& a) {
260 return svabs_s32_z(svptrue_b32(), a);
261}
262
263template <>
264EIGEN_STRONG_INLINE numext::int32_t predux<PacketXi>(const PacketXi& a) {
265 return static_cast<numext::int32_t>(svaddv_s32(svptrue_b32(), a));
266}
267
268template <>
269EIGEN_STRONG_INLINE numext::int32_t predux_mul<PacketXi>(const PacketXi& a) {
270 EIGEN_STATIC_ASSERT((EIGEN_ARM64_SVE_VL % 128 == 0), EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT);
271
272 // Multiply the vector by its reverse
273 svint32_t prod = svmul_s32_z(svptrue_b32(), a, svrev_s32(a));
274 svint32_t half_prod;
275
276 // Extract the high half of the vector. Depending on the VL more reductions need to be done
277 if (EIGEN_ARM64_SVE_VL >= 2048) {
278 half_prod = svtbl_s32(prod, svindex_u32(32, 1));
279 prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
280 }
281 if (EIGEN_ARM64_SVE_VL >= 1024) {
282 half_prod = svtbl_s32(prod, svindex_u32(16, 1));
283 prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
284 }
285 if (EIGEN_ARM64_SVE_VL >= 512) {
286 half_prod = svtbl_s32(prod, svindex_u32(8, 1));
287 prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
288 }
289 if (EIGEN_ARM64_SVE_VL >= 256) {
290 half_prod = svtbl_s32(prod, svindex_u32(4, 1));
291 prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
292 }
293 // Last reduction
294 half_prod = svtbl_s32(prod, svindex_u32(2, 1));
295 prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
296
297 // The reduction is done to the first element.
298 return pfirst<PacketXi>(prod);
299}
300
301template <>
302EIGEN_STRONG_INLINE numext::int32_t predux_min<PacketXi>(const PacketXi& a) {
303 return svminv_s32(svptrue_b32(), a);
304}
305
306template <>
307EIGEN_STRONG_INLINE numext::int32_t predux_max<PacketXi>(const PacketXi& a) {
308 return svmaxv_s32(svptrue_b32(), a);
309}
310
311template <int N>
312EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<PacketXi, N>& kernel) {
313 int buffer[packet_traits<numext::int32_t>::size * N] = {0};
314 int i = 0;
315
316 PacketXi stride_index = svindex_s32(0, N);
317
318 for (i = 0; i < N; i++) {
319 svst1_scatter_s32index_s32(svptrue_b32(), buffer + i, stride_index, kernel.packet[i]);
320 }
321 for (i = 0; i < N; i++) {
322 kernel.packet[i] = svld1_s32(svptrue_b32(), buffer + i * packet_traits<numext::int32_t>::size);
323 }
324}
325
326/********************************* float32 ************************************/
327
328typedef svfloat32_t PacketXf __attribute__((arm_sve_vector_bits(EIGEN_ARM64_SVE_VL)));
329
330template <>
331struct packet_traits<float> : default_packet_traits {
332 typedef PacketXf type;
333 typedef PacketXf half;
334
335 enum {
336 Vectorizable = 1,
337 AlignedOnScalar = 1,
338 size = sve_packet_size_selector<float, EIGEN_ARM64_SVE_VL>::size,
339
340 HasAdd = 1,
341 HasSub = 1,
342 HasShift = 1,
343 HasMul = 1,
344 HasNegate = 1,
345 HasAbs = 1,
346 HasArg = 0,
347 HasAbs2 = 1,
348 HasMin = 1,
349 HasMax = 1,
350 HasConj = 1,
351 HasSetLinear = 0,
352 HasBlend = 0,
353 HasReduxp = 0, // Not implemented in SVE
354
355 HasDiv = 1,
356
357 HasSin = EIGEN_FAST_MATH,
358 HasCos = EIGEN_FAST_MATH,
359 HasLog = 1,
360 HasExp = 1,
361 HasSqrt = 0,
362 HasTanh = EIGEN_FAST_MATH,
363 HasErf = EIGEN_FAST_MATH
364 };
365};
366
367template <>
368struct unpacket_traits<PacketXf> {
369 typedef float type;
370 typedef PacketXf half; // Half not yet implemented
371 typedef PacketXi integer_packet;
372
373 enum {
374 size = sve_packet_size_selector<float, EIGEN_ARM64_SVE_VL>::size,
375 alignment = Aligned64,
376 vectorizable = true,
377 masked_load_available = false,
378 masked_store_available = false
379 };
380};
381
382template <>
383EIGEN_STRONG_INLINE PacketXf pset1<PacketXf>(const float& from) {
384 return svdup_n_f32(from);
385}
386
387template <>
388EIGEN_STRONG_INLINE PacketXf pset1frombits<PacketXf>(numext::uint32_t from) {
389 return svreinterpret_f32_u32(svdup_n_u32_z(svptrue_b32(), from));
390}
391
392template <>
393EIGEN_STRONG_INLINE PacketXf plset<PacketXf>(const float& a) {
394 float c[packet_traits<float>::size];
395 for (int i = 0; i < packet_traits<float>::size; i++) c[i] = i;
396 return svadd_f32_z(svptrue_b32(), pset1<PacketXf>(a), svld1_f32(svptrue_b32(), c));
397}
398
399template <>
400EIGEN_STRONG_INLINE PacketXf padd<PacketXf>(const PacketXf& a, const PacketXf& b) {
401 return svadd_f32_z(svptrue_b32(), a, b);
402}
403
404template <>
405EIGEN_STRONG_INLINE PacketXf psub<PacketXf>(const PacketXf& a, const PacketXf& b) {
406 return svsub_f32_z(svptrue_b32(), a, b);
407}
408
409template <>
410EIGEN_STRONG_INLINE PacketXf pnegate(const PacketXf& a) {
411 return svneg_f32_z(svptrue_b32(), a);
412}
413
414template <>
415EIGEN_STRONG_INLINE PacketXf pconj(const PacketXf& a) {
416 return a;
417}
418
419template <>
420EIGEN_STRONG_INLINE PacketXf pmul<PacketXf>(const PacketXf& a, const PacketXf& b) {
421 return svmul_f32_z(svptrue_b32(), a, b);
422}
423
424template <>
425EIGEN_STRONG_INLINE PacketXf pdiv<PacketXf>(const PacketXf& a, const PacketXf& b) {
426 return svdiv_f32_z(svptrue_b32(), a, b);
427}
428
429template <>
430EIGEN_STRONG_INLINE PacketXf pmadd(const PacketXf& a, const PacketXf& b, const PacketXf& c) {
431 return svmla_f32_z(svptrue_b32(), c, a, b);
432}
433
434template <>
435EIGEN_STRONG_INLINE PacketXf pmin<PacketXf>(const PacketXf& a, const PacketXf& b) {
436 return svmin_f32_z(svptrue_b32(), a, b);
437}
438
439template <>
440EIGEN_STRONG_INLINE PacketXf pmin<PropagateNaN, PacketXf>(const PacketXf& a, const PacketXf& b) {
441 return pmin<PacketXf>(a, b);
442}
443
444template <>
445EIGEN_STRONG_INLINE PacketXf pmin<PropagateNumbers, PacketXf>(const PacketXf& a, const PacketXf& b) {
446 return svminnm_f32_z(svptrue_b32(), a, b);
447}
448
449template <>
450EIGEN_STRONG_INLINE PacketXf pmax<PacketXf>(const PacketXf& a, const PacketXf& b) {
451 return svmax_f32_z(svptrue_b32(), a, b);
452}
453
454template <>
455EIGEN_STRONG_INLINE PacketXf pmax<PropagateNaN, PacketXf>(const PacketXf& a, const PacketXf& b) {
456 return pmax<PacketXf>(a, b);
457}
458
459template <>
460EIGEN_STRONG_INLINE PacketXf pmax<PropagateNumbers, PacketXf>(const PacketXf& a, const PacketXf& b) {
461 return svmaxnm_f32_z(svptrue_b32(), a, b);
462}
463
464// Float comparisons in SVE return svbool (predicate). Use svdup to set active
465// lanes to 1 (0xffffffffu) and inactive lanes to 0.
466template <>
467EIGEN_STRONG_INLINE PacketXf pcmp_le<PacketXf>(const PacketXf& a, const PacketXf& b) {
468 return svreinterpret_f32_u32(svdup_n_u32_z(svcmple_f32(svptrue_b32(), a, b), 0xffffffffu));
469}
470
471template <>
472EIGEN_STRONG_INLINE PacketXf pcmp_lt<PacketXf>(const PacketXf& a, const PacketXf& b) {
473 return svreinterpret_f32_u32(svdup_n_u32_z(svcmplt_f32(svptrue_b32(), a, b), 0xffffffffu));
474}
475
476template <>
477EIGEN_STRONG_INLINE PacketXf pcmp_eq<PacketXf>(const PacketXf& a, const PacketXf& b) {
478 return svreinterpret_f32_u32(svdup_n_u32_z(svcmpeq_f32(svptrue_b32(), a, b), 0xffffffffu));
479}
480
481// Do a predicate inverse (svnot_b_z) on the predicate resulted from the
482// greater/equal comparison (svcmpge_f32). Then fill a float vector with the
483// active elements.
484template <>
485EIGEN_STRONG_INLINE PacketXf pcmp_lt_or_nan<PacketXf>(const PacketXf& a, const PacketXf& b) {
486 return svreinterpret_f32_u32(svdup_n_u32_z(svnot_b_z(svptrue_b32(), svcmpge_f32(svptrue_b32(), a, b)), 0xffffffffu));
487}
488
489template <>
490EIGEN_STRONG_INLINE PacketXf pfloor<PacketXf>(const PacketXf& a) {
491 return svrintm_f32_z(svptrue_b32(), a);
492}
493
494template <>
495EIGEN_STRONG_INLINE PacketXf ptrue<PacketXf>(const PacketXf& /*a*/) {
496 return svreinterpret_f32_u32(svdup_n_u32_z(svptrue_b32(), 0xffffffffu));
497}
498
499// Logical Operations are not supported for float, so reinterpret casts
500template <>
501EIGEN_STRONG_INLINE PacketXf pand<PacketXf>(const PacketXf& a, const PacketXf& b) {
502 return svreinterpret_f32_u32(svand_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
503}
504
505template <>
506EIGEN_STRONG_INLINE PacketXf por<PacketXf>(const PacketXf& a, const PacketXf& b) {
507 return svreinterpret_f32_u32(svorr_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
508}
509
510template <>
511EIGEN_STRONG_INLINE PacketXf pxor<PacketXf>(const PacketXf& a, const PacketXf& b) {
512 return svreinterpret_f32_u32(sveor_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
513}
514
515template <>
516EIGEN_STRONG_INLINE PacketXf pandnot<PacketXf>(const PacketXf& a, const PacketXf& b) {
517 return svreinterpret_f32_u32(svbic_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
518}
519
520template <>
521EIGEN_STRONG_INLINE PacketXf pload<PacketXf>(const float* from) {
522 EIGEN_DEBUG_ALIGNED_LOAD return svld1_f32(svptrue_b32(), from);
523}
524
525template <>
526EIGEN_STRONG_INLINE PacketXf ploadu<PacketXf>(const float* from) {
527 EIGEN_DEBUG_UNALIGNED_LOAD return svld1_f32(svptrue_b32(), from);
528}
529
530template <>
531EIGEN_STRONG_INLINE PacketXf ploaddup<PacketXf>(const float* from) {
532 svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
533 indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
534 return svld1_gather_u32index_f32(svptrue_b32(), from, indices);
535}
536
537template <>
538EIGEN_STRONG_INLINE PacketXf ploadquad<PacketXf>(const float* from) {
539 svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
540 indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
541 indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a0, a0, a1, a1, a1, a1, ...}
542 return svld1_gather_u32index_f32(svptrue_b32(), from, indices);
543}
544
545template <>
546EIGEN_STRONG_INLINE void pstore<float>(float* to, const PacketXf& from) {
547 EIGEN_DEBUG_ALIGNED_STORE svst1_f32(svptrue_b32(), to, from);
548}
549
550template <>
551EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const PacketXf& from) {
552 EIGEN_DEBUG_UNALIGNED_STORE svst1_f32(svptrue_b32(), to, from);
553}
554
555template <>
556EIGEN_DEVICE_FUNC inline PacketXf pgather<float, PacketXf>(const float* from, Index stride) {
557 // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
558 svint32_t indices = svindex_s32(0, stride);
559 return svld1_gather_s32index_f32(svptrue_b32(), from, indices);
560}
561
562template <>
563EIGEN_DEVICE_FUNC inline void pscatter<float, PacketXf>(float* to, const PacketXf& from, Index stride) {
564 // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
565 svint32_t indices = svindex_s32(0, stride);
566 svst1_scatter_s32index_f32(svptrue_b32(), to, indices, from);
567}
568
569template <>
570EIGEN_STRONG_INLINE float pfirst<PacketXf>(const PacketXf& a) {
571 // svlasta returns the first element if all predicate bits are 0
572 return svlasta_f32(svpfalse_b(), a);
573}
574
575template <>
576EIGEN_STRONG_INLINE PacketXf preverse(const PacketXf& a) {
577 return svrev_f32(a);
578}
579
580template <>
581EIGEN_STRONG_INLINE PacketXf pabs(const PacketXf& a) {
582 return svabs_f32_z(svptrue_b32(), a);
583}
584
585// TODO(tellenbach): Should this go into MathFunctions.h? If so, change for
586// all vector extensions and the generic version.
587template <>
588EIGEN_STRONG_INLINE PacketXf pfrexp<PacketXf>(const PacketXf& a, PacketXf& exponent) {
589 return pfrexp_generic(a, exponent);
590}
591
592template <>
593EIGEN_STRONG_INLINE float predux<PacketXf>(const PacketXf& a) {
594 return svaddv_f32(svptrue_b32(), a);
595}
596
597// Other reduction functions:
598// mul
599// Only works for SVE Vls multiple of 128
600template <>
601EIGEN_STRONG_INLINE float predux_mul<PacketXf>(const PacketXf& a) {
602 EIGEN_STATIC_ASSERT((EIGEN_ARM64_SVE_VL % 128 == 0), EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT);
603 // Multiply the vector by its reverse
604 svfloat32_t prod = svmul_f32_z(svptrue_b32(), a, svrev_f32(a));
605 svfloat32_t half_prod;
606
607 // Extract the high half of the vector. Depending on the VL more reductions need to be done
608 if (EIGEN_ARM64_SVE_VL >= 2048) {
609 half_prod = svtbl_f32(prod, svindex_u32(32, 1));
610 prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
611 }
612 if (EIGEN_ARM64_SVE_VL >= 1024) {
613 half_prod = svtbl_f32(prod, svindex_u32(16, 1));
614 prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
615 }
616 if (EIGEN_ARM64_SVE_VL >= 512) {
617 half_prod = svtbl_f32(prod, svindex_u32(8, 1));
618 prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
619 }
620 if (EIGEN_ARM64_SVE_VL >= 256) {
621 half_prod = svtbl_f32(prod, svindex_u32(4, 1));
622 prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
623 }
624 // Last reduction
625 half_prod = svtbl_f32(prod, svindex_u32(2, 1));
626 prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
627
628 // The reduction is done to the first element.
629 return pfirst<PacketXf>(prod);
630}
631
632template <>
633EIGEN_STRONG_INLINE float predux_min<PacketXf>(const PacketXf& a) {
634 return svminv_f32(svptrue_b32(), a);
635}
636
637template <>
638EIGEN_STRONG_INLINE float predux_max<PacketXf>(const PacketXf& a) {
639 return svmaxv_f32(svptrue_b32(), a);
640}
641
642template <int N>
643EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<PacketXf, N>& kernel) {
644 float buffer[packet_traits<float>::size * N] = {0};
645 int i = 0;
646
647 PacketXi stride_index = svindex_s32(0, N);
648
649 for (i = 0; i < N; i++) {
650 svst1_scatter_s32index_f32(svptrue_b32(), buffer + i, stride_index, kernel.packet[i]);
651 }
652
653 for (i = 0; i < N; i++) {
654 kernel.packet[i] = svld1_f32(svptrue_b32(), buffer + i * packet_traits<float>::size);
655 }
656}
657
658template <>
659EIGEN_STRONG_INLINE PacketXf pldexp<PacketXf>(const PacketXf& a, const PacketXf& exponent) {
660 return pldexp_generic(a, exponent);
661}
662
663} // namespace internal
664} // namespace Eigen
665
666#endif // EIGEN_PACKET_MATH_SVE_H
@ Aligned64
Definition Constants.h:239
Namespace containing all symbols from the Eigen library.
Definition Core:137