Blender
V5.0
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 <gtest/gtest.h>
6
7
#include "
util/math.h
"
8
#include "
util/system.h
"
9
#include "
util/types.h
"
10
11
CCL_NAMESPACE_BEGIN
12
13
static
bool
validate_cpu_capabilities
()
14
{
15
16
#if defined(__KERNEL_AVX2__)
17
return
system_cpu_support_avx2
();
18
#elif defined(__KERNEL_AVX__)
19
return
system_cpu_support_avx();
20
#elif defined(__KERNEL_SSE42__)
21
return
system_cpu_support_sse42
();
22
#else
23
return
false
;
24
#endif
25
}
26
27
/* These are not just static variables because we don't want to run the
28
* constructor until we know the instructions are supported. */
29
static
vfloat8
float8_a
()
30
{
31
return
make_vfloat8
(0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f);
32
}
33
34
static
vfloat8
float8_b
()
35
{
36
return
make_vfloat8
(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f);
37
}
38
39
static
vfloat8
float8_c
()
40
{
41
return
make_vfloat8
(1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f);
42
}
43
44
#define INIT_FLOAT8_TEST \
45
if (!validate_cpu_capabilities()) \
46
return;
47
48
#define compare_vector_scalar(a, b) \
49
for (size_t index = 0; index < 8; index++) \
50
EXPECT_FLOAT_EQ(a[index], b);
51
52
#define compare_vector_vector(a, b) \
53
for (size_t index = 0; index < 8; index++) \
54
EXPECT_FLOAT_EQ(a[index], b[index]);
55
56
#define compare_vector_vector_near(a, b, abserror) \
57
for (size_t index = 0; index < 8; index++) \
58
EXPECT_NEAR(a[index], b[index], abserror);
59
60
#define basic_test_vv(a, b, op) \
61
INIT_FLOAT8_TEST \
62
vfloat8 c = a op b; \
63
for (size_t i = 0; i < 8; i++) \
64
EXPECT_FLOAT_EQ(c[i], a[i] op b[i]);
65
66
/* vector op float tests */
67
#define basic_test_vf(a, b, op) \
68
INIT_FLOAT8_TEST \
69
vfloat8 c = a op b; \
70
for (size_t i = 0; i < 8; i++) \
71
EXPECT_FLOAT_EQ(c[i], a[i] op b);
72
73
static
const
float
float_b
= 1.5f;
74
75
TEST
(
TEST_CATEGORY_NAME
, float8_add_vv){
76
basic_test_vv
(
float8_a
(),
float8_b
(), +)}
TEST
(
TEST_CATEGORY_NAME
, float8_sub_vv){
77
basic_test_vv
(
float8_a
(),
float8_b
(), -)}
TEST
(
TEST_CATEGORY_NAME
, float8_mul_vv){
78
basic_test_vv
(
float8_a
(),
float8_b
(), *)}
TEST
(
TEST_CATEGORY_NAME
, float8_div_vv){
79
basic_test_vv
(
float8_a
(),
float8_b
(), /)}
TEST
(
TEST_CATEGORY_NAME
, float8_add_vf){
80
basic_test_vf
(
float8_a
(),
float_b
, +)}
TEST
(
TEST_CATEGORY_NAME
, float8_sub_vf){
81
basic_test_vf
(
float8_a
(),
float_b
, -)}
TEST
(
TEST_CATEGORY_NAME
, float8_mul_vf){
82
basic_test_vf
(
float8_a
(),
float_b
, *)}
TEST
(
TEST_CATEGORY_NAME
, float8_div_vf){
83
basic_test_vf
(
float8_a
(),
float_b
, /)}
84
85
TEST
(
TEST_CATEGORY_NAME
, float8_ctor)
86
{
87
INIT_FLOAT8_TEST
88
compare_vector_scalar
(
make_vfloat8
(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f),
89
static_cast<
float
>
(index));
90
compare_vector_scalar
(
make_vfloat8
(1.0f), 1.0f);
91
}
92
93
TEST
(
TEST_CATEGORY_NAME
, float8_sqrt)
94
{
95
INIT_FLOAT8_TEST
96
compare_vector_vector
(
sqrt
(
make_vfloat8
(1.0f, 4.0f, 9.0f, 16.0f, 25.0f, 36.0f, 49.0f, 64.0f)),
97
make_vfloat8
(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f));
98
}
99
100
TEST
(
TEST_CATEGORY_NAME
, float8_min_max)
101
{
102
INIT_FLOAT8_TEST
103
compare_vector_vector
(
min
(
float8_a
(),
float8_b
()),
float8_a
());
104
compare_vector_vector
(
max
(
float8_a
(),
float8_b
()),
float8_b
());
105
}
106
107
TEST
(
TEST_CATEGORY_NAME
, float8_shuffle)
108
{
109
INIT_FLOAT8_TEST
110
vfloat8 res0 = shuffle<0, 1, 2, 3, 1, 3, 2, 0>(
float8_a
());
111
compare_vector_vector
(res0,
make_vfloat8
(0.1f, 0.2f, 0.3f, 0.4f, 0.6f, 0.8f, 0.7f, 0.5f));
112
vfloat8 res1 = shuffle<3>(
float8_a
());
113
compare_vector_vector
(res1,
make_vfloat8
(0.4f, 0.4f, 0.4f, 0.4f, 0.8f, 0.8f, 0.8f, 0.8f));
114
vfloat8 res2 = shuffle<3, 2, 1, 0>(
float8_a
(),
float8_b
());
115
compare_vector_vector
(res2,
make_vfloat8
(0.4f, 0.3f, 2.0f, 1.0f, 0.8f, 0.7f, 6.0f, 5.0f));
116
}
117
118
CCL_NAMESPACE_END
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
sqrt
#define sqrt
Definition
gpu_shader_cxx_builtin.hh:119
CCL_NAMESPACE_BEGIN
Definition
python.cpp:37
min
#define min(a, b)
Definition
sort.cc:36
system_cpu_support_avx2
bool system_cpu_support_avx2()
Definition
system.cpp:220
system_cpu_support_sse42
bool system_cpu_support_sse42()
Definition
system.cpp:215
system.h
max
max
Definition
text_draw.cc:251
make_vfloat8
ccl_device_inline vfloat8 make_vfloat8(const float f)
Definition
types_float8.h:72
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:44
basic_test_vv
#define basic_test_vv(a, b, op)
Definition
util_float8_test.h:60
validate_cpu_capabilities
static CCL_NAMESPACE_BEGIN bool validate_cpu_capabilities()
Definition
util_float8_test.h:13
float8_c
static vfloat8 float8_c()
Definition
util_float8_test.h:39
compare_vector_vector
#define compare_vector_vector(a, b)
Definition
util_float8_test.h:52
float_b
static const float float_b
Definition
util_float8_test.h:73
basic_test_vf
#define basic_test_vf(a, b, op)
Definition
util_float8_test.h:67
compare_vector_scalar
#define compare_vector_scalar(a, b)
Definition
util_float8_test.h:48
float8_b
static vfloat8 float8_b()
Definition
util_float8_test.h:34
float8_a
static vfloat8 float8_a()
Definition
util_float8_test.h:29
TEST
TEST(TEST_CATEGORY_NAME, float8_add_vv)
Definition
util_float8_test.h:75
Generated on
for Blender by
doxygen
1.16.1