diff options
author | Brecht Van Lommel <brecht> | 2022-11-01 17:16:55 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-11-08 14:28:40 +0300 |
commit | e1b3d9112730bc3b569ffff732a1558752ded146 (patch) | |
tree | 27caad945dcc9ce7313b4c84cd0efbab6f70503c /intern/cycles/test/util_float8_test.h | |
parent | 32ec0521c542bb78a0080f8091856ec085030f09 (diff) |
Refactor: replace Cycles sse/avx types by vectorized float4/int4/float8/int8
The distinction existed for legacy reasons, to easily port of Embree
intersection code without affecting the main vector types. However we are now
using SIMD for these types as well, so no good reason to keep the distinction.
Also more consistently pass these vector types by value in inline functions.
Previously it was partially changed for functions used by Metal to avoid having
to add address space qualifiers, simple to do it everywhere.
Also removes function declarations for vector math headers, serves no real
purpose.
Differential Revision: https://developer.blender.org/D16146
Diffstat (limited to 'intern/cycles/test/util_float8_test.h')
-rw-r--r-- | intern/cycles/test/util_float8_test.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/intern/cycles/test/util_float8_test.h b/intern/cycles/test/util_float8_test.h new file mode 100644 index 00000000000..54701afaf8b --- /dev/null +++ b/intern/cycles/test/util_float8_test.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#include "testing/testing.h" +#include "util/math.h" +#include "util/system.h" +#include "util/types.h" + +CCL_NAMESPACE_BEGIN + +static bool validate_cpu_capabilities() +{ + +#if defined(__KERNEL_AVX2__) + return system_cpu_support_avx2(); +#elif defined(__KERNEL_AVX__) + return system_cpu_support_avx(); +#elif defined(__KERNEL_SSE2__) + return system_cpu_support_sse2(); +#else + return false; +#endif +} + +#define INIT_FLOAT8_TEST \ + if (!validate_cpu_capabilities()) \ + return; \ +\ + const vfloat8 float8_a = make_vfloat8(0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f); \ + const vfloat8 float8_b = make_vfloat8(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f); \ + const vfloat8 float8_c = make_vfloat8(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f); + +#define compare_vector_scalar(a, b) \ + for (size_t index = 0; index < 8; index++) \ + EXPECT_FLOAT_EQ(a[index], b); + +#define compare_vector_vector(a, b) \ + for (size_t index = 0; index < 8; index++) \ + EXPECT_FLOAT_EQ(a[index], b[index]); + +#define compare_vector_vector_near(a, b, abserror) \ + for (size_t index = 0; index < 8; index++) \ + EXPECT_NEAR(a[index], b[index], abserror); + +#define basic_test_vv(a, b, op) \ + INIT_FLOAT8_TEST \ + vfloat8 c = a op b; \ + for (size_t i = 0; i < 8; i++) \ + EXPECT_FLOAT_EQ(c[i], a[i] op b[i]); + +/* vector op float tests */ +#define basic_test_vf(a, b, op) \ + INIT_FLOAT8_TEST \ + vfloat8 c = a op b; \ + for (size_t i = 0; i < 8; i++) \ + EXPECT_FLOAT_EQ(c[i], a[i] op b); + +static const float float_b = 1.5f; + +TEST(TEST_CATEGORY_NAME, + float8_add_vv){basic_test_vv(float8_a, float8_b, +)} TEST(TEST_CATEGORY_NAME, float8_sub_vv){ + basic_test_vv(float8_a, float8_b, -)} TEST(TEST_CATEGORY_NAME, float8_mul_vv){ + basic_test_vv(float8_a, float8_b, *)} TEST(TEST_CATEGORY_NAME, float8_div_vv){ + basic_test_vv(float8_a, float8_b, /)} TEST(TEST_CATEGORY_NAME, float8_add_vf){ + basic_test_vf(float8_a, float_b, +)} TEST(TEST_CATEGORY_NAME, float8_sub_vf){ + basic_test_vf(float8_a, float_b, -)} TEST(TEST_CATEGORY_NAME, float8_mul_vf){ + basic_test_vf(float8_a, float_b, *)} TEST(TEST_CATEGORY_NAME, + float8_div_vf){basic_test_vf(float8_a, float_b, /)} + +TEST(TEST_CATEGORY_NAME, float8_ctor) +{ + INIT_FLOAT8_TEST + compare_vector_scalar(make_vfloat8(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f), + static_cast<float>(index)); + compare_vector_scalar(make_vfloat8(1.0f), 1.0f); +} + +TEST(TEST_CATEGORY_NAME, float8_sqrt) +{ + INIT_FLOAT8_TEST + compare_vector_vector(sqrt(make_vfloat8(1.0f, 4.0f, 9.0f, 16.0f, 25.0f, 36.0f, 49.0f, 64.0f)), + make_vfloat8(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f)); +} + +TEST(TEST_CATEGORY_NAME, float8_min_max) +{ + INIT_FLOAT8_TEST + compare_vector_vector(min(float8_a, float8_b), float8_a); + compare_vector_vector(max(float8_a, float8_b), float8_b); +} + +TEST(TEST_CATEGORY_NAME, float8_shuffle) +{ + INIT_FLOAT8_TEST + vfloat8 res0 = shuffle<0, 1, 2, 3, 1, 3, 2, 0>(float8_a); + compare_vector_vector(res0, make_vfloat8(0.1f, 0.2f, 0.3f, 0.4f, 0.6f, 0.8f, 0.7f, 0.5f)); + vfloat8 res1 = shuffle<3>(float8_a); + compare_vector_vector(res1, make_vfloat8(0.4f, 0.4f, 0.4f, 0.4f, 0.8f, 0.8f, 0.8f, 0.8f)); + vfloat8 res2 = shuffle<3, 2, 1, 0>(float8_a, float8_b); + compare_vector_vector(res2, make_vfloat8(0.4f, 0.3f, 2.0f, 1.0f, 0.8f, 0.7f, 6.0f, 5.0f)); +} + +CCL_NAMESPACE_END |