-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexamples_load.cpp
More file actions
130 lines (115 loc) · 2.83 KB
/
examples_load.cpp
File metadata and controls
130 lines (115 loc) · 2.83 KB
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
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright © 2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
* Matthias Kretz <m.kretz@gsi.de>
*/
#define UB_LOADS 1
#include "simd"
void g(auto);
void cvt(const std::array<float, 4>& x)
{
g(std::simd(x));
}
void cvt()
{
int carr[] = {0, 1, 2, 3, 4};
g(std::simd(carr));
}
void cvt2()
{
g(std::simd(std::array{0, 1, 2, 3, 4}));
}
void load_ub(const std::vector<float>& x)
{
g(std::simd_load(x));
}
void load_zero(const std::vector<float>& x)
{
g(std::simd_load(x, std::simd_flag_default_init));
}
#if 0
void load_IFNDR(const std::vector<float>& x)
{
std::span<const float> chunk(x.begin(), 7);
g(std::simd_load(chunk));
}
#endif
void iter_ub1(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
for (auto it = x.begin(); it < x.end(); it += V::size)
{
std::span<const float, V::size()> chunk(it, V::size());
acc += chunk;
}
g(acc);
}
void iter_ub2(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
for (auto it = x.begin(); it < x.end(); it += V::size)
acc += std::simd_load(it, x.end());
g(acc);
}
void iter_zero1(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
for (auto it = x.begin(); it < x.end(); it += V::size)
acc += std::simd_load(it, x.end(), std::simd_flag_default_init);
g(acc);
}
void iter_ub3(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
for (auto it = x.begin(); it < x.end(); it += V::size)
{
std::span<const float> chunk(it, V::size());
acc += std::simd_load(chunk, std::simd_flag_default_init);
}
g(acc);
}
void iter_zero_efficient1(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
auto it = x.begin();
for (; it + V::size() <= x.end(); it += V::size)
{
std::span<const float, V::size> chunk(it, V::size());
acc += chunk;
}
std::span<const float> chunk(it, x.end());
acc += std::simd_load(chunk, std::simd_flag_default_init);
g(acc);
}
void iter_zero_efficient2(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
auto it = x.begin();
for (; it + V::size() <= x.end(); it += V::size)
{
std::span<const float> chunk(it, x.end());
acc += std::simd_load(chunk);
}
std::span<const float> chunk(it, x.end());
acc += std::simd_load(chunk, std::simd_flag_default_init);
g(acc);
}
void iter_zero_sadly_not_efficient(const std::vector<float>& x)
{
using V = std::simd<float>;
V acc {};
auto it = x.begin();
for (; it + V::size() <= x.end(); it += V::size)
{
std::span<const float> chunk(it, x.end());
acc += std::simd_load(chunk, std::simd_flag_default_init);
}
std::span<const float> chunk(it, x.end());
acc += std::simd_load(chunk, std::simd_flag_default_init);
g(acc);
}