From e265f7ed8e59c26e15f2c35162c6b8da1c5d594f Mon Sep 17 00:00:00 2001 From: David Tellenbach Date: Wed, 28 Oct 2020 20:15:09 +0000 Subject: Add support for Armv8.2-a __fp16 Armv8.2-a provides a native half-precision floating point (__fp16 aka. float16_t). This patch introduces * __fp16 as underlying type of Eigen::half if this type is available * the packet types Packet4hf and Packet8hf representing float16x4_t and float16x8_t respectively * packet-math for the above packets with corresponding scalar type Eigen::half The packet-math functionality has been implemented by Ashutosh Sharma . This closes #1940. --- Eigen/src/Core/NumTraits.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Eigen/src/Core/NumTraits.h') diff --git a/Eigen/src/Core/NumTraits.h b/Eigen/src/Core/NumTraits.h index fbeead83e..16bd74b1d 100644 --- a/Eigen/src/Core/NumTraits.h +++ b/Eigen/src/Core/NumTraits.h @@ -77,6 +77,30 @@ struct default_digits_impl // Integer } // end namespace internal +namespace numext { +/** \internal bit-wise cast without changing the underlying bit representation. */ + +// TODO: Replace by std::bit_cast (available in C++20) +template +EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src& src) { +#if EIGEN_HAS_TYPE_TRAITS + // The behaviour of memcpy is not specified for non-trivially copyable types + EIGEN_STATIC_ASSERT(std::is_trivially_copyable::value, THIS_TYPE_IS_NOT_SUPPORTED); + EIGEN_STATIC_ASSERT(std::is_trivially_copyable::value && std::is_default_constructible::value, + THIS_TYPE_IS_NOT_SUPPORTED); +#endif + + EIGEN_STATIC_ASSERT(sizeof(Src) == sizeof(Tgt), THIS_TYPE_IS_NOT_SUPPORTED); + Tgt tgt; + EIGEN_USING_STD(memcpy) + memcpy(&tgt, &src, sizeof(Tgt)); + return tgt; +} + +/** \internal extract the bits of the float \a x */ +EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC numext::uint32_t as_uint(float x) { return bit_cast(x); } +} // namespace numext + /** \class NumTraits * \ingroup Core_Module * -- cgit v1.2.3