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.
This commit is contained in:
Robin Gareus 2022-01-03 02:34:53 +01:00
parent b90bfa2597
commit 47d34bfbfb
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 11 additions and 11 deletions

View File

@ -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

View File

@ -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;