// SPDX-FileCopyrightText: The Eigen Authors // SPDX-License-Identifier: MPL-2.0 #include "main.h" template EIGEN_DONT_INLINE void store_ptrue(Scalar* output) { const Packet zero = Eigen::internal::pset1(Scalar(0)); Eigen::internal::pstoreu(output, Eigen::internal::ptrue(zero)); } template EIGEN_DONT_INLINE void store_extended_scalar_constants(Scalar* output) { output[0] = Eigen::internal::psignmask(); output[1] = Eigen::internal::pinf(); output[2] = Eigen::internal::pnan(); } template EIGEN_DONT_INLINE Eigen::numext::uint32_t extended_to_float_bits(const volatile Scalar* input) { const float narrowed = static_cast(*input); return Eigen::numext::bit_cast(narrowed); } template ::Vectorizable> struct packetmath_fastmath_runner { static void run() {} }; template struct packetmath_fastmath_runner { static void run() { typedef typename Eigen::internal::packet_traits::type Packet; const int packet_size = Eigen::internal::unpacket_traits::size; Scalar output[packet_size]; for (int i = 0; i < packet_size; ++i) { output[i] = Scalar(0); } store_ptrue(output); for (int i = 0; i < packet_size; ++i) { const unsigned char* lane_bytes = reinterpret_cast(output + i); bool has_nonzero_byte = false; for (std::size_t j = 0; j < sizeof(Scalar); ++j) { has_nonzero_byte = has_nonzero_byte || lane_bytes[j] != 0; } VERIFY(has_nonzero_byte); } } }; template ::unsigned_type>::value> struct extended_scalar_constant_runner { static void run() {} }; template struct extended_scalar_constant_runner { static void run() { Scalar actual[3]; store_extended_scalar_constants(actual); // Floating-point classification is optimized away under -ffinite-math-only. Narrow through a volatile pointer and // inspect the resulting integer bits instead; this also avoids indeterminate padding in x87 long double objects. typedef Eigen::numext::uint32_t Bits; const Bits sign_bits = extended_to_float_bits(actual + 0); const Bits inf_bits = extended_to_float_bits(actual + 1); const Bits nan_bits = extended_to_float_bits(actual + 2); VERIFY_IS_EQUAL(sign_bits, Bits(0x80000000u)); VERIFY_IS_EQUAL(inf_bits, Bits(0x7f800000u)); VERIFY_IS_EQUAL(nan_bits & Bits(0x7fc00000u), Bits(0x7fc00000u)); } }; EIGEN_DECLARE_TEST(packetmath_fastmath) { CALL_SUBTEST(packetmath_fastmath_runner::run()); CALL_SUBTEST(packetmath_fastmath_runner::run()); CALL_SUBTEST(packetmath_fastmath_runner::run()); CALL_SUBTEST(packetmath_fastmath_runner::run()); CALL_SUBTEST(extended_scalar_constant_runner::run()); }