Eigen  5.0.1
 
Loading...
Searching...
No Matches
TypeCasting.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2023 Zang Ruochen <zangruochen@loongson.cn>
5// Copyright (C) 2024 XiWei Gu <guxiwei-hf@loongson.cn>
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_TYPE_CASTING_LSX_H
13#define EIGEN_TYPE_CASTING_LSX_H
14
15// IWYU pragma: private
16#include "../../InternalHeaderCheck.h"
17
18namespace Eigen {
19
20namespace internal {
21
22//==============================================================================
23// type_casting_traits
24//==============================================================================
25
26// float <-> double
27template <>
28struct type_casting_traits<float, double> : vectorized_type_casting_traits<float, double> {};
29template <>
30struct type_casting_traits<double, float> : vectorized_type_casting_traits<double, float> {};
31
32// float <-> integer types
33template <>
34struct type_casting_traits<float, int8_t> : vectorized_type_casting_traits<float, int8_t> {};
35template <>
36struct type_casting_traits<int8_t, float> : vectorized_type_casting_traits<int8_t, float> {};
37template <>
38struct type_casting_traits<float, uint8_t> : vectorized_type_casting_traits<float, uint8_t> {};
39template <>
40struct type_casting_traits<uint8_t, float> : vectorized_type_casting_traits<uint8_t, float> {};
41template <>
42struct type_casting_traits<float, int16_t> : vectorized_type_casting_traits<float, int16_t> {};
43template <>
44struct type_casting_traits<int16_t, float> : vectorized_type_casting_traits<int16_t, float> {};
45template <>
46struct type_casting_traits<float, uint16_t> : vectorized_type_casting_traits<float, uint16_t> {};
47template <>
48struct type_casting_traits<uint16_t, float> : vectorized_type_casting_traits<uint16_t, float> {};
49template <>
50struct type_casting_traits<float, int32_t> : vectorized_type_casting_traits<float, int32_t> {};
51template <>
52struct type_casting_traits<int32_t, float> : vectorized_type_casting_traits<int32_t, float> {};
53template <>
54struct type_casting_traits<float, uint32_t> : vectorized_type_casting_traits<float, uint32_t> {};
55template <>
56struct type_casting_traits<uint32_t, float> : vectorized_type_casting_traits<uint32_t, float> {};
57template <>
58struct type_casting_traits<float, int64_t> : vectorized_type_casting_traits<float, int64_t> {};
59template <>
60struct type_casting_traits<int64_t, float> : vectorized_type_casting_traits<int64_t, float> {};
61template <>
62struct type_casting_traits<float, uint64_t> : vectorized_type_casting_traits<float, uint64_t> {};
63template <>
64struct type_casting_traits<uint64_t, float> : vectorized_type_casting_traits<uint64_t, float> {};
65
66// double <-> integer types
67template <>
68struct type_casting_traits<double, int8_t> : vectorized_type_casting_traits<double, int8_t> {};
69template <>
70struct type_casting_traits<int8_t, double> : vectorized_type_casting_traits<int8_t, double> {};
71template <>
72struct type_casting_traits<double, uint8_t> : vectorized_type_casting_traits<double, uint8_t> {};
73template <>
74struct type_casting_traits<uint8_t, double> : vectorized_type_casting_traits<uint8_t, double> {};
75template <>
76struct type_casting_traits<double, int16_t> : vectorized_type_casting_traits<double, int16_t> {};
77template <>
78struct type_casting_traits<int16_t, double> : vectorized_type_casting_traits<int16_t, double> {};
79template <>
80struct type_casting_traits<double, uint16_t> : vectorized_type_casting_traits<double, uint16_t> {};
81template <>
82struct type_casting_traits<uint16_t, double> : vectorized_type_casting_traits<uint16_t, double> {};
83template <>
84struct type_casting_traits<double, int32_t> : vectorized_type_casting_traits<double, int32_t> {};
85template <>
86struct type_casting_traits<int32_t, double> : vectorized_type_casting_traits<int32_t, double> {};
87template <>
88struct type_casting_traits<double, uint32_t> : vectorized_type_casting_traits<double, uint32_t> {};
89template <>
90struct type_casting_traits<uint32_t, double> : vectorized_type_casting_traits<uint32_t, double> {};
91template <>
92struct type_casting_traits<double, int64_t> : vectorized_type_casting_traits<double, int64_t> {};
93template <>
94struct type_casting_traits<int64_t, double> : vectorized_type_casting_traits<int64_t, double> {};
95template <>
96struct type_casting_traits<double, uint64_t> : vectorized_type_casting_traits<double, uint64_t> {};
97template <>
98struct type_casting_traits<uint64_t, double> : vectorized_type_casting_traits<uint64_t, double> {};
99
100// int8_t <-> other integer types
101template <>
102struct type_casting_traits<int8_t, int16_t> : vectorized_type_casting_traits<int8_t, int16_t> {};
103template <>
104struct type_casting_traits<int16_t, int8_t> : vectorized_type_casting_traits<int16_t, int8_t> {};
105template <>
106struct type_casting_traits<int8_t, uint16_t> : vectorized_type_casting_traits<int8_t, uint16_t> {};
107template <>
108struct type_casting_traits<uint16_t, int8_t> : vectorized_type_casting_traits<uint16_t, int8_t> {};
109template <>
110struct type_casting_traits<int8_t, int32_t> : vectorized_type_casting_traits<int8_t, int32_t> {};
111template <>
112struct type_casting_traits<int32_t, int8_t> : vectorized_type_casting_traits<int32_t, int8_t> {};
113template <>
114struct type_casting_traits<int8_t, uint32_t> : vectorized_type_casting_traits<int8_t, uint32_t> {};
115template <>
116struct type_casting_traits<uint32_t, int8_t> : vectorized_type_casting_traits<uint32_t, int8_t> {};
117template <>
118struct type_casting_traits<int8_t, int64_t> : vectorized_type_casting_traits<int8_t, int64_t> {};
119template <>
120struct type_casting_traits<int64_t, int8_t> : vectorized_type_casting_traits<int64_t, int8_t> {};
121template <>
122struct type_casting_traits<int8_t, uint64_t> : vectorized_type_casting_traits<int8_t, uint64_t> {};
123template <>
124struct type_casting_traits<uint64_t, int8_t> : vectorized_type_casting_traits<uint64_t, int8_t> {};
125
126// uint8_t <-> other integer types
127template <>
128struct type_casting_traits<uint8_t, int16_t> : vectorized_type_casting_traits<uint8_t, int16_t> {};
129template <>
130struct type_casting_traits<int16_t, uint8_t> : vectorized_type_casting_traits<int16_t, uint8_t> {};
131template <>
132struct type_casting_traits<uint8_t, uint16_t> : vectorized_type_casting_traits<uint8_t, uint16_t> {};
133template <>
134struct type_casting_traits<uint16_t, uint8_t> : vectorized_type_casting_traits<uint16_t, uint8_t> {};
135template <>
136struct type_casting_traits<uint8_t, int32_t> : vectorized_type_casting_traits<uint8_t, int32_t> {};
137template <>
138struct type_casting_traits<int32_t, uint8_t> : vectorized_type_casting_traits<int32_t, uint8_t> {};
139template <>
140struct type_casting_traits<uint8_t, uint32_t> : vectorized_type_casting_traits<uint8_t, uint32_t> {};
141template <>
142struct type_casting_traits<uint32_t, uint8_t> : vectorized_type_casting_traits<uint32_t, uint8_t> {};
143template <>
144struct type_casting_traits<uint8_t, int64_t> : vectorized_type_casting_traits<uint8_t, int64_t> {};
145template <>
146struct type_casting_traits<int64_t, uint8_t> : vectorized_type_casting_traits<int64_t, uint8_t> {};
147template <>
148struct type_casting_traits<uint8_t, uint64_t> : vectorized_type_casting_traits<uint8_t, uint64_t> {};
149template <>
150struct type_casting_traits<uint64_t, uint8_t> : vectorized_type_casting_traits<uint64_t, uint8_t> {};
151
152// int16_t <-> wider integer types
153template <>
154struct type_casting_traits<int16_t, int32_t> : vectorized_type_casting_traits<int16_t, int32_t> {};
155template <>
156struct type_casting_traits<int32_t, int16_t> : vectorized_type_casting_traits<int32_t, int16_t> {};
157template <>
158struct type_casting_traits<int16_t, uint32_t> : vectorized_type_casting_traits<int16_t, uint32_t> {};
159template <>
160struct type_casting_traits<uint32_t, int16_t> : vectorized_type_casting_traits<uint32_t, int16_t> {};
161template <>
162struct type_casting_traits<int16_t, int64_t> : vectorized_type_casting_traits<int16_t, int64_t> {};
163template <>
164struct type_casting_traits<int64_t, int16_t> : vectorized_type_casting_traits<int64_t, int16_t> {};
165template <>
166struct type_casting_traits<int16_t, uint64_t> : vectorized_type_casting_traits<int16_t, uint64_t> {};
167template <>
168struct type_casting_traits<uint64_t, int16_t> : vectorized_type_casting_traits<uint64_t, int16_t> {};
169
170// uint16_t <-> wider integer types
171template <>
172struct type_casting_traits<uint16_t, int32_t> : vectorized_type_casting_traits<uint16_t, int32_t> {};
173template <>
174struct type_casting_traits<int32_t, uint16_t> : vectorized_type_casting_traits<int32_t, uint16_t> {};
175template <>
176struct type_casting_traits<uint16_t, uint32_t> : vectorized_type_casting_traits<uint16_t, uint32_t> {};
177template <>
178struct type_casting_traits<uint32_t, uint16_t> : vectorized_type_casting_traits<uint32_t, uint16_t> {};
179template <>
180struct type_casting_traits<uint16_t, int64_t> : vectorized_type_casting_traits<uint16_t, int64_t> {};
181template <>
182struct type_casting_traits<int64_t, uint16_t> : vectorized_type_casting_traits<int64_t, uint16_t> {};
183template <>
184struct type_casting_traits<uint16_t, uint64_t> : vectorized_type_casting_traits<uint16_t, uint64_t> {};
185template <>
186struct type_casting_traits<uint64_t, uint16_t> : vectorized_type_casting_traits<uint64_t, uint16_t> {};
187
188// int32_t <-> 64-bit integer types
189template <>
190struct type_casting_traits<int32_t, int64_t> : vectorized_type_casting_traits<int32_t, int64_t> {};
191template <>
192struct type_casting_traits<int64_t, int32_t> : vectorized_type_casting_traits<int64_t, int32_t> {};
193template <>
194struct type_casting_traits<int32_t, uint64_t> : vectorized_type_casting_traits<int32_t, uint64_t> {};
195template <>
196struct type_casting_traits<uint64_t, int32_t> : vectorized_type_casting_traits<uint64_t, int32_t> {};
197
198// uint32_t <-> 64-bit integer types
199template <>
200struct type_casting_traits<uint32_t, int64_t> : vectorized_type_casting_traits<uint32_t, int64_t> {};
201template <>
202struct type_casting_traits<int64_t, uint32_t> : vectorized_type_casting_traits<int64_t, uint32_t> {};
203template <>
204struct type_casting_traits<uint32_t, uint64_t> : vectorized_type_casting_traits<uint32_t, uint64_t> {};
205template <>
206struct type_casting_traits<uint64_t, uint32_t> : vectorized_type_casting_traits<uint64_t, uint32_t> {};
207
208//==============================================================================
209// preinterpret
210//==============================================================================
211template <>
212EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f, Packet4i>(const Packet4i& a) {
213 return (__m128)((__m128i)a);
214}
215template <>
216EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f, Packet4ui>(const Packet4ui& a) {
217 return (__m128)((__m128i)a);
218}
219template <>
220EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d, Packet2l>(const Packet2l& a) {
221 return (__m128d)((__m128i)a);
222}
223template <>
224EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d, Packet2ul>(const Packet2ul& a) {
225 return (__m128d)((__m128i)a);
226}
227template <>
228EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d, Packet4i>(const Packet4i& a) {
229 return (__m128d)((__m128i)a);
230}
231template <>
232EIGEN_STRONG_INLINE Packet16c preinterpret<Packet16c, Packet16uc>(const Packet16uc& a) {
233 return (__m128i)a;
234}
235template <>
236EIGEN_STRONG_INLINE Packet8s preinterpret<Packet8s, Packet8us>(const Packet8us& a) {
237 return (__m128i)a;
238}
239template <>
240EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i, Packet4f>(const Packet4f& a) {
241 return (__m128i)a;
242}
243template <>
244EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i, Packet4ui>(const Packet4ui& a) {
245 return (__m128i)a;
246}
247template <>
248EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i, Packet2d>(const Packet2d& a) {
249 return (__m128i)a;
250}
251template <>
252EIGEN_STRONG_INLINE Packet2l preinterpret<Packet2l, Packet2d>(const Packet2d& a) {
253 return (__m128i)a;
254}
255template <>
256EIGEN_STRONG_INLINE Packet16uc preinterpret<Packet16uc, Packet16c>(const Packet16c& a) {
257 return (__m128i)a;
258}
259template <>
260EIGEN_STRONG_INLINE Packet8us preinterpret<Packet8us, Packet8s>(const Packet8s& a) {
261 return (__m128i)a;
262}
263template <>
264EIGEN_STRONG_INLINE Packet4ui preinterpret<Packet4ui, Packet4f>(const Packet4f& a) {
265 return (__m128i)a;
266}
267template <>
268EIGEN_STRONG_INLINE Packet4ui preinterpret<Packet4ui, Packet4i>(const Packet4i& a) {
269 return (__m128i)a;
270}
271template <>
272EIGEN_STRONG_INLINE Packet2ul preinterpret<Packet2ul, Packet2d>(const Packet2d& a) {
273 return (__m128i)a;
274}
275template <>
276EIGEN_STRONG_INLINE Packet2ul preinterpret<Packet2ul, Packet2l>(const Packet2l& a) {
277 return (__m128i)a;
278}
279
280template <>
281EIGEN_STRONG_INLINE Packet2l pcast<Packet4f, Packet2l>(const Packet4f& a) {
282 Packet2d tmp = __lsx_vfcvtl_d_s(a);
283 return __lsx_vftintrz_l_d(tmp);
284}
285template <>
286EIGEN_STRONG_INLINE Packet2ul pcast<Packet4f, Packet2ul>(const Packet4f& a) {
287 Packet2d tmp = __lsx_vfcvtl_d_s(a);
288 return __lsx_vftintrz_lu_d(tmp);
289}
290template <>
291EIGEN_STRONG_INLINE Packet4i pcast<Packet4f, Packet4i>(const Packet4f& a) {
292 return __lsx_vftintrz_w_s(a);
293}
294template <>
295EIGEN_STRONG_INLINE Packet4ui pcast<Packet4f, Packet4ui>(const Packet4f& a) {
296 return __lsx_vftintrz_wu_s(a);
297}
298template <>
299EIGEN_STRONG_INLINE Packet8s pcast<Packet4f, Packet8s>(const Packet4f& a, const Packet4f& b) {
300 return __lsx_vpickev_h(__lsx_vftintrz_w_s(b), __lsx_vftintrz_w_s(a));
301}
302template <>
303EIGEN_STRONG_INLINE Packet8us pcast<Packet4f, Packet8us>(const Packet4f& a, const Packet4f& b) {
304 return __lsx_vpickev_h(__lsx_vftintrz_wu_s(b), __lsx_vftintrz_wu_s(a));
305}
306template <>
307EIGEN_STRONG_INLINE Packet16c pcast<Packet4f, Packet16c>(const Packet4f& a, const Packet4f& b, const Packet4f& c,
308 const Packet4f& d) {
309 Packet8s tmp1 = __lsx_vpickev_h(__lsx_vftintrz_w_s(b), __lsx_vftintrz_w_s(a));
310 Packet8s tmp2 = __lsx_vpickev_h(__lsx_vftintrz_w_s(d), __lsx_vftintrz_w_s(c));
311 return __lsx_vpickev_b((__m128i)tmp2, (__m128i)tmp1);
312}
313template <>
314EIGEN_STRONG_INLINE Packet16uc pcast<Packet4f, Packet16uc>(const Packet4f& a, const Packet4f& b, const Packet4f& c,
315 const Packet4f& d) {
316 Packet8us tmp1 = __lsx_vpickev_h(__lsx_vftintrz_wu_s(b), __lsx_vftintrz_wu_s(a));
317 Packet8us tmp2 = __lsx_vpickev_h(__lsx_vftintrz_wu_s(d), __lsx_vftintrz_wu_s(c));
318 return __lsx_vpickev_b((__m128i)tmp2, (__m128i)tmp1);
319}
320
321template <>
322EIGEN_STRONG_INLINE Packet4f pcast<Packet16c, Packet4f>(const Packet16c& a) {
323 Packet8s tmp1 = __lsx_vsllwil_h_b((__m128i)a, 0);
324 Packet4i tmp2 = __lsx_vsllwil_w_h((__m128i)tmp1, 0);
325 return __lsx_vffint_s_w(tmp2);
326}
327template <>
328EIGEN_STRONG_INLINE Packet2l pcast<Packet16c, Packet2l>(const Packet16c& a) {
329 Packet8s tmp1 = __lsx_vsllwil_h_b((__m128i)a, 0);
330 Packet4i tmp2 = __lsx_vsllwil_w_h((__m128i)tmp1, 0);
331 return __lsx_vsllwil_d_w((__m128i)tmp2, 0);
332}
333template <>
334EIGEN_STRONG_INLINE Packet2ul pcast<Packet16c, Packet2ul>(const Packet16c& a) {
335 Packet8s tmp1 = __lsx_vsllwil_h_b((__m128i)a, 0);
336 Packet4i tmp2 = __lsx_vsllwil_w_h((__m128i)tmp1, 0);
337 return (Packet2ul)__lsx_vsllwil_d_w((__m128i)tmp2, 0);
338}
339template <>
340EIGEN_STRONG_INLINE Packet4i pcast<Packet16c, Packet4i>(const Packet16c& a) {
341 Packet8s tmp1 = __lsx_vsllwil_h_b((__m128i)a, 0);
342 return __lsx_vsllwil_w_h((__m128i)tmp1, 0);
343}
344template <>
345EIGEN_STRONG_INLINE Packet4ui pcast<Packet16c, Packet4ui>(const Packet16c& a) {
346 Packet8s tmp1 = __lsx_vsllwil_h_b((__m128i)a, 0);
347 return (Packet4ui)__lsx_vsllwil_w_h((__m128i)tmp1, 0);
348}
349template <>
350EIGEN_STRONG_INLINE Packet8s pcast<Packet16c, Packet8s>(const Packet16c& a) {
351 return __lsx_vsllwil_h_b((__m128i)a, 0);
352}
353template <>
354EIGEN_STRONG_INLINE Packet8us pcast<Packet16c, Packet8us>(const Packet16c& a) {
355 return (Packet8us)__lsx_vsllwil_h_b((__m128i)a, 0);
356}
357
358template <>
359EIGEN_STRONG_INLINE Packet4f pcast<Packet16uc, Packet4f>(const Packet16uc& a) {
360 Packet8us tmp1 = __lsx_vsllwil_hu_bu((__m128i)a, 0);
361 Packet4ui tmp2 = __lsx_vsllwil_wu_hu((__m128i)tmp1, 0);
362 return __lsx_vffint_s_wu(tmp2);
363}
364template <>
365EIGEN_STRONG_INLINE Packet2ul pcast<Packet16uc, Packet2ul>(const Packet16uc& a) {
366 Packet8us tmp1 = __lsx_vsllwil_hu_bu((__m128i)a, 0);
367 Packet4ui tmp2 = __lsx_vsllwil_wu_hu((__m128i)tmp1, 0);
368 return __lsx_vsllwil_du_wu((__m128i)tmp2, 0);
369}
370template <>
371EIGEN_STRONG_INLINE Packet2l pcast<Packet16uc, Packet2l>(const Packet16uc& a) {
372 Packet8us tmp1 = __lsx_vsllwil_hu_bu((__m128i)a, 0);
373 Packet4ui tmp2 = __lsx_vsllwil_wu_hu((__m128i)tmp1, 0);
374 return (Packet2l)__lsx_vsllwil_du_wu((__m128i)tmp2, 0);
375}
376template <>
377EIGEN_STRONG_INLINE Packet4ui pcast<Packet16uc, Packet4ui>(const Packet16uc& a) {
378 Packet8us tmp1 = __lsx_vsllwil_hu_bu((__m128i)a, 0);
379 return __lsx_vsllwil_wu_hu((__m128i)tmp1, 0);
380}
381template <>
382EIGEN_STRONG_INLINE Packet4i pcast<Packet16uc, Packet4i>(const Packet16uc& a) {
383 Packet8us tmp1 = __lsx_vsllwil_hu_bu((__m128i)a, 0);
384 return (Packet4i)__lsx_vsllwil_wu_hu((__m128i)tmp1, 0);
385}
386template <>
387EIGEN_STRONG_INLINE Packet8us pcast<Packet16uc, Packet8us>(const Packet16uc& a) {
388 return __lsx_vsllwil_hu_bu((__m128i)a, 0);
389}
390template <>
391EIGEN_STRONG_INLINE Packet8s pcast<Packet16uc, Packet8s>(const Packet16uc& a) {
392 return (Packet8s)__lsx_vsllwil_hu_bu((__m128i)a, 0);
393}
394
395template <>
396EIGEN_STRONG_INLINE Packet4f pcast<Packet8s, Packet4f>(const Packet8s& a) {
397 Packet4i tmp1 = __lsx_vsllwil_w_h((__m128i)a, 0);
398 return __lsx_vffint_s_w(tmp1);
399}
400template <>
401EIGEN_STRONG_INLINE Packet2l pcast<Packet8s, Packet2l>(const Packet8s& a) {
402 Packet4i tmp1 = __lsx_vsllwil_w_h((__m128i)a, 0);
403 return __lsx_vsllwil_d_w((__m128i)tmp1, 0);
404}
405template <>
406EIGEN_STRONG_INLINE Packet2ul pcast<Packet8s, Packet2ul>(const Packet8s& a) {
407 Packet4i tmp1 = __lsx_vsllwil_w_h((__m128i)a, 0);
408 return (Packet2ul)__lsx_vsllwil_d_w((__m128i)tmp1, 0);
409}
410template <>
411EIGEN_STRONG_INLINE Packet4i pcast<Packet8s, Packet4i>(const Packet8s& a) {
412 return __lsx_vsllwil_w_h((__m128i)a, 0);
413}
414template <>
415EIGEN_STRONG_INLINE Packet4ui pcast<Packet8s, Packet4ui>(const Packet8s& a) {
416 return (Packet4ui)__lsx_vsllwil_w_h((__m128i)a, 0);
417}
418template <>
419EIGEN_STRONG_INLINE Packet16c pcast<Packet8s, Packet16c>(const Packet8s& a, const Packet8s& b) {
420 return __lsx_vpickev_b((__m128i)b, (__m128i)a);
421}
422template <>
423EIGEN_STRONG_INLINE Packet16uc pcast<Packet8s, Packet16uc>(const Packet8s& a, const Packet8s& b) {
424 return (Packet16uc)__lsx_vpickev_b((__m128i)b, (__m128i)a);
425}
426
427template <>
428EIGEN_STRONG_INLINE Packet4f pcast<Packet8us, Packet4f>(const Packet8us& a) {
429 Packet4ui tmp1 = __lsx_vsllwil_wu_hu((__m128i)a, 0);
430 return __lsx_vffint_s_wu(tmp1);
431}
432template <>
433EIGEN_STRONG_INLINE Packet2ul pcast<Packet8us, Packet2ul>(const Packet8us& a) {
434 Packet4ui tmp1 = __lsx_vsllwil_wu_hu((__m128i)a, 0);
435 return __lsx_vsllwil_du_wu((__m128i)tmp1, 0);
436}
437template <>
438EIGEN_STRONG_INLINE Packet2l pcast<Packet8us, Packet2l>(const Packet8us& a) {
439 Packet4ui tmp1 = __lsx_vsllwil_wu_hu((__m128i)a, 0);
440 return (Packet2l)__lsx_vsllwil_du_wu((__m128i)tmp1, 0);
441}
442template <>
443EIGEN_STRONG_INLINE Packet4ui pcast<Packet8us, Packet4ui>(const Packet8us& a) {
444 return __lsx_vsllwil_wu_hu((__m128i)a, 0);
445}
446template <>
447EIGEN_STRONG_INLINE Packet4i pcast<Packet8us, Packet4i>(const Packet8us& a) {
448 return (Packet4i)__lsx_vsllwil_wu_hu((__m128i)a, 0);
449}
450template <>
451EIGEN_STRONG_INLINE Packet16uc pcast<Packet8us, Packet16uc>(const Packet8us& a, const Packet8us& b) {
452 return __lsx_vpickev_b((__m128i)b, (__m128i)a);
453}
454template <>
455EIGEN_STRONG_INLINE Packet16c pcast<Packet8us, Packet16c>(const Packet8us& a, const Packet8us& b) {
456 return (Packet16c)__lsx_vpickev_b((__m128i)b, (__m128i)a);
457}
458
459template <>
460EIGEN_STRONG_INLINE Packet4f pcast<Packet4i, Packet4f>(const Packet4i& a) {
461 return __lsx_vffint_s_w(a);
462}
463template <>
464EIGEN_STRONG_INLINE Packet2l pcast<Packet4i, Packet2l>(const Packet4i& a) {
465 return __lsx_vsllwil_d_w((__m128i)a, 0);
466}
467template <>
468EIGEN_STRONG_INLINE Packet2ul pcast<Packet4i, Packet2ul>(const Packet4i& a) {
469 return (Packet2ul)__lsx_vsllwil_d_w((__m128i)a, 0);
470}
471template <>
472EIGEN_STRONG_INLINE Packet8s pcast<Packet4i, Packet8s>(const Packet4i& a, const Packet4i& b) {
473 return __lsx_vpickev_h((__m128i)b, (__m128i)a);
474}
475template <>
476EIGEN_STRONG_INLINE Packet8us pcast<Packet4i, Packet8us>(const Packet4i& a, const Packet4i& b) {
477 return (Packet8us)__lsx_vpickev_h((__m128i)b, (__m128i)a);
478}
479template <>
480EIGEN_STRONG_INLINE Packet16c pcast<Packet4i, Packet16c>(const Packet4i& a, const Packet4i& b, const Packet4i& c,
481 const Packet4i& d) {
482 Packet8s tmp1 = __lsx_vpickev_h((__m128i)b, (__m128i)a);
483 Packet8s tmp2 = __lsx_vpickev_h((__m128i)d, (__m128i)c);
484 return __lsx_vpickev_b((__m128i)tmp2, (__m128i)tmp1);
485}
486template <>
487EIGEN_STRONG_INLINE Packet16uc pcast<Packet4i, Packet16uc>(const Packet4i& a, const Packet4i& b, const Packet4i& c,
488 const Packet4i& d) {
489 Packet8s tmp1 = __lsx_vpickev_h((__m128i)b, (__m128i)a);
490 Packet8s tmp2 = __lsx_vpickev_h((__m128i)d, (__m128i)c);
491 return (Packet16uc)__lsx_vpickev_b((__m128i)tmp2, (__m128i)tmp1);
492}
493
494template <>
495EIGEN_STRONG_INLINE Packet4f pcast<Packet4ui, Packet4f>(const Packet4ui& a) {
496 return __lsx_vffint_s_wu(a);
497}
498template <>
499EIGEN_STRONG_INLINE Packet2ul pcast<Packet4ui, Packet2ul>(const Packet4ui& a) {
500 return __lsx_vsllwil_du_wu((__m128i)a, 0);
501}
502template <>
503EIGEN_STRONG_INLINE Packet2l pcast<Packet4ui, Packet2l>(const Packet4ui& a) {
504 return (Packet2l)__lsx_vsllwil_du_wu((__m128i)a, 0);
505}
506template <>
507EIGEN_STRONG_INLINE Packet8us pcast<Packet4ui, Packet8us>(const Packet4ui& a, const Packet4ui& b) {
508 return __lsx_vpickev_h((__m128i)b, (__m128i)a);
509}
510template <>
511EIGEN_STRONG_INLINE Packet8s pcast<Packet4ui, Packet8s>(const Packet4ui& a, const Packet4ui& b) {
512 return (Packet8s)__lsx_vpickev_h((__m128i)b, (__m128i)a);
513}
514template <>
515EIGEN_STRONG_INLINE Packet16uc pcast<Packet4ui, Packet16uc>(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c,
516 const Packet4ui& d) {
517 Packet8us tmp1 = __lsx_vpickev_h((__m128i)b, (__m128i)a);
518 Packet8us tmp2 = __lsx_vpickev_h((__m128i)d, (__m128i)c);
519 return __lsx_vpickev_b((__m128i)tmp2, (__m128i)tmp1);
520}
521template <>
522EIGEN_STRONG_INLINE Packet16c pcast<Packet4ui, Packet16c>(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c,
523 const Packet4ui& d) {
524 Packet8us tmp1 = __lsx_vpickev_h((__m128i)b, (__m128i)a);
525 Packet8us tmp2 = __lsx_vpickev_h((__m128i)d, (__m128i)c);
526 return (Packet16c)__lsx_vpickev_b((__m128i)tmp2, (__m128i)tmp1);
527}
528
529template <>
530EIGEN_STRONG_INLINE Packet4f pcast<Packet2l, Packet4f>(const Packet2l& a, const Packet2l& b) {
531 return __lsx_vfcvt_s_d(__lsx_vffint_d_l(b), __lsx_vffint_d_l(a));
532}
533template <>
534EIGEN_STRONG_INLINE Packet4i pcast<Packet2l, Packet4i>(const Packet2l& a, const Packet2l& b) {
535 return __lsx_vpickev_w((__m128i)b, (__m128i)a);
536}
537template <>
538EIGEN_STRONG_INLINE Packet4ui pcast<Packet2l, Packet4ui>(const Packet2l& a, const Packet2l& b) {
539 return (Packet4ui)__lsx_vpickev_w((__m128i)b, (__m128i)a);
540}
541template <>
542EIGEN_STRONG_INLINE Packet8s pcast<Packet2l, Packet8s>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
543 const Packet2l& d) {
544 Packet4i tmp1 = __lsx_vpickev_w((__m128i)b, (__m128i)a);
545 Packet4i tmp2 = __lsx_vpickev_w((__m128i)d, (__m128i)c);
546 return __lsx_vpickev_h((__m128i)tmp2, (__m128i)tmp1);
547}
548template <>
549EIGEN_STRONG_INLINE Packet8us pcast<Packet2l, Packet8us>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
550 const Packet2l& d) {
551 Packet4i tmp1 = __lsx_vpickev_w((__m128i)b, (__m128i)a);
552 Packet4i tmp2 = __lsx_vpickev_w((__m128i)d, (__m128i)c);
553 return (Packet8us)__lsx_vpickev_h((__m128i)tmp2, (__m128i)tmp1);
554}
555template <>
556EIGEN_STRONG_INLINE Packet16c pcast<Packet2l, Packet16c>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
557 const Packet2l& d, const Packet2l& e, const Packet2l& f,
558 const Packet2l& g, const Packet2l& h) {
559 const Packet8s abcd = pcast<Packet2l, Packet8s>(a, b, c, d);
560 const Packet8s efgh = pcast<Packet2l, Packet8s>(e, f, g, h);
561 return __lsx_vpickev_b((__m128i)efgh, (__m128i)abcd);
562}
563template <>
564EIGEN_STRONG_INLINE Packet16uc pcast<Packet2l, Packet16uc>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
565 const Packet2l& d, const Packet2l& e, const Packet2l& f,
566 const Packet2l& g, const Packet2l& h) {
567 const Packet8us abcd = pcast<Packet2l, Packet8us>(a, b, c, d);
568 const Packet8us efgh = pcast<Packet2l, Packet8us>(e, f, g, h);
569 return __lsx_vpickev_b((__m128i)efgh, (__m128i)abcd);
570}
571
572template <>
573EIGEN_STRONG_INLINE Packet4f pcast<Packet2ul, Packet4f>(const Packet2ul& a, const Packet2ul& b) {
574 return __lsx_vfcvt_s_d(__lsx_vffint_d_lu(b), __lsx_vffint_d_lu(a));
575}
576template <>
577EIGEN_STRONG_INLINE Packet4ui pcast<Packet2ul, Packet4ui>(const Packet2ul& a, const Packet2ul& b) {
578 return __lsx_vpickev_w((__m128i)b, (__m128i)a);
579}
580template <>
581EIGEN_STRONG_INLINE Packet4i pcast<Packet2ul, Packet4i>(const Packet2ul& a, const Packet2ul& b) {
582 return (Packet4i)__lsx_vpickev_w((__m128i)b, (__m128i)a);
583}
584template <>
585EIGEN_STRONG_INLINE Packet8us pcast<Packet2ul, Packet8us>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
586 const Packet2ul& d) {
587 Packet4ui tmp1 = __lsx_vpickev_w((__m128i)b, (__m128i)a);
588 Packet4ui tmp2 = __lsx_vpickev_w((__m128i)d, (__m128i)c);
589 return __lsx_vpickev_h((__m128i)tmp2, (__m128i)tmp1);
590}
591template <>
592EIGEN_STRONG_INLINE Packet8s pcast<Packet2ul, Packet8s>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
593 const Packet2ul& d) {
594 Packet4ui tmp1 = __lsx_vpickev_w((__m128i)b, (__m128i)a);
595 Packet4ui tmp2 = __lsx_vpickev_w((__m128i)d, (__m128i)c);
596 return (Packet8s)__lsx_vpickev_h((__m128i)tmp2, (__m128i)tmp1);
597}
598template <>
599EIGEN_STRONG_INLINE Packet16uc pcast<Packet2ul, Packet16uc>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
600 const Packet2ul& d, const Packet2ul& e, const Packet2ul& f,
601 const Packet2ul& g, const Packet2ul& h) {
602 const Packet8s abcd = pcast<Packet2ul, Packet8s>(a, b, c, d);
603 const Packet8s efgh = pcast<Packet2ul, Packet8s>(e, f, g, h);
604 return __lsx_vpickev_b((__m128i)efgh, (__m128i)abcd);
605}
606template <>
607EIGEN_STRONG_INLINE Packet16c pcast<Packet2ul, Packet16c>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
608 const Packet2ul& d, const Packet2ul& e, const Packet2ul& f,
609 const Packet2ul& g, const Packet2ul& h) {
610 const Packet8us abcd = pcast<Packet2ul, Packet8us>(a, b, c, d);
611 const Packet8us efgh = pcast<Packet2ul, Packet8us>(e, f, g, h);
612 return __lsx_vpickev_b((__m128i)efgh, (__m128i)abcd);
613}
614
615template <>
616EIGEN_STRONG_INLINE Packet4f pcast<Packet2d, Packet4f>(const Packet2d& a, const Packet2d& b) {
617 return __lsx_vfcvt_s_d(b, a);
618}
619template <>
620EIGEN_STRONG_INLINE Packet2l pcast<Packet2d, Packet2l>(const Packet2d& a) {
621 return __lsx_vftintrz_l_d(a);
622}
623template <>
624EIGEN_STRONG_INLINE Packet2ul pcast<Packet2d, Packet2ul>(const Packet2d& a) {
625 return __lsx_vftintrz_lu_d(a);
626}
627template <>
628EIGEN_STRONG_INLINE Packet4i pcast<Packet2d, Packet4i>(const Packet2d& a, const Packet2d& b) {
629 return __lsx_vpickev_w(__lsx_vftintrz_l_d(b), __lsx_vftintrz_l_d(a));
630}
631template <>
632EIGEN_STRONG_INLINE Packet4ui pcast<Packet2d, Packet4ui>(const Packet2d& a, const Packet2d& b) {
633 return __lsx_vpickev_w(__lsx_vftintrz_lu_d(b), __lsx_vftintrz_lu_d(a));
634}
635template <>
636EIGEN_STRONG_INLINE Packet8s pcast<Packet2d, Packet8s>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
637 const Packet2d& d) {
638 Packet4i tmp1 = __lsx_vpickev_w(__lsx_vftintrz_l_d(b), __lsx_vftintrz_l_d(a));
639 Packet4i tmp2 = __lsx_vpickev_w(__lsx_vftintrz_l_d(d), __lsx_vftintrz_l_d(c));
640 return __lsx_vpickev_h((__m128i)tmp2, (__m128i)tmp1);
641}
642template <>
643EIGEN_STRONG_INLINE Packet8us pcast<Packet2d, Packet8us>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
644 const Packet2d& d) {
645 Packet4ui tmp1 = __lsx_vpickev_w(__lsx_vftintrz_lu_d(b), __lsx_vftintrz_lu_d(a));
646 Packet4ui tmp2 = __lsx_vpickev_w(__lsx_vftintrz_lu_d(d), __lsx_vftintrz_lu_d(c));
647 return __lsx_vpickev_h((__m128i)tmp2, (__m128i)tmp1);
648}
649template <>
650EIGEN_STRONG_INLINE Packet16c pcast<Packet2d, Packet16c>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
651 const Packet2d& d, const Packet2d& e, const Packet2d& f,
652 const Packet2d& g, const Packet2d& h) {
653 const Packet8s abcd = pcast<Packet2d, Packet8s>(a, b, c, d);
654 const Packet8s efgh = pcast<Packet2d, Packet8s>(e, f, g, h);
655 return __lsx_vpickev_b((__m128i)efgh, (__m128i)abcd);
656}
657template <>
658EIGEN_STRONG_INLINE Packet16uc pcast<Packet2d, Packet16uc>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
659 const Packet2d& d, const Packet2d& e, const Packet2d& f,
660 const Packet2d& g, const Packet2d& h) {
661 const Packet8us abcd = pcast<Packet2d, Packet8us>(a, b, c, d);
662 const Packet8us efgh = pcast<Packet2d, Packet8us>(e, f, g, h);
663 return __lsx_vpickev_b((__m128i)efgh, (__m128i)abcd);
664}
665
666template <>
667EIGEN_STRONG_INLINE Packet2d pcast<Packet4f, Packet2d>(const Packet4f& a) {
668 return __lsx_vfcvtl_d_s(a);
669}
670template <>
671EIGEN_STRONG_INLINE Packet2d pcast<Packet16c, Packet2d>(const Packet16c& a) {
672 Packet8s tmp1 = __lsx_vsllwil_h_b((__m128i)a, 0);
673 Packet4i tmp2 = __lsx_vsllwil_w_h((__m128i)tmp1, 0);
674 return __lsx_vffint_d_l(__lsx_vsllwil_d_w((__m128i)tmp2, 0));
675}
676template <>
677EIGEN_STRONG_INLINE Packet2d pcast<Packet16uc, Packet2d>(const Packet16uc& a) {
678 Packet8us tmp1 = __lsx_vsllwil_hu_bu((__m128i)a, 0);
679 Packet4ui tmp2 = __lsx_vsllwil_wu_hu((__m128i)tmp1, 0);
680 return __lsx_vffint_d_lu(__lsx_vsllwil_du_wu((__m128i)tmp2, 0));
681}
682template <>
683EIGEN_STRONG_INLINE Packet2d pcast<Packet8s, Packet2d>(const Packet8s& a) {
684 Packet4i tmp = __lsx_vsllwil_w_h((__m128i)a, 0);
685 return __lsx_vffint_d_l(__lsx_vsllwil_d_w((__m128i)tmp, 0));
686}
687template <>
688EIGEN_STRONG_INLINE Packet2d pcast<Packet8us, Packet2d>(const Packet8us& a) {
689 Packet4ui tmp = __lsx_vsllwil_wu_hu((__m128i)a, 0);
690 return __lsx_vffint_d_lu(__lsx_vsllwil_du_wu((__m128i)tmp, 0));
691}
692template <>
693EIGEN_STRONG_INLINE Packet2d pcast<Packet4i, Packet2d>(const Packet4i& a) {
694 return __lsx_vffint_d_l(__lsx_vsllwil_d_w((__m128i)a, 0));
695}
696template <>
697EIGEN_STRONG_INLINE Packet2d pcast<Packet4ui, Packet2d>(const Packet4ui& a) {
698 return __lsx_vffint_d_lu(__lsx_vsllwil_du_wu((__m128i)a, 0));
699}
700template <>
701EIGEN_STRONG_INLINE Packet2d pcast<Packet2l, Packet2d>(const Packet2l& a) {
702 return __lsx_vffint_d_l(a);
703}
704template <>
705EIGEN_STRONG_INLINE Packet2d pcast<Packet2ul, Packet2d>(const Packet2ul& a) {
706 return __lsx_vffint_d_lu(a);
707}
708
709} // end namespace internal
710
711} // end namespace Eigen
712
713#endif // EIGEN_TYPE_CASTING_LSX_H