From 003a97e0bf509c7eb8b1ae6bdc3f26976d514ab2 Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Tue, 18 Feb 2020 06:42:35 -0700 Subject: Cycles: Fix failing avxf cross test on AVX2 cycles_util_avxf_avx2_test failed on the cross test, since it wasn't immediately clear why, the test was disabled. After looking into it, this test when build for AVX2 is generating FMA instructions where the intermediate results have "infinite" precision [1] leading to slightly different results. This diff re-enables the cross test and allows for a small error in the results. [1] https://www.felixcloutier.com/x86/vfmadd132ps:vfmadd213ps:vfmadd231ps Differential Revision: https://developer.blender.org/D6873 Reviewers: brecht --- intern/cycles/test/util_avxf_test.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/intern/cycles/test/util_avxf_test.h b/intern/cycles/test/util_avxf_test.h index 1dd677e35e6..353c8fa9b28 100644 --- a/intern/cycles/test/util_avxf_test.h +++ b/intern/cycles/test/util_avxf_test.h @@ -44,6 +44,10 @@ bool validate_cpu_capabilities() for (size_t index = 0; index < a.size; index++) \ EXPECT_FLOAT_EQ(a[index], b[index]); +#define compare_vector_vector_near(a, b, abserror) \ + for (size_t index = 0; index < a.size; index++) \ + EXPECT_NEAR(a[index], b[index], abserror); + #define basic_test_vv(a, b, op) \ VALIDATECPU \ avxf c = a op b; \ @@ -190,23 +194,21 @@ TEST(util_avx, avxf_shuffle) compare_vector_vector(res, avxf(0.4f, 0.2f, 0.1f, 0.3f, 0.5f, 0.6f, 0.7f, 0.8f)); } -/* XXX Test Fails on AVX2, needs further investigation before it can be enabled */ -#if 0 TEST(util_avx, avxf_cross) { - VALIDATECPU - avxf res = cross(avxf_b, avxf_c); - compare_vector_vector(res, - avxf(0.0f, - -9.5367432e-07f, - 0.0f, - 4.7683716e-07f, - 0.0f, - -3.8146973e-06f, - 3.8146973e-06f, - 3.8146973e-06f)); + VALIDATECPU + avxf res = cross(avxf_b, avxf_c); + compare_vector_vector_near(res, + avxf(0.0f, + -9.5367432e-07f, + 0.0f, + 4.7683716e-07f, + 0.0f, + -3.8146973e-06f, + 3.8146973e-06f, + 3.8146973e-06f), + 0.000002000f); } -#endif TEST(util_avx, avxf_dot3) { -- cgit v1.2.3