Windows
I used the modified makefile from mikeb originally, but fiddled for windows that has the following:
Code: Select all
# To build crafty:
#
# You want to set up for maximum optimization, but typically you will
# need to experiment to see which options provide the fastest code. The
# following option descriptions explain each option. To use one or more
# of these options, to the "opt =" line that follows the explanations and
# add the options you want, being careful to stay inside the single quote
# marks.
#
# -DAFFINITY Include code to set processor/thread affinity on windows
# systems. Note this will not work on Apple OS X as it does
# not support any sort of processor affinity mechanism.
# WARNING: know what you are doing before using this. If
# you test multiple copies of Crafty (each copy using just
# one thread) you can have bogus results because if compiled
# with -DAFFINITY, even a single-cpu execution will lock led
# itself onto processor zero (since it only has thread #0)
# which is probably NOT what you want. This is intended to
# be used when you run Crafty using a complete dedicated
# machine with nothing else running at the same time.
# -DBOOKDIR Path to the directory containing the book binary files.
# The default for all such path values is "." if you don't
# specify a path with this macro definition.
# -DCPUS=n Defines the maximum number of CPUS Crafty will be able
# to use in a SMP system. Note that this is the max you
# will be able to use. You need to use the smpmt=n command
# to make crafty use more than the default 1 process.
# -DDEBUG This is used for testing changes. Enabling this option
# greatly slows Crafty down, but every time a move is made,
# the corresponding position is checked to make sure all of
# the bitboards are set correctly.
# -DEPD If you want full EPD support built in.
# -DINLINEASM Compiles with the Intel assembly code for FirstOne(),
# LastOne() and PopCnt(). This is for gcc-style inlining
# and now works with the Intel C/C++ compiler as well. It
# also has a MSVC compatible version included.
# -DLOGDIR Path to the directory where Crafty puts the log.nnn and
# game.nnn files.
# -DNODES This enables the sn=x command. Crafty will search until
# exactly X nodes have been searched, then the search
# terminates as if time ran out.
# -DNOEGTB Eliminates the egtb code for compilers that can't deal
# with the large egtb.cpp code/templates.
# -DNUMA Says this system is NUMA, which is mainly used for Linux
# or Windows systems, and references libnuma, needed for the
# NUMA calls (crafty doesn't use many of these, it does the
# memory setup stuff itself)
# -DPOPCNT Says this system is a newer Intel/AMD processor with the
# built-in hardware popcnt instruction.
# -DPOSITIONS Causes Crafty to emit FEN strings, one per book line, as
# it creates a book. I use this to create positions to use
# for cluster testing.
# -DRCDIR Path to the directory where we look for the .craftyrc or
# crafty.rc (windows) file.
# -DSKILL Enables the "skill" command which allows you to arbitrarily
# lower Crafty's playing skill so it does not seem so
# invincible to non-GM-level players.
# -DTBDIR Path to the directory where the endgame tablebase files
# are found. default = "./TB"
# -DTEST Displays evaluation table after each move (in the logfile)
# -DTRACE This enables the "trace" command so that the search tree
# can be dumped while running.
# -Dwindows This identifies the target O/S as being windows-based, if this
# option is omitted, windows is assumed.
# $(MAKE) -j windows-gcc
# $(MAKE) -j windows-clang
default:
$(MAKE) -j windows-gcc
help:
@echo "You must specify the system which you want to compile for:"
@echo ""
@echo "make windows-gcc windows w/gcc compiler"
@echo "make windows-icc windows w/icc compiler"
@echo "make profile profile-guided-optimizations"
@echo " (edit Makefile to make the profile"
@echo " option use the right compiler)"
@echo ""
quick:
$(MAKE) target=WINDOWS \
CC=gcc CXX=g++ \
opt='-DTEST -DTRACE -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -Wno-array-bounds -pipe -O3 -pthread' \
CXFLAGS='-Wall -Wno-array-bounds -pipe -O3 -pthread' \
LDFLAGS='$(LDFLAGS) -pthread -lstdc++' \
crafty-make
windows-gcc:
@rm -rf *.o
@rm -rf log.*
@rm -rf game.*
$(MAKE) -j target=WINDOWS \
CC=gcc CXX=gcc \
opt=' -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -pipe -Wno-array-bounds -Ofast --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -O3 -msse4.2 -mpopcnt -Os -Ofast -O3 -fprofile-use -fprofile-correction \
-pthread' \
CXFLAGS='-Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -Os -Ofast -O3 -fprofile-use -fprofile-correction \
-pthread' \
LDFLAGS='$(LDFLAGS) -fprofile-use -pthread -lstdc++' \
crafty-make
windows-gcc-profile:
@rm -rf *.o
@rm -rf log.*
@rm -rf game.*
$(MAKE) -j target=WINDOWS \
CC=gcc CXX=gcc \
opt=' -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD' \
CFLAGS='-Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -flto -Os -Ofast -O3 -fprofile-arcs -pthread' \
CXFLAGS='-Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -flto -Os -Ofast -O3 -fprofile-arcs -pthread' \
LDFLAGS='$(LDFLAGS) -fprofile-arcs -pthread -lstdc++ ' \
crafty-make
windows-gcc-hy:
$(MAKE) -j target=WINDOWS \
CC=gcc CXX=g++ \
opt='-DTEST -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -Wno-array-bounds -pipe -O3 -fprofile-use \
-fprofile-correction -pthread' \
CXFLAGS='-Wall -Wno-array-bounds -pipe -O3 -fprofile-use \
-fprofile-correction -pthread' \
LDFLAGS='$(LDFLAGS) -fprofile-use -pthread -lstdc++' \
crafty-make
windows-gcc-profile-hy:
$(MAKE) -j target=WINDOWS \
CC=gcc CXX=g++ \
opt='-DTEST -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -Wno-array-bounds -pipe -O3 -fprofile-arcs \
-pthread' \
CXFLAGS='-Wall -Wno-array-bounds -pipe -O3 -fprofile-arcs \
-pthread' \
LDFLAGS='$(LDFLAGS) -fprofile-arcs -pthread -lstdc++ ' \
crafty-make
windows-clang:
@/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata merge -output=crafty.profdata *.profraw
$(MAKE) -j target=WINDOWS \
CC=gcc CXX=g++ \
opt='-DTEST -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -Wno-array-bounds -pipe -O3 \
-fprofile-instr-use=crafty.profdata' \
CXFLAGS='-Wall -Wno-array-bounds -pipe -O3 \
-fprofile-instr-use=crafty.profdata' \
LDFLAGS='$(LDFLAGS) -fprofile-use -lstdc++' \
crafty-make
windows-clang-profile:
$(MAKE) -j target=WINDOWS \
CC=gcc CXX=g++ \
opt='-DTEST -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -Wno-array-bounds -pipe -O3 \
-fprofile-instr-generate' \
CXFLAGS='-Wall -Wno-array-bounds -pipe -O3 \
-fprofile-instr-generate' \
LDFLAGS='$(LDFLAGS) -fprofile-instr-generate -lstdc++ ' \
crafty-make
windows-icc:
$(MAKE) -j target=WINDOWS \
CC=icc CXX=icc \
opt='-DTEST -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -w -O3 -prof_use -prof_dir ./prof -fno-alias \
-pthread' \
CXFLAGS='-Wall -w -O3 -prof_use -prof_dir ./prof -pthread' \
LDFLAGS='$(LDFLAGS) -pthread -lstdc++' \
crafty-make
windows-icc-profile:
$(MAKE) -j target=WINDOWS \
CC=icc CXX=icc \
opt='-DTEST -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD ' \
CFLAGS='-Wall -w -O2 -prof_gen -prof_dir ./prof -fno-alias \
-pthread' \
CXFLAGS='-Wall -w -O2 -prof_gen -prof_dir ./prof -pthread' \
LDFLAGS='$(LDFLAGS) -pthread -lstdc++ ' \
crafty-make
profile:
@rm -rf *.o
@rm -rf log.*
@rm -rf game.*
@rm -rf prof
@rm -rf *.gcda
@mkdir prof
@touch *.c *.cpp *.h
$(MAKE) -j windows-gcc-profile
@echo "!/bin/csh" > runprof
@echo "./crafty <<EOF" >>runprof
@echo "pgo -3" >>runprof
@echo "display nomoves" >>runprof
@echo "ponder off" >>runprof
@echo "egtb" >>runprof
@echo "setboard /k/rnn////5RBB/K/ w" >>runprof
@echo "mt=2" >>runprof
@echo "st=2" >>runprof
@echo "go" >>runprof
@echo "setboard /k/3p/p2P1p/P2P1P///K/ w" >>runprof
@echo "go" >>runprof
@echo "mt=0" >>runprof
@echo "quit" >>runprof
@echo "EOF" >>runprof
@chmod +x runprof
@./runprof
@rm runprof
@touch *.c *.cpp *.h
$(MAKE) -j windows-gcc
@strip crafty.exe
#
# one of the two following definitions for "objects" should be used. The
# default is to compile everything separately. However, if you use the
# definition that refers to crafty.o, that will compile using the file crafty.c
# which #includes every source file into one large glob. This gives the
# compiler max opportunity to inline functions as appropriate. You should try
# compiling both ways to see which way produces the fastest code.
#
#objects = main.o iterate.o time.o search.o quiesce.o evaluate.o thread.o \
repeat.o hash.o next.o history.o movgen.o make.o unmake.o attacks.o \
swap.o boolean.o utility.o probe.o book.o drawn.o epd.o epdglue.o \
init.o input.o autotune.o interrupt.o option.o output.o ponder.o \
resign.o root.o learn.o setboard.o test.o validate.o annotate.o \
analyze.o evtest.o bench.o edit.o data.o
objects = crafty.o
# Do not change anything below this line!
opts = $(opt) -D$(target)
# @$(MAKE) -j opt='$(opt)' CXFLAGS='$(CXFLAGS)' CFLAGS='$(CFLAGS)' crafty
crafty-make:
@$(MAKE) opt='$(opt)' CXFLAGS='$(CXFLAGS)' CFLAGS='$(CFLAGS)' crafty
crafty.o: *.c *.h
crafty: $(objects) egtb.o
$(CC) $(LDFLAGS) -o crafty $(objects) egtb.o -lm $(LIBS)
evaluate.o: evaluate.h
egtb.o: egtb.cpp
$(CXX) -c $(CXFLAGS) $(opts) egtb.cpp
clean:
-rm -f *.o crafty
$(objects): chess.h data.h
.c.o:
$(CC) $(CFLAGS) $(opts) -c $*.c
.s.o:
$(AS) $(AFLAGS) -o $*.o $*.s
With option:
With build session as follows:
Code: Select all
DCorbit@dcorbit MINGW64 /f/project/dcorbit/crafty-25.0.1
$ make windows-gcc-profile
make -j target=WINDOWS \
CC=gcc CXX=gcc \
opt=' -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD' \
CFLAGS='-Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -flto -Os -Ofast -O3 -fprofile-arcs -pthread' \
CXFLAGS='-Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -flto -Os -Ofast -O3 -fprofile-arcs -pthread' \
LDFLAGS=' -fprofile-arcs -pthread -lstdc++ ' \
crafty-make
make[1]: Entering directory '/f/project/dcorbit/crafty-25.0.1'
make[2]: Entering directory '/f/project/dcorbit/crafty-25.0.1'
gcc -Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -flto -Os -Ofast -O3 -fprofile-arcs -pthread -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD -DWINDOWS -c crafty.c
gcc -c -Wall -pipe -Wno-array-bounds --param l1-cache-size=64 --param l2-cache-size=256 -l3-cache-size=12228 -march=native -msse4.2 -mpopcnt -flto -Os -Ofast -O3 -fprofile-arcs -pthread -DINLINEASM -DPOPCNT -DCPUS=24 -DEPD -DWINDOWS egtb.cpp
In file included from egtb.cpp:54:0:
lock.h:18:0: warning: ignoring #pragma intrinsic [-Wunknown-pragmas]
# pragma intrinsic (_InterlockedExchange)
^
In file included from chess.h:77:0,
from iterate.c:1,
from crafty.c:13:
lock.h:18:0: warning: ignoring #pragma intrinsic [-Wunknown-pragmas]
# pragma intrinsic (_InterlockedExchange)
^
In file included from chess.h:646:0,
from iterate.c:1,
from crafty.c:13:
inline.h: In function 'MSB':
inline.h:76:23: warning: passing argument 1 of '_BitScanReverse64' from incompatible pointer type [-Wincompatible-pointer-types]
_BitScanReverse64(&v, a);
^
In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/winnt.h:27:0,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/minwindef.h:163,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/windef.h:8,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/windows.h:69,
from chess.h:51,
from iterate.c:1,
from crafty.c:13:
C:/msys64/mingw64/x86_64-w64-mingw32/include/psdk_inc/intrin-impl.h:750:1: note: expected 'long unsigned int *' but argument is of type 'int *'
__buildbitscan(_BitScanReverse64, unsigned __int64, "bsr{q %[Mask],%[Index] | %[Index],%[Mask]}")
^
In file included from chess.h:646:0,
from iterate.c:1,
from crafty.c:13:
inline.h: In function 'LSB':
inline.h:83:23: warning: passing argument 1 of '_BitScanForward64' from incompatible pointer type [-Wincompatible-pointer-types]
_BitScanForward64(&v, a);
^
In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/winnt.h:27:0,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/minwindef.h:163,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/windef.h:8,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/windows.h:69,
from chess.h:51,
from iterate.c:1,
from crafty.c:13:
C:/msys64/mingw64/x86_64-w64-mingw32/include/psdk_inc/intrin-impl.h:743:1: note: expected 'long unsigned int *' but argument is of type 'int *'
__buildbitscan(_BitScanForward64, unsigned __int64, "bsf{q %[Mask],%[Index] | %[Index],%[Mask]}")
^
In file included from crafty.c:13:0:
iterate.c: In function 'Iterate':
iterate.c:244:49: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
NumaStartThread(ThreadInit, (void *) proc);
^
iterate.c:51:15: warning: unused variable 'pt' [-Wunused-variable]
pthread_t pt;
^
In file included from crafty.c:28:0:
utility.c: In function 'ReadClock':
utility.c:1425:14: warning: unused variable 'tUser64' [-Wunused-variable]
uint64_t tUser64;
^
utility.c:1424:42: warning: unused variable 'ftUser' [-Wunused-variable]
FILETIME ftCreate, ftExit, ftKernel, ftUser;
^
utility.c:1424:32: warning: unused variable 'ftKernel' [-Wunused-variable]
FILETIME ftCreate, ftExit, ftKernel, ftUser;
^
utility.c:1424:24: warning: unused variable 'ftExit' [-Wunused-variable]
FILETIME ftCreate, ftExit, ftKernel, ftUser;
^
utility.c:1424:14: warning: unused variable 'ftCreate' [-Wunused-variable]
FILETIME ftCreate, ftExit, ftKernel, ftUser;
^
utility.c:1423:12: warning: unused variable 'hThread' [-Wunused-variable]
HANDLE hThread;
^
utility.c: In function 'WinNumaInit':
utility.c:2703:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [-Wformat=]
printf("System is NUMA. %d nodes reported by Windows\n",
^
utility.c:2708:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]
printf("Node %d CPUs: ", ulNode);
^
utility.c:2716:40: warning: format '%d' expects argument of type 'int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]
printf("%d ", ulCPU);
^
utility.c:2728:24: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]
printf("Current ideal CPU is %u\n", dwCPU);
^
utility.c:2734:36: warning: format '%d' expects argument of type 'int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]
printf("Exchanging nodes 0 and %d\n", ulNode);
^
utility.c:2680:15: warning: unused variable 'dwMask' [-Wunused-variable]
DWORD_PTR dwMask;
^
utility.c: In function 'NumaStartThread':
utility.c:2761:16: warning: format '%d' expects argument of type 'int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]
printf("Starting thread on node %d CPU mask %I64d\n", ulNumaNode,
^
In file included from crafty.c:41:0:
init.c: In function 'Initialize':
init.c:67:26: warning: overflow in implicit constant conversion [-Woverflow]
fseek(book_file, -sizeof(int), SEEK_END);
^
init.c:22:29: warning: unused variable 'node' [-Wunused-variable]
int i, j, v, major, id, node;
^
init.c:22:9: warning: unused variable 'i' [-Wunused-variable]
int i, j, v, major, id, node;
^
init.c: In function 'InitializeHashTables':
init.c:804:6: warning: type of 'fault_in' defaults to 'int' [-Wimplicit-int]
void InitializeHashTables(fault_in) {
^
egtb.cpp: In function 'void* PvMalloc(size_t)':
egtb.cpp:334:64: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'size_t {aka long long unsigned int}' [-Wformat=]
printf ("*** Cannot allocate %lu bytes of memory\n", cb);
^
egtb.cpp: In function 'void VInitEnumerations()':
egtb.cpp:1310:66: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'size_t {aka long long unsigned int}' [-Wformat=]
printf ("\nAllocated %luk\n\n", (cbAllocated + 1023)/1024);
^
egtb.cpp: In function 'void VCheckSize(int, color, int, INDEX, char*)':
egtb.cpp:6238:45: warning: unknown conversion type character 'l' in format [-Wformat=]
rgchTbName, cbOk1, cbOk2, cb);
^
egtb.cpp:6238:45: warning: unknown conversion type character 'l' in format [-Wformat=]
egtb.cpp:6238:45: warning: unknown conversion type character 'l' in format [-Wformat=]
egtb.cpp:6238:45: warning: too many arguments for format [-Wformat-extra-args]
gcc -fprofile-arcs -pthread -lstdc++ -o crafty crafty.o egtb.o -lm
make[2]: Leaving directory '/f/project/dcorbit/crafty-25.0.1'
make[1]: Leaving directory '/f/project/dcorbit/crafty-25.0.1'
DCorbit@dcorbit MINGW64 /f/project/dcorbit/crafty-25.0.1
$