Additional comments and fix typo in unit test.

This commit is contained in:
Nick Thompson 2021-04-08 09:18:51 -04:00
parent 6f9515aa94
commit 91bec19e97
3 changed files with 12 additions and 3 deletions

@ -2704,6 +2704,7 @@ inline VTKM_EXEC_CONT T DifferenceOfProducts(T a, T b, T c, T d)
// This is a bit awkward. clang-11 does not define FP_FAST_FMA, but still compiles this to the correct assembly.
// Windows, however, generates truly horrendous assembly from this, with no fmas, to the extent I assume it could
// contort itself into a performance bug.
// That said, MSVC converts even a*b - c*d into horrible assembly, so it may be a wash.
// You'd want to just use #ifdef FP_FAST_FMA, but then you'd lose the (correct) generated assembly on clang.
// See: https://stackoverflow.com/a/40765925/904050
T cd = c * d;

@ -1306,6 +1306,7 @@ inline VTKM_EXEC_CONT T DifferenceOfProducts(T a, T b, T c, T d)
// This is a bit awkward. clang-11 does not define FP_FAST_FMA, but still compiles this to the correct assembly.
// Windows, however, generates truly horrendous assembly from this, with no fmas, to the extent I assume it could
// contort itself into a performance bug.
// That said, MSVC converts even a*b - c*d into horrible assembly, so it may be a wash.
// You'd want to just use #ifdef FP_FAST_FMA, but then you'd lose the (correct) generated assembly on clang.
// See: https://stackoverflow.com/a/40765925/904050
T cd = c * d;

@ -931,7 +931,7 @@ VTKM_EXEC
void TestQuadraticRoots() const
{
{
// (x-1)(x+1) = x^2 - 1:
// (x-1)(x+1) = x² - 1:
auto roots = vtkm::QuadraticRoots(1.0f, 0.0f, -1.0f);
vtkm::UInt64 dist = vtkm::FloatDistance(-1.0f, roots.first);
@ -940,11 +940,18 @@ void TestQuadraticRoots() const
dist = vtkm::FloatDistance(1.0f, roots.second);
VTKM_MATH_ASSERT(dist < 3, "Float distance for quadratic roots exceeds 3 ulps.");
// No real roots:
roots = vtkm::QuadraticRoots(1.0f, 0.0f, 1.0f);
VTKM_MATH_ASSERT(vtkm::IsNan(roots.first),
"Roots should be Nan for a quadratic with complex roots.");
VTKM_MATH_ASSERT(vtkm::IsNan(roots.second),
"Roots should be Nan for a quadratic with complex roots.");
#ifdef FP_FAST_FMA
// Wikipedia example:
// x^2 + 200x - 0.000015 = 0 has roots
// x² + 200x - 0.000015 = 0 has roots
// -200.000000075, 7.5e-8
roots = vtkm::QuadraticRoots(1.0f, 0.0f, -1.0f);
roots = vtkm::QuadraticRoots(1.0f, 200.0f, -0.000015f);
dist = vtkm::FloatDistance(-200.000000075f, roots.first);
VTKM_MATH_ASSERT(dist < 3, "Float distance for quadratic roots exceeds 3 ulps.");