|
Orrery
A GPU-accelerated N-body gravitational simulator
|
Which vector extensions this processor has, asked at run time. More...
#include <string_view>Go to the source code of this file.
Classes | |
| struct | orrery::backend::CpuFeatures |
| The instruction set extensions this project can make use of. More... | |
Functions | |
| const CpuFeatures & | orrery::backend::cpu_features () noexcept |
| What this processor supports, computed once and cached. | |
| std::string_view | orrery::backend::cpu_brand () noexcept |
| The processor's own name for itself, or an empty view where it does not offer one. | |
Which vector extensions this processor has, asked at run time.
Phase 7 adds an AVX2 kernel beside the scalar one, and the two have to coexist in one binary. The alternative, building the whole project for the machine it was compiled on, is rejected in ADR-0018: it makes every binary unshippable, it makes a crash on an older machine the first symptom, and it silently vectorises the reference kernel that the fast one is supposed to be measured against.
So the AVX2 kernel is compiled in a translation unit of its own with the instruction set enabled, the rest of the project is compiled for the baseline, and this file answers the question that decides which of them runs.
Two things have to be true before an AVX2 instruction may be executed, and asking only the first is a well-known way to produce an illegal instruction on a machine that reports the feature. The processor must implement it, and the operating system must have enabled the register state it uses, since a kernel that does not save the upper halves of the vector registers across a context switch would otherwise corrupt them. Both are checked below.
Nothing here is on a hot path. The answer is computed once, on first use, and the kernel dispatch reads it once per force evaluation.
|
nodiscardnoexcept |
What this processor supports, computed once and cached.
The result cannot change while the process runs, and the detection is a few serialising instructions, so it is worth not repeating. Thread safe: the initialisation happens on first call under the guarantee C++ gives a function-local static.
|
nodiscardnoexcept |
The processor's own name for itself, or an empty view where it does not offer one.
Recorded beside every measurement rather than used to decide anything. A performance figure filed without saying which processor produced it is not a measurement of anything, and section 7 of the implementation plan asks Phase 7's harness to record the machine state alongside the numbers. Dispatch uses the feature bits above and never this string, because a name is a marketing decision and a feature bit is an answer.