diff --git a/Makefile b/Makefile index 13d387a..7eb18e8 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,11 @@ -# Define the directories +# Define directories SRC_DIR := source OBJ_DIR := obj -# Set default C++ compiler, but allow override from the command line CXX ?= g++ - -# Set default executable name, but allow override from the command line EXE ?= Eleanor +EVALFILE := ./nnue.bin -EVALFILE = ./nnue.bin - -# Determine platform ifeq ($(OS),Windows_NT) EXE_EXT := .exe MKDIR := mkdir @@ -25,29 +20,30 @@ endif MAKEFLAGS += -j -# List of source files +# Source and object files SRCS := $(wildcard $(SRC_DIR)/*.cpp) +OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS)) -# Link the executable -$(EXE)$(EXE_EXT): $(SRCS) - $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $(SRCS) ./external/fmt/format.cc -o $@ -O3 -lpthread -march=native -flto -ftree-vectorize +# Final binary +$(EXE)$(EXE_EXT): $(OBJS) + $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -lpthread -march=native -flto -ftree-vectorize -# Rule to compile source files to object files +# Compile .cpp -> .o $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) $(CXX) -std=c++23 -c -o $@ $< -O3 -lpthread -march=native -flto -ftree-vectorize -# Create the object directory if it doesn't exist +# Create object directory $(OBJ_DIR): $(MKDIR) $(OBJ_DIR) -# Clean up build artifacts +# Clean up and rebuild .PHONY: clean clean: ifeq ($(OS),Windows_NT) @if exist $(OBJ_DIR) $(RM) $(OBJ_DIR) @if exist $(EXE)$(EXE_EXT) $(DEL) $(EXE)$(EXE_EXT) else - @rm -rf $(OBJ_DIR) - @rm -f $(EXE)$(EXE_EXT) + @$(RM) $(OBJ_DIR) + @$(DEL) $(EXE)$(EXE_EXT) endif $(MAKE) diff --git a/source/board.h b/source/board.h index 9a95964..5ac1cbc 100644 --- a/source/board.h +++ b/source/board.h @@ -10,8 +10,8 @@ constexpr int noEPTarget = -1; constexpr int MAX_MOVES = 218; -thread_local inline int positionIndex = 0; -thread_local inline U64 positionHistory[1000]; +inline int positionIndex = 0; +inline U64 positionHistory[1000]; class Board { public: diff --git a/source/search.cpp b/source/search.cpp index 2b74cac..ebe253c 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -10,16 +10,16 @@ namespace SEARCH { -thread_local U64 nodes = 0; -thread_local U64 nodesToGo = 0; -thread_local bool benchStarted = false; +U64 nodes = 0; +U64 nodesToGo = 0; +bool benchStarted = false; -thread_local static inline int timeToSearch = 0; -thread_local static inline bool doingNullMove = false; +static inline int timeToSearch = 0; +static inline bool doingNullMove = false; -thread_local inline PVLine pvLine; +inline PVLine pvLine; -thread_local Stopwatch sw; +Stopwatch sw; void InitLMRTable() { for (int depth = 0; depth <= MAX_DEPTH; depth++) { diff --git a/source/search.h b/source/search.h index d90542f..4b31cdb 100644 --- a/source/search.h +++ b/source/search.h @@ -19,15 +19,15 @@ constexpr int MAX_DEPTH = 64; constexpr int MAX_PLY = 128; constexpr int MAX_HISTORY = 16384; -thread_local extern U64 nodes; -thread_local extern bool benchStarted; +extern U64 nodes; +extern bool benchStarted; constexpr int inf = 100000; -thread_local inline bool searchStopped = false; +inline bool searchStopped = false; // [id][ply] -thread_local inline int killerMoves[2][MAX_PLY]; +inline int killerMoves[2][MAX_PLY]; inline int lmrTable[MAX_DEPTH+1][MAX_MOVES]; @@ -75,7 +75,7 @@ public: } }; -thread_local inline History history; +inline History history; class PVLine { private: diff --git a/source/stopwatch.h b/source/stopwatch.h index fe47086..47ab088 100644 --- a/source/stopwatch.h +++ b/source/stopwatch.h @@ -3,20 +3,20 @@ class Stopwatch { private: - std::chrono::high_resolution_clock::time_point start = - std::chrono::high_resolution_clock::now(); + std::chrono::steady_clock::time_point start = + std::chrono::steady_clock::now(); public: void Restart() { - start = std::chrono::high_resolution_clock::now(); + start = std::chrono::steady_clock::now(); } int GetElapsedMS() { - auto current = std::chrono::high_resolution_clock::now(); + auto current = std::chrono::steady_clock::now(); return std::chrono::duration_cast(current - start).count(); } double GetElapsedSec() { - auto current = std::chrono::high_resolution_clock::now(); + auto current = std::chrono::steady_clock::now(); return std::chrono::duration_cast< std::chrono::duration>(current - start).count(); } diff --git a/source/tt.h b/source/tt.h index a6e4136..e8607c4 100644 --- a/source/tt.h +++ b/source/tt.h @@ -21,7 +21,7 @@ constexpr U64 maxHash = (64* 1000000) / sizeof(TTEntry); // 5 MB constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry); -thread_local inline U64 hashSize = defaultHash; +inline U64 hashSize = defaultHash; constexpr int invalidEntry = 111111; @@ -61,4 +61,4 @@ public: void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); }; -thread_local inline TTable TT; +inline TTable TT;