Stockfish
  • Stockfish
  • NNUE
    • Documentation
    • Experiments
      • Remove 8th Subnetwork
      • Store Key in Accumulator Cache
      • Tweak fwdOut Multipliers
      • Improve Accumulator Update Heuristics
      • Remove Duplicate Perspective Code
      • Update All Accumulators
  • Improve Build System
    • Overview
    • Rewrite Makefile
    • Tests
Powered by GitBook
On this page
  • Use CXX/CXXFLAGS
  • Compiler Type Detection
  • MinGW
  • Makefile in Subdirectory
  • Build Profiles
  • native
  • x86
  • ARM
  • Compiler Options
  • GCC
  • Clang
  • ICX
  • Miscellaneous
  • strip
  • install
  • format
  • profile-build
  1. Improve Build System

Rewrite Makefile

This page covers how Makefile is rewritten.

Use CXX/CXXFLAGS

Instead of specifying COMP variable, users can now set CXX and CXXFLAGS directly. This is one of the primary objectives of the proposal.

Targets such as build, profile-build, etc., do require a valid CXX variable, representing a C++ compiler command.

ifeq ($(shell command -v $(CXX) 2> /dev/null),)
    $(error Compiler $(CXX) not found)
endif

Internal compiler options are now appended to SF_CXXFLAGS and SF_LDFLAGS variables.

Compiler Type Detection

When CXX is properly set, it checks predefined macros to determine the compiler type. It's assumed that compiler is GNU compatible - currently GCC, Clang, and ICX are supported.

define test-compiler-macro
$(shell echo | $(CXX) -dM -x c++ -E - | \
        grep -E "^#define[[:space:]]+$(1)$|([[:space:]]+.*)" > /dev/null 2>&1 && echo 1)
endef

define get-compiler-macro
$(shell echo | $(CXX) -dM -x c++ -E - | \
        grep -E "^#define[[:space:]]+$(1)$|([[:space:]]+.*)" | \
        sed "s/^#define[[:space:]]\{1,\}$(1)[[:space:]]\{1,\}\+//")
endef
  • ICX: __INTEL_LLVM_COMPILER

  • LLVM/Clang: __clang__

    • Apple Clang (Xcode): "Apple" in __VERSION__ macro

  • GCC: __GNUC__

MinGW

Checks if __MINGW32__ macro is set when the compiler is GCC or Clang. When detected, the name of the Stockfish executable file is set to "stockfish.exe".

Makefile in Subdirectory

If ARCH is not set to native, the Makefile in the arch/ directory is included based on the selected build profile. The sub-Makefile adds compiler flags specific to the machine and target architecture (i.e. -mavx2), and exports arch-specific help message and config-sanity rule.

  • x86*: arch/i386

  • arm*: arch/arm

  • Others: arch/generic

Build Profiles

native

Removed get_native_properties.sh and use -march=native compiler option. Also defines ARCH_NATIVE macro so that specific extensions/features can be selectively enabled/disabled within the code.

x86

NO_AVX512 option is introduced and available for AVX-512 presets. 512-bit SIMD instructions are not used if this option is set.

  • x86-64-avx512-vnni

    • Synonym to x86-64-vnni512, or x86-64-vnni256 if NO_AVX512 is set.

    • Removed -mavx512dq.

  • x86-64-avx512

    • Added -mavx512vl.

  • x86-64-bmi: New profile

    • Inherits x86-64-avx and has -mbmi.

    • Some AMD processors support BMI1 only.

  • x86-64-avx: New profile

    • Inherits x86-64-popcnt and has -mavx.

    • Targets Intel Sandy Bridge and Ivy Bridge processors.

  • x86-64-popcnt: New profile (replaces x86-64-sse41-popcnt)

    • Added -msse4.2.

  • x86-64-sse41: New profile

    • Inherits x86-64-ssse3 and has -msse4.1.

    • Targets non-Intel/AMD x86 processors (e.g. VIA Nano)

  • x86-64-abm: New profile

    • Inherits x86-64-sse2 and has -msse3, -msse4a and -mabm.

    • Some AMD processors support SSE4a but no SSSE3/SSE4.1. Compilers enable __POPCNT__ flag.

  • x86-64-sse3-popcnt: Retired (equal to x86-64-abm)

  • x86-32-sse41-popcnt: Retired

  • x86-32-sse2: Retired

ARM

  • armv7

    • Removed Neon support. (NDK)

    • Removed -mthumb. (NDK)

  • armv7-neon

    • Added -mfloat-abi=softfp. This option is now present regardless of the compiler type.

    • Removed -mthumb. (NDK)

Compiler Options

GCC

  • Add -flto=jobserver instead of -flto if GCC version is 12 or above.

        ifeq ($(shell expr $(GCC_VERSION) \< 12),1)
            SF_CXXFLAGS += -flto
            SF_LDFLAGS  += -flto
        else
            SF_CXXFLAGS += -flto=jobserver
            SF_LDFLAGS  += -flto=jobserver
        endif

Clang

  • Use xcrun llvm-profdata if compiler is Apple Clang.

        ifneq ($(findstring Apple,$(call get-compiler-macro,__VERSION__)),)
            CLANG_APPLE := y
            LLVM_PROFDATA := xcrun llvm-profdata
        else

ICX

  • Removed undocumented or default options: --intel, -pedantic, -Wdeprecated, -Wconditional-uninitialized

  • Fixed PGO build options.

icx-profile-make:
	@$(MAKE) --no-print-directory \
		CXXFLAGS="-fprofile-generate" LDFLAGS="-fprofile-generate" all

icx-profile-use:
	@llvm-profdata merge *.profraw --output stockfish.profdata
	@$(MAKE) --no-print-directory \
		CXXFLAGS="-fprofile-use=stockfish.profdata" \
		LDFLAGS="-fprofile-use=stockfish.profdata" \
		all

Miscellaneous

strip

Both stockfish and stockfish.exe are stripped if exist.

install

Removed - prefix.

format

Set CLANG_FORMAT as a target-specific variable.

Prints a message if clang-format is not installed.

profile-build

Renamed WINE variable to EMULATE.

Last updated 8 months ago