I have some code that depends on CPU and OS support for various CPU features.
In particular I need to check for various SIMD instruction set support.
Namely sse2
, avx
, avx2
, fma4
, and neon
.
(neon
being the ARM SIMD feature. I'm less interested in that; given less ARM end-users.)
What I am doing right now is:
function cpu_flags()
if is_linux()
cpuinfo = readstring(`cat /proc/cpuinfo`);
cpu_flag_string = match(r"flags\t\t: (.*)", cpuinfo).captures[1]
elseif is_apple()
sysinfo = readstring(`sysctl -a`);
cpu_flag_string = match(r"machdep.cpu.features: (.*)", cpuinfo).captures[1]
else
@assert is_windows()
warn("CPU Feature detection does not work on windows.")
cpu_flag_string = ""
end
split(lowercase(cpu_flag_string))
end
This has two downsides:
- It doesn't work on windows
- I'm just not sure it is correct; it it? Or does it screw up, if for example the OS has a feature disabled, but physically the CPU supports it?
So my questions is:
- How can I make this work on windows.
- Is this correct, or even a OK way to go about getting this information?
This is part of a build script (with BinDeps.jl); so I need a solution that doesn't involve opening a GUI. And ideally one that doesn't add a 3rd party dependency. Extracting the information from GCC somehow would work, since I already require GCC to compile some shared libraries. (choosing which libraries, is what this code to detect the instruction set is for)