mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix arm32 float division and related bugs
(cherry picked from commit 81b48065ea)
This commit is contained in:
committed by
C. Antonio Sanchez
parent
526a6328e2
commit
72f77ccb3e
@@ -631,6 +631,85 @@ Scalar log2(Scalar x) {
|
||||
return Scalar(EIGEN_LOG2E) * std::log(x);
|
||||
}
|
||||
|
||||
// Create a functor out of a function so it can be passed (with overloads)
|
||||
// to another function as an input argument.
|
||||
#define CREATE_FUNCTOR(Name, Func) \
|
||||
struct Name { \
|
||||
template<typename T> \
|
||||
T operator()(const T& val) const { \
|
||||
return Func(val); \
|
||||
} \
|
||||
}
|
||||
|
||||
CREATE_FUNCTOR(psqrt_functor, internal::psqrt);
|
||||
CREATE_FUNCTOR(prsqrt_functor, internal::prsqrt);
|
||||
|
||||
// TODO(rmlarsen): Run this test for more functions.
|
||||
template <bool Cond, typename Scalar, typename Packet, typename RefFunctorT, typename FunctorT>
|
||||
void packetmath_test_IEEE_corner_cases(const RefFunctorT& ref_fun,
|
||||
const FunctorT& fun) {
|
||||
const int PacketSize = internal::unpacket_traits<Packet>::size;
|
||||
const Scalar norm_min = (std::numeric_limits<Scalar>::min)();
|
||||
const Scalar norm_max = (std::numeric_limits<Scalar>::max)();
|
||||
|
||||
constexpr int size = PacketSize * 2;
|
||||
EIGEN_ALIGN_MAX Scalar data1[size];
|
||||
EIGEN_ALIGN_MAX Scalar data2[size];
|
||||
EIGEN_ALIGN_MAX Scalar ref[size];
|
||||
for (int i = 0; i < size; ++i) {
|
||||
data1[i] = data2[i] = ref[i] = Scalar(0);
|
||||
}
|
||||
|
||||
// Test for subnormals.
|
||||
if (Cond && std::numeric_limits<Scalar>::has_denorm == std::denorm_present && !EIGEN_ARCH_ARM) {
|
||||
|
||||
for (int scale = 1; scale < 5; ++scale) {
|
||||
// When EIGEN_FAST_MATH is 1 we relax the conditions slightly, and allow the function
|
||||
// to return the same value for subnormals as the reference would return for zero with
|
||||
// the same sign as the input.
|
||||
#if EIGEN_FAST_MATH
|
||||
data1[0] = Scalar(scale) * std::numeric_limits<Scalar>::denorm_min();
|
||||
data1[1] = -data1[0];
|
||||
test::packet_helper<Cond, Packet> h;
|
||||
h.store(data2, fun(h.load(data1)));
|
||||
for (int i=0; i < PacketSize; ++i) {
|
||||
const Scalar ref_zero = ref_fun(data1[i] < 0 ? -Scalar(0) : Scalar(0));
|
||||
const Scalar ref_val = ref_fun(data1[i]);
|
||||
VERIFY(((std::isnan)(data2[i]) && (std::isnan)(ref_val)) || data2[i] == ref_zero ||
|
||||
verifyIsApprox(data2[i], ref_val));
|
||||
}
|
||||
#else
|
||||
CHECK_CWISE1_IF(Cond, ref_fun, fun);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Test for smallest normalized floats.
|
||||
data1[0] = norm_min;
|
||||
data1[1] = -data1[0];
|
||||
CHECK_CWISE1_IF(Cond, ref_fun, fun);
|
||||
|
||||
// Test for largest floats.
|
||||
data1[0] = norm_max;
|
||||
data1[1] = -data1[0];
|
||||
CHECK_CWISE1_IF(Cond, ref_fun, fun);
|
||||
|
||||
// Test for zeros.
|
||||
data1[0] = Scalar(0.0);
|
||||
data1[1] = -data1[0];
|
||||
CHECK_CWISE1_IF(Cond, ref_fun, fun);
|
||||
|
||||
// Test for infinities.
|
||||
data1[0] = NumTraits<Scalar>::infinity();
|
||||
data1[1] = -data1[0];
|
||||
CHECK_CWISE1_IF(Cond, ref_fun, fun);
|
||||
|
||||
// Test for quiet NaNs.
|
||||
data1[0] = std::numeric_limits<Scalar>::quiet_NaN();
|
||||
data1[1] = -std::numeric_limits<Scalar>::quiet_NaN();
|
||||
CHECK_CWISE1_IF(Cond, ref_fun, fun);
|
||||
}
|
||||
|
||||
template <typename Scalar, typename Packet>
|
||||
void packetmath_real() {
|
||||
typedef internal::packet_traits<Scalar> PacketTraits;
|
||||
@@ -735,13 +814,15 @@ void packetmath_real() {
|
||||
CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp);
|
||||
if (PacketTraits::HasExp) {
|
||||
// Check denormals:
|
||||
#if !EIGEN_ARCH_ARM
|
||||
for (int j=0; j<3; ++j) {
|
||||
data1[0] = Scalar(std::ldexp(1, NumTraits<Scalar>::min_exponent()-j));
|
||||
CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp);
|
||||
data1[0] = -data1[0];
|
||||
CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// zero
|
||||
data1[0] = Scalar(0);
|
||||
CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp);
|
||||
|
||||
Reference in New Issue
Block a user