-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_quantize.cpp
157 lines (134 loc) · 4.17 KB
/
bench_quantize.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
// Copyright(c) 2019-2020 Jesse Yurkovich
// SPDX-License-Identifier: GPL-3.0-only
#include <benchmark/benchmark.h>
#include "blenlib/BLI_math_geom.h"
#include "draw/GPU_vertex_format.h"
#include "geo_quadsphere1.h"
//
// Baseline: GPU_normal_convert_i10_v3
//
static void BB_GPU_normal_convert_i10_v3(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
// Setup
float normals[48][3];
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
__m128 n;
normal_tri_m128(&n,
load_m128_f3(verts[tris[i][0]]),
load_m128_f3(verts[tris[i][1]]),
load_m128_f3(verts[tris[i][2]]));
store_f3_m128(normals[i], n);
}
// Benchmark
for (auto _ : state) {
for (int i = 0; i < 48; i++) {
GPUPackedNormal pn = GPU_normal_convert_i10_v3(normals[i]);
benchmark::DoNotOptimize(pn);
}
}
}
//
// Variant: GPU_normal_convert_i10_v3: pass-through to GPU_normal_convert_i10_m128
//
static void BB_GPU_normal_convert_i10_v3_pass(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
// Setup
float normals[48][3];
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
__m128 n;
normal_tri_m128(&n,
load_m128_f3(verts[tris[i][0]]),
load_m128_f3(verts[tris[i][1]]),
load_m128_f3(verts[tris[i][2]]));
store_f3_m128(normals[i], n);
}
// Benchmark
for (auto _ : state) {
for (int i = 0; i < 48; i++) {
GPUPackedNormal pn = GPU_normal_convert_i10_v3_pass(normals[i]);
benchmark::DoNotOptimize(pn);
}
}
}
//
// SSE Variant: GPU_normal_convert_i10_v3 see: load from f3
//
static void BB_GPU_normal_convert_i10_m128_lf3(benchmark::State &state)
{
const float(*verts)[3] = geo_quadsphere1_f3_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
// Setup
float normals[48][3];
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
__m128 n;
normal_tri_m128(&n,
load_m128_f3(verts[tris[i][0]]),
load_m128_f3(verts[tris[i][1]]),
load_m128_f3(verts[tris[i][2]]));
store_f3_m128(normals[i], n);
}
// Benchmark
for (auto _ : state) {
for (int i = 0; i < 48; i++) {
GPUPackedNormal pn = GPU_normal_convert_i10_m128(load_m128_f3(normals[i]));
benchmark::DoNotOptimize(pn);
}
}
}
//
// SSE Variant: GPU_normal_convert_i10_v3 see: load from f4
//
static void BB_GPU_normal_convert_i10_m128_lf4(benchmark::State &state)
{
const float(*verts)[4] = geo_quadsphere1_f4_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
// Setup
float normals[48][4];
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
__m128 n;
normal_tri_m128(&n,
load_m128_f4(verts[tris[i][0]]),
load_m128_f4(verts[tris[i][1]]),
load_m128_f4(verts[tris[i][2]]));
store_f4_m128(normals[i], n);
}
// Benchmark
for (auto _ : state) {
for (int i = 0; i < 48; i++) {
GPUPackedNormal pn = GPU_normal_convert_i10_m128(load_m128_f4(normals[i]));
benchmark::DoNotOptimize(pn);
}
}
}
//
// SSE Speed-of-light: GPU_normal_convert_i10_v3 see: load from xmm
//
static void BB_GPU_normal_convert_i10_m128_native(benchmark::State &state)
{
const float(*verts)[4] = geo_quadsphere1_f4_verts;
const int(*tris)[3] = geo_quadspehere1_indices;
// Setup
__m128 normals[48];
for (int i = 0; i < geo_quadsphehere1_numtris; i++) {
normal_tri_m128(&normals[i],
load_m128_f4(verts[tris[i][0]]),
load_m128_f4(verts[tris[i][1]]),
load_m128_f4(verts[tris[i][2]]));
}
// Benchmark
for (auto _ : state) {
for (int i = 0; i < 48; i++) {
GPUPackedNormal pn = GPU_normal_convert_i10_m128(normals[i]);
benchmark::DoNotOptimize(pn);
}
}
}
BENCHMARK(BB_GPU_normal_convert_i10_v3);
BENCHMARK(BB_GPU_normal_convert_i10_v3_pass);
BENCHMARK(BB_GPU_normal_convert_i10_m128_lf3);
BENCHMARK(BB_GPU_normal_convert_i10_m128_lf4);
BENCHMARK(BB_GPU_normal_convert_i10_m128_native);