---------------------------------------------------------------
How to Compile Crafty 19.x with Dev-Cpp (gcc/g++) under Windows
---------------------------------------------------------------
                         A "Cook Book"

I used version 4.9.8.5 (a stable beta of version 5) incl.
gcc/g++ 3.2 ('mingw special 20020817-1') under Win 2000 and an
AMD Athlon 900 MHz.

Successfully tested with Crafty versions 19.2 and 19.6.

No change of source code necessary!
                                                      Date: 13.12.2003

----------------------------------------------------------------------
                            CONTENTS
----------------------------------------------------------------------

Introduction

Ch. 1: Ways to Compile Crafty
       1.1 - Very Quick: Compile from Command Prompt Window
       1.2 - Using the IDE GUI of Dev-C++
             1.2.1 - Further Speed Optimisations
       1.3 - Using Your Own Makefile from the IDE GUI

Ch. 2: How to Evaluate Crafty Calculation Speed

Ch. 3: Execution Speed Measurements for Different Compiler Settings

----------------------------------------------------------------------
----------------------------------------------------------------------

------------
Introduction
------------
The quickest and simplest way to get the best optimised code (.exe
file) is to simply follow the chapters 1 and 1.1.
[of course, better optimisation settings might be possible. If you
find some, please let me know.]

You only need to read ch. 1.2 and 1.3 if you are interested in using
the Dev-C++ IDE, or if you (unexpectedly) face some problems when
following the steps of ch. 1.1.

Chapter 2 explains how the execution speed of the generated exe file
can be measured.

Chapter 3 shows such measurement results made by myself.


-----------------------------
Ch. 1: Ways to Compile Crafty
-----------------------------

Preparation steps:

(1) Goto http://www.bloodshed.net/dev/devcpp.html and
    - Download devcpp4980.exe from
            http://www.c-view.org/soft/devcpp/downloads/devcpp4980.exe
         or http://mapage.noos.fr/dev5/devcpp4980.exe
         or http://prdownloads.sourceforge.net/dev-cpp/devcpp4980.exe
    - Download latest update (currently [13.12.2003] ver 4.9.8.5) from
            http://bloodshed.net/dev/devcpp4985.zip
      [this is a DELTA to above install, so you need both]
      
    - Install Dev-C++ to
        C:\Dev-Cpp\
      Note: This installation process consists of 2 steps:
        - First install devcpp4980.exe as usual.
        - Then copy the contents of devcpp4985.zip to the
          corresponding installation target directory and
          sub-directories.
          (This means some older files are overwritten)
      
(2) Download Crafty 19.6 from
          ftp://ftp.cis.uab.edu/pub/hyatt/v19/crafty-19.6.zip
    
(3) Extract the contents of crafty-19.6.zip to a working directory,
    for example to
       C:\c-files\crafty\

(3-b) Copy the contents of *this* zip file, i.e. the files
        - Makefile
        - Makefile_tiny
        - Makefile_org_crafty_1906_modified
        - Makefile_org_crafty_1906
        - Compile_Crafty_with_Dev-Cpp.bat
        - How_to_compile_crafty_19.x_under_Dev-Cpp.txt
        - How_to_compile_crafty_19.x_under_Dev-Cpp.html
        - Make_a_crafty.exe-very_quickly.txt
        - Make_a_crafty.exe-very_quickly.html
      to the same directory, e.g. to "C:\c-files\crafty\".
      This will overwrite the original file "Makefile" that was
      contained in crafty-19.6.zip. This is intended!
      (Note that the file "Makefile_org_crafty_1906" is an identical
      copy of this original makefile.)


1.1 - Very Quick: Compile from Command Prompt Window
====================================================
In your Crafty source code directory, simply double-click

    "Compile_Crafty_with_Dev-Cpp.bat".
   
--> This will compile and link the crafty source code and create an
    executable "crafty.exe".

    - FINISHED! -

Note: If Dev-C++ was installed to another directory than C:\Dev-Cpp\,
      then the "Compile_Crafty_with_Dev-Cpp.bat" must me modified
      accordingly.

