Skip to content

Commit

Permalink
Cfish 12
Browse files Browse the repository at this point in the history
  • Loading branch information
syzygy1 committed Sep 13, 2020
1 parent 25329e2 commit af19c28
Show file tree
Hide file tree
Showing 5 changed files with 558 additions and 219 deletions.
103 changes: 60 additions & 43 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ vnni = no
neon = no
ARCH = auto
native = no
embed = no
STRIP = strip

### 2.2 Architecture specific

Expand Down Expand Up @@ -386,16 +388,17 @@ ifeq ($(COMP),gcc)
LDFLAGS += -m$(bits)
endif

ifeq ($(arch),$(filter $(arch),armv7))
LDFLAGS += -latomic
endif

ifneq ($(KERNEL),Darwin)
LDFLAGS += -Wl,--no-as-needed
endif

ifneq ($(KERNEL),$(filter $(KERNEL),Linux Darwin Haiku))
CFLAGS += -Wno-pedantic-ms-format
endif

gccversion = $(shell $(CC) --version)
gccisclang = $(findstring clang,$(gccversion))
endif

ifeq ($(COMP),mingw)
Expand Down Expand Up @@ -424,15 +427,21 @@ endif
ifeq ($(COMP),icc)
comp=icc
CC=icc
CFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
CFLAGS += -diag-disable 344,711,2259,2330 -Wcheck -Wabi -Wdeprecated -strict-ansi
endif

ifeq ($(COMP),clang)
comp=clang
CC=clang
CFLAGS += -pedantic -Wextra -Wshadow
# -Wno-missing-braces -Wno-missing-field-initializers -Wno-unknown-attributes
ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))

ifneq ($(KERNEL),Darwin)
ifneq ($(KERNEL),OpenBSD)
LDFLAGS += -latomic
endif
endif

ifeq ($(arch),$(filter $(arch),armv7 armv8))
ifeq ($(OS),Android)
CFLAGS += -m$(bits)
LDFLAGS += -m$(bits)
Expand All @@ -441,11 +450,6 @@ ifeq ($(COMP),clang)
CFLAGS += -m$(bits)
LDFLAGS += -m$(bits)
endif

ifeq ($(KERNEL),Darwin)
CFLAGS +=
DEPENDFLAGS +=
endif
endif

ifneq ($(COMP),mingw)
Expand All @@ -454,17 +458,6 @@ ifeq ($(KERNEL),$(filter $(KERNEL),Linux Darwin Haiku))
endif
endif

ifeq ($(comp),icc)
profile_make = icc-profile-make
profile_use = icc-profile-use
else ifeq ($(comp),clang)
profile_make = clang-profile-make
profile_use = clang-profile-use
else
profile_make = gcc-profile-make
profile_use = gcc-profile-use
endif

ifeq ($(KERNEL),Darwin)
CFLAGS += -arch $(arch) -mmacosx-version-min=10.14
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.14
Expand All @@ -475,32 +468,54 @@ endif
# binutils. Currently we don't know how to make PGO builds with the NDK yet.
ifeq ($(COMP),ndk)
CFLAGS += -fPIE
comp=clang
ifeq ($(arch),armv7)
comp=armv7a-linux-androideabi16-clang
CC=armv7a-linux-androideabi16-clang
CCFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
CFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
STRIP=arm-linux-androideabi-strip
endif
ifeq ($(arch),armv8)
comp=aarch64-linux-android21-clang
CC=aarch64-linux-android21-clang
STRIP=aarch64-linux-android-strip
endif
LDFLAGS += -pie -lm -latomic
LDFLAGS += -static -latomic -z muldefs
endif

### Allow overwriting CC from command line
ifdef COMPCC
CC=$(COMPCC)
endif

ifeq ($(comp),icc)
profile_make = icc-profile-make
profile_use = icc-profile-use
else ifeq ($(comp),clang)
profile_make = clang-profile-make
profile_use = clang-profile-use
else
profile_make = gcc-profile-make
profile_use = gcc-profile-use
endif

### Sometimes gcc is really clang
ifeq ($(COMP),gcc)
gccversion = $(shell $(CC) --version)
gccisclang = $(findstring clang,$(gccversion))
ifneq ($(gccisclang),)
profile_make = clang-profile-make
profile_use = clang-profile-use
endif
endif

### On mingw use Windows threads, otherwise POSIX
ifneq ($(comp),mingw)
# On Android Bionic's C library comes with its own pthread implementation bundled in
ifneq ($(OS),Android)
# Haiku has pthreads in its libroot, so only link it in on other platforms
ifneq ($(KERNEL),Haiku)
LDFLAGS += -lpthread
ifneq ($(COMP),ndk)
LDFLAGS += -lpthread
endif
endif
endif
endif
Expand Down Expand Up @@ -544,19 +559,14 @@ ifeq ($(bits),64)
CFLAGS += -DIS_64BIT
endif

