Skip to content

Commit

Permalink
incremental-compilation (#164)
Browse files Browse the repository at this point in the history
bench: 3853493
  • Loading branch information
connormcmonigle authored Jul 4, 2023
1 parent 615292a commit d63abf9
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 129 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ build/*
.vscode/*
.idea/*
cmake-build-debug/*
*.o
*.d
*.gcda
95 changes: 69 additions & 26 deletions build/makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,92 @@
EXE = seer
SRC = ../src/seer.cc ../syzygy/tbprobe.c ../src/search/*.cc ../src/chess/*.cc ../src/engine/*.cc
CC = g++

EVALFILE = weights/0xddf7a131.bin
CC = gcc
CXX = g++

OPSLIMIT = 1000000000
CXXSTANDARD = 17
CSTANDARD = 17

EVALFILE = weights/0xddf7a131.bin
OPSLIMIT = 1000000000

CXXSRC += $(wildcard ../src/*.cc )
CXXSRC += $(wildcard ../src/search/*.cc)
CXXSRC += $(wildcard ../src/chess/*.cc)
CXXSRC += $(wildcard ../src/engine/*.cc)

CSRC := ../syzygy/tbprobe.c

INCLUDE = ../include
INCBIN = ../incbin
SYZYGY = ../syzygy

CXXFLAGS += -std=c++$(CXXSTANDARD)
CXXFLAGS += -O3 -g -DNDEBUG -march=native -mtune=native -fopenmp -flto -fwhole-program
CXXFLAGS += -Wall -Wextra
CXXFLAGS += -O3 -g -DNDEBUG -march=native -mtune=native -fopenmp
CXXFLAGS += -Wall -Wextra -pedantic
CXXFLAGS += -fconstexpr-ops-limit=$(OPSLIMIT)
CXXFLAGS += -I$(INCLUDE) -I$(INCBIN) -I$(SYZYGY)
CXXFLAGS += -DEVALFILE=\"$(EVALFILE)\"

THREADSANFLAGS += $(CXXFLAGS) -fsanitize=thread
ADDRESSSANFLAGS += $(CXXFLAGS) -fsanitize=address
UBSANFLAGS += $(CXXFLAGS) -fsanitize=undefined
TUNEFLAGS += $(CXXFLAGS) -DTUNE
CFLAGS += -std=c$(CSTANDARD)
CFLAGS += -O3 -g -DNDEBUG -march=native -mtune=native -fopenmp
CFLAGS += -Wall -Wextra -pedantic

CPPFLAGS += -MMD
CPPFLAGS += -I$(INCLUDE)
CPPFLAGS += -I$(INCBIN)
CPPFLAGS += -I$(SYZYGY)

LIBS = -lpthread
LDFLAGS = -lpthread

default:
$(CC) $(SRC) $(CXXFLAGS) $(LIBS) -o $(EXE)
COBJECTS += $(CSRC:%.c=%.o)
CDEPENDS += $(CSRC:%.c=%.d)

CXXOBJECTS += $(CXXSRC:%.cc=%.o)
CXXDEPENDS += $(CXXSRC:%.cc=%.d)

.PHONY: default
default: flto

.PHONY: pgo
pgo:
rm -f *.gcda
$(CC) -fprofile-generate $(SRC) $(CXXFLAGS) $(LIBS) -o $(EXE)
$(MAKE) clean
$(MAKE) profileclean
$(MAKE) profilegenerate EXE=$(EXE) CC=$(CC) CXX=$(CXX) EVALFILE=$(EVALFILE)
./$(EXE) bench
$(CC) -fprofile-use $(SRC) $(CXXFLAGS) $(LIBS) -o $(EXE)
rm -f *.gcda
$(MAKE) clean
$(MAKE) profileuse EXE=$(EXE) CC=$(CC) CXX=$(CXX) EVALFILE=$(EVALFILE)
$(MAKE) profileclean

.PHONY: profilegenerate
profilegenerate: CXXFLAGS += -fprofile-generate
profilegenerate: CFLAGS += -fprofile-generate
profilegenerate: flto

.PHONY: profileuse
profileuse: CXXFLAGS += -fprofile-use
profileuse: CFLAGS += -fprofile-use
profileuse: flto

.PHONY: flto
flto: CXXFLAGS += -flto -fwhole-program
flto: CFLAGS += -flto -fwhole-program
flto: binary

.PHONY: plain
flto: binary

.PHONY: binary
binary: $(CXXOBJECTS) $(COBJECTS)
+$(CXX) $(CXXFLAGS) -o $(EXE) $^ $(LDFLAGS)

threadsan:
$(CC) $(SRC) $(THREADSANFLAGS) $(LIBS) -o $(EXE)
.PHONY: clean
clean:
rm -f $(CXXOBJECTS) $(CXXDEPENDS)
rm -f $(COBJECTS) $(CDEPENDS)

addresssan:
$(CC) $(SRC) $(ADDRESSSANFLAGS) $(LIBS) -o $(EXE)
.PHONY: profileclean
profileclean:
rm -f $(CSRC:%.c=%.gcda)
rm -f $(CXXSRC:%.cc=%.gcda)

ubsan:
$(CC) $(SRC) $(UBSANFLAGS) $(LIBS) -o $(EXE)

tune:
$(CC) $(SRC) $(TUNEFLAGS) $(LIBS) -o $(EXE)
-include $(CXXDEPENDS) $(CDEPENDS)
48 changes: 0 additions & 48 deletions build/makefile-clang

This file was deleted.

3 changes: 1 addition & 2 deletions include/chess/square.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ template <typename T>
inline constexpr bool is_square_v = std::is_same_v<T, square> || std::is_same_v<T, tbl_square>;

struct square_set_iterator {
using difference_type = long;
using value_type = square;
using pointer = const square*;
using reference = const square&;
using iterator_category = std::output_iterator_tag;
using iterator_category = std::input_iterator_tag;

square::data_type remaining;

Expand Down
2 changes: 1 addition & 1 deletion include/search/history_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace constants {
inline constexpr std::size_t num_squares = 64;
inline constexpr std::size_t num_pieces = 6;

}; // namespace constants
} // namespace constants

struct context {
chess::move follow;
Expand Down
22 changes: 11 additions & 11 deletions syzygy/tbchess.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ static const uint64_t anti2board_table[15] =
0x0001020408102040ull,
};

static inline std::size_t diag2index(uint64_t b)
static inline size_t diag2index(uint64_t b)
{
b *= 0x0101010101010101ull;
b >>= 56;
b >>= 1;
return (std::size_t)b;
return (size_t)b;
}

static inline std::size_t anti2index(uint64_t b)
static inline size_t anti2index(uint64_t b)
{
return diag2index(b);
}
Expand All @@ -327,8 +327,8 @@ static uint64_t bishop_attacks(unsigned sq, uint64_t occ)
unsigned d = diag(sq), a = anti(sq);
uint64_t d_occ = occ & (diag2board(d) & ~BOARD_EDGE);
uint64_t a_occ = occ & (anti2board(a) & ~BOARD_EDGE);
std::size_t d_idx = diag2index(d_occ);
std::size_t a_idx = anti2index(a_occ);
size_t d_idx = diag2index(d_occ);
size_t a_idx = anti2index(a_occ);
uint64_t d_attacks = diag_attacks_table[sq][d_idx];
uint64_t a_attacks = anti_attacks_table[sq][a_idx];
return d_attacks | a_attacks;
Expand Down Expand Up @@ -399,20 +399,20 @@ static void bishop_attacks_init(void)
static uint64_t rank_attacks_table[64][64];
static uint64_t file_attacks_table[64][64];

static inline std::size_t rank2index(uint64_t b, unsigned r)
static inline size_t rank2index(uint64_t b, unsigned r)
{
b >>= (8 * r);
b >>= 1;
return (std::size_t)b;
return (size_t)b;
}

static inline std::size_t file2index(uint64_t b, unsigned f)
static inline size_t file2index(uint64_t b, unsigned f)
{
b >>= f;
b *= 0x0102040810204080ull;
b >>= 56;
b >>= 1;
return (std::size_t)b;
return (size_t)b;
}

#define rank2board(r) (0xFFull << (8 * (r)))
Expand All @@ -424,8 +424,8 @@ static uint64_t rook_attacks(unsigned sq, uint64_t occ)
unsigned r = rank(sq), f = file(sq);
uint64_t r_occ = occ & (rank2board(r) & ~BOARD_RANK_EDGE);
uint64_t f_occ = occ & (file2board(f) & ~BOARD_FILE_EDGE);
std::size_t r_idx = rank2index(r_occ, r);
std::size_t f_idx = file2index(f_occ, f);
size_t r_idx = rank2index(r_occ, r);
size_t f_idx = file2index(f_occ, f);
uint64_t r_attacks = rank_attacks_table[sq][r_idx];
uint64_t f_attacks = file_attacks_table[sq][f_idx];
return r_attacks | f_attacks;
Expand Down
Loading

0 comments on commit d63abf9

Please sign in to comment.