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
17 # 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
19 flags=$(awk '/^flags[ \t]*:|^Features[ \t]*:/{gsub(/^flags[ \t]*:[ \t]*|^Features[ \t]*:[ \t]*|[_.]/, ""); line=$0} END{print line}' /proc/cpuinfo)
22 # Check for gcc march "znver1" or "znver2" https://en.wikichip.org/wiki/amd/cpuid
24 vendor_id=$(awk '/^vendor_id/{print $3; exit}' /proc/cpuinfo)
25 cpu_family=$(awk '/^cpu family/{print $4; exit}' /proc/cpuinfo)
26 [ "$vendor_id" = "AuthenticAMD" ] && [ "$cpu_family" = "23" ] && znver_1_2=true
29 # Set the file CPU x86_64 architecture
31 if check_flags 'avx512vnni' 'avx512dq' 'avx512f' 'avx512bw' 'avx512vl'; then
32 true_arch='x86-64-vnni256'
33 elif check_flags 'avx512f' 'avx512bw'; then
34 true_arch='x86-64-avx512'
35 elif [ -z "${znver_1_2+1}" ] && check_flags 'bmi2'; then
36 true_arch='x86-64-bmi2'
37 elif check_flags 'avx2'; then
38 true_arch='x86-64-avx2'
39 elif check_flags 'sse41' && check_flags 'popcnt'; then
40 true_arch='x86-64-sse41-popcnt'
46 # Check the system type
50 'Darwin') # Mac OSX system
53 true_arch='apple-silicon'
54 file_arch='x86-64-sse41-popcnt' # Supported by Rosetta 2
57 flags=$(sysctl -n machdep.cpu.features machdep.cpu.leaf7_features | tr '\n' ' ' | tr '[:upper:]' '[:lower:]' | tr -d '_.')
59 if [ "$true_arch" = 'x86-64-vnni256' ] || [ "$true_arch" = 'x86-64-avx512' ]; then
60 file_arch='x86-64-bmi2'
67 'Linux') # Linux system
82 if check_flags 'dotprod'; then
83 true_arch="$true_arch-dotprod"
89 if check_flags 'neon'; then
90 true_arch="$true_arch-neon"
93 *) # Unsupported machine type, exit with error
94 printf 'Unsupported machine type: %s\n' "$uname_m"
100 'CYGWIN'*|'MINGW'*|'MSYS'*) # Windows system with POSIX compatibility layer
108 # Unknown system type, exit with error
109 printf 'Unsupported system type: %s\n' "$uname_s"
114 if [ -z "$file_arch" ]; then
118 file_name="stockfish-$file_os-$file_arch.$file_ext"
120 printf '%s %s\n' "$true_arch" "$file_name"