mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
- Add new target `macos-lipo`.
- Created by compiling a universal x86 binary (no PGO) and a standard Apple silicon binary (with PGO), then combining them into a Mach-O fat binary
- To keep only one copy of the net, we add custom loading logic in the x86 section. The executable reads its own path and mmaps the net that's in the ARM section.
- The offset and size (from the executable base) of the mapping is injected after compilation in `patch_x86_slice.sh`
- avx512 on macOS isn't advertised in the xcr0 register by default. The simple solution I came up with is to execute a dummy AVX512 instruction, which sets up the register, before calling `__builtin_cpu_init`.
Some housekeeping as well:
- Rename `armv8-universal` -> `arm64-universal`.
- Add standard copyright headers to the files we've added recently.
Potential follow-ups:
- Disservin's Makefile cleanup
- Alternative ideas for the net loading. In particular, this will error out if the user strips the binary (since that'll invalidate the offset).
closes https://github.com/official-stockfish/Stockfish/pull/6860
No functional change
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
63 lines
1.7 KiB
Bash
Executable File
63 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Usage: check_universal_macos.sh STOCKFISH_EXE [EXPECTED_BENCH]
|
|
|
|
set -eu
|
|
|
|
STOCKFISH_EXE=$1
|
|
|
|
extract() {
|
|
awk -F: -v lbl="$1" '$0 ~ lbl {
|
|
sub(/^[[:space:]]+/, "", $2); sub(/[[:space:]]+$/, "", $2); print $2; exit
|
|
}'
|
|
}
|
|
|
|
FAIL=0
|
|
|
|
BINARY_SIZE=$(wc -c < "$STOCKFISH_EXE")
|
|
MAX_SIZE=$((150 * 1024 * 1024))
|
|
if [ "$BINARY_SIZE" -gt "$MAX_SIZE" ]; then
|
|
printf 'check_universal_macos.sh: binary size %d bytes exceeds 150 MB limit\n' "$BINARY_SIZE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
native_bench=$(arch -arm64 "$STOCKFISH_EXE" bench 2>&1 | extract "Nodes searched" || true)
|
|
if [ -z "$native_bench" ]; then
|
|
echo "check_universal_macos.sh: arm64 run produced no bench" >&2
|
|
FAIL=1
|
|
else
|
|
printf 'native (arm64) bench %s\n' "$native_bench" >&2
|
|
fi
|
|
|
|
x86_bench=$(arch -x86_64 "$STOCKFISH_EXE" bench 2>&1 | extract "Nodes searched" || true)
|
|
if [ -z "$x86_bench" ]; then
|
|
echo "check_universal_macos.sh: x86_64 (Rosetta) run produced no bench (crashed?)" >&2
|
|
FAIL=1
|
|
else
|
|
printf 'x86_64 (Rosetta) bench %s\n' "$x86_bench" >&2
|
|
fi
|
|
|
|
# Should match
|
|
if [ "$native_bench" != "$x86_bench" ]; then
|
|
printf 'check_universal_macos.sh: slice bench mismatch: arm64=%s x86_64=%s\n' \
|
|
"$native_bench" "$x86_bench" >&2
|
|
FAIL=1
|
|
fi
|
|
|
|
# Check that under Rosetta, SSE41 is detected
|
|
x86_compiler=$(arch -x86_64 "$STOCKFISH_EXE" compiler 2>&1 || true)
|
|
if printf '%s\n' "$x86_compiler" | grep -q 'SSE41'; then
|
|
printf 'x86_64 (Rosetta) compiler reports SSE41 ok\n' >&2
|
|
else
|
|
echo "check_universal_macos.sh: x86_64 compiler output missing SSE41" >&2
|
|
printf '%s\n' "$x86_compiler" >&2
|
|
FAIL=1
|
|
fi
|
|
|
|
if [ "$FAIL" != 0 ]; then
|
|
echo "check_universal_macos.sh: failed"
|
|
exit 1
|
|
fi
|
|
|
|
echo "check_universal_macos.sh: Good! Universal macOS binary works."
|