From e9e058ba6febd9a6c586aaaf0fa085f743732f94 Mon Sep 17 00:00:00 2001 From: Ilya Tagunov Date: Wed, 20 Nov 2024 09:53:56 +0000 Subject: [PATCH] tests: math: interpolation: disable floating point contraction This test cannot tolerate any loss of precision, including the one caused by the compiler contracting floating points operations together, like in fused multiply-add (FMA). Some toolchains enable FP contraction by default, so disable it for the specific test and let the user decide themselves whether precision or performance is needed for their specific application. Co-authored-by: Jordan Yates Co-authored-by: Ilya Tagunov Signed-off-by: Ilya Tagunov --- tests/lib/math/interpolation/src/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/lib/math/interpolation/src/main.c b/tests/lib/math/interpolation/src/main.c index 95753a1decf575..807947919beb56 100644 --- a/tests/lib/math/interpolation/src/main.c +++ b/tests/lib/math/interpolation/src/main.c @@ -6,6 +6,18 @@ #include #include + +#ifdef __clang__ +/* + * Floating-point contraction merges an operation of the form (a*b + c) from + * two operations (fmul, fadd) into a single operation (fmadd). This can change + * the value of the resulting LSB, causing problems when the expected value is + * some multiple of 0.5f and the rounding functions are used. Disable + * contraction for the tests to ensure this doesn't occur. + */ +#pragma STDC FP_CONTRACT OFF +#endif + #include ZTEST(interpolation, test_interpolation_oob)