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
173
174
175
176
177
178
179
180
181
/*
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
*
* This file is part of IsoSpec.
*
* IsoSpec is free software: you can redistribute it and/or modify
* it under the terms of the Simplified ("2-clause") BSD licence.
*
* IsoSpec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the Simplified BSD Licence
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
*/
// ---------------------------------------------------------------------------
// Runtime ISA dispatch.
//
// A single binary can carry several builds of the two batched fill kernels --
// one per instruction-set level -- and pick the best one the CPU actually
// supports, at run time. This matters because the distributed builds have no
// -march at all (the PyPI wheel is compiled at the x86-64 baseline, so its
// vectors are 2 doubles wide), while the machines running them are mostly
// AVX2-or-better.
//
// Why it is built this way, and not the two obvious easier ways:
//
// * __attribute__((target(...))) / target_clones() cannot do it.
// std::experimental::simd fixes its ABI when the templates are instantiated,
// from the -march preprocessor macros; a target attribute applied afterwards
// changes only the *encoding*. Measured: fixed_size_simd<double,8> inside a
// target("avx512f") function on a baseline TU emits nothing but xmm, and
// native_simd<double> under target_clones still reports 2 lanes. So the
// levels have to be separate translation units, each with its own -march.
//
// * Those TUs must not include the library's own headers. A TU compiled at
// -march=x86-64-v4 emits VEX/EVEX code into the COMDAT copies of every
// inline and template function it instantiates, and the linker then picks
// one copy of each for the whole program -- by link order. Measured: the
// same two objects linked in the opposite order gave a surviving copy of a
// shared inline function using %zmm, reachable from baseline code paths,
// i.e. SIGILL on any CPU without AVX-512.
//
// Hence the interface below is deliberately POD-only: raw pointers and doubles,
// no IsoSpec types, nothing with a definition that could be duplicated. The
// kernel bodies (isa_kernel_impl.h) are static, and only the tables below have
// external linkage. libstdc++'s simd internals are all always_inline, so they
// leave no mergeable symbols behind either -- verified with nm on both TUs.
// ---------------------------------------------------------------------------
namespace // namespace IsoSpec