-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_normal_tri.cpp
172 lines (139 loc) · 4.31 KB
/
bench_normal_tri.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright(c) 2019-2020 Jesse Yurkovich
// SPDX-License-Identifier: GPL-3.0-only
#include <benchmark/benchmark.h>
#include "blenlib/BLI_math_vector.h"
#include "blenlib/BLI_math_geom.h"
#include "geo_quadsphere1.h"
//
// Baseline: normal_tri_v3
//
static void BB_normal_tri_v3(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
float n[3];
normal_tri_v3(n, verts[tris[i][0]], verts[tris[i][1]], verts[tris[i][2]]);
benchmark::DoNotOptimize(n);
}
}
}
//
// Variant: normal_tri_v3: pass-through to normal_tri_m128
//
static void BB_normal_tri_v3_pass(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
float n[3];
normal_tri_v3_pass(n, verts[tris[i][0]], verts[tris[i][1]], verts[tris[i][2]]);
benchmark::DoNotOptimize(n);
}
}
}
//
// Variant: normal_tri_v3: re-implemented as normal_tri_m128
//
static void BB_normal_tri_v3_sse(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
float n[3];
normal_tri_v3_sse(n, verts[tris[i][0]], verts[tris[i][1]], verts[tris[i][2]]);
benchmark::DoNotOptimize(n);
}
}
}
//
// SSE Variant: normal_tri_v3 load from f3, store to f3
//
static void BB_normal_tri_m128_lf3sf3(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
float n[3];
__m128 no;
normal_tri_m128(&no,
load_m128_f3(verts[tris[i][0]]),
load_m128_f3(verts[tris[i][1]]),
load_m128_f3(verts[tris[i][2]]));
store_f3_m128(n, no);
benchmark::DoNotOptimize(n);
}
}
}
//
// SSE Variant: normal_tri_v3 load from f3, store to f4
//
static void BB_normal_tri_m128_lf3sf4(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
float n[4];
__m128 temp;
normal_tri_m128(&temp,
load_m128_f3(verts[tris[i][0]]),
load_m128_f3(verts[tris[i][1]]),
load_m128_f3(verts[tris[i][2]]));
store_f4_m128(n, temp);
benchmark::DoNotOptimize(n);
}
}
}
//
// SSE Variant: normal_tri_v3 load from f4, store to f4
//
static void BB_normal_tri_m128_lf4sf4(benchmark::State &state)
{
const float(*verts)[4] = geo_quadsphere1_f4_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
float n[4];
__m128 temp;
normal_tri_m128(&temp,
load_m128_f4(verts[tris[i][0]]),
load_m128_f4(verts[tris[i][1]]),
load_m128_f4(verts[tris[i][2]]));
store_f4_m128(n, temp);
benchmark::DoNotOptimize(n);
}
}
}
//
// SSE Speed-of-light: normal_tri_v3 native: load from native, store to native
//
static void BB_normal_tri_m128_native(benchmark::State &state)
{
const float(*verts)[4] = geo_quadsphere1_f4_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
// Setup: simulate __m128s already being available (not in hot path)...
__m128 xmmverts[26];
for (int i = 0; i < geo_quadsphehere1_numverts; i++) {
xmmverts[i] = load_m128_f4(verts[i]);
}
// Benchmark
for (auto _ : state) {
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
__m128 n;
normal_tri_m128(&n, xmmverts[tris[i][0]], xmmverts[tris[i][1]], xmmverts[tris[i][2]]);
benchmark::DoNotOptimize(n);
}
}
}
BENCHMARK(BB_normal_tri_v3);
BENCHMARK(BB_normal_tri_v3_pass);
BENCHMARK(BB_normal_tri_v3_sse);
BENCHMARK(BB_normal_tri_m128_lf3sf3);
BENCHMARK(BB_normal_tri_m128_lf3sf4);
BENCHMARK(BB_normal_tri_m128_lf4sf4);
BENCHMARK(BB_normal_tri_m128_native);