Eigen  5.0.1
 
Loading...
Searching...
No Matches
PacketMathDecl.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2024 Kseniya Zaytseva <kseniya.zaytseva@syntacore.com>
5// Copyright (C) 2025 Chip Kerchner <ckerchner@tenstorrent.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_PACKET_MATH_RVV10_DECL_H
13#define EIGEN_PACKET_MATH_RVV10_DECL_H
14
15// IWYU pragma: private
16#include "../../InternalHeaderCheck.h"
17
18namespace Eigen {
19namespace internal {
20#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
21#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
22#endif
23
24#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
25#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
26#endif
27
28#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
29
30template <typename Scalar, std::size_t VectorLength, std::size_t VectorLMul>
31struct rvv_packet_size_selector {
32 enum { size = VectorLength * VectorLMul / (sizeof(Scalar) * CHAR_BIT) };
33};
34
35template <std::size_t VectorLength, std::size_t VectorLMul>
36struct rvv_packet_alignment_selector {
37 enum {
38 alignment =
39 (VectorLength * VectorLMul) >= 1024
41 : ((VectorLength * VectorLMul) >= 512 ? Aligned64
42 : ((VectorLength * VectorLMul) >= 256 ? Aligned32 : Aligned16))
43 };
44};
45
46typedef vbool64_t PacketMask64;
47typedef vbool32_t PacketMask32;
48typedef vbool16_t PacketMask16;
49typedef vbool8_t PacketMask8;
50typedef vbool4_t PacketMask4;
51
52template <typename Packet>
53struct rvv_half_packet {
54 typedef Packet type;
55};
56
57template <typename Packet>
58using rvv_half_packet_t = typename rvv_half_packet<Packet>::type;
59
60template <typename Scalar, typename Packet, std::size_t VectorLMul>
61struct rvv_default_unpacket_traits {
62 typedef Scalar type;
63 typedef rvv_half_packet_t<Packet> half;
64 typedef numext::uint8_t mask_t;
65 enum {
66 size = rvv_packet_size_selector<Scalar, EIGEN_RISCV64_RVV_VL, VectorLMul>::size,
67 alignment = rvv_packet_alignment_selector<EIGEN_RISCV64_RVV_VL, VectorLMul>::alignment,
68 vectorizable = true,
69 masked_load_available = false,
70 masked_store_available = false
71 };
72};
73
74/********************************* short **************************************/
75
76typedef eigen_packet_wrapper<vint16m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 18> Packet1Xs;
77typedef eigen_packet_wrapper<vuint16m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 19> Packet1Xsu;
78
79typedef eigen_packet_wrapper<vint16m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 20> Packet2Xs;
80typedef eigen_packet_wrapper<vuint16m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 21>
81 Packet2Xsu;
82
83typedef eigen_packet_wrapper<vint16m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 22> Packet4Xs;
84typedef eigen_packet_wrapper<vuint16m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 23>
85 Packet4Xsu;
86
87template <>
88struct rvv_half_packet<Packet2Xs> {
89 typedef Packet1Xs type;
90};
91template <>
92struct rvv_half_packet<Packet4Xs> {
93 typedef Packet2Xs type;
94};
95
96template <>
97struct unpacket_traits<Packet1Xs> : rvv_default_unpacket_traits<numext::int16_t, Packet1Xs, 1> {};
98
99template <>
100struct unpacket_traits<Packet2Xs> : rvv_default_unpacket_traits<numext::int16_t, Packet2Xs, 2> {};
101
102template <>
103struct unpacket_traits<Packet4Xs> : rvv_default_unpacket_traits<numext::int16_t, Packet4Xs, 4> {};
104
105/********************************* int32 **************************************/
106typedef eigen_packet_wrapper<vint32m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 0> Packet1Xi;
107typedef eigen_packet_wrapper<vuint32m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 1> Packet1Xu;
108
109typedef eigen_packet_wrapper<vint32m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 2> Packet2Xi;
110typedef eigen_packet_wrapper<vuint32m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 3> Packet2Xu;
111
112typedef eigen_packet_wrapper<vint32m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 4> Packet4Xi;
113typedef eigen_packet_wrapper<vuint32m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 5> Packet4Xu;
114
115template <>
116struct rvv_half_packet<Packet2Xi> {
117 typedef Packet1Xi type;
118};
119template <>
120struct rvv_half_packet<Packet4Xi> {
121 typedef Packet2Xi type;
122};
123
124template <>
125struct unpacket_traits<Packet1Xi> : rvv_default_unpacket_traits<numext::int32_t, Packet1Xi, 1> {};
126template <>
127struct unpacket_traits<Packet2Xi> : rvv_default_unpacket_traits<numext::int32_t, Packet2Xi, 2> {};
128template <>
129struct unpacket_traits<Packet4Xi> : rvv_default_unpacket_traits<numext::int32_t, Packet4Xi, 4> {};
130
131/********************************* int64 **************************************/
132
133typedef eigen_packet_wrapper<vint64m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 9> Packet1Xl;
134typedef eigen_packet_wrapper<vuint64m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 10> Packet1Xul;
135
136typedef eigen_packet_wrapper<vint64m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 11> Packet2Xl;
137typedef eigen_packet_wrapper<vuint64m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 12>
138 Packet2Xul;
139
140typedef eigen_packet_wrapper<vint64m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 13> Packet4Xl;
141typedef eigen_packet_wrapper<vuint64m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 14>
142 Packet4Xul;
143
144template <>
145struct rvv_half_packet<Packet2Xl> {
146 typedef Packet1Xl type;
147};
148template <>
149struct rvv_half_packet<Packet4Xl> {
150 typedef Packet2Xl type;
151};
152
153template <>
154struct unpacket_traits<Packet1Xl> : rvv_default_unpacket_traits<numext::int64_t, Packet1Xl, 1> {};
155
156template <>
157struct unpacket_traits<Packet2Xl> : rvv_default_unpacket_traits<numext::int64_t, Packet2Xl, 2> {};
158
159template <>
160struct unpacket_traits<Packet4Xl> : rvv_default_unpacket_traits<numext::int64_t, Packet4Xl, 4> {};
161
162/********************************* float32 ************************************/
163
164typedef eigen_packet_wrapper<vfloat32m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 6> Packet1Xf;
165typedef eigen_packet_wrapper<vfloat32m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 7>
166 Packet2Xf;
167typedef eigen_packet_wrapper<vfloat32m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 8>
168 Packet4Xf;
169
170template <>
171struct rvv_half_packet<Packet2Xf> {
172 typedef Packet1Xf type;
173};
174template <>
175struct rvv_half_packet<Packet4Xf> {
176 typedef Packet2Xf type;
177};
178
179template <>
180struct unpacket_traits<Packet1Xf> : rvv_default_unpacket_traits<float, Packet1Xf, 1> {
181 typedef Packet1Xi integer_packet;
182 typedef PacketMask32 packet_mask;
183};
184
185template <>
186struct unpacket_traits<Packet2Xf> : rvv_default_unpacket_traits<float, Packet2Xf, 2> {
187 typedef Packet2Xi integer_packet;
188 typedef PacketMask16 packet_mask;
189};
190
191template <>
192struct unpacket_traits<Packet4Xf> : rvv_default_unpacket_traits<float, Packet4Xf, 4> {
193 typedef Packet4Xi integer_packet;
194 typedef PacketMask8 packet_mask;
195};
196
197/********************************* double ************************************/
198
199typedef eigen_packet_wrapper<vfloat64m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 15> Packet1Xd;
200typedef eigen_packet_wrapper<vfloat64m2_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 2))), 16>
201 Packet2Xd;
202typedef eigen_packet_wrapper<vfloat64m4_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL * 4))), 17>
203 Packet4Xd;
204
205template <>
206struct rvv_half_packet<Packet2Xd> {
207 typedef Packet1Xd type;
208};
209template <>
210struct rvv_half_packet<Packet4Xd> {
211 typedef Packet2Xd type;
212};
213
214template <>
215struct unpacket_traits<Packet1Xd> : rvv_default_unpacket_traits<double, Packet1Xd, 1> {
216 typedef Packet1Xl integer_packet;
217 typedef PacketMask64 packet_mask;
218};
219
220template <>
221struct unpacket_traits<Packet2Xd> : rvv_default_unpacket_traits<double, Packet2Xd, 2> {
222 typedef Packet2Xl integer_packet;
223 typedef PacketMask32 packet_mask;
224};
225
226template <>
227struct unpacket_traits<Packet4Xd> : rvv_default_unpacket_traits<double, Packet4Xd, 4> {
228 typedef Packet4Xl integer_packet;
229 typedef PacketMask16 packet_mask;
230};
231
232/********************************* char ************************************/
233
234typedef eigen_packet_wrapper<vint8m1_t __attribute__((riscv_rvv_vector_bits(EIGEN_RISCV64_RVV_VL))), 28> Packet1Xc;
235
236template <>
237struct unpacket_traits<Packet1Xc> : rvv_default_unpacket_traits<numext::int8_t, Packet1Xc, 1> {};
238
239/********************************* default **************************************/
240
241#if EIGEN_RISCV64_DEFAULT_LMUL == 1
242typedef Packet1Xs PacketXs;
243typedef Packet1Xsu PacketXsu;
244typedef Packet1Xi PacketXi;
245typedef Packet1Xu PacketXu;
246typedef Packet1Xl PacketXl;
247typedef Packet1Xul PacketXul;
248typedef Packet1Xf PacketXf;
249typedef Packet1Xd PacketXd;
250#elif EIGEN_RISCV64_DEFAULT_LMUL == 2
251typedef Packet2Xs PacketXs;
252typedef Packet2Xsu PacketXsu;
253typedef Packet2Xi PacketXi;
254typedef Packet2Xu PacketXu;
255typedef Packet2Xl PacketXl;
256typedef Packet2Xul PacketXul;
257typedef Packet2Xf PacketXf;
258typedef Packet2Xd PacketXd;
259#elif EIGEN_RISCV64_DEFAULT_LMUL == 4
260typedef Packet4Xs PacketXs;
261typedef Packet4Xsu PacketXsu;
262typedef Packet4Xi PacketXi;
263typedef Packet4Xu PacketXu;
264typedef Packet4Xl PacketXl;
265typedef Packet4Xul PacketXul;
266typedef Packet4Xf PacketXf;
267typedef Packet4Xd PacketXd;
268#endif
269
270template <typename Scalar, typename Packet>
271struct rvv_default_packet_traits : default_packet_traits {
272 typedef Packet type;
273 typedef rvv_half_packet_t<type> half;
274
275 enum {
276 size = unpacket_traits<Packet>::size,
277 Vectorizable = 1,
278 AlignedOnScalar = 1,
279 HasCmp = 1
280 };
281};
282
283template <typename Scalar, typename Packet>
284struct rvv_default_float_packet_traits : rvv_default_packet_traits<Scalar, Packet> {
285 enum {
286 HasDiv = 1,
287 HasSin = EIGEN_FAST_MATH,
288 HasCos = EIGEN_FAST_MATH,
289 HasTan = EIGEN_FAST_MATH,
290 HasSinh = 1,
291 HasCosh = 1,
292 HasASinh = 1,
293 HasACosh = 1,
294 HasATan = 1,
295 HasATanh = 1,
296 HasLog = 1,
297 HasExp = 1,
298 HasLog10 = 1,
299 HasLog1p = 1,
300 HasExpm1 = 1,
301 HasPow = 1,
302 HasSqrt = 1,
303 HasCbrt = 1,
304 HasRsqrt = 1,
305 HasTanh = EIGEN_FAST_MATH,
306 HasErf = EIGEN_FAST_MATH,
307 HasErfc = EIGEN_FAST_MATH
308 };
309};
310
311template <>
312struct packet_traits<numext::int16_t> : rvv_default_packet_traits<numext::int16_t, PacketXs> {};
313
314template <>
315struct packet_traits<numext::int32_t> : rvv_default_packet_traits<numext::int32_t, PacketXi> {};
316
317template <>
318struct packet_traits<numext::int64_t> : rvv_default_packet_traits<numext::int64_t, PacketXl> {};
319
320template <>
321struct packet_traits<float> : rvv_default_float_packet_traits<float, PacketXf> {};
322
323template <>
324struct packet_traits<double> : rvv_default_float_packet_traits<double, PacketXd> {};
325
326/********************************* prefetch **************************************/
327
328template <>
329EIGEN_STRONG_INLINE void prefetch<numext::int16_t>(const numext::int16_t* addr) {
330#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
331 __builtin_prefetch(addr);
332#endif
333}
334
335template <>
336EIGEN_STRONG_INLINE void prefetch<numext::int32_t>(const numext::int32_t* addr) {
337#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
338 __builtin_prefetch(addr);
339#endif
340}
341
342template <>
343EIGEN_STRONG_INLINE void prefetch<numext::int64_t>(const numext::int64_t* addr) {
344#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
345 __builtin_prefetch(addr);
346#endif
347}
348
349} // namespace internal
350} // namespace Eigen
351
352#endif // EIGEN_PACKET_MATH_RVV10_DECL_H
@ Aligned64
Definition Constants.h:240
@ Aligned128
Definition Constants.h:241
@ Aligned32
Definition Constants.h:239
@ Aligned16
Definition Constants.h:238