From 47d34bfbfb4a796aabdd73742a5543fa4008b19c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 3 Jan 2022 02:34:53 +0100 Subject: [PATCH] Tweak FPU test for FMA FMA may return *more precise* results since there is no intermediate rounding when computing (a + b * c). (b * c) is evaluate with infinite precision and only the final result after adding a is rounded to float32. This allows for a FLT_EPSILON difference compared to rounding (b * c) first. --- libs/ardour/test/fpu_test.cc | 18 +++++++++--------- libs/ardour/test/fpu_test.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libs/ardour/test/fpu_test.cc b/libs/ardour/test/fpu_test.cc index b0b89621ee..dd4b865e76 100644 --- a/libs/ardour/test/fpu_test.cc +++ b/libs/ardour/test/fpu_test.cc @@ -37,7 +37,7 @@ FPUTest::tearDown () } void -FPUTest::run (size_t align_max) +FPUTest::run (size_t align_max, float const max_diff) { apply_gain_to_buffer (_test1, _size, 1.33); default_apply_gain_to_buffer (_comp1, _size, 1.33); @@ -58,16 +58,16 @@ FPUTest::run (size_t align_max) CPPUNIT_ASSERT_MESSAGE (string_compose ("Compute peak not aligned off: %1 cnt: %2", off, cnt), fabsf (pk_test - pk_comp) < 1e-6); - /* mix buffers w/gain */ - mix_buffers_with_gain (&_test1[off], &_test2[off], cnt, 0.45); - default_mix_buffers_with_gain (&_comp1[off], &_comp2[off], cnt, 0.45); - compare (string_compose ("Mix Buffers w/gain not aligned off: %1 cnt: %2", off, cnt), cnt); - /* mix buffers w/o gain */ mix_buffers_no_gain (&_test1[off], &_test2[off], cnt); default_mix_buffers_no_gain (&_comp1[off], &_comp2[off], cnt); compare (string_compose ("Mix Buffers no gain not aligned off: %1 cnt: %2", off, cnt), cnt); + /* mix buffers w/gain */ + mix_buffers_with_gain (&_test1[off], &_test2[off], cnt, 0.45); + default_mix_buffers_with_gain (&_comp1[off], &_comp2[off], cnt, 0.45); + compare (string_compose ("Mix Buffers w/gain not aligned off: %1 cnt: %2", off, cnt), cnt, max_diff); + /* copy vector */ copy_vector (&_test1[off], &_test2[off], cnt); default_copy_vector (&_comp1[off], &_comp2[off], cnt); @@ -86,11 +86,11 @@ FPUTest::run (size_t align_max) } void -FPUTest::compare (std::string msg, size_t cnt) +FPUTest::compare (std::string msg, size_t cnt, float max_diff) { size_t err = 0; for (size_t i = 0; i < cnt; ++i) { - if (_test1[i] != _comp1[i]) { + if (fabsf (_test1[i] - _comp1[i]) > max_diff) { ++err; } } @@ -123,7 +123,7 @@ FPUTest::avxFmaTest () mix_buffers_no_gain = x86_sse_avx_mix_buffers_no_gain; copy_vector = x86_sse_avx_copy_vector; - run (align_max); + run (align_max, FLT_EPSILON); } void diff --git a/libs/ardour/test/fpu_test.h b/libs/ardour/test/fpu_test.h index d66673322e..552a69126e 100644 --- a/libs/ardour/test/fpu_test.h +++ b/libs/ardour/test/fpu_test.h @@ -36,8 +36,8 @@ public: #endif private: - void run (size_t); - void compare (std::string, size_t); + void run (size_t, float const max_diff = 0); + void compare (std::string, size_t, float const max_diff = 0); ARDOUR::compute_peak_t compute_peak; ARDOUR::find_peaks_t find_peaks;