Note: You should get 7 warnings altogether, and zero errors.

Note: The .exe file generated here is the same as the one generated
      when following the instructions of ch. 1.3. Both are best
      optimised according to my knowledge.

    
1.2 - Using the IDE GUI of Dev-C++
==================================

After the above preparation steps (1) to (3-b), continue as follows:
    
(4) Start the GUI Integrated Development Environment (IDE) of
    Dev-CPP by starting C:\Dev-Cpp\devcpp.exe.
    
(5) Create a new project:
    - MENU: File -> New -> Project...
      -> select Console application
      -> find an appropriate project name, e.g. crafty1906
      -> select C++ -Project
         (NOT C-Project, because otherwise, later the linking will
         fail!)
      -> click Ok
    - Save the project file for example under
      c:\c-files\crafty\crafty1906.dev
    --> A new project comes up with a default file "main.c"
    --> In the project browser on the left, expand the tree and right-
        click on main.c and select "remove file" and then click "do
        not save"
    --> Now you should have a completely empty project --> very well!
    
(6) Include source files to the project:
    - On the left, right-click on the project and select "Add To
      Project"
      --> Mark all .c and .h and .cpp files in "c:\c-files\crafty\",
          EXCEPT crafty.c and dgtdrv.c (!!)
          Note: These two files are not needed at all! If included in
          the project, they will cause compilation errors!
    --> Now the project tree on the left should contain all those
        files, 62 files altogether. Ok? -> very well!

(7) Continue as follows:
    - Goto MENU -> Project -> Project Options
    - Select the second pane "Files"
      -> Now all .c, .h an the one .cpp file should be checked for the
         boxes "Include in Compilation", "Include in linking" and
         "Compile file as C++".
      -> Mark all files *except* egtb.cpp and UNcheck the box "Compile
         file as C++". Now all files should be unchecked for this,
         except "egtb.cpp", which is still checked to be compiled as
         C++.
    - Select the 4th pane "Parameters"
      -> Add the following command line option to BOTH the C-Compiler
         (left field) and the C++ compiler (middle field):
         "-DNT_i386" (without quotation marks)
         Remark: This causes the variable "NT_i386" to be defined when
                 the pre-compiler starts. This is necessary for
                 compiling the code for the Windows target.
         
      --> click Ok.
      
    --> Now your project is well configured. If you want, you can save
        the project now, to save the changes.
    
(8) Compile the project by clicking the compile button or pressing
    CTRL-F9.

(9) Now an exe-file should be created after some time, for example
       c:\c-files\crafty\crafty1906.exe
    Note: You should get 7 warnings altogether, and zero errors.
    

1.2.1 - Further Speed Optimisations
-----------------------------------
Execution speed of the generated exe file can (and should!) be
increased by this:
- MENU -> Project -> Project Options:
  Select the 3rd pane "Compiler -> Optimisation -> Further
  Optimisations":
  --> Select "Best Optimisation"->Yes.
- Select the 4th pane "Parameters"
  -> Add the following command line option to BOTH the C-Compiler
     (left field) and the C++ compiler (middle field)
     [in addition to -DNT_i386, which is already there]:
     "-fomit-frame-pointer" (without quotation marks)
- click Ok

Now, possibly delete the *.o files and delete or rename the exe file
of your directory and compile another time. You exe file generated now
should be significantly faster then before.

Even better speed-optimised code (compare test list of ch. 3) is
generated when using your own makefile, as described in ch 1.1 (see
above) or ch. 1.3 (see below). Note that both alternatives produce 
identical .exe-files.


1.3 - Using Your Own Makefile from the IDE GUI
==============================================
- If not already done, do the steps (1) to (6) of ch. 1 / ch. 1.2.
- Now go to MENU -> Project -> Project Options -> Select the pane
 "Makefile"
- Check the box "Use custom makefile"
- Select the makefile in the field below.

  ATTENTION: The makefile must have the name "Makefile" literally!
     Otherwise, if it is called for example "MakefCraftyDevcpp", you
     will get an error! Therefore, rename or delete another unwanted
     makefile called "Makefile" and substitute it by your own
     makefile called nothing different but "Makefile".
  
  The makefile to be used can be either the file
     "Makefile"
  provided along with this "cook book", or the file
     "Makefile_org_crafty_1906_modified"
  (after renaming it to "Makefile" of course).