### 3.5 prefetch
ifeq ($(prefetch),yes)
ifeq ($(sse),yes)
CFLAGS += -msse
DEPENDFLAGS += -msse
endif
else
### 3.5 prefetch and sse
ifeq ($(prefetch),no)
CFLAGS += -DNO_PREFETCH
endif

### 3.6 popcnt
ifeq ($(popcnt),yes)
ifeq ($(arch),$(filter $(arch),ppc64 armv8))
ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
CFLAGS += -DUSE_POPCNT
else
ifeq ($(comp),icc)
Expand Down Expand Up @@ -618,6 +628,10 @@ ifeq ($(sse2),yes)
endif
endif

ifeq ($(sse),yes)
CFLAGS += -msse -DUSE_SSE
endif

ifeq ($(mmx),yes)
CFLAGS += -DUSE_MMX
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
Expand Down Expand Up @@ -660,6 +674,9 @@ endif
ifeq ($(nnue),yes)
CFLAGS += -DNNUE
OBJS += nnue.o
ifeq ($(embed),yes)
CFLAGS += -DNNUE_EMBEDDED
endif
endif

### 3.9 Link Time Optimization
Expand All @@ -668,10 +685,7 @@ endif
ifeq ($(lto),yes)
ifeq ($(optimize),yes)
ifeq ($(debug),no)
ifeq ($(COMP),ndk)
CFLAGS += -fltho=thin
LDFLAGS += $(CFLAGS)
else ifeq ($(comp),clang)
ifeq ($(comp),clang)
CFLAGS += -flto=thin
ifneq ($(findstring MINGW,$(KERNEL)),)
CFLAGS += -fuse-ld=lld
Expand Down Expand Up @@ -711,7 +725,7 @@ endif
### breaks Android 4.0 and earlier.
ifeq ($(arch),armv7)
CFLAGS += -fPIE
LDFLAGS += -fPIE -pie
LDFLAGS += -fPIE
endif


Expand Down Expand Up @@ -813,7 +827,7 @@ profile-build: net config-sanity objclean profileclean
pgo: profile-build

strip:
strip $(EXE)
$(STRIP) $(EXE)

install:
-mkdir -p -m 755 $(BINDIR)
Expand All @@ -824,7 +838,7 @@ clean: objclean profileclean
@rm -f .depend core

net:
$(eval nnuenet := $(shell grep EvalFile ucioption.c | grep OPT_TYPE_STRING | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
$(eval nnuenet := $(shell grep DefaultEvalFile evaluate.h | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
@echo "Default net: $(nnuenet)"
$(eval nnuedownloadurl := https://tests.stockfishchess.org/api/nn/$(nnuenet))
$(eval curl_or_wget := $(shell if hash curl 2>/dev/null; then echo "curl -skL"; elif hash wget 2>/dev/null; then echo "wget -qO-"; fi))
Expand Down Expand Up @@ -874,6 +888,7 @@ config-sanity:
@echo "vnni: '$(vnni)'"
@echo "neon: '$(neon)'"
@echo "native: '$(native)'"
@echo "embed: '$(embed)'"
@echo ""
@echo "Flags:"
@echo "CC: $(CC)"
Expand Down Expand Up @@ -902,7 +917,9 @@ config-sanity:
@test "$(vnni)" = "yes" || test "$(vnni)" = "no"
@test "$(neon)" = "yes" || test "$(neon)" = "no"
@test "$(native)" = "yes" || test "$(native)" = "no"
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
@test "$(embed)" = "yes" || test "$(embed)" = "no"
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
|| test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"

$(EXE): $(OBJS)
$(CC) -o $@ $(OBJS) $(LDFLAGS)
Expand Down
2 changes: 2 additions & 0 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "types.h"

#define DefaultEvalFile "nn-308d71810dff.nnue"

enum { Tempo = 28 };

#ifdef NNUE
Expand Down
2 changes: 1 addition & 1 deletion src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

// Version number. If Version is left empty, then compile date in the format
// DD-MM-YY and show in engine_info.
char Version[] = "";
char Version[] = "12";

#ifndef _WIN32
pthread_mutex_t ioMutex = PTHREAD_MUTEX_INITIALIZER;
Expand Down
12 changes: 12 additions & 0 deletions src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ INLINE uint16_t read_le_u16(void *p)
return from_le_u16(*(uint16_t *)p);
}

INLINE uint32_t readu_le_u32(const void *p)
{
const uint8_t *q = p;
return q[0] | (q[1] << 8) | (q[2] << 16) | (q[3] << 24);
}

INLINE uint16_t readu_le_u16(const void *p)
{
const uint8_t *q = p;
return q[0] | (q[1] << 8);
}

#endif
Loading

0 comments on commit af19c28

Please sign in to comment.