Blender V4.3
util_float8_test.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6#include "util/math.h"
7#include "util/system.h"
8#include "util/types.h"
9
11
13{
14
15#if defined(__KERNEL_AVX2__)
17#elif defined(__KERNEL_AVX__)
18 return system_cpu_support_avx();
19#elif defined(__KERNEL_SSE42__)
21#else
22 return false;
23#endif
24}
25
26/* These are not just static variables because we don't want to run the
27 * constructor until we know the instructions are supported. */
28static vfloat8 float8_a()
29{
30 return make_vfloat8(0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f);
31}
32
33static vfloat8 float8_b()
34{
35 return make_vfloat8(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f);
36}
37
38static vfloat8 float8_c()
39{
40 return make_vfloat8(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f);
41}
42
43#define INIT_FLOAT8_TEST \
44 if (!validate_cpu_capabilities()) \
45 return;
46
47#define compare_vector_scalar(a, b) \
48 for (size_t index = 0; index < 8; index++) \
49 EXPECT_FLOAT_EQ(a[index], b);
50
51#define compare_vector_vector(a, b) \
52 for (size_t index = 0; index < 8; index++) \
53 EXPECT_FLOAT_EQ(a[index], b[index]);
54
55#define compare_vector_vector_near(a, b, abserror) \
56 for (size_t index = 0; index < 8; index++) \
57 EXPECT_NEAR(a[index], b[index], abserror);
58
59#define basic_test_vv(a, b, op) \
60 INIT_FLOAT8_TEST \
61 vfloat8 c = a op b; \
62 for (size_t i = 0; i < 8; i++) \
63 EXPECT_FLOAT_EQ(c[i], a[i] op b[i]);
64
65/* vector op float tests */
66#define basic_test_vf(a, b, op) \
67 INIT_FLOAT8_TEST \
68 vfloat8 c = a op b; \
69 for (size_t i = 0; i < 8; i++) \
70 EXPECT_FLOAT_EQ(c[i], a[i] op b);
71
72static const float float_b = 1.5f;
73
83
85{
87 compare_vector_scalar(make_vfloat8(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f),
88 static_cast<float>(index));
90}
91
93{
95 compare_vector_vector(sqrt(make_vfloat8(1.0f, 4.0f, 9.0f, 16.0f, 25.0f, 36.0f, 49.0f, 64.0f)),
96 make_vfloat8(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f));
97}
98
105
106TEST(TEST_CATEGORY_NAME, float8_shuffle)
107{
109 vfloat8 res0 = shuffle<0, 1, 2, 3, 1, 3, 2, 0>(float8_a());
110 compare_vector_vector(res0, make_vfloat8(0.1f, 0.2f, 0.3f, 0.4f, 0.6f, 0.8f, 0.7f, 0.5f));
111 vfloat8 res1 = shuffle<3>(float8_a());
112 compare_vector_vector(res1, make_vfloat8(0.4f, 0.4f, 0.4f, 0.4f, 0.8f, 0.8f, 0.8f, 0.8f));
113 vfloat8 res2 = shuffle<3, 2, 1, 0>(float8_a(), float8_b());
114 compare_vector_vector(res2, make_vfloat8(0.4f, 0.3f, 2.0f, 1.0f, 0.8f, 0.7f, 6.0f, 5.0f));
115}
116
sqrt(x)+1/max(0
#define CCL_NAMESPACE_END
#define min(a, b)
Definition sort.c:32
bool system_cpu_support_avx2()
Definition system.cpp:227
bool system_cpu_support_sse42()
Definition system.cpp:222
float max
ccl_device_inline vfloat8 make_vfloat8(float f)
#define TEST_CATEGORY_NAME
#define INIT_FLOAT8_TEST
#define basic_test_vv(a, b, op)
static CCL_NAMESPACE_BEGIN bool validate_cpu_capabilities()
static vfloat8 float8_c()
#define compare_vector_vector(a, b)
static const float float_b
#define basic_test_vf(a, b, op)
#define compare_vector_scalar(a, b)
static vfloat8 float8_b()
static vfloat8 float8_a()
TEST(TEST_CATEGORY_NAME, float8_add_vv)