Note: The .exe file generated here is the same as the one generated
      when following the instructions of ch. 1.1. Both are best
      optimised according to my knowledge.


-----------------------------------------------
Ch. 2: How to Evaluate Crafty Calculation Speed
-----------------------------------------------
The following tests are designed to compare different compiled
versions of Crafty on the same machine for comparing calculation speed
differences.

- Copy the crafty.exe file to be measured to a location where it is
  completely standalone, i.e. without any opening book accessible,
  i.e. no book.bin files in the same directory as the exe file.
- Start the exe -> a DOS box opens.

- Test 1: (repeat 2 or 3 times to see how it varies)
  - type "perf" <enter>
  
    --> this will show a performance figure. The higher the better.
        (or a number of seconds: The lower the better)

- Test 2: (repeat 2 or 3 times to see how it varies)
  - type "noise 10000000" <enter> [suppress display while thinking]
  - type "st 2" <enter>           [set fixed thinking time of 2 sec]
  - type "e2e4" <enter>           [make a starting move e2-e4]
    --> Now Crafty will think for 2 seconds.
    --> Read the number for "nodes" and "evals". Higher is better!
  
Some of these test results are presented in ch. 3.


-------------------------------------------------------------------
Ch. 3: Execution Speed Measurements for Different Compiler Settings
-------------------------------------------------------------------
Some measurement results.

PC Configuration: AMD Athlon 900, 256 MByte RAM, Windows 2000


Crafty 19.06:
-------------                       | "perf"              nodes per 2sec
                                    | (smaller=better)    (larger=better)
                                    |
                                    | gener. made/unmade  nodes   evals
Compiler Setting:                   | (performance in percent of last row)
------------------------------------+---------------------------------------
                                    |
Compile from IDE, no optimisations  | 3.49s  12.04s       339860  154975
                                    | (66%)   (63%)        (63%)   (66%)
                                    | 
                                    | 
Compile from IDE, set               | 2.47s   8.47s       484818  212096
"Best Optimisation" (corresponding  | (93%)   (90%)        (90%)   (91%)
to option -O3)                      | 
                                    | 
Compile from IDE, set               | 2.40s   7.78s       478781  208939
"Best Optimisation" and             | (96%)   (98%)        (89%)   (89%)
"-fomit-frame-pointer"              | 
                                    | 
Use own Makefile, as above, but     | 2.44s   7.76s       493939  215116
w/o "-DUSE_ATTACK_FUNCTIONS"        | (94%)   (98%)        (92%)   (92%)
                                    | 
                                    | 
Use own Makefile, as above, but     | 2.34s   8.37s       493939  215116
w/o "-fomit-frame-pointer"          | (98%)   (91%)        (92%)   (92%)
                                    | 
                                    | 
Use own Makefile, as above, but     |  2.28s  8.03s       533160  232414
with "-m486"                        | (101%)  (95%)        (99%)   (99%)
                                    | 
                                    | 
Use own Makefile, as above          | 2.30s   7.62s       536177  233882
(acc. to ch. 1.1. or ch. 1.3)       | (100%) (100%)       (100%)  (100%)
                                    | 

For comparison:

Crafty 19.2         
-----------         
                                    | 
Compiled with own makefile above:   |  2.32s  7.64s       534457  256886
                                    | (100%) (100%)       (100%)  (100%)
                                    | 
Executable downloaded               |  2.07s  6.29s       655082  310738
from Crafty's programmer's          | (112%) (121%)       (123%)  (121%)
website at                          |
ftp://ftp.cis.uab.edu/pub/hyatt/v19/crafty-19.02.exe
(probably compiled with MSVC)       |
                                    |
------------------------------------+-----------------------------------
--> MSVC is faster than gcc 3.2     |
    by... (for Crafty 19.2)         |   12%    21%          23%     21%
                                    |
------------------------------------+-----------------------------------
