mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix rint for SSE/NEON.
It seems *sometimes* with aggressive optimizations the combination `psub(padd(a, b), b)` trick to force rounding is compiled away. Here we replace with inline assembly to prevent this (I tried `volatile`, but that leads to additional loads from memory). Also fixed an edge case for large inputs `a` where adding `b` bumps the value up a power of two and ends up rounding away more than just the fractional part. If we are over `2^digits` then just return the input. This edge case was missed in the test since the test was comparing approximate equality, which was still satisfied. Adding a strict equality option catches it.
This commit is contained in:
@@ -108,6 +108,23 @@ template<typename Scalar> bool areApprox(const Scalar* a, const Scalar* b, int s
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename Scalar> bool areEqual(const Scalar* a, const Scalar* b, int size)
|
||||
{
|
||||
for (int i=0; i<size; ++i)
|
||||
{
|
||||
if (a[i] != b[i])
|
||||
{
|
||||
if((numext::isnan)(a[i]) && (numext::isnan)(b[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::cout << "ref: [" << Map<const Matrix<Scalar,1,Dynamic> >(a,size) << "]" << " != vec: [" << Map<const Matrix<Scalar,1,Dynamic> >(b,size) << "]\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#define CHECK_CWISE1(REFOP, POP) { \
|
||||
for (int i=0; i<PacketSize; ++i) \
|
||||
ref[i] = REFOP(data1[i]); \
|
||||
@@ -178,6 +195,14 @@ struct packet_helper<false,Packet>
|
||||
VERIFY(test::areApprox(ref, data2, PacketSize) && #POP); \
|
||||
}
|
||||
|
||||
#define CHECK_CWISE1_EXACT_IF(COND, REFOP, POP) if(COND) { \
|
||||
test::packet_helper<COND,Packet> h; \
|
||||
for (int i=0; i<PacketSize; ++i) \
|
||||
ref[i] = Scalar(REFOP(data1[i])); \
|
||||
h.store(data2, POP(h.load(data1))); \
|
||||
VERIFY(test::areEqual(ref, data2, PacketSize) && #POP); \
|
||||
}
|
||||
|
||||
#define CHECK_CWISE2_IF(COND, REFOP, POP) if(COND) { \
|
||||
test::packet_helper<COND,Packet> h; \
|
||||
for (int i=0; i<PacketSize; ++i) \
|
||||
|
||||
Reference in New Issue
Block a user