Blender
V4.3
intern
cycles
test
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
10
CCL_NAMESPACE_BEGIN
11
12
static
bool
validate_cpu_capabilities
()
13
{
14
15
#if defined(__KERNEL_AVX2__)
16
return
system_cpu_support_avx2
();
17
#elif defined(__KERNEL_AVX__)
18
return
system_cpu_support_avx();
19
#elif defined(__KERNEL_SSE42__)
20
return
system_cpu_support_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. */
28
static
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
33
static
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
38
static
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
72
static
const
float
float_b
= 1.5f;
73
74
TEST
(
TEST_CATEGORY_NAME
, float8_add_vv){
75
basic_test_vv
(
float8_a
(),
float8_b
(), +)}
TEST
(
TEST_CATEGORY_NAME
, float8_sub_vv){
76
basic_test_vv
(
float8_a
(),
float8_b
(), -)}
TEST
(
TEST_CATEGORY_NAME
, float8_mul_vv){
77
basic_test_vv
(
float8_a
(),
float8_b
(), *)}
TEST
(
TEST_CATEGORY_NAME
, float8_div_vv){
78
basic_test_vv
(
float8_a
(),
float8_b
(), /)}
TEST
(
TEST_CATEGORY_NAME
, float8_add_vf){
79
basic_test_vf
(
float8_a
(),
float_b
, +)}
TEST
(
TEST_CATEGORY_NAME
, float8_sub_vf){
80
basic_test_vf
(
float8_a
(),
float_b
, -)}
TEST
(
TEST_CATEGORY_NAME
, float8_mul_vf){
81
basic_test_vf
(
float8_a
(),
float_b
, *)}
TEST
(
TEST_CATEGORY_NAME
, float8_div_vf){
82
basic_test_vf
(
float8_a
(),
float_b
, /)}
83
84
TEST
(
TEST_CATEGORY_NAME
, float8_ctor)
85
{
86
INIT_FLOAT8_TEST
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));
89
compare_vector_scalar
(
make_vfloat8
(1.0f), 1.0f);
90
}
91
92
TEST
(
TEST_CATEGORY_NAME
, float8_sqrt)
93
{
94
INIT_FLOAT8_TEST
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
99
TEST
(
TEST_CATEGORY_NAME
, float8_min_max)
100
{
101
INIT_FLOAT8_TEST
102
compare_vector_vector
(
min
(
float8_a
(),
float8_b
()),
float8_a
());
103
compare_vector_vector
(
max
(
float8_a
(),
float8_b
()),
float8_b
());
104
}
105
106
TEST
(
TEST_CATEGORY_NAME
, float8_shuffle)
107
{
108
INIT_FLOAT8_TEST
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
117
CCL_NAMESPACE_END
sqrt
sqrt(x)+1/max(0
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
CCL_NAMESPACE_BEGIN
Definition
python.cpp:44
min
#define min(a, b)
Definition
sort.c:32
system_cpu_support_avx2
bool system_cpu_support_avx2()
Definition
system.cpp:227
system_cpu_support_sse42
bool system_cpu_support_sse42()
Definition
system.cpp:222
system.h
max
float max
Definition
transform_gizmo_3d.cc:93
make_vfloat8
ccl_device_inline vfloat8 make_vfloat8(float f)
Definition
types_float8_impl.h:56
math.h
types.h
TEST_CATEGORY_NAME
#define TEST_CATEGORY_NAME
Definition
util_float8_avx2_test.cpp:9
INIT_FLOAT8_TEST
#define INIT_FLOAT8_TEST
Definition
util_float8_test.h:43
basic_test_vv
#define basic_test_vv(a, b, op)
Definition
util_float8_test.h:59
validate_cpu_capabilities
static CCL_NAMESPACE_BEGIN bool validate_cpu_capabilities()
Definition
util_float8_test.h:12
float8_c
static vfloat8 float8_c()
Definition
util_float8_test.h:38
compare_vector_vector
#define compare_vector_vector(a, b)
Definition
util_float8_test.h:51
float_b
static const float float_b
Definition
util_float8_test.h:72
basic_test_vf
#define basic_test_vf(a, b, op)
Definition
util_float8_test.h:66
compare_vector_scalar
#define compare_vector_scalar(a, b)
Definition
util_float8_test.h:47
float8_b
static vfloat8 float8_b()
Definition
util_float8_test.h:33
float8_a
static vfloat8 float8_a()
Definition
util_float8_test.h:28
TEST
TEST(TEST_CATEGORY_NAME, float8_add_vv)
Definition
util_float8_test.h:74
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0