4 # Returns properties of the native system.
5 # best architecture as supported by the CPU
6 # filename of the best binary uploaded as an artifact during CI
9 # Check if all the given flags are present in the CPU flags list
12 printf '%s\n' "$flags" | grep -q -w "$flag" || return 1
16 # Set the CPU flags list
18 flags="$(awk '/^flags[ \t]*:/{gsub(/^flags[ \t]*:[ \t]*/, ""); line=$0} END{print line}' /proc/cpuinfo) $(awk '/^Features[ \t]*:/{gsub(/^Features[ \t]*:[ \t]*/, ""); line=$0} END{print line}' /proc/cpuinfo)"
19 # remove underscores and points from flags, e.g. gcc uses avx512vnni, while some cpuinfo can have avx512_vnni, some systems use sse4_1 others sse4.1
20 flags=$(printf '%s' "$flags" | sed "s/[_.]//g")
23 # Check for gcc march "znver1" or "znver2" https://en.wikichip.org/wiki/amd/cpuid
25 vendor_id=$(awk '/^vendor_id/{print $3; exit}' /proc/cpuinfo)
26 cpu_family=$(awk '/^cpu family/{print $4; exit}' /proc/cpuinfo)
27 [ "$vendor_id" = "AuthenticAMD" ] && [ "$cpu_family" = "23" ] && znver_1_2=true
30 # Set the file CPU x86_64 architecture
32 if check_flags 'avx512vnni' 'avx512dq' 'avx512f' 'avx512bw' 'avx512vl'; then
33 true_arch='x86-64-vnni256'
34 elif check_flags 'avx512f' 'avx512bw'; then
35 true_arch='x86-64-avx512'
36 elif [ -z "${znver_1_2+1}" ] && check_flags 'bmi2'; then
37 true_arch='x86-64-bmi2'
38 elif check_flags 'avx2'; then
39 true_arch='x86-64-avx2'
40 elif check_flags 'sse41' && check_flags 'popcnt'; then
41 true_arch='x86-64-sse41-popcnt'
47 # Check the system type
51 'Darwin') # Mac OSX system
54 true_arch='apple-silicon'
55 file_arch='x86-64-sse41-popcnt' # Supported by Rosetta 2
58 flags=$(sysctl -n machdep.cpu.features machdep.cpu.leaf7_features | tr '\n' ' ' | tr '[:upper:]' '[:lower:]' | sed "s/[_.]//g")
60 if [ "$true_arch" = 'x86-64-vnni256' ] || [ "$true_arch" = 'x86-64-avx512' ]; then
61 file_arch='x86-64-bmi2'
68 'Linux') # Linux system
83 if check_flags 'dotprod'; then
84 true_arch="$true_arch-dotprod"
90 if check_flags 'neon'; then
91 true_arch="$true_arch-neon"
94 *) # Unsupported machine type, exit with error
95 printf 'Unsupported machine type: %s\n' "$uname_m"
101 'CYGWIN'*|'MINGW'*|'MSYS'*) # Windows system with POSIX compatibility layer
109 # Unknown system type, exit with error
110 printf 'Unsupported system type: %s\n' "$uname_s"
115 if [ -z "$file_arch" ]; then
119 file_name="stockfish-$file_os-$file_arch.$file_ext"
121 printf '%s %s\n' "$true_arch" "$file_name"