diff --git a/Eigen/src/Core/GenericPacketMath.h b/Eigen/src/Core/GenericPacketMath.h index cb8848731..39bba577a 100644 --- a/Eigen/src/Core/GenericPacketMath.h +++ b/Eigen/src/Core/GenericPacketMath.h @@ -162,12 +162,17 @@ EIGEN_DEVICE_FUNC inline TgtPacket pcast(const SrcPacket& a, const SrcPacket& /*b*/) { return static_cast(a); } - template EIGEN_DEVICE_FUNC inline TgtPacket pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/) { return static_cast(a); } +template +EIGEN_DEVICE_FUNC inline TgtPacket +pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/, + const SrcPacket& /*e*/, const SrcPacket& /*f*/, const SrcPacket& /*g*/, const SrcPacket& /*h*/) { + return static_cast(a); +} /** \internal \returns reinterpret_cast(a) */ template diff --git a/Eigen/src/Core/arch/NEON/PacketMath.h b/Eigen/src/Core/arch/NEON/PacketMath.h index ddd43c377..340e1b1c5 100644 --- a/Eigen/src/Core/arch/NEON/PacketMath.h +++ b/Eigen/src/Core/arch/NEON/PacketMath.h @@ -338,7 +338,7 @@ struct packet_traits : default_packet_traits Vectorizable = 1, AlignedOnScalar = 1, size = 2, - HasHalfPacket = 1, + HasHalfPacket = 0, HasCmp = 1, HasAdd = 1, @@ -368,7 +368,7 @@ struct packet_traits : default_packet_traits Vectorizable = 1, AlignedOnScalar = 1, size = 2, - HasHalfPacket = 1, + HasHalfPacket = 0, HasCmp = 1, HasAdd = 1, diff --git a/Eigen/src/Core/arch/NEON/TypeCasting.h b/Eigen/src/Core/arch/NEON/TypeCasting.h index 68d24dc5c..80be213d2 100644 --- a/Eigen/src/Core/arch/NEON/TypeCasting.h +++ b/Eigen/src/Core/arch/NEON/TypeCasting.h @@ -2,6 +2,7 @@ // for linear algebra. // // Copyright (C) 2018 Rasmus Munk Larsen +// Copyright (C) 2020 Antonio Sanchez // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed @@ -14,265 +15,1397 @@ namespace Eigen { namespace internal { -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; +//============================================================================== +// pcast, SrcType = float +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet4f& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet2f& a) { + return a; +} -template<> EIGEN_STRONG_INLINE Packet2f pcast(const Packet2i& a) { return vcvt_f32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet2f pcast(const Packet2ui& a) { return vcvt_f32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet2f pcast(const Packet2l& a) -{ return vcvt_f32_s32(vmovn_s64(a)); } -template<> EIGEN_STRONG_INLINE Packet2f pcast(const Packet2ul& a) -{ return vcvt_f32_u32(vmovn_u64(a)); } -template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4c& a) -{ return vcvtq_f32_s32(vmovl_s16(vget_low_s16(vmovl_s8(vreinterpret_s8_s32(vdup_n_s32(a)))))); } -template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4uc& a) -{ return vcvtq_f32_s32(vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vdup_n_u32(a))))))); } -template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4s& a) -{ return vcvtq_f32_s32(vmovl_s16(a)); } -template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4us& a) -{ return vcvtq_f32_s32(vreinterpretq_s32_u32(vmovl_u16(a))); } -template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4i& a) { return vcvtq_f32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4ui& a) { return vcvtq_f32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet4c pcast(const Packet4f& a) -{ - const int16x4_t b = vmovn_s32(vcvtq_s32_f32(a)); - return vget_lane_s32(vreinterpret_s32_s8(vmovn_s16(vcombine_s16(b, b))), 0); +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +// If float64 exists, first convert to that to keep as much precision as possible. +#if EIGEN_ARCH_ARM64 +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet4f& a) { + // Discard second half of input. + return vcvtq_s64_f64(vcvt_f64_f32(vget_low_f32(a))); } -template<> EIGEN_STRONG_INLINE Packet4c pcast(const Packet4uc& a) -{ return static_cast(a); } -template<> EIGEN_STRONG_INLINE Packet4c pcast(const Packet4s& a) -{ return vget_lane_s32(vreinterpret_s32_s8(vmovn_s16(vcombine_s16(a, a))), 0); } -template<> EIGEN_STRONG_INLINE Packet4c pcast(const Packet4us& a) -{ - const int16x4_t b = vreinterpret_s16_u16(a); - return vget_lane_s32(vreinterpret_s32_s8(vmovn_s16(vcombine_s16(b, b))), 0); +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet4f& a) { + // Discard second half of input. + return vcvtq_u64_f64(vcvt_f64_f32(vget_low_f32(a))); } -template<> EIGEN_STRONG_INLINE Packet4c pcast(const Packet4i& a) -{ - const int16x4_t b = vmovn_s32(a); - return vget_lane_s32(vreinterpret_s32_s8(vmovn_s16(vcombine_s16(b, b))), 0); +#else +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet4f& a) { + // Discard second half of input. + return vmovl_s32(vget_low_s32(vcvtq_s32_f32(a))); } -template<> EIGEN_STRONG_INLINE Packet4c pcast(const Packet4ui& a) -{ - const int16x4_t b = vmovn_s32(vreinterpretq_s32_u32(a)); - return vget_lane_s32(vreinterpret_s32_s8(vmovn_s16(vcombine_s16(b, b))), 0); +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet4f& a) { + // Discard second half of input. + return vmovl_u32(vget_low_u32(vcvtq_u32_f32(a))); } -template<> EIGEN_STRONG_INLINE Packet8c pcast(const Packet8uc& a) { return vreinterpret_s8_u8(a); } -template<> EIGEN_STRONG_INLINE Packet8c pcast(const Packet8s& a) { return vmovn_s16(a); } -template<> EIGEN_STRONG_INLINE Packet8c pcast(const Packet8us& a) -{ return vreinterpret_s8_u8(vmovn_u16(a)); } -template<> EIGEN_STRONG_INLINE Packet16c pcast(const Packet16uc& a) -{ return vreinterpretq_s8_u8(a); } -template<> EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4f& a) -{ - const uint16x4_t b = vmovn_u32(vreinterpretq_u32_s32(vcvtq_s32_f32(a))); - return vget_lane_u32(vreinterpret_u32_u8(vmovn_u16(vcombine_u16(b, b))), 0); -} -template<> EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4i& a) -{ - const uint16x4_t b = vmovn_u32(vreinterpretq_u32_s32(a)); - return vget_lane_u32(vreinterpret_u32_u8(vmovn_u16(vcombine_u16(b, b))), 0); -} -template<> EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4ui& a) -{ - const uint16x4_t b = vmovn_u32(a); - return vget_lane_u32(vreinterpret_u32_u8(vmovn_u16(vcombine_u16(b, b))), 0); -} -template<> EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4c& a) -{ return static_cast(a); } -template<> EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4s& a) -{ - const uint16x4_t b = vreinterpret_u16_s16(a); - return vget_lane_u32(vreinterpret_u32_u8(vmovn_u16(vcombine_u16(b, b))), 0); -} -template<> EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4us& a) -{ return vget_lane_u32(vreinterpret_u32_u8(vmovn_u16(vcombine_u16(a, a))), 0); } -template<> EIGEN_STRONG_INLINE Packet8uc pcast(const Packet8c& a) { return vreinterpret_u8_s8(a); } -template<> EIGEN_STRONG_INLINE Packet8uc pcast(const Packet8s& a) -{ return vreinterpret_u8_s8(vmovn_s16(a)); } -template<> EIGEN_STRONG_INLINE Packet8uc pcast(const Packet8us& a) { return vmovn_u16(a); } -template<> EIGEN_STRONG_INLINE Packet16uc pcast(const Packet16c& a) -{ return vreinterpretq_u8_s8(a); } -template<> EIGEN_STRONG_INLINE Packet4s pcast(const Packet4f& a) -{ return vmovn_s32(vcvtq_s32_f32(a)); } -template<> EIGEN_STRONG_INLINE Packet4s pcast(const Packet4c& a) -{ return vget_low_s16(vmovl_s8(vreinterpret_s8_s32(vdup_n_s32(a)))); } -template<> EIGEN_STRONG_INLINE Packet4s pcast(const Packet4uc& a) -{ return vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(vreinterpret_u8_u32(vdup_n_u32(a))))); } -template<> EIGEN_STRONG_INLINE Packet4s pcast(const Packet4us& a) -{ return vreinterpret_s16_u16(a); } -template<> EIGEN_STRONG_INLINE Packet4s pcast(const Packet4i& a) { return vmovn_s32(a); } -template<> EIGEN_STRONG_INLINE Packet4s pcast(const Packet4ui& a) -{ return vmovn_s32(vreinterpretq_s32_u32(a)); } -template<> EIGEN_STRONG_INLINE Packet8s pcast(const Packet8uc& a) -{ return vreinterpretq_s16_u16(vmovl_u8(a)); } -template<> EIGEN_STRONG_INLINE Packet8s pcast(const Packet8c& a) { return vmovl_s8(a); } -template<> EIGEN_STRONG_INLINE Packet8s pcast(const Packet8us& a) -{ return vreinterpretq_s16_u16(a); } -template<> EIGEN_STRONG_INLINE Packet4us pcast(const Packet4f& a) -{ return vmovn_u32(vreinterpretq_u32_s32(vcvtq_s32_f32(a))); } -template<> EIGEN_STRONG_INLINE Packet4us pcast(const Packet4c& a) -{ return vget_low_u16(vreinterpretq_u16_s16(vmovl_s8(vreinterpret_s8_s32(vdup_n_s32(a))))); } -template<> EIGEN_STRONG_INLINE Packet4us pcast(const Packet4uc& a) -{ return vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vdup_n_u32(a)))); } -template<> EIGEN_STRONG_INLINE Packet4us pcast(const Packet4s& a) -{ return vreinterpret_u16_s16(a); } -template<> EIGEN_STRONG_INLINE Packet4us pcast(const Packet4i& a) -{ return vmovn_u32(vreinterpretq_u32_s32(a)); } -template<> EIGEN_STRONG_INLINE Packet4us pcast(const Packet4ui& a) { return vmovn_u32(a); } -template<> EIGEN_STRONG_INLINE Packet8us pcast(const Packet8c& a) -{ return vreinterpretq_u16_s16(vmovl_s8(a)); } -template<> EIGEN_STRONG_INLINE Packet8us pcast(const Packet8uc& a) { return vmovl_u8(a); } -template<> EIGEN_STRONG_INLINE Packet8us pcast(const Packet8s& a) -{ return vreinterpretq_u16_s16(a); } -template<> EIGEN_STRONG_INLINE Packet2i pcast(const Packet2f& a) { return vcvt_s32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet2i pcast(const Packet2ui& a) -{ return vreinterpret_s32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet2i pcast(const Packet2l& a) -{ return vmovn_s64(a); } -template<> EIGEN_STRONG_INLINE Packet2i pcast(const Packet2ul& a) -{ return vmovn_s64(vreinterpretq_s64_u64(a)); } -template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4f& a) { return vcvtq_s32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4c& a) -{ return vmovl_s16(vget_low_s16(vmovl_s8(vreinterpret_s8_s32(vdup_n_s32(a))))); } -template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4uc& a) -{ return vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vdup_n_u32(a)))))); } -template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4s& a) { return vmovl_s16(a); } -template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4us& a) -{ return vreinterpretq_s32_u32(vmovl_u16(a)); } -template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4ui& a) -{ return vreinterpretq_s32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2f& a) { return vcvt_u32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2i& a) -{ return vreinterpret_u32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2l& a) -{ return vmovn_u64(vreinterpretq_u64_s64(a)); } -template<> EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2ul& a) -{ return vmovn_u64(a); } -template<> EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4f& a) { return vcvtq_u32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4c& a) -{ return vreinterpretq_u32_s32(vmovl_s16(vget_low_s16(vmovl_s8(vreinterpret_s8_s32(vdup_n_s32(a)))))); } -template<> EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4uc& a) -{ return vmovl_u16(vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vdup_n_u32(a))))); } -template<> EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4s& a) -{ return vreinterpretq_u32_s32(vmovl_s16(a)); } -template<> EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4us& a) { return vmovl_u16(a); } -template<> EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4i& a) -{ return vreinterpretq_u32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet2l pcast(const Packet2f& a) -{ return vmovl_s32(vcvt_s32_f32(a)); } -template<> EIGEN_STRONG_INLINE Packet2l pcast(const Packet2i& a) -{ return vmovl_s32(a); } -template<> EIGEN_STRONG_INLINE Packet2l pcast(const Packet2ui& a) -{ return vreinterpretq_s64_u64(vmovl_u32(a)); } -template<> EIGEN_STRONG_INLINE Packet2l pcast(const Packet2ul& a) -{ return vreinterpretq_s64_u64(a); } -template<> EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2f& a) -{ return vmovl_u32(vcvt_u32_f32(a)); } -template<> EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2i& a) -{ return vreinterpretq_u64_s64(vmovl_s32(a)); } -template<> EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2ui& a) -{ return vmovl_u32(a); } -template<> EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2l& a) -{ return vreinterpretq_u64_s64(a); } +#endif // EIGEN_ARCH_ARM64 -template<> EIGEN_STRONG_INLINE Packet2f preinterpret(const Packet2i& a) -{ return vreinterpret_f32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet2f preinterpret(const Packet2ui& a) -{ return vreinterpret_f32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet4f preinterpret(const Packet4i& a) -{ return vreinterpretq_f32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet4f preinterpret(const Packet4ui& a) -{ return vreinterpretq_f32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet4c preinterpret(const Packet4uc& a) -{ return static_cast(a); } -template<> EIGEN_STRONG_INLINE Packet8c preinterpret(const Packet8uc& a) -{ return vreinterpret_s8_u8(a); } -template<> EIGEN_STRONG_INLINE Packet16c preinterpret(const Packet16uc& a) -{ return vreinterpretq_s8_u8(a); } -template<> EIGEN_STRONG_INLINE Packet4uc preinterpret(const Packet4c& a) -{ return static_cast(a); } -template<> EIGEN_STRONG_INLINE Packet8uc preinterpret(const Packet8c& a) -{ return vreinterpret_u8_s8(a); } -template<> EIGEN_STRONG_INLINE Packet16uc preinterpret(const Packet16c& a) -{ return vreinterpretq_u8_s8(a); } -template<> EIGEN_STRONG_INLINE Packet4s preinterpret(const Packet4us& a) -{ return vreinterpret_s16_u16(a); } -template<> EIGEN_STRONG_INLINE Packet8s preinterpret(const Packet8us& a) -{ return vreinterpretq_s16_u16(a); } -template<> EIGEN_STRONG_INLINE Packet4us preinterpret(const Packet4s& a) -{ return vreinterpret_u16_s16(a); } -template<> EIGEN_STRONG_INLINE Packet8us preinterpret(const Packet8s& a) -{ return vreinterpretq_u16_s16(a); } -template<> EIGEN_STRONG_INLINE Packet2i preinterpret(const Packet2f& a) -{ return vreinterpret_s32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet2i preinterpret(const Packet2ui& a) -{ return vreinterpret_s32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet4i preinterpret(const Packet4f& a) -{ return vreinterpretq_s32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet4i preinterpret(const Packet4ui& a) -{ return vreinterpretq_s32_u32(a); } -template<> EIGEN_STRONG_INLINE Packet2ui preinterpret(const Packet2f& a) -{ return vreinterpret_u32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet2ui preinterpret(const Packet2i& a) -{ return vreinterpret_u32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet4ui preinterpret(const Packet4f& a) -{ return vreinterpretq_u32_f32(a); } -template<> EIGEN_STRONG_INLINE Packet4ui preinterpret(const Packet4i& a) -{ return vreinterpretq_u32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet2l preinterpret(const Packet2ul& a) -{ return vreinterpretq_s64_u64(a); } -template<> EIGEN_STRONG_INLINE Packet2ul preinterpret(const Packet2l& a) -{ return vreinterpretq_u64_s64(a); } +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet4f& a) { + return vcvtq_s32_f32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet2f& a) { + return vcvt_s32_f32(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4f& a) { + return vcvtq_u32_f32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2f& a) { + return vcvt_u32_f32(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet4f& a, const Packet4f& b) { + return vcombine_s16(vmovn_s32(vcvtq_s32_f32(a)), vmovn_s32(vcvtq_s32_f32(b))); +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet2f& a, const Packet2f& b) { + return vmovn_s32(vcombine_s32(vcvt_s32_f32(a), vcvt_s32_f32(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet4f& a, const Packet4f& b) { + return vcombine_u16(vmovn_u32(vcvtq_u32_f32(a)), vmovn_u32(vcvtq_u32_f32(b))); +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet2f& a, const Packet2f& b) { + return vmovn_u32(vcombine_u32(vcvt_u32_f32(a), vcvt_u32_f32(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet4f& a, const Packet4f& b, const Packet4f& c, + const Packet4f& d) { + const int16x8_t ab_s16 = pcast(a, b); + const int16x8_t cd_s16 = pcast(c, d); + return vcombine_s8(vmovn_s16(ab_s16), vmovn_s16(cd_s16)); +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet2f& a, const Packet2f& b, const Packet2f& c, + const Packet2f& d) { + const int16x4_t ab_s16 = pcast(a, b); + const int16x4_t cd_s16 = pcast(c, d); + return vmovn_s16(vcombine_s16(ab_s16, cd_s16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet4f& a, const Packet4f& b, const Packet4f& c, + const Packet4f& d) { + const uint16x8_t ab_u16 = pcast(a, b); + const uint16x8_t cd_u16 = pcast(c, d); + return vcombine_u8(vmovn_u16(ab_u16), vmovn_u16(cd_u16)); +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet2f& a, const Packet2f& b, const Packet2f& c, + const Packet2f& d) { + const uint16x4_t ab_u16 = pcast(a, b); + const uint16x4_t cd_u16 = pcast(c, d); + return vmovn_u16(vcombine_u16(ab_u16, cd_u16)); +} + +//============================================================================== +// pcast, SrcType = int8_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet16c& a) { + // Discard all but first 4 bytes. + return vcvtq_f32_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a))))); +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet8c& a) { + // Discard all but first 2 bytes. + return vcvt_f32_s32(vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(a))))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet16c& a) { + // Discard all but first two bytes. + return vmovl_s32(vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a)))))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet16c& a) { + return vreinterpretq_u64_s64(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet16c& a) { + // Discard all but first 4 bytes. + return vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a)))); +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet8c& a) { + // Discard all but first 2 bytes. + return vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(a)))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet16c& a) { + return vreinterpretq_u32_s32(pcast(a)); +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet8c& a) { + return vreinterpret_u32_s32(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet16c& a) { + // Discard second half of input. + return vmovl_s8(vget_low_s8(a)); +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet8c& a) { + // Discard second half of input. + return vget_low_s16(vmovl_s8(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet16c& a) { + return vreinterpretq_u16_s16(pcast(a)); +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet8c& a) { + return vreinterpret_u16_s16(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet16c& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet8c& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet4c pcast(const Packet4c& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet16c& a) { + return vreinterpretq_u8_s8(a); +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet8c& a) { + return vreinterpret_u8_s8(a); +} +template <> +EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4c& a) { + return static_cast(a); +} + +//============================================================================== +// pcast, SrcType = uint8_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet16uc& a) { + // Discard all but first 4 bytes. + return vcvtq_f32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a))))); +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet8uc& a) { + // Discard all but first 2 bytes. + return vcvt_f32_u32(vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(a))))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet16uc& a) { + // Discard all but first two bytes. + return vmovl_u32(vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a)))))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet16uc& a) { + return vreinterpretq_s64_u64(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet16uc& a) { + // Discard all but first 4 bytes. + return vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a)))); +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet8uc& a) { + // Discard all but first 2 bytes. + return vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(a)))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet16uc& a) { + return vreinterpretq_s32_u32(pcast(a)); +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet8uc& a) { + return vreinterpret_s32_u32(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet16uc& a) { + // Discard second half of input. + return vmovl_u8(vget_low_u8(a)); +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet8uc& a) { + // Discard second half of input. + return vget_low_u16(vmovl_u8(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet16uc& a) { + return vreinterpretq_s16_u16(pcast(a)); +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet8uc& a) { + return vreinterpret_s16_u16(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet16uc& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet8uc& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet4uc pcast(const Packet4uc& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet16uc& a) { + return vreinterpretq_s8_u8(a); +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet8uc& a) { + return vreinterpret_s8_u8(a); +} +template <> +EIGEN_STRONG_INLINE Packet4c pcast(const Packet4uc& a) { + return static_cast(a); +} + +//============================================================================== +// pcast, SrcType = int16_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet8s& a) { + // Discard second half of input. + return vcvtq_f32_s32(vmovl_s16(vget_low_s16(a))); +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet4s& a) { + // Discard second half of input. + return vcvt_f32_s32(vget_low_s32(vmovl_s16(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet8s& a) { + // Discard all but first two values. + return vmovl_s32(vget_low_s32(vmovl_s16(vget_low_s16(a)))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet8s& a) { + return vreinterpretq_u64_s64(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet8s& a) { + // Discard second half of input. + return vmovl_s16(vget_low_s16(a)); +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet4s& a) { + // Discard second half of input. + return vget_low_s32(vmovl_s16(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet8s& a) { + return vreinterpretq_u32_s32(pcast(a)); +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet4s& a) { + return vreinterpret_u32_s32(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet8s& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet4s& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet8s& a) { + return vreinterpretq_u16_s16(a); +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet4s& a) { + return vreinterpret_u16_s16(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet8s& a, const Packet8s& b) { + return vcombine_s8(vmovn_s16(a), vmovn_s16(b)); +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet4s& a, const Packet4s& b) { + return vmovn_s16(vcombine_s16(a, b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet8s& a, const Packet8s& b) { + return vcombine_u8(vmovn_u16(vreinterpretq_u16_s16(a)), vmovn_u16(vreinterpretq_u16_s16(b))); +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet4s& a, const Packet4s& b) { + return vmovn_u16(vcombine_u16(vreinterpret_u16_s16(a), vreinterpret_u16_s16(b))); +} + +//============================================================================== +// pcast, SrcType = uint16_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet8us& a) { + // Discard second half of input. + return vcvtq_f32_u32(vmovl_u16(vget_low_u16(a))); +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet4us& a) { + // Discard second half of input. + return vcvt_f32_u32(vget_low_u32(vmovl_u16(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet8us& a) { + // Discard all but first two values. + return vmovl_u32(vget_low_u32(vmovl_u16(vget_low_u16(a)))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet8us& a) { + return vreinterpretq_s64_u64(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet8us& a) { + // Discard second half of input. + return vmovl_u16(vget_low_u16(a)); +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet4us& a) { + // Discard second half of input. + return vget_low_u32(vmovl_u16(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet8us& a) { + return vreinterpretq_s32_u32(pcast(a)); +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet4us& a) { + return vreinterpret_s32_u32(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet8us& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet4us& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet8us& a) { + return vreinterpretq_s16_u16(a); +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet4us& a) { + return vreinterpret_s16_u16(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet8us& a, const Packet8us& b) { + return vcombine_u8(vmovn_u16(a), vmovn_u16(b)); +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet4us& a, const Packet4us& b) { + return vmovn_u16(vcombine_u16(a, b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet8us& a, const Packet8us& b) { + return vreinterpretq_s8_u8(pcast(a, b)); +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet4us& a, const Packet4us& b) { + return vreinterpret_s8_u8(pcast(a, b)); +} + +//============================================================================== +// pcast, SrcType = int32_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet4i& a) { + return vcvtq_f32_s32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet2i& a) { + return vcvt_f32_s32(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet4i& a) { + // Discard second half of input. + return vmovl_s32(vget_low_s32(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet4i& a) { + return vreinterpretq_u64_s64(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet4i& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet2i& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4i& a) { + return vreinterpretq_u32_s32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2i& a) { + return vreinterpret_u32_s32(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet4i& a, const Packet4i& b) { + return vcombine_s16(vmovn_s32(a), vmovn_s32(b)); +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet2i& a, const Packet2i& b) { + return vmovn_s32(vcombine_s32(a, b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet4i& a, const Packet4i& b) { + return vcombine_u16(vmovn_u32(vreinterpretq_u32_s32(a)), vmovn_u32(vreinterpretq_u32_s32(b))); +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet2i& a, const Packet2i& b) { + return vmovn_u32(vreinterpretq_u32_s32(vcombine_s32(a, b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet4i& a, const Packet4i& b, const Packet4i& c, + const Packet4i& d) { + const int16x8_t ab_s16 = pcast(a, b); + const int16x8_t cd_s16 = pcast(c, d); + return vcombine_s8(vmovn_s16(ab_s16), vmovn_s16(cd_s16)); +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet2i& a, const Packet2i& b, const Packet2i& c, + const Packet2i& d) { + const int16x4_t ab_s16 = vmovn_s32(vcombine_s32(a, b)); + const int16x4_t cd_s16 = vmovn_s32(vcombine_s32(c, d)); + return vmovn_s16(vcombine_s16(ab_s16, cd_s16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet4i& a, const Packet4i& b, const Packet4i& c, + const Packet4i& d) { + const uint16x8_t ab_u16 = pcast(a, b); + const uint16x8_t cd_u16 = pcast(c, d); + return vcombine_u8(vmovn_u16(ab_u16), vmovn_u16(cd_u16)); +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet2i& a, const Packet2i& b, const Packet2i& c, + const Packet2i& d) { + const uint16x4_t ab_u16 = pcast(a, b); + const uint16x4_t cd_u16 = pcast(c, d); + return vmovn_u16(vcombine_u16(ab_u16, cd_u16)); +} + +//============================================================================== +// pcast, SrcType = uint32_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet4ui& a) { + return vcvtq_f32_u32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2f pcast(const Packet2ui& a) { + return vcvt_f32_u32(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet4ui& a) { + // Discard second half of input. + return vmovl_u32(vget_low_u32(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet4ui& a) { + return vreinterpretq_s64_u64(pcast(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet4ui& a) { + return a; +} +template <> +EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2ui& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet4ui& a) { + return vreinterpretq_s32_u32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2i pcast(const Packet2ui& a) { + return vreinterpret_s32_u32(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet4ui& a, const Packet4ui& b) { + return vcombine_u16(vmovn_u32(a), vmovn_u32(b)); +} +template <> +EIGEN_STRONG_INLINE Packet4us pcast(const Packet2ui& a, const Packet2ui& b) { + return vmovn_u32(vcombine_u32(a, b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet4ui& a, const Packet4ui& b) { + return vreinterpretq_s16_u16(pcast(a, b)); +} +template <> +EIGEN_STRONG_INLINE Packet4s pcast(const Packet2ui& a, const Packet2ui& b) { + return vreinterpret_s16_u16(pcast(a, b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c, + const Packet4ui& d) { + const uint16x8_t ab_u16 = vcombine_u16(vmovn_u32(a), vmovn_u32(b)); + const uint16x8_t cd_u16 = vcombine_u16(vmovn_u32(c), vmovn_u32(d)); + return vcombine_u8(vmovn_u16(ab_u16), vmovn_u16(cd_u16)); +} +template <> +EIGEN_STRONG_INLINE Packet8uc pcast(const Packet2ui& a, const Packet2ui& b, const Packet2ui& c, + const Packet2ui& d) { + const uint16x4_t ab_u16 = vmovn_u32(vcombine_u32(a, b)); + const uint16x4_t cd_u16 = vmovn_u32(vcombine_u32(c, d)); + return vmovn_u16(vcombine_u16(ab_u16, cd_u16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c, + const Packet4ui& d) { + return vreinterpretq_s8_u8(pcast(a, b, c, d)); +} +template <> +EIGEN_STRONG_INLINE Packet8c pcast(const Packet2ui& a, const Packet2ui& b, const Packet2ui& c, + const Packet2ui& d) { + return vreinterpret_s8_u8(pcast(a, b, c, d)); +} + +//============================================================================== +// pcast, SrcType = int64_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet2l& a, const Packet2l& b) { + return vcvtq_f32_s32(vcombine_s32(vmovn_s64(a), vmovn_s64(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet2l& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2l& a) { + return vreinterpretq_u64_s64(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet2l& a, const Packet2l& b) { + return vcombine_s32(vmovn_s64(a), vmovn_s64(b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet2l& a, const Packet2l& b) { + return vcombine_u32(vmovn_u64(vreinterpretq_u64_s64(a)), vmovn_u64(vreinterpretq_u64_s64(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet2l& a, const Packet2l& b, const Packet2l& c, + const Packet2l& d) { + const int32x4_t ab_s32 = pcast(a, b); + const int32x4_t cd_s32 = pcast(c, d); + return vcombine_s16(vmovn_s32(ab_s32), vmovn_s32(cd_s32)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet2l& a, const Packet2l& b, const Packet2l& c, + const Packet2l& d) { + const uint32x4_t ab_u32 = pcast(a, b); + const uint32x4_t cd_u32 = pcast(c, d); + return vcombine_u16(vmovn_u32(ab_u32), vmovn_u32(cd_u32)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet2l& a, const Packet2l& b, const Packet2l& c, + const Packet2l& d, const Packet2l& e, const Packet2l& f, + const Packet2l& g, const Packet2l& h) { + const int16x8_t abcd_s16 = pcast(a, b, c, d); + const int16x8_t efgh_s16 = pcast(e, f, g, h); + return vcombine_s8(vmovn_s16(abcd_s16), vmovn_s16(efgh_s16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet2l& a, const Packet2l& b, const Packet2l& c, + const Packet2l& d, const Packet2l& e, const Packet2l& f, + const Packet2l& g, const Packet2l& h) { + const uint16x8_t abcd_u16 = pcast(a, b, c, d); + const uint16x8_t efgh_u16 = pcast(e, f, g, h); + return vcombine_u8(vmovn_u16(abcd_u16), vmovn_u16(efgh_u16)); +} + +//============================================================================== +// pcast, SrcType = uint64_t +//============================================================================== +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet2ul& a, const Packet2ul& b) { + return vcvtq_f32_u32(vcombine_u32(vmovn_u64(a), vmovn_u64(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2ul& a) { + return a; +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet2ul& a) { + return vreinterpretq_s64_u64(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet2ul& a, const Packet2ul& b) { + return vcombine_u32(vmovn_u64(a), vmovn_u64(b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet2ul& a, const Packet2ul& b) { + return vreinterpretq_s32_u32(pcast(a, b)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c, + const Packet2ul& d) { + const uint16x4_t ab_u16 = vmovn_u32(vcombine_u32(vmovn_u64(a), vmovn_u64(b))); + const uint16x4_t cd_u16 = vmovn_u32(vcombine_u32(vmovn_u64(c), vmovn_u64(d))); + return vcombine_u16(ab_u16, cd_u16); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c, + const Packet2ul& d) { + return vreinterpretq_s16_u16(pcast(a, b, c, d)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c, + const Packet2ul& d, const Packet2ul& e, const Packet2ul& f, + const Packet2ul& g, const Packet2ul& h) { + const uint16x8_t abcd_u16 = pcast(a, b, c, d); + const uint16x8_t efgh_u16 = pcast(e, f, g, h); + return vcombine_u8(vmovn_u16(abcd_u16), vmovn_u16(efgh_u16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c, + const Packet2ul& d, const Packet2ul& e, const Packet2ul& f, + const Packet2ul& g, const Packet2ul& h) { + return vreinterpretq_s8_u8(pcast(a, b, c, d, e, f, g, h)); +} + +//============================================================================== +// preinterpret +//============================================================================== +template <> +EIGEN_STRONG_INLINE Packet2f preinterpret(const Packet2i& a) { + return vreinterpret_f32_s32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2f preinterpret(const Packet2ui& a) { + return vreinterpret_f32_u32(a); +} +template <> +EIGEN_STRONG_INLINE Packet4f preinterpret(const Packet4i& a) { + return vreinterpretq_f32_s32(a); +} +template <> +EIGEN_STRONG_INLINE Packet4f preinterpret(const Packet4ui& a) { + return vreinterpretq_f32_u32(a); +} + +template <> +EIGEN_STRONG_INLINE Packet4c preinterpret(const Packet4uc& a) { + return static_cast(a); +} +template <> +EIGEN_STRONG_INLINE Packet8c preinterpret(const Packet8uc& a) { + return vreinterpret_s8_u8(a); +} +template <> +EIGEN_STRONG_INLINE Packet16c preinterpret(const Packet16uc& a) { + return vreinterpretq_s8_u8(a); +} + +template <> +EIGEN_STRONG_INLINE Packet4uc preinterpret(const Packet4c& a) { + return static_cast(a); +} +template <> +EIGEN_STRONG_INLINE Packet8uc preinterpret(const Packet8c& a) { + return vreinterpret_u8_s8(a); +} +template <> +EIGEN_STRONG_INLINE Packet16uc preinterpret(const Packet16c& a) { + return vreinterpretq_u8_s8(a); +} + +template <> +EIGEN_STRONG_INLINE Packet4s preinterpret(const Packet4us& a) { + return vreinterpret_s16_u16(a); +} +template <> +EIGEN_STRONG_INLINE Packet8s preinterpret(const Packet8us& a) { + return vreinterpretq_s16_u16(a); +} + +template <> +EIGEN_STRONG_INLINE Packet4us preinterpret(const Packet4s& a) { + return vreinterpret_u16_s16(a); +} +template <> +EIGEN_STRONG_INLINE Packet8us preinterpret(const Packet8s& a) { + return vreinterpretq_u16_s16(a); +} + +template <> +EIGEN_STRONG_INLINE Packet2i preinterpret(const Packet2f& a) { + return vreinterpret_s32_f32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2i preinterpret(const Packet2ui& a) { + return vreinterpret_s32_u32(a); +} +template <> +EIGEN_STRONG_INLINE Packet4i preinterpret(const Packet4f& a) { + return vreinterpretq_s32_f32(a); +} +template <> +EIGEN_STRONG_INLINE Packet4i preinterpret(const Packet4ui& a) { + return vreinterpretq_s32_u32(a); +} + +template <> +EIGEN_STRONG_INLINE Packet2ui preinterpret(const Packet2f& a) { + return vreinterpret_u32_f32(a); +} +template <> +EIGEN_STRONG_INLINE Packet2ui preinterpret(const Packet2i& a) { + return vreinterpret_u32_s32(a); +} +template <> +EIGEN_STRONG_INLINE Packet4ui preinterpret(const Packet4f& a) { + return vreinterpretq_u32_f32(a); +} +template <> +EIGEN_STRONG_INLINE Packet4ui preinterpret(const Packet4i& a) { + return vreinterpretq_u32_s32(a); +} + +template <> +EIGEN_STRONG_INLINE Packet2l preinterpret(const Packet2ul& a) { + return vreinterpretq_s64_u64(a); +} +template <> +EIGEN_STRONG_INLINE Packet2ul preinterpret(const Packet2l& a) { + return vreinterpretq_u64_s64(a); +} #if EIGEN_ARCH_ARM64 -template<> EIGEN_STRONG_INLINE Packet2f pcast(const Packet2d& a) { return vcvt_f32_f64(a); } -template<> EIGEN_STRONG_INLINE Packet2d pcast(const Packet2f& a) { return vcvt_f64_f32(a); } -template<> EIGEN_STRONG_INLINE Packet2d pcast(const Packet2i& a) { return vcvtq_f64_s64(vmovl_s32(a)); } -template<> EIGEN_STRONG_INLINE Packet2d pcast(const Packet2ui& a) { return vcvtq_f64_u64(vmovl_u32(a)); } -template<> EIGEN_STRONG_INLINE Packet2d pcast(const Packet2l& a) { return vcvtq_f64_s64(a); } -template<> EIGEN_STRONG_INLINE Packet2d pcast(const Packet2ul& a) { return vcvtq_f64_u64(a); } -template<> EIGEN_STRONG_INLINE Packet2i pcast(const Packet2d& a) { return vcvt_s32_f32(vcvt_f32_f64(a)); } -template<> EIGEN_STRONG_INLINE Packet2ui pcast(const Packet2d& a) { return vcvt_u32_f32(vcvt_f32_f64(a)); } -template<> EIGEN_STRONG_INLINE Packet2l pcast(const Packet2d& a) { return vcvtq_s64_f64(a); } -template<> EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2d& a) { return vcvtq_u64_f64(a); } +//============================================================================== +// pcast/preinterpret, Double +//============================================================================== -template<> EIGEN_STRONG_INLINE Packet2d preinterpret(const Packet2l& a) -{ return vreinterpretq_f64_s64(a); } -template<> EIGEN_STRONG_INLINE Packet2d preinterpret(const Packet2ul& a) -{ return vreinterpretq_f64_u64(a); } -template<> EIGEN_STRONG_INLINE Packet2l preinterpret(const Packet2d& a) -{ return vreinterpretq_s64_f64(a); } -template<> EIGEN_STRONG_INLINE Packet2ul preinterpret(const Packet2d& a) -{ return vreinterpretq_u64_f64(a); } +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet2d& a) { + return a; +} -#endif // EIGEN_ARCH_ARM64 +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4f pcast(const Packet2d& a, const Packet2d& b) { + return vcombine_f32(vcvt_f32_f64(a), vcvt_f32_f64(b)); +} -} // end namespace internal +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2l pcast(const Packet2d& a) { + return vcvtq_s64_f64(a); +} -} // end namespace Eigen +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2ul pcast(const Packet2d& a) { + return vcvtq_u64_f64(a); +} -#endif // EIGEN_TYPE_CASTING_NEON_H +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4i pcast(const Packet2d& a, const Packet2d& b) { + return vcombine_s32(vmovn_s64(vcvtq_s64_f64(a)), vmovn_s64(vcvtq_s64_f64(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet4ui pcast(const Packet2d& a, const Packet2d& b) { + return vcombine_u32(vmovn_u64(vcvtq_u64_f64(a)), vmovn_u64(vcvtq_u64_f64(b))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8s pcast(const Packet2d& a, const Packet2d& b, const Packet2d& c, + const Packet2d& d) { + const int32x4_t ab_s32 = pcast(a, b); + const int32x4_t cd_s32 = pcast(c, d); + return vcombine_s16(vmovn_s32(ab_s32), vmovn_s32(cd_s32)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet8us pcast(const Packet2d& a, const Packet2d& b, const Packet2d& c, + const Packet2d& d) { + const uint32x4_t ab_u32 = pcast(a, b); + const uint32x4_t cd_u32 = pcast(c, d); + return vcombine_u16(vmovn_u32(ab_u32), vmovn_u32(cd_u32)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16c pcast(const Packet2d& a, const Packet2d& b, const Packet2d& c, + const Packet2d& d, const Packet2d& e, const Packet2d& f, + const Packet2d& g, const Packet2d& h) { + const int16x8_t abcd_s16 = pcast(a, b, c, d); + const int16x8_t efgh_s16 = pcast(e, f, g, h); + return vcombine_s8(vmovn_s16(abcd_s16), vmovn_s16(efgh_s16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet16uc pcast(const Packet2d& a, const Packet2d& b, const Packet2d& c, + const Packet2d& d, const Packet2d& e, const Packet2d& f, + const Packet2d& g, const Packet2d& h) { + const uint16x8_t abcd_u16 = pcast(a, b, c, d); + const uint16x8_t efgh_u16 = pcast(e, f, g, h); + return vcombine_u8(vmovn_u16(abcd_u16), vmovn_u16(efgh_u16)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet4f& a) { + // Discard second-half of input. + return vcvt_f64_f32(vget_low_f32(a)); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet16c& a) { + // Discard all but first two values. + return vcvt_f64_f32(pcast(vget_low_s8(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet16uc& a) { + // Discard all but first two values. + return vcvt_f64_f32(pcast(vget_low_u8(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet8s& a) { + // Discard all but first two values. + return vcvt_f64_f32(pcast(vget_low_s16(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet8us& a) { + // Discard all but first two values. + return vcvt_f64_f32(pcast(vget_low_u16(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet4i& a) { + // Discard second half of input. + return vcvtq_f64_s64(vmovl_s32(vget_low_s32(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet4ui& a) { + // Discard second half of input. + return vcvtq_f64_u64(vmovl_u32(vget_low_u32(a))); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet2l& a) { + return vcvtq_f64_s64(a); +} + +template <> +struct type_casting_traits { + enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; +}; +template <> +EIGEN_STRONG_INLINE Packet2d pcast(const Packet2ul& a) { + return vcvtq_f64_u64(a); +} + +template <> +EIGEN_STRONG_INLINE Packet2d preinterpret(const Packet2l& a) { + return vreinterpretq_f64_s64(a); +} +template <> +EIGEN_STRONG_INLINE Packet2d preinterpret(const Packet2ul& a) { + return vreinterpretq_f64_u64(a); +} +template <> +EIGEN_STRONG_INLINE Packet2l preinterpret(const Packet2d& a) { + return vreinterpretq_s64_f64(a); +} +template <> +EIGEN_STRONG_INLINE Packet2ul preinterpret(const Packet2d& a) { + return vreinterpretq_u64_f64(a); +} + +#endif // EIGEN_ARCH_ARM64 + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_TYPE_CASTING_NEON_H diff --git a/test/packetmath.cpp b/test/packetmath.cpp index a82b2b87a..a57a3b6a5 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -11,95 +11,264 @@ #include "packetmath_test_shared.h" template -inline T REF_ADD(const T& a, const T& b) { return a + b;} +inline T REF_ADD(const T& a, const T& b) { + return a + b; +} template -inline T REF_SUB(const T& a, const T& b) { return a - b;} +inline T REF_SUB(const T& a, const T& b) { + return a - b; +} template -inline T REF_MUL(const T& a, const T& b) { return a * b;} +inline T REF_MUL(const T& a, const T& b) { + return a * b; +} template -inline T REF_DIV(const T& a, const T& b) { return a / b;} +inline T REF_DIV(const T& a, const T& b) { + return a / b; +} template -inline T REF_ABS_DIFF(const T& a, const T& b) { return a>b ? a - b : b-a;} +inline T REF_ABS_DIFF(const T& a, const T& b) { + return a > b ? a - b : b - a; +} // Specializations for bool. template <> -inline bool REF_ADD(const bool& a, const bool& b) { return a || b;} +inline bool REF_ADD(const bool& a, const bool& b) { + return a || b; +} template <> -inline bool REF_SUB(const bool& a, const bool& b) { return a ^ b;} +inline bool REF_SUB(const bool& a, const bool& b) { + return a ^ b; +} template <> -inline bool REF_MUL(const bool& a, const bool& b) { return a && b;} +inline bool REF_MUL(const bool& a, const bool& b) { + return a && b; +} // Uses pcast to cast from one array to another. -template -struct pcast_array { - static void cast(const typename internal::unpacket_traits::type* src, size_t size, typename internal::unpacket_traits::type* dst) { - static const int TgtPacketSize = internal::unpacket_traits::size; - for (size_t i=0; i(internal::ploadu(src+i))); - } - } -}; +template +struct pcast_array; -template -struct pcast_array{ - static void cast(const typename internal::unpacket_traits::type* src, size_t size, typename internal::unpacket_traits::type* dst) { +template +struct pcast_array { + typedef typename internal::unpacket_traits::type SrcScalar; + typedef typename internal::unpacket_traits::type TgtScalar; + static void cast(const SrcScalar* src, size_t size, TgtScalar* dst) { static const int SrcPacketSize = internal::unpacket_traits::size; static const int TgtPacketSize = internal::unpacket_traits::size; - for (size_t i=0; i(src+i); - SrcPacket b = internal::ploadu(src+i+SrcPacketSize); - internal::pstoreu(dst+i, internal::pcast(a, b)); + size_t i; + for (i = 0; i < size && i + SrcPacketSize <= size; i += TgtPacketSize) { + internal::pstoreu(dst + i, internal::pcast(internal::ploadu(src + i))); + } + // Leftovers that cannot be loaded into a packet. + for (; i < size; ++i) { + dst[i] = static_cast(src[i]); } } }; -template -struct pcast_array{ - static void cast(const typename internal::unpacket_traits::type* src, size_t size, typename internal::unpacket_traits::type* dst) { +template +struct pcast_array { + static void cast(const typename internal::unpacket_traits::type* src, size_t size, + typename internal::unpacket_traits::type* dst) { static const int SrcPacketSize = internal::unpacket_traits::size; static const int TgtPacketSize = internal::unpacket_traits::size; - for (size_t i=0; i(src+i); - SrcPacket b = internal::ploadu(src+i+SrcPacketSize); - SrcPacket c = internal::ploadu(src+i+2*SrcPacketSize); - SrcPacket d = internal::ploadu(src+i+3*SrcPacketSize); - internal::pstoreu(dst+i, internal::pcast(a, b)); + for (size_t i = 0; i < size; i += TgtPacketSize) { + SrcPacket a = internal::ploadu(src + i); + SrcPacket b = internal::ploadu(src + i + SrcPacketSize); + internal::pstoreu(dst + i, internal::pcast(a, b)); } } }; -template +template +struct pcast_array { + static void cast(const typename internal::unpacket_traits::type* src, size_t size, + typename internal::unpacket_traits::type* dst) { + static const int SrcPacketSize = internal::unpacket_traits::size; + static const int TgtPacketSize = internal::unpacket_traits::size; + for (size_t i = 0; i < size; i += TgtPacketSize) { + SrcPacket a = internal::ploadu(src + i); + SrcPacket b = internal::ploadu(src + i + SrcPacketSize); + SrcPacket c = internal::ploadu(src + i + 2 * SrcPacketSize); + SrcPacket d = internal::ploadu(src + i + 3 * SrcPacketSize); + internal::pstoreu(dst + i, internal::pcast(a, b, c, d)); + } + } +}; + +template +struct pcast_array { + static void cast(const typename internal::unpacket_traits::type* src, size_t size, + typename internal::unpacket_traits::type* dst) { + static const int SrcPacketSize = internal::unpacket_traits::size; + static const int TgtPacketSize = internal::unpacket_traits::size; + for (size_t i = 0; i < size; i += TgtPacketSize) { + SrcPacket a = internal::ploadu(src + i); + SrcPacket b = internal::ploadu(src + i + SrcPacketSize); + SrcPacket c = internal::ploadu(src + i + 2 * SrcPacketSize); + SrcPacket d = internal::ploadu(src + i + 3 * SrcPacketSize); + SrcPacket e = internal::ploadu(src + i + 4 * SrcPacketSize); + SrcPacket f = internal::ploadu(src + i + 5 * SrcPacketSize); + SrcPacket g = internal::ploadu(src + i + 6 * SrcPacketSize); + SrcPacket h = internal::ploadu(src + i + 7 * SrcPacketSize); + internal::pstoreu(dst + i, internal::pcast(a, b, c, d, e, f, g, h)); + } + } +}; + +template struct test_cast_helper; -template +template struct test_cast_helper { static void run() {} }; -template +// Generates random values that fit in both SrcScalar and TgtScalar without +// overflowing when cast. +template +struct random_without_cast_overflow { + static SrcScalar value() { return internal::random(); } +}; + +// Widening integer cast signed to unsigned. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if::IsInteger && NumTraits::IsInteger && + !NumTraits::IsSigned && + (std::numeric_limits::digits < std::numeric_limits::digits || + (std::numeric_limits::digits == std::numeric_limits::digits && + NumTraits::IsSigned))>::type> { + static SrcScalar value() { + SrcScalar a = internal::random(); + return a < SrcScalar(0) ? -(a + 1) : a; + } +}; + +// Narrowing integer cast to unsigned. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if< + NumTraits::IsInteger && NumTraits::IsInteger && !NumTraits::IsSigned && + (std::numeric_limits::digits > std::numeric_limits::digits)>::type> { + static SrcScalar value() { + TgtScalar b = internal::random(); + return static_cast(b < TgtScalar(0) ? -(b + 1) : b); + } +}; + +// Narrowing integer cast to signed. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if< + NumTraits::IsInteger && NumTraits::IsInteger && NumTraits::IsSigned && + (std::numeric_limits::digits > std::numeric_limits::digits)>::type> { + static SrcScalar value() { + TgtScalar b = internal::random(); + return static_cast(b); + } +}; + +// Unsigned to signed narrowing cast. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if::IsInteger && NumTraits::IsInteger && + !NumTraits::IsSigned && NumTraits::IsSigned && + (std::numeric_limits::digits == + std::numeric_limits::digits)>::type> { + static SrcScalar value() { return internal::random() / 2; } +}; + +template +struct is_floating_point { + enum { value = 0 }; +}; +template <> +struct is_floating_point { + enum { value = 1 }; +}; +template <> +struct is_floating_point { + enum { value = 1 }; +}; +template <> +struct is_floating_point { + enum { value = 1 }; +}; +template <> +struct is_floating_point { + enum { value = 1 }; +}; + +// Floating-point to integer, full precision. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if::value && NumTraits::IsInteger && + (std::numeric_limits::digits <= + std::numeric_limits::digits)>::type> { + static SrcScalar value() { return static_cast(internal::random()); } +}; + +// Floating-point to integer, narrowing precision. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if::value && NumTraits::IsInteger && + (std::numeric_limits::digits > + std::numeric_limits::digits)>::type> { + static SrcScalar value() { + static const int BitShift = std::numeric_limits::digits - std::numeric_limits::digits; + return static_cast(internal::random() >> BitShift); + } +}; + +// Floating-point target from integer, re-use above logic. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if::IsInteger && is_floating_point::value>::type> { + static SrcScalar value() { + return static_cast(random_without_cast_overflow::value()); + } +}; + +// Floating-point narrowing conversion. +template +struct random_without_cast_overflow< + SrcScalar, TgtScalar, + typename internal::enable_if::value && is_floating_point::value && + (std::numeric_limits::digits > + std::numeric_limits::digits)>::type> { + static SrcScalar value() { return static_cast(internal::random()); } +}; + +template struct test_cast_helper { static void run() { typedef typename internal::unpacket_traits::type SrcScalar; typedef typename internal::unpacket_traits::type TgtScalar; static const int SrcPacketSize = internal::unpacket_traits::size; static const int TgtPacketSize = internal::unpacket_traits::size; - static const int DataSize = SrcPacketSize*SrcCoeffRatio; - VERIFY(DataSize == TgtPacketSize*TgtCoeffRatio && "Packet sizes and cast ratios are mismatched."); + static const int BlockSize = SrcPacketSize * SrcCoeffRatio; + eigen_assert(BlockSize == TgtPacketSize * TgtCoeffRatio && "Packet sizes and cast ratios are mismatched."); + static const int DataSize = 10 * BlockSize; EIGEN_ALIGN_MAX SrcScalar data1[DataSize]; EIGEN_ALIGN_MAX TgtScalar data2[DataSize]; EIGEN_ALIGN_MAX TgtScalar ref[DataSize]; // Construct a packet of scalars that will not overflow when casting - for (int i=0; i::Random().value(); - const TgtScalar b = Array::Random().value(); - const SrcScalar c = sizeof(TgtScalar) > sizeof(SrcScalar) ? static_cast(b) : a; - data1[i] = (NumTraits::IsSigned && !NumTraits::IsSigned) ? numext::abs(c) : c; + for (int i = 0; i < DataSize; ++i) { + data1[i] = random_without_cast_overflow::value(); } - for (int i=0; i(data1[i]); + for (int i = 0; i < DataSize; ++i) ref[i] = static_cast(data1[i]); pcast_array::cast(data1, DataSize, data2); @@ -107,48 +276,72 @@ struct test_cast_helper -void test_cast() { - typedef typename internal::packet_traits SrcPacketTraits; - typedef typename internal::packet_traits TgtPacketTraits; - typedef typename internal::type_casting_traits TypeCastingTraits; - static const int SrcCoeffRatio = TypeCastingTraits::SrcCoeffRatio; - static const int TgtCoeffRatio = TypeCastingTraits::TgtCoeffRatio; - - static const bool HasFullCast = TypeCastingTraits::VectorizedCast; - static const bool HasHalfCast = HasFullCast && internal::packet_traits::HasHalfPacket && internal::packet_traits::HasHalfPacket; - - test_cast_helper::run(); - test_cast_helper::run(); -} - -template void packetmath_pcast_ops() { - const static bool IsFullPacket = internal::is_same::type,Packet>::value; - if (IsFullPacket) { - test_cast(); - test_cast(); - test_cast(); - test_cast(); - test_cast(); - test_cast(); - test_cast(); - test_cast(); - test_cast(); - test_cast(); +template +struct test_cast { + static void run() { + typedef typename internal::unpacket_traits::type SrcScalar; + typedef typename internal::unpacket_traits::type TgtScalar; + typedef typename internal::type_casting_traits TypeCastingTraits; + static const int SrcCoeffRatio = TypeCastingTraits::SrcCoeffRatio; + static const int TgtCoeffRatio = TypeCastingTraits::TgtCoeffRatio; + static const int SrcPacketSize = internal::unpacket_traits::size; + static const int TgtPacketSize = internal::unpacket_traits::size; + static const bool HasCast = + internal::unpacket_traits::vectorizable && internal::unpacket_traits::vectorizable && + TypeCastingTraits::VectorizedCast && (SrcPacketSize * SrcCoeffRatio == TgtPacketSize * TgtCoeffRatio); + test_cast_helper::run(); } +}; + +template ::type, + bool Vectorized = internal::packet_traits::Vectorizable, + bool HasHalf = !internal::is_same::half, TgtPacket>::value> +struct test_cast_runner; + +template +struct test_cast_runner { + static void run() { test_cast::run(); } +}; + +template +struct test_cast_runner { + static void run() { + test_cast::run(); + test_cast_runner::half>::run(); + } +}; + +template +struct test_cast_runner { + static void run() {} +}; + +template +void packetmath_pcast_ops() { + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); + test_cast_runner::run(); } -template -void packetmath_boolean_mask_ops() -{ +template +void packetmath_boolean_mask_ops() { const int PacketSize = internal::unpacket_traits::size; - const int size = 2*PacketSize; + const int size = 2 * PacketSize; EIGEN_ALIGN_MAX Scalar data1[size]; EIGEN_ALIGN_MAX Scalar data2[size]; EIGEN_ALIGN_MAX Scalar ref[size]; - for (int i=0; i(); } CHECK_CWISE1(internal::ptrue, internal::ptrue); @@ -163,82 +356,68 @@ void packetmath_boolean_mask_ops() // Packet16b representing bool does not support ptrue, pandnot or pcmp_eq, since the scalar path // (for some compilers) compute the bitwise and with 0x1 of the results to keep the value in [0,1]. #ifdef EIGEN_PACKET_MATH_SSE_H -template<> -void packetmath_boolean_mask_ops() -{ -} +template <> +void packetmath_boolean_mask_ops() {} #endif -template void packetmath() -{ +template +void packetmath() { typedef internal::packet_traits PacketTraits; const int PacketSize = internal::unpacket_traits::size; typedef typename NumTraits::Real RealScalar; if (g_first_pass) - std::cerr << "=== Testing packet of type '" << typeid(Packet).name() - << "' and scalar type '" << typeid(Scalar).name() - << "' and size '" << PacketSize << "' ===\n" ; + std::cerr << "=== Testing packet of type '" << typeid(Packet).name() << "' and scalar type '" + << typeid(Scalar).name() << "' and size '" << PacketSize << "' ===\n"; const int max_size = PacketSize > 4 ? PacketSize : 4; - const int size = PacketSize*max_size; + const int size = PacketSize * max_size; EIGEN_ALIGN_MAX Scalar data1[size]; EIGEN_ALIGN_MAX Scalar data2[size]; EIGEN_ALIGN_MAX Scalar data3[size]; EIGEN_ALIGN_MAX Scalar ref[size]; RealScalar refvalue = RealScalar(0); - for (int i=0; i()/RealScalar(PacketSize); - data2[i] = internal::random()/RealScalar(PacketSize); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random() / RealScalar(PacketSize); + data2[i] = internal::random() / RealScalar(PacketSize); refvalue = (std::max)(refvalue, numext::abs(data1[i])); } internal::pstore(data2, internal::pload(data1)); VERIFY(test::areApprox(data1, data2, PacketSize) && "aligned load/store"); - for (int offset=0; offset(data1+offset)); - VERIFY(test::areApprox(data1+offset, data2, PacketSize) && "internal::ploadu"); + for (int offset = 0; offset < PacketSize; ++offset) { + internal::pstore(data2, internal::ploadu(data1 + offset)); + VERIFY(test::areApprox(data1 + offset, data2, PacketSize) && "internal::ploadu"); } - for (int offset=0; offset(data1)); - VERIFY(test::areApprox(data1, data2+offset, PacketSize) && "internal::pstoreu"); + for (int offset = 0; offset < PacketSize; ++offset) { + internal::pstoreu(data2 + offset, internal::pload(data1)); + VERIFY(test::areApprox(data1, data2 + offset, PacketSize) && "internal::pstoreu"); } - if (internal::unpacket_traits::masked_load_available) - { + if (internal::unpacket_traits::masked_load_available) { test::packet_helper::masked_load_available, Packet> h; unsigned long long max_umask = (0x1ull << PacketSize); - for (int offset=0; offset> k) ? data1[k+offset] : Scalar(0); + for (int offset = 0; offset < PacketSize; ++offset) { + for (unsigned long long umask = 0; umask < max_umask; ++umask) { + h.store(data2, h.load(data1 + offset, umask)); + for (int k = 0; k < PacketSize; ++k) data3[k] = ((umask & (0x1ull << k)) >> k) ? data1[k + offset] : Scalar(0); VERIFY(test::areApprox(data3, data2, PacketSize) && "internal::ploadu masked"); } } } - if (internal::unpacket_traits::masked_store_available) - { + if (internal::unpacket_traits::masked_store_available) { test::packet_helper::masked_store_available, Packet> h; unsigned long long max_umask = (0x1ull << PacketSize); - for (int offset=0; offset(Scalar(0))); - h.store(data2, h.loadu(data1+offset), umask); - for (int k=0; k> k) ? data1[k+offset] : Scalar(0); + h.store(data2, h.loadu(data1 + offset), umask); + for (int k = 0; k < PacketSize; ++k) data3[k] = ((umask & (0x1ull << k)) >> k) ? data1[k + offset] : Scalar(0); VERIFY(test::areApprox(data3, data2, PacketSize) && "internal::pstoreu masked"); } } @@ -248,110 +427,95 @@ template void packetmath() VERIFY((!PacketTraits::Vectorizable) || PacketTraits::HasSub); VERIFY((!PacketTraits::Vectorizable) || PacketTraits::HasMul); - CHECK_CWISE2_IF(PacketTraits::HasAdd, REF_ADD, internal::padd); - CHECK_CWISE2_IF(PacketTraits::HasSub, REF_SUB, internal::psub); - CHECK_CWISE2_IF(PacketTraits::HasMul, REF_MUL, internal::pmul); + CHECK_CWISE2_IF(PacketTraits::HasAdd, REF_ADD, internal::padd); + CHECK_CWISE2_IF(PacketTraits::HasSub, REF_SUB, internal::psub); + CHECK_CWISE2_IF(PacketTraits::HasMul, REF_MUL, internal::pmul); CHECK_CWISE2_IF(PacketTraits::HasDiv, REF_DIV, internal::pdiv); - if (PacketTraits::HasNegate) - CHECK_CWISE1(internal::negate, internal::pnegate); + if (PacketTraits::HasNegate) CHECK_CWISE1(internal::negate, internal::pnegate); CHECK_CWISE1(numext::conj, internal::pconj); - for(int offset=0;offset<3;++offset) - { - for (int i=0; i(data1[offset])); VERIFY(test::areApprox(ref, data2, PacketSize) && "internal::pset1"); } { - for (int i=0; i(data1, A0, A1, A2, A3); - internal::pstore(data2+0*PacketSize, A0); - internal::pstore(data2+1*PacketSize, A1); - internal::pstore(data2+2*PacketSize, A2); - internal::pstore(data2+3*PacketSize, A3); - VERIFY(test::areApprox(ref, data2, 4*PacketSize) && "internal::pbroadcast4"); + internal::pstore(data2 + 0 * PacketSize, A0); + internal::pstore(data2 + 1 * PacketSize, A1); + internal::pstore(data2 + 2 * PacketSize, A2); + internal::pstore(data2 + 3 * PacketSize, A3); + VERIFY(test::areApprox(ref, data2, 4 * PacketSize) && "internal::pbroadcast4"); } { - for (int i=0; i(data1, A0, A1); - internal::pstore(data2+0*PacketSize, A0); - internal::pstore(data2+1*PacketSize, A1); - VERIFY(test::areApprox(ref, data2, 2*PacketSize) && "internal::pbroadcast2"); + internal::pstore(data2 + 0 * PacketSize, A0); + internal::pstore(data2 + 1 * PacketSize, A1); + VERIFY(test::areApprox(ref, data2, 2 * PacketSize) && "internal::pbroadcast2"); } VERIFY(internal::isApprox(data1[0], internal::pfirst(internal::pload(data1))) && "internal::pfirst"); - if(PacketSize>1) - { + if (PacketSize > 1) { // apply different offsets to check that ploaddup is robust to unaligned inputs - for(int offset=0;offset<4;++offset) - { - for(int i=0;i(data1+offset)); + for (int offset = 0; offset < 4; ++offset) { + for (int i = 0; i < PacketSize / 2; ++i) ref[2 * i + 0] = ref[2 * i + 1] = data1[offset + i]; + internal::pstore(data2, internal::ploaddup(data1 + offset)); VERIFY(test::areApprox(ref, data2, PacketSize) && "ploaddup"); } } - if(PacketSize>2) - { + if (PacketSize > 2) { // apply different offsets to check that ploadquad is robust to unaligned inputs - for(int offset=0;offset<4;++offset) - { - for(int i=0;i(data1+offset)); + for (int offset = 0; offset < 4; ++offset) { + for (int i = 0; i < PacketSize / 4; ++i) + ref[4 * i + 0] = ref[4 * i + 1] = ref[4 * i + 2] = ref[4 * i + 3] = data1[offset + i]; + internal::pstore(data2, internal::ploadquad(data1 + offset)); VERIFY(test::areApprox(ref, data2, PacketSize) && "ploadquad"); } } ref[0] = Scalar(0); - for (int i=0; i(data1)), refvalue) && "internal::predux"); - if(PacketSize==8 && internal::unpacket_traits::half>::size ==4) // so far, predux_half_downto4 is only required in such a case + if (PacketSize == 8 && internal::unpacket_traits::half>::size == + 4) // so far, predux_half_downto4 is only required in such a case { - int HalfPacketSize = PacketSize>4 ? PacketSize/2 : PacketSize; - for (int i=0; i 4 ? PacketSize / 2 : PacketSize; + for (int i = 0; i < HalfPacketSize; ++i) ref[i] = Scalar(0); + for (int i = 0; i < PacketSize; ++i) ref[i % HalfPacketSize] += data1[i]; internal::pstore(data2, internal::predux_half_dowto4(internal::pload(data1))); VERIFY(test::areApprox(ref, data2, HalfPacketSize) && "internal::predux_half_dowto4"); } ref[0] = Scalar(1); - for (int i=0; i(data1))) && "internal::predux_mul"); - for (int i=0; i(data1))); VERIFY(test::areApprox(ref, data2, PacketSize) && "internal::preverse"); internal::PacketBlock kernel; - for (int i=0; i(data1+i*PacketSize); + for (int i = 0; i < PacketSize; ++i) { + kernel.packet[i] = internal::pload(data1 + i * PacketSize); } ptranspose(kernel); - for (int i=0; i(data1); Packet elsePacket = internal::pload(data2); @@ -372,22 +536,21 @@ template void packetmath() for (int i = 0; i < PacketSize; ++i) { // "if" mask unsigned char v = internal::random() ? 0xff : 0; - char* bytes = (char*)(data1+i); - for(int k=0; k(); + data1[i + PacketSize] = internal::random(); // "else" packet - data1[i+2*PacketSize] = internal::random(); + data1[i + 2 * PacketSize] = internal::random(); } CHECK_CWISE3_IF(true, internal::pselect, internal::pselect); } CHECK_CWISE1_IF(PacketTraits::HasSqrt, numext::sqrt, internal::psqrt); - for (int i=0; i(); } CHECK_CWISE1(internal::pzero, internal::pzero); @@ -399,34 +562,29 @@ template void packetmath() packetmath_pcast_ops(); } - - -template void packetmath_real() -{ +template +void packetmath_real() { typedef internal::packet_traits PacketTraits; const int PacketSize = internal::unpacket_traits::size; - const int size = PacketSize*4; - EIGEN_ALIGN_MAX Scalar data1[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar data2[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar ref[PacketSize*4]; + const int size = PacketSize * 4; + EIGEN_ALIGN_MAX Scalar data1[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar data2[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar ref[PacketSize * 4]; - for (int i=0; i(0,1) * std::pow(Scalar(10), internal::random(-6,6)); - data2[i] = internal::random(0,1) * std::pow(Scalar(10), internal::random(-6,6)); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random(0, 1) * std::pow(Scalar(10), internal::random(-6, 6)); + data2[i] = internal::random(0, 1) * std::pow(Scalar(10), internal::random(-6, 6)); } - if(internal::random(0,1)<0.1f) - data1[internal::random(0, PacketSize)] = 0; + if (internal::random(0, 1) < 0.1f) data1[internal::random(0, PacketSize)] = 0; CHECK_CWISE1_IF(PacketTraits::HasLog, std::log, internal::plog); - CHECK_CWISE1_IF(PacketTraits::HasRsqrt, Scalar(1)/std::sqrt, internal::prsqrt); + CHECK_CWISE1_IF(PacketTraits::HasRsqrt, Scalar(1) / std::sqrt, internal::prsqrt); - for (int i=0; i(-1,1) * std::pow(Scalar(10), internal::random(-3,3)); - data2[i] = internal::random(-1,1) * std::pow(Scalar(10), internal::random(-3,3)); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random(-1, 1) * std::pow(Scalar(10), internal::random(-3, 3)); + data2[i] = internal::random(-1, 1) * std::pow(Scalar(10), internal::random(-3, 3)); } CHECK_CWISE1_IF(PacketTraits::HasSin, std::sin, internal::psin); CHECK_CWISE1_IF(PacketTraits::HasCos, std::cos, internal::pcos); @@ -438,40 +596,35 @@ template void packetmath_real() CHECK_CWISE1_IF(PacketTraits::HasRint, numext::rint, internal::print); // See bug 1785. - for (int i=0; i(-1,1); - data2[i] = internal::random(-1,1); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random(-1, 1); + data2[i] = internal::random(-1, 1); } CHECK_CWISE1_IF(PacketTraits::HasASin, std::asin, internal::pasin); CHECK_CWISE1_IF(PacketTraits::HasACos, std::acos, internal::pacos); - for (int i=0; i(-87,88); - data2[i] = internal::random(-87,88); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random(-87, 88); + data2[i] = internal::random(-87, 88); } CHECK_CWISE1_IF(PacketTraits::HasExp, std::exp, internal::pexp); - for (int i=0; i(-1,1) * std::pow(Scalar(10), internal::random(-6,6)); - data2[i] = internal::random(-1,1) * std::pow(Scalar(10), internal::random(-6,6)); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random(-1, 1) * std::pow(Scalar(10), internal::random(-6, 6)); + data2[i] = internal::random(-1, 1) * std::pow(Scalar(10), internal::random(-6, 6)); } data1[0] = 1e-20; CHECK_CWISE1_IF(PacketTraits::HasTanh, std::tanh, internal::ptanh); - if(PacketTraits::HasExp && PacketSize>=2) - { + if (PacketTraits::HasExp && PacketSize >= 2) { data1[0] = std::numeric_limits::quiet_NaN(); data1[1] = std::numeric_limits::epsilon(); - test::packet_helper h; + test::packet_helper h; h.store(data2, internal::pexp(h.load(data1))); VERIFY((numext::isnan)(data2[0])); VERIFY_IS_EQUAL(std::exp(std::numeric_limits::epsilon()), data2[1]); @@ -498,24 +651,23 @@ template void packetmath_real() if (PacketTraits::HasTanh) { // NOTE this test migh fail with GCC prior to 6.3, see MathFunctionsImpl.h for details. data1[0] = std::numeric_limits::quiet_NaN(); - test::packet_helper::HasTanh,Packet> h; + test::packet_helper::HasTanh, Packet> h; h.store(data2, internal::ptanh(h.load(data1))); VERIFY((numext::isnan)(data2[0])); } if (PacketTraits::HasExp) { internal::scalar_logistic_op logistic; - for (int i=0; i(-20,20); + for (int i = 0; i < size; ++i) { + data1[i] = internal::random(-20, 20); } - test::packet_helper h; + test::packet_helper h; h.store(data2, logistic.packetOp(h.load(data1))); - for (int i=0; i void packetmath_real() CHECK_CWISE1_IF(PacketTraits::HasExpm1, std::expm1, internal::pexpm1); #endif - if(PacketSize>=2) - { + if (PacketSize >= 2) { data1[0] = std::numeric_limits::quiet_NaN(); data1[1] = std::numeric_limits::epsilon(); - if(PacketTraits::HasLog) - { - test::packet_helper h; + if (PacketTraits::HasLog) { + test::packet_helper h; h.store(data2, internal::plog(h.load(data1))); VERIFY((numext::isnan)(data2[0])); VERIFY_IS_EQUAL(std::log(std::numeric_limits::epsilon()), data2[1]); @@ -566,45 +716,41 @@ template void packetmath_real() h.store(data2, internal::plog(h.load(data1))); VERIFY((numext::isinf)(data2[0])); } - if(PacketTraits::HasLog1p) { - test::packet_helper h; + if (PacketTraits::HasLog1p) { + test::packet_helper h; data1[0] = Scalar(-2); data1[1] = -std::numeric_limits::infinity(); h.store(data2, internal::plog1p(h.load(data1))); VERIFY((numext::isnan)(data2[0])); VERIFY((numext::isnan)(data2[1])); } - if(PacketTraits::HasSqrt) - { - test::packet_helper h; + if (PacketTraits::HasSqrt) { + test::packet_helper h; data1[0] = Scalar(-1.0f); data1[1] = -std::numeric_limits::denorm_min(); h.store(data2, internal::psqrt(h.load(data1))); VERIFY((numext::isnan)(data2[0])); VERIFY((numext::isnan)(data2[1])); } - if(PacketTraits::HasCos) - { - test::packet_helper h; - for(Scalar k = 1; k::epsilon(); k*=2) - { - for(int k1=0;k1<=1; ++k1) - { - data1[0] = (2*k+k1 )*Scalar(EIGEN_PI)/2 * internal::random(0.8,1.2); - data1[1] = (2*k+2+k1)*Scalar(EIGEN_PI)/2 * internal::random(0.8,1.2); - h.store(data2, internal::pcos(h.load(data1))); - h.store(data2+PacketSize, internal::psin(h.load(data1))); - VERIFY(data2[0]<=Scalar(1.) && data2[0]>=Scalar(-1.)); - VERIFY(data2[1]<=Scalar(1.) && data2[1]>=Scalar(-1.)); - VERIFY(data2[PacketSize+0]<=Scalar(1.) && data2[PacketSize+0]>=Scalar(-1.)); - VERIFY(data2[PacketSize+1]<=Scalar(1.) && data2[PacketSize+1]>=Scalar(-1.)); + if (PacketTraits::HasCos) { + test::packet_helper h; + for (Scalar k = 1; k < Scalar(10000) / std::numeric_limits::epsilon(); k *= 2) { + for (int k1 = 0; k1 <= 1; ++k1) { + data1[0] = (2 * k + k1) * Scalar(EIGEN_PI) / 2 * internal::random(0.8, 1.2); + data1[1] = (2 * k + 2 + k1) * Scalar(EIGEN_PI) / 2 * internal::random(0.8, 1.2); + h.store(data2, internal::pcos(h.load(data1))); + h.store(data2 + PacketSize, internal::psin(h.load(data1))); + VERIFY(data2[0] <= Scalar(1.) && data2[0] >= Scalar(-1.)); + VERIFY(data2[1] <= Scalar(1.) && data2[1] >= Scalar(-1.)); + VERIFY(data2[PacketSize + 0] <= Scalar(1.) && data2[PacketSize + 0] >= Scalar(-1.)); + VERIFY(data2[PacketSize + 1] <= Scalar(1.) && data2[PacketSize + 1] >= Scalar(-1.)); - VERIFY_IS_APPROX(numext::abs2(data2[0])+numext::abs2(data2[PacketSize+0]), Scalar(1)); - VERIFY_IS_APPROX(numext::abs2(data2[1])+numext::abs2(data2[PacketSize+1]), Scalar(1)); + VERIFY_IS_APPROX(numext::abs2(data2[0]) + numext::abs2(data2[PacketSize + 0]), Scalar(1)); + VERIFY_IS_APPROX(numext::abs2(data2[1]) + numext::abs2(data2[PacketSize + 1]), Scalar(1)); } } - data1[0] = std::numeric_limits::infinity(); + data1[0] = std::numeric_limits::infinity(); data1[1] = -std::numeric_limits::infinity(); h.store(data2, internal::psin(h.load(data1))); VERIFY((numext::isnan)(data2[0])); @@ -614,7 +760,7 @@ template void packetmath_real() VERIFY((numext::isnan)(data2[0])); VERIFY((numext::isnan)(data2[1])); - data1[0] = std::numeric_limits::quiet_NaN(); + data1[0] = std::numeric_limits::quiet_NaN(); h.store(data2, internal::psin(h.load(data1))); VERIFY((numext::isnan)(data2[0])); h.store(data2, internal::pcos(h.load(data1))); @@ -622,27 +768,26 @@ template void packetmath_real() data1[0] = -Scalar(0.); h.store(data2, internal::psin(h.load(data1))); - VERIFY( internal::biteq(data2[0], data1[0]) ); + VERIFY(internal::biteq(data2[0], data1[0])); h.store(data2, internal::pcos(h.load(data1))); VERIFY_IS_EQUAL(data2[0], Scalar(1)); } } } -template void packetmath_notcomplex() -{ +template +void packetmath_notcomplex() { typedef internal::packet_traits PacketTraits; const int PacketSize = internal::unpacket_traits::size; - EIGEN_ALIGN_MAX Scalar data1[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar data2[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar ref[PacketSize*4]; + EIGEN_ALIGN_MAX Scalar data1[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar data2[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar ref[PacketSize * 4]; - Array::Map(data1, PacketSize*4).setRandom(); + Array::Map(data1, PacketSize * 4).setRandom(); ref[0] = data1[0]; - for (int i=0; i(data1))) && "internal::predux_min"); VERIFY((!PacketTraits::Vectorizable) || PacketTraits::HasMin); @@ -654,12 +799,10 @@ template void packetmath_notcomplex() CHECK_CWISE2_IF(PacketTraits::HasAbsDiff, REF_ABS_DIFF, internal::pabsdiff); ref[0] = data1[0]; - for (int i=0; i(data1))) && "internal::predux_max"); - for (int i=0; i(data1[0])); VERIFY(test::areApprox(ref, data2, PacketSize) && "internal::plset"); @@ -676,167 +819,158 @@ template void packetmath_notcomplex() // } // predux_any - for (unsigned int i=0; i(data1))) && "internal::predux_any(0000)"); - for(int k=0; k(data1)) && "internal::predux_any(0101)"); - for (unsigned int i=0; i(data1))) && "internal::predux_any(0000)"); + for (int k = 0; k < PacketSize; ++k) { + for (unsigned int i = 0; i < sizeof(Scalar); ++i) data1_bits[k * sizeof(Scalar) + i] = 0xff; + VERIFY(internal::predux_any(internal::pload(data1)) && "internal::predux_any(0101)"); + for (unsigned int i = 0; i < sizeof(Scalar); ++i) data1_bits[k * sizeof(Scalar) + i] = 0x00; } } } -template void test_conj_helper(Scalar* data1, Scalar* data2, Scalar* ref, Scalar* pval) -{ +template +void test_conj_helper(Scalar* data1, Scalar* data2, Scalar* ref, Scalar* pval) { const int PacketSize = internal::unpacket_traits::size; internal::conj_if cj0; internal::conj_if cj1; - internal::conj_helper cj; - internal::conj_helper pcj; + internal::conj_helper cj; + internal::conj_helper pcj; - for(int i=0;i(data1),internal::pload(data2))); + internal::pstore(pval, pcj.pmul(internal::pload(data1), internal::pload(data2))); VERIFY(test::areApprox(ref, pval, PacketSize) && "conj_helper pmul"); - for(int i=0;i(data1),internal::pload(data2),internal::pload(pval))); + internal::pstore( + pval, pcj.pmadd(internal::pload(data1), internal::pload(data2), internal::pload(pval))); VERIFY(test::areApprox(ref, pval, PacketSize) && "conj_helper pmadd"); } -template void packetmath_complex() -{ +template +void packetmath_complex() { const int PacketSize = internal::unpacket_traits::size; - const int size = PacketSize*4; - EIGEN_ALIGN_MAX Scalar data1[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar data2[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar ref[PacketSize*4]; - EIGEN_ALIGN_MAX Scalar pval[PacketSize*4]; + const int size = PacketSize * 4; + EIGEN_ALIGN_MAX Scalar data1[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar data2[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar ref[PacketSize * 4]; + EIGEN_ALIGN_MAX Scalar pval[PacketSize * 4]; - for (int i=0; i() * Scalar(1e2); data2[i] = internal::random() * Scalar(1e2); } - test_conj_helper (data1,data2,ref,pval); - test_conj_helper (data1,data2,ref,pval); - test_conj_helper (data1,data2,ref,pval); - test_conj_helper (data1,data2,ref,pval); + test_conj_helper(data1, data2, ref, pval); + test_conj_helper(data1, data2, ref, pval); + test_conj_helper(data1, data2, ref, pval); + test_conj_helper(data1, data2, ref, pval); { - for(int i=0;i(data1))); + for (int i = 0; i < PacketSize; ++i) ref[i] = Scalar(std::imag(data1[i]), std::real(data1[i])); + internal::pstore(pval, internal::pcplxflip(internal::pload(data1))); VERIFY(test::areApprox(ref, pval, PacketSize) && "pcplxflip"); } } -template void packetmath_scatter_gather() -{ +template +void packetmath_scatter_gather() { typedef typename NumTraits::Real RealScalar; const int PacketSize = internal::unpacket_traits::size; EIGEN_ALIGN_MAX Scalar data1[PacketSize]; RealScalar refvalue = 0; - for (int i=0; i()/RealScalar(PacketSize); + for (int i = 0; i < PacketSize; ++i) { + data1[i] = internal::random() / RealScalar(PacketSize); } - int stride = internal::random(1,20); + int stride = internal::random(1, 20); - EIGEN_ALIGN_MAX Scalar buffer[PacketSize*20]; - memset(buffer, 0, 20*PacketSize*sizeof(Scalar)); + EIGEN_ALIGN_MAX Scalar buffer[PacketSize * 20]; + memset(buffer, 0, 20 * PacketSize * sizeof(Scalar)); Packet packet = internal::pload(data1); internal::pscatter(buffer, packet, stride); - for (int i = 0; i < PacketSize*20; ++i) { - if ((i%stride) == 0 && i()/RealScalar(PacketSize); + for (int i = 0; i < PacketSize * 7; ++i) { + buffer[i] = internal::random() / RealScalar(PacketSize); } packet = internal::pgather(buffer, 7); internal::pstore(data1, packet); for (int i = 0; i < PacketSize; ++i) { - VERIFY(test::isApproxAbs(data1[i], buffer[i*7], refvalue) && "pgather"); + VERIFY(test::isApproxAbs(data1[i], buffer[i * 7], refvalue) && "pgather"); } } namespace Eigen { namespace test { -template -struct runall { // i.e. float or double +template +struct runall { // i.e. float or double static void run() { - packetmath(); - packetmath_scatter_gather(); - packetmath_notcomplex(); - packetmath_real(); + packetmath(); + packetmath_scatter_gather(); + packetmath_notcomplex(); + packetmath_real(); } }; -template -struct runall { // i.e. int +template +struct runall { // i.e. int static void run() { - packetmath(); - packetmath_scatter_gather(); - packetmath_notcomplex(); + packetmath(); + packetmath_scatter_gather(); + packetmath_notcomplex(); } }; -template -struct runall { // i.e. complex +template +struct runall { // i.e. complex static void run() { - packetmath(); - packetmath_scatter_gather(); - packetmath_complex(); + packetmath(); + packetmath_scatter_gather(); + packetmath_complex(); } }; -} -} +} // namespace test +} // namespace Eigen - -EIGEN_DECLARE_TEST(packetmath) -{ +EIGEN_DECLARE_TEST(packetmath) { g_first_pass = true; - for(int i = 0; i < g_repeat; i++) { - - CALL_SUBTEST_1( test::runner::run() ); - CALL_SUBTEST_2( test::runner::run() ); - CALL_SUBTEST_3( test::runner::run() ); - CALL_SUBTEST_4( test::runner::run() ); - CALL_SUBTEST_5( test::runner::run() ); - CALL_SUBTEST_6( test::runner::run() ); - CALL_SUBTEST_7( test::runner::run() ); - CALL_SUBTEST_8( test::runner::run() ); - CALL_SUBTEST_9( test::runner::run() ); - CALL_SUBTEST_10( test::runner::run() ); - CALL_SUBTEST_11( test::runner >::run() ); - CALL_SUBTEST_12( test::runner >::run() ); - CALL_SUBTEST_13(( packetmath::type>() )); + for (int i = 0; i < g_repeat; i++) { + CALL_SUBTEST_1(test::runner::run()); + CALL_SUBTEST_2(test::runner::run()); + CALL_SUBTEST_3(test::runner::run()); + CALL_SUBTEST_4(test::runner::run()); + CALL_SUBTEST_5(test::runner::run()); + CALL_SUBTEST_6(test::runner::run()); + CALL_SUBTEST_7(test::runner::run()); + CALL_SUBTEST_8(test::runner::run()); + CALL_SUBTEST_9(test::runner::run()); + CALL_SUBTEST_10(test::runner::run()); + CALL_SUBTEST_11(test::runner >::run()); + CALL_SUBTEST_12(test::runner >::run()); + CALL_SUBTEST_13((packetmath::type>())); #ifdef EIGEN_PACKET_MATH_SSE_H - CALL_SUBTEST_14(( packetmath::type>() )); + CALL_SUBTEST_14((packetmath::type>())); #endif - CALL_SUBTEST_15(( packetmath::type>() )); + CALL_SUBTEST_15((packetmath::type>())); g_first_pass = false; } }