232 changes: 116 additions & 116 deletions src/chess.h
Expand Up @@ -38,11 +38,6 @@
#include <stdlib.h>
#include <string.h>
#pragma once
# if !defined (UNIX)
# define RESTRICT __restrict
# else
# define RESTRICT
# endif
# if !defined(CPUS)
# define CPUS 1
# endif
Expand All @@ -52,15 +47,14 @@
# endif
# define CDECL
# define STDCALL
/* Provide reasonable defaults for UNIX systems. */
/* Provide reasonable defaults for non-UNIX systems. */
# if !defined(UNIX)
# undef STDCALL
# define STDCALL __stdcall
# ifdef VC_INLINE32
# undef CDECL
# define CDECL __cdecl
# endif
# undef CDECL
# define CDECL __cdecl
# endif
/* Define paths for internal files. */
# if !defined(BOOKDIR)
# define BOOKDIR "."
# endif
Expand Down Expand Up @@ -147,10 +141,10 @@ typedef struct {
typedef struct {
uint64_t key;
int32_t score_mg, score_eg;
unsigned char defects_k[2];
unsigned char defects_m[2];
unsigned char defects_q[2];
unsigned char passed[2];
uint8_t defects_k[2];
uint8_t defects_m[2];
uint8_t defects_q[2];
uint8_t passed[2];
} PAWN_HASH_ENTRY;
typedef struct {
uint64_t entry[3];
Expand All @@ -172,9 +166,9 @@ typedef struct {
int phase;
int order;
int remaining;
unsigned *last;
unsigned done[10];
unsigned *exclude;
uint32_t *last;
uint32_t done[10];
uint32_t *exclude;
} NEXT_MOVE;
/*
root_move.status:
Expand Down Expand Up @@ -202,9 +196,9 @@ typedef struct {
# pragma pack()
# endif
typedef struct {
unsigned char position[8];
unsigned char status;
unsigned char percent_play;
uint8_t position[8];
uint8_t status;
uint8_t percent_play;
} BB_POSITION;
struct personality_term {
char *description;
Expand All @@ -213,12 +207,12 @@ struct personality_term {
void *value;
};
struct autotune {
unsigned int min;
unsigned int max;
unsigned int increment;
int32_t min;
int32_t max;
int32_t increment;
char description[64];
char command[16];
unsigned int *parameter;
int32_t *parameter;
};
typedef struct tree {
/* commonly used variables */
Expand Down Expand Up @@ -281,8 +275,8 @@ typedef struct thread {
TREE *tree;
uint64_t blocks;
uint64_t max_blocks;
unsigned int idle;
volatile unsigned int terminate;
uint32_t idle;
volatile uint32_t terminate;
char filler[40];
} THREAD;
/*
Expand Down Expand Up @@ -320,47 +314,53 @@ typedef struct thread {
# define LEGAL 1
# define IN_WINDOW 2
# define FAIL_HIGH 3
#define PopCnt(v) __builtin_popcountll(v)
#define LSB(v) __builtin_ctzll(v)
#define MSB(v) (63 - __builtin_clzll(v))
#if defined(UNIX)
# define PopCnt(v) __builtin_popcountll(v)
# define LSB(v) __builtin_ctzll(v)
# define MSB(v) (63 - __builtin_clzll(v))
#else
# define PopCnt(v) __popcnt64(v)
# define LSB(v) (63 - __lzcnt64(v & -v))
# define MSB(v) (63 - __lzcnt64(v))
#endif
void AlignedMalloc(void **, uint64_t, size_t);
void AlignedRemalloc(void **, uint64_t, size_t);
void Analyze(void);
void Annotate(void);
void AnnotateHeaderHTML(char *, FILE *);
void AnnotateFooterHTML(FILE *);
void AnnotatePositionHTML(TREE *RESTRICT, int, FILE *);
void AnnotatePositionHTML(TREE *, int, FILE *);
char *AnnotateVtoNAG(int, int, int, int);
void AnnotateHeaderTeX(FILE *);
void AnnotateFooterTeX(FILE *);
void AnnotatePositionTeX(TREE *, int, FILE *);
uint64_t atoiKMB(char *);
int Attacks(TREE *RESTRICT, int, int);
uint64_t Attacked(TREE *RESTRICT, int, uint64_t);
uint64_t AttacksFrom(TREE *RESTRICT, int, int);
uint64_t AttacksTo(TREE *RESTRICT, int);
int Attacks(TREE *, int, int);
uint64_t Attacked(TREE *, int, uint64_t);
uint64_t AttacksFrom(TREE *, int, int);
uint64_t AttacksTo(TREE *, int);
void AutoTune(int, char **);
int Bench(int, int);
int Book(TREE *RESTRICT, int);
int Book(TREE *, int);
void BookClusterIn(FILE *, int, BOOK_POSITION *);
void BookClusterOut(FILE *, int, BOOK_POSITION *);
int BookIn32(unsigned char *);
float BookIn32f(unsigned char *);
uint64_t BookIn64(unsigned char *);
int BookIn32(uint8_t *);
float BookIn32f(uint8_t *);
uint64_t BookIn64(uint8_t *);
int BookMask(char *);
unsigned char *BookOut32(int);
unsigned char *BookOut32f(float);
unsigned char *BookOut64(uint64_t);
int BookPonderMove(TREE *RESTRICT, int);
void Bookup(TREE *RESTRICT, int, char **);
uint8_t *BookOut32(int);
uint8_t *BookOut32f(float);
uint8_t *BookOut64(uint64_t);
int BookPonderMove(TREE *, int);
void Bookup(TREE *, int, char **);
void BookSort(BB_POSITION *, int, int);
int BookupCompare(const void *, const void *);
int CDECL BookupCompare(const void *, const void *);
BB_POSITION BookupNextPosition(int, int);
int CheckInput(void);
void ClearHashTableScores(void);
int ComputeDifficulty(int, int);
void CopyFromParent(TREE *RESTRICT);
void CopyToParent(TREE *RESTRICT, TREE *RESTRICT, int);
void CopyFromParent(TREE *);
void CopyToParent(TREE *, TREE *, int);
void CraftyExit(int);
void DisplayArray(int *, int);
void DisplayArrayX2(int *, int *, int);
Expand All @@ -373,42 +373,42 @@ void DisplayFT(int, int, int);
char *DisplayHHMM(unsigned);
char *DisplayHHMMSS(unsigned);
char *DisplayKMB(uint64_t, int);
void DisplayFail(TREE *RESTRICT, int, int, int, int, int, int, int);
char *DisplayPath(TREE *RESTRICT, int, PATH *);
void DisplayPV(TREE *RESTRICT, int, int, int, PATH *, int);
void DisplayFail(TREE *, int, int, int, int, int, int, int);
char *DisplayPath(TREE *, int, PATH *);
void DisplayPV(TREE *, int, int, int, PATH *, int);
char *DisplayTime(unsigned);
char *Display2Times(unsigned);
char *DisplayTimeKibitz(unsigned);
void DisplayChessMove(char *, int);
int Drawn(TREE *RESTRICT, int);
int Drawn(TREE *, int);
int DTZtoWDL(int, int);
void Edit(void);
int Evaluate(TREE *RESTRICT, int, int, int, int);
void EvaluateBishops(TREE *RESTRICT, int);
void EvaluateCastling(TREE *RESTRICT, int, int);
int EvaluateDraws(TREE *RESTRICT, int, int, int);
int Evaluate(TREE *, int, int, int, int);
void EvaluateBishops(TREE *, int);
void EvaluateCastling(TREE *, int, int);
int EvaluateDraws(TREE *, int, int, int);
int EvaluateHasOpposition(int, int, int);
void EvaluateKing(TREE *RESTRICT, int, int);
int EvaluateKingsFile(TREE * RESTRICT, int, int, int);
void EvaluateKnights(TREE *RESTRICT, int);
void EvaluateMate(TREE *RESTRICT, int);
void EvaluateMaterial(TREE *RESTRICT, int);
void EvaluatePassedPawns(TREE *RESTRICT, int, int);
void EvaluatePassedPawnRaces(TREE *RESTRICT, int);
void EvaluatePawns(TREE *RESTRICT, int);
void EvaluateQueens(TREE *RESTRICT, int);
void EvaluateRooks(TREE *RESTRICT, int);
int EvaluateWinningChances(TREE *RESTRICT, int, int);
void EvaluateKing(TREE *, int, int);
int EvaluateKingsFile(TREE * , int, int, int);
void EvaluateKnights(TREE *, int);
void EvaluateMate(TREE *, int);
void EvaluateMaterial(TREE *, int);
void EvaluatePassedPawns(TREE *, int);
void EvaluatePassedPawnRaces(TREE *, int);
void EvaluatePawns(TREE *, int);
void EvaluateQueens(TREE *, int);
void EvaluateRooks(TREE *, int);
int EvaluateWinningChances(TREE *, int, int);
void EVTest(char *);
int Exclude(TREE *RESTRICT, int, int);
int FindBlockID(TREE *RESTRICT);
char *FormatPV(TREE *RESTRICT, int, PATH);
int Exclude(TREE *, int, int);
int FindBlockID(TREE *);
char *FormatPV(TREE *, int, PATH);
int FTbSetCacheSize(void *, unsigned long);
int GameOver(int);
unsigned *GenerateCaptures(TREE *RESTRICT, int, int, unsigned *);
unsigned *GenerateCheckEvasions(TREE *RESTRICT, int, int, unsigned *);
unsigned *GenerateChecks(TREE *RESTRICT, int, unsigned *);
unsigned *GenerateNoncaptures(TREE *RESTRICT, int, int, unsigned *);
unsigned *GenerateCaptures(TREE *, int, int, unsigned *);
unsigned *GenerateCheckEvasions(TREE *, int, int, unsigned *);
unsigned *GenerateChecks(TREE *, int, unsigned *);
unsigned *GenerateNoncaptures(TREE *, int, int, unsigned *);
TREE *GetBlock(TREE *, int);
void Initialize(void);
void InitializeAttackBoards(void);
Expand All @@ -427,91 +427,91 @@ void InitializeLMP(void);
void InitializeLMR(void);
void InitializeSMP(void);
int IInitializeTb(char *);
int InputMove(TREE *RESTRICT, int, int, int, int, char *);
int InputMoveICS(TREE *RESTRICT, int, int, int, int, char *);
int InputMove(TREE *, int, int, int, int, char *);
int InputMoveICS(TREE *, int, int, int, int, char *);
uint64_t InterposeSquares(int, int, int);
void Interrupt(int);
int InvalidPosition(TREE *RESTRICT);
int InvalidPosition(TREE *);
int Iterate(int, int, int);
int Join(int64_t);
void Kibitz(int, int, int, int, int, uint64_t, int, int, char *);
void History(TREE *RESTRICT, int, int, int, int, int*);
void History(TREE *, int, int, int, int, int*);
int KingPawnSquare(int, int, int, int);
int LearnAdjust(int);
void LearnBook(void);
int LearnFunction(int, int, int, int);
void LearnValue(int, int);
void MakeMove(TREE *RESTRICT, int, int, int);
void MakeMoveRoot(TREE *RESTRICT, int, int);
int Mated(TREE *RESTRICT, int, int);
void MakeMove(TREE *, int, int, int);
void MakeMoveRoot(TREE *, int, int);
int Mated(TREE *, int, int);
int RootMoveEGTB(int);
int NextMove(TREE *RESTRICT, int, int, int, int);
int NextRootMove(TREE *RESTRICT, TREE *RESTRICT, int);
int NextMove(TREE *, int, int, int, int);
int NextRootMove(TREE *, TREE *, int);
int NextRootMoveParallel(void);
void NextSort(TREE *RESTRICT, int);
int Option(TREE *RESTRICT);
void NextSort(TREE *, int);
int Option(TREE *);
int OptionMatch(char *, char *);
void OptionPerft(TREE *RESTRICT, int, int, int);
void Output(TREE *RESTRICT);
char *OutputMove(TREE *RESTRICT, int, int, int);
void OptionPerft(TREE *, int, int, int);
void Output(TREE *);
char *OutputMove(TREE *, int, int, int);
int ParseTime(char *);
void Pass(void);
int PinnedOnKing(TREE *RESTRICT, int, int);
int PinnedOnKing(TREE *, int, int);
int Ponder(int);
void Print(int, char *, ...);
int ProbeDTZ(TREE * RESTRICT tree, int ply, int wtm);
int HashProbe(TREE *RESTRICT, int, int, int, int, int, int*);
void HashStore(TREE *RESTRICT, int, int, int, int, int, int);
void HashStorePV(TREE *RESTRICT, int, int);
int Quiesce(TREE *RESTRICT, int, int, int, int, int);
int QuiesceEvasions(TREE *RESTRICT, int, int, int, int);
int ProbeDTZ(TREE * tree, int ply, int wtm);
int HashProbe(TREE *, int, int, int, int, int, int*);
void HashStore(TREE *, int, int, int, int, int, int);
void HashStorePV(TREE *, int, int);
int Quiesce(TREE *, int, int, int, int, int);
int QuiesceEvasions(TREE *, int, int, int, int);
unsigned Random32(void);
uint64_t Random64(void);
int Read(int, char *);
int ReadChessMove(TREE *RESTRICT, FILE *, int, int);
int ReadChessMove(TREE *, FILE *, int, int);
void ReadClear(void);
unsigned ReadClock(void);
int ReadPGN(FILE *, int);
int ReadNextMove(TREE *RESTRICT, char *, int, int);
int ReadNextMove(TREE *, char *, int, int);
int ReadParse(char *, char *args[], char *);
int ReadInput(void);
int Repeat(TREE *RESTRICT, int);
int Repeat3x(TREE *RESTRICT);
void ResignOrDraw(TREE *RESTRICT, int);
int Repeat(TREE *, int);
int Repeat3x(TREE *);
void ResignOrDraw(TREE *, int);
void RestoreGame(void);
void RootMoveList(int);
int Search(TREE *RESTRICT, int, int, int, int, int, int, int);
int SearchMove(TREE *RESTRICT, int, int, int, int, int, int, int, int, int);
int SearchMoveList(TREE *RESTRICT, int, int, int, int, int, int *, int, int, int);
int SearchNull(TREE * RESTRICT, int, int, int, int);
void Trace(TREE *RESTRICT, int, int, int, int, int, const char *, int, int, int);
int Search(TREE *, int, int, int, int, int, int, int);
int SearchMove(TREE *, int, int, int, int, int, int, int, int, int);
int SearchMoveList(TREE *, int, int, int, int, int, int *, int, int, int);
int SearchNull(TREE * , int, int, int, int);
void Trace(TREE *, int, int, int, int, int, const char *, int, int, int);
void SetBoard(TREE *, int, char **, int);
void SetChessBitBoards(TREE *);
void SharedFree(void *address);
void SortRootMoves(TREE *RESTRICT, int);
int Split(TREE *RESTRICT);
void SortRootMoves(TREE *, int);
int Split(TREE *);
int StrCnt(char *, char);
int SEE(TREE *RESTRICT, int, int);
int SEEO(TREE *RESTRICT, int, int);
int SEE(TREE *, int, int);
int SEEO(TREE *, int, int);
void Test(char *, FILE *, int, int);
void TestEPD(char *, FILE *, int, int);
void ThreadAffinity(int);
void *STDCALL ThreadInit(void *);
# if !defined(UNIX)
void ThreadMalloc(int64_t);
# endif
int ThreadSplit(TREE *RESTRICT, int, int, int, int, int);
void ThreadStop(TREE *RESTRICT);
void ThreadTrace(TREE * RESTRICT, int, int);
int ThreadWait(int, TREE *RESTRICT);
int ThreadSplit(TREE *, int, int, int, int, int);
void ThreadStop(TREE *);
void ThreadTrace(TREE * , int, int);
int ThreadWait(int, TREE *);
int Threat(TREE *, int, int, int, int);
void TimeAdjust(int, int);
int TimeCheck(TREE *RESTRICT, int);
int TimeCheck(TREE *, int);
void TimeSet(int);
void UnmakeMove(TREE *RESTRICT, int, int, int);
int ValidMove(TREE *RESTRICT, int, int, int);
int VerifyMove(TREE *RESTRICT, int, int, int);
void ValidatePosition(TREE *RESTRICT, int, int, char *);
void UnmakeMove(TREE *, int, int, int);
int ValidMove(TREE *, int, int, int);
int VerifyMove(TREE *, int, int, int);
void ValidatePosition(TREE *, int, int, char *);
void WaitForAllThreadsInitialized(void);
# if !defined(UNIX)
extern void *WinMallocInterleaved(size_t, int);
Expand Down
1 change: 1 addition & 0 deletions src/crafty.c
Expand Up @@ -51,3 +51,4 @@
#include "test.c"
#include "time.c"
#include "validate.c"
#include "boolean.c"
58 changes: 29 additions & 29 deletions src/data.c
Expand Up @@ -22,13 +22,13 @@ char cmd_buffer[4096];
char *args[512];
char buffer[4096];
int line_length = 80;
unsigned char convert_buff[8];
uint8_t convert_buff[8];
int nargs;
int failhi_delta, faillo_delta;
int ponder_value;
int move_actually_played;
int ponder_move;
unsigned ponder_moves[256];
uint32_t ponder_moves[256];
int num_ponder_moves;
int book_move;
int book_learn_eval[LEARN_INTERVAL];
Expand Down Expand Up @@ -423,13 +423,13 @@ uint64_t minus8dir[65];
uint64_t minus9dir[65];
uint64_t mask_eptest[64];
POSITION display;
#if !defined(INLINEASM)
//unsigned char msb[65536];
//unsigned char lsb[65536];
#if defined(NO_INTRIN)
uint8_t msb[65536];
uint8_t lsb[65536];
#endif
unsigned char msb_8bit[256];
unsigned char lsb_8bit[256];
unsigned char pop_cnt_8bit[256];
uint8_t msb_8bit[256];
uint8_t lsb_8bit[256];
uint8_t pop_cnt_8bit[256];
uint64_t mask_pawn_connected[2][64];
uint64_t mask_pawn_isolated[64];
uint64_t mask_passed[2][64];
Expand Down Expand Up @@ -564,9 +564,9 @@ int absolute_time_limit;
int search_time_limit;
int burp;
int quit = 0;
unsigned opponent_start_time, opponent_end_time;
unsigned program_start_time, program_end_time;
unsigned start_time, end_time;
uint32_t opponent_start_time, opponent_end_time;
uint32_t program_start_time, program_end_time;
uint32_t start_time, end_time;
TREE *block[MAX_BLOCKS + 1];
THREAD thread[CPUS];
#if (CPUS > 1)
Expand All @@ -575,13 +575,13 @@ lock_t lock_smp, lock_io;
pthread_attr_t attributes;
#endif
#endif
unsigned int hardware_processors;
unsigned int smp_max_threads = 0;
unsigned int smp_split_group = 8; /* max threads per group */
unsigned int smp_split_at_root = 1; /* enable split at root */
unsigned int smp_min_split_depth = 5; /* don't split within 5 plies of tips */
unsigned int smp_gratuitous_depth = 10; /* gratuitous splits if depth > 10 */
unsigned int smp_gratuitous_limit = 6; /* max gratuitous splits / thread */
int32_t hardware_processors;
int32_t smp_max_threads = 0;
int32_t smp_split_group = 8; /* max threads per group */
int32_t smp_split_at_root = 1; /* enable split at root */
int32_t smp_min_split_depth = 5; /* don't split within 5 plies of tips */
int32_t smp_gratuitous_depth = 10; /* gratuitous splits if depth > 10 */
int32_t smp_gratuitous_limit = 6; /* max gratuitous splits / thread */
int smp_nice = 1; /* terminate idle threads */
int smp_affinity = 0; /* anything >= 0 is enabled */
int smp_affinity_increment = 1; /* if physical cores are zero - N-1
Expand All @@ -607,18 +607,18 @@ struct autotune tune[16] = {
{10, 16, 2, "min gratuitous split depth", "smpgsd", &smp_gratuitous_depth},
{ 1, 8, 2, "gratuitous split limit", "smpgsl", &smp_gratuitous_limit},
};
unsigned parallel_splits;
unsigned parallel_splits_wasted;
unsigned parallel_aborts;
unsigned parallel_joins;
unsigned busy_percent = 0;
uint32_t parallel_splits;
uint32_t parallel_splits_wasted;
uint32_t parallel_aborts;
uint32_t parallel_joins;
uint32_t busy_percent = 0;
uint64_t game_max_blocks = 0;
volatile int smp_split = 0;
volatile int smp_threads = 0;
volatile uint32_t smp_threads = 0;
volatile int initialized_threads = 0;
int crafty_is_white = 0;
unsigned nodes_between_time_checks = 1000000;
unsigned nodes_per_second = 1000000;
uint64_t nodes_between_time_checks = 1000000;
uint64_t nodes_per_second = 1000000;
int next_time_check = 100000;
int transposition_age = 0;
int thinking = 0;
Expand All @@ -642,7 +642,7 @@ int booking = 0;
************************************************************
*/
int display_options = 1 | 2 | 8 | 16 | 32 | 2048;
unsigned noise_level = 100;
uint64_t noise_level = 100;
int noise_block = 0;
int tc_moves = 60;
int tc_time = 180000;
Expand Down Expand Up @@ -728,7 +728,7 @@ const uint64_t magic_bishop_mask[64] = {
0x0028440200000000ull, 0x0050080402000000ull, 0x0020100804020000ull,
0x0040201008040200ull
};
const unsigned magic_bishop_shift[64] = {
const uint32_t magic_bishop_shift[64] = {
58, 59, 59, 59, 59, 59, 59, 58,
59, 59, 59, 59, 59, 59, 59, 59,
59, 59, 57, 57, 57, 57, 59, 59,
Expand Down Expand Up @@ -926,7 +926,7 @@ const uint64_t magic_rook_mask[64] = {
0x6E10101010101000ull, 0x5E20202020202000ull, 0x3E40404040404000ull,
0x7E80808080808000ull
};
const unsigned magic_rook_shift[64] = {
const uint32_t magic_rook_shift[64] = {
52, 53, 53, 53, 53, 53, 53, 52,
53, 54, 54, 54, 54, 54, 54, 53,
53, 54, 54, 54, 54, 54, 54, 53,
Expand Down
68 changes: 36 additions & 32 deletions src/data.h
Expand Up @@ -87,7 +87,7 @@ extern char cmd_buffer[4096];
extern char *args[512];
extern char buffer[4096];
extern int line_length;
extern unsigned char convert_buff[8];
extern uint8_t convert_buff[8];
extern int nargs;
extern int kibitz;
extern int game_wtm;
Expand Down Expand Up @@ -127,7 +127,7 @@ extern int search_move;
extern int ponder;
extern int ponder_move;
extern int force;
extern unsigned ponder_moves[256];
extern uint32_t ponder_moves[256];
extern int num_ponder_moves;
extern char initial_position[80];
extern int predicted;
Expand Down Expand Up @@ -157,9 +157,9 @@ extern int absolute_time_limit;
extern int search_time_limit;
extern int burp;
extern int quit;
extern unsigned opponent_start_time, opponent_end_time;
extern unsigned program_start_time, program_end_time;
extern unsigned start_time, end_time;
extern uint32_t opponent_start_time, opponent_end_time;
extern uint32_t program_start_time, program_end_time;
extern uint32_t start_time, end_time;
extern TREE *block[MAX_BLOCKS + 1];
extern THREAD thread[CPUS];
#if (CPUS > 1)
Expand All @@ -168,40 +168,40 @@ extern lock_t lock_smp, lock_io;
extern pthread_attr_t attributes;
# endif
#endif
extern unsigned int hardware_processors;
extern unsigned int smp_max_threads;
extern unsigned int smp_split_group;
extern unsigned int smp_split_at_root;
extern unsigned int smp_min_split_depth;
extern unsigned int smp_gratuitous_depth;
extern unsigned int smp_gratuitous_limit;
extern int smp_nice;
extern int smp_affinity;
extern int smp_affinity_increment;
extern int smp_numa;
extern int autotune_params;
extern int32_t hardware_processors;
extern int32_t smp_max_threads;
extern int32_t smp_split_group;
extern int32_t smp_split_at_root;
extern int32_t smp_min_split_depth;
extern int32_t smp_gratuitous_depth;
extern int32_t smp_gratuitous_limit;
extern int32_t smp_nice;
extern int32_t smp_affinity;
extern int32_t smp_affinity_increment;
extern int32_t smp_numa;
extern int32_t autotune_params;
extern struct autotune tune[16];
extern unsigned smp_split_nodes;
extern unsigned parallel_splits;
extern unsigned parallel_splits_wasted;
extern unsigned parallel_aborts;
extern unsigned parallel_joins;
extern unsigned busy_percent;
extern uint32_t smp_split_nodes;
extern uint32_t parallel_splits;
extern uint32_t parallel_splits_wasted;
extern uint32_t parallel_aborts;
extern uint32_t parallel_joins;
extern uint32_t busy_percent;
extern uint64_t game_max_blocks;
extern volatile int smp_split;
extern volatile int smp_threads;
extern volatile uint32_t smp_threads;
extern volatile int initialized_threads;
extern int crafty_is_white;
extern unsigned nodes_between_time_checks;
extern unsigned nodes_per_second;
extern uint64_t nodes_between_time_checks;
extern uint64_t nodes_per_second;
extern int next_time_check;
extern int transposition_age;
extern int thinking;
extern int pondering;
extern int puzzling;
extern int booking;
extern int display_options;
extern unsigned noise_level;
extern uint64_t noise_level;
extern int noise_block;
extern int tc_moves;
extern int tc_time;
Expand Down Expand Up @@ -261,7 +261,7 @@ extern const char empty_sqs[9];
extern const int mate[64];
extern const uint64_t magic_rook[64];
extern const uint64_t magic_rook_mask[64];
extern const unsigned magic_rook_shift[64];
extern const uint32_t magic_rook_shift[64];
extern const uint64_t mobility_mask_b[4];
extern const uint64_t mobility_mask_r[4];
extern int16_t *magic_bishop_mobility_indices[64];
Expand All @@ -272,7 +272,7 @@ extern int16_t *magic_rook_mobility_indices[64];
extern int16_t magic_rook_mobility_table[102400];
extern const uint64_t magic_bishop[64];
extern const uint64_t magic_bishop_mask[64];
extern const unsigned magic_bishop_shift[64];
extern const uint32_t magic_bishop_shift[64];
extern uint64_t *magic_bishop_indices[64];
extern uint64_t magic_bishop_table[5248];
extern int16_t *magic_bishop_mobility_indices[64];
Expand Down Expand Up @@ -314,9 +314,13 @@ extern uint64_t minus7dir[65];
extern uint64_t minus8dir[65];
extern uint64_t minus9dir[65];
extern uint64_t mask_eptest[64];
extern unsigned char msb_8bit[256];
extern unsigned char lsb_8bit[256];
extern unsigned char pop_cnt_8bit[256];
#if defined(NO_INTRIN)
uint8_t msb[65536];
uint8_t lsb[65536];
#endif
extern uint8_t msb_8bit[256];
extern uint8_t lsb_8bit[256];
extern uint8_t pop_cnt_8bit[256];
extern uint64_t mask_pawn_connected[2][64];
extern uint64_t mask_pawn_isolated[64];
extern uint64_t mask_passed[2][64];
Expand Down
2 changes: 1 addition & 1 deletion src/drawn.c
Expand Up @@ -23,7 +23,7 @@
* *
*******************************************************************************
*/
int Drawn(TREE * RESTRICT tree, int value) {
int Drawn(TREE *tree, int value) {
/*
************************************************************
* *
Expand Down
2 changes: 1 addition & 1 deletion src/epdglue.c
Expand Up @@ -374,7 +374,7 @@ static mT EGMapFromHostMove(liT move) {

/*--> EGGetIndexedHostPosition: copy from indexed host position */
static
void EGGetIndexedHostPosition(TREE * RESTRICT tree, siT posdex, int active) {
void EGGetIndexedHostPosition(TREE *tree, siT posdex, int active) {
sqT sq;
rbT rb;
cT actc;
Expand Down
34 changes: 17 additions & 17 deletions src/evaluate.c
Expand Up @@ -16,7 +16,7 @@
* *
*******************************************************************************
*/
int Evaluate(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta) {
int Evaluate(TREE *tree, int ply, int wtm, int alpha, int beta) {
PAWN_HASH_ENTRY *ptable;
PXOR *pxtable;
int score, side, can_win = 3, phase, lscore, cutoff;
Expand Down Expand Up @@ -199,7 +199,7 @@ int Evaluate(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta) {
if (tree->pawn_score.passed[black] || tree->pawn_score.passed[white]) {
for (side = black; side <= white; side++)
if (tree->pawn_score.passed[side])
EvaluatePassedPawns(tree, side, wtm);
EvaluatePassedPawns(tree, side);
if ((TotalPieces(white, occupied) == 0 &&
tree->pawn_score.passed[black])
|| (TotalPieces(black, occupied) == 0 &&
Expand Down Expand Up @@ -321,7 +321,7 @@ int Evaluate(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta) {
* *
*******************************************************************************
*/
void EvaluateBishops(TREE * RESTRICT tree, int side) {
void EvaluateBishops(TREE *tree, int side) {
uint64_t temp, moves;
int square, special, i, mobility;
int score_eg = 0, score_mg = 0, enemy = Flip(side), tpawns;
Expand Down Expand Up @@ -450,7 +450,7 @@ void EvaluateBishops(TREE * RESTRICT tree, int side) {
* *
*******************************************************************************
*/
void EvaluateCastling(TREE * RESTRICT tree, int ply, int side) {
void EvaluateCastling(TREE *tree, int ply, int side) {
int enemy = Flip(side), oq, score_mg = 0;;

/*
Expand Down Expand Up @@ -490,7 +490,7 @@ void EvaluateCastling(TREE * RESTRICT tree, int ply, int side) {
* *
*******************************************************************************
*/
int EvaluateDraws(TREE * RESTRICT tree, int ply, int can_win, int score) {
int EvaluateDraws(TREE *tree, int ply, int can_win, int score) {
/*
************************************************************
* *
Expand Down Expand Up @@ -616,7 +616,7 @@ int EvaluateHasOpposition(int on_move, int king, int enemy_king) {
* *
*******************************************************************************
*/
void EvaluateKing(TREE * RESTRICT tree, int ply, int side) {
void EvaluateKing(TREE *tree, int ply, int side) {
int score_eg = 0, score_mg = 0, defects;
int ksq = KingSQ(side), enemy = Flip(side);

Expand Down Expand Up @@ -695,7 +695,7 @@ void EvaluateKing(TREE * RESTRICT tree, int ply, int side) {
* *
*******************************************************************************
*/
int EvaluateKingsFile(TREE * RESTRICT tree, int side, int first, int last) {
int EvaluateKingsFile(TREE *tree, int side, int first, int last) {
int defects = 0, file, enemy = Flip(side);

for (file = first; file <= last; file++)
Expand Down Expand Up @@ -727,7 +727,7 @@ int EvaluateKingsFile(TREE * RESTRICT tree, int side, int first, int last) {
* *
*******************************************************************************
*/
void EvaluateKnights(TREE * RESTRICT tree, int side) {
void EvaluateKnights(TREE *tree, int side) {
uint64_t temp;
int square, special, i, score_eg = 0, score_mg = 0, enemy = Flip(side);

Expand Down Expand Up @@ -792,7 +792,7 @@ void EvaluateKnights(TREE * RESTRICT tree, int side) {
* *
*******************************************************************************
*/
void EvaluateMate(TREE * RESTRICT tree, int side) {
void EvaluateMate(TREE *tree, int side) {
int mate_score = 0, enemy = Flip(side);

/*
Expand Down Expand Up @@ -844,7 +844,7 @@ void EvaluateMate(TREE * RESTRICT tree, int side) {
* *
*******************************************************************************
*/
void EvaluateMaterial(TREE * RESTRICT tree, int wtm) {
void EvaluateMaterial(TREE *tree, int wtm) {
int score_mg, score_eg, majors, minors;

/*
Expand Down Expand Up @@ -913,7 +913,7 @@ void EvaluateMaterial(TREE * RESTRICT tree, int wtm) {
* *
*******************************************************************************
*/
void EvaluatePassedPawns(TREE * RESTRICT tree, int side, int wtm) {
void EvaluatePassedPawns(TREE *tree, int side) {
uint64_t behind, forward, backward, attacked, defended, thispawn;
int file, square, score, score_mg = 0, score_eg = 0, next_sq;
int pawns, rank, mg_base, eg_base, bonus, enemy = Flip(side);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ void EvaluatePassedPawns(TREE * RESTRICT tree, int side, int wtm) {
* *
*******************************************************************************
*/
void EvaluatePassedPawnRaces(TREE * RESTRICT tree, int wtm) {
void EvaluatePassedPawnRaces(TREE *tree, int wtm) {
uint64_t pawns, thispawn;
int file, square, queen_distance, pawnsq, passed, side, enemy;
int queener[2] = { 8, 8 };
Expand Down Expand Up @@ -1242,11 +1242,11 @@ void EvaluatePassedPawnRaces(TREE * RESTRICT tree, int wtm) {
* *
*******************************************************************************
*/
void EvaluatePawns(TREE * RESTRICT tree, int side) {
void EvaluatePawns(TREE *tree, int side) {
uint64_t pawns, attackers, defenders;
uint64_t doubled, supported, connected, passed, backward;
int square, file, rank, score_eg = 0, score_mg = 0, enemy = Flip(side);
unsigned int isolated, pawn_files = 0;
uint32_t isolated, pawn_files = 0;

/*
************************************************************
Expand Down Expand Up @@ -1440,7 +1440,7 @@ void EvaluatePawns(TREE * RESTRICT tree, int side) {
* *
*******************************************************************************
*/
void EvaluateQueens(TREE * RESTRICT tree, int side) {
void EvaluateQueens(TREE *tree, int side) {
uint64_t temp;
int square, i, score_mg = 0, score_eg = 0, enemy = Flip(side);

Expand Down Expand Up @@ -1491,7 +1491,7 @@ void EvaluateQueens(TREE * RESTRICT tree, int side) {
* *
*******************************************************************************
*/
void EvaluateRooks(TREE * RESTRICT tree, int side) {
void EvaluateRooks(TREE *tree, int side) {
uint64_t temp, moves;
int square, rank, file, i, mobility, score_mg = 0, score_eg = 0;
int enemy = Flip(side);
Expand Down Expand Up @@ -1616,7 +1616,7 @@ void EvaluateRooks(TREE * RESTRICT tree, int side) {
* *
*******************************************************************************
*/
int EvaluateWinningChances(TREE * RESTRICT tree, int side, int wtm) {
int EvaluateWinningChances(TREE *tree, int side, int wtm) {
int square, ekd, promote, majors, minors, enemy = Flip(side);

if (!Pawns(side)) {
Expand Down
6 changes: 3 additions & 3 deletions src/hash.c
Expand Up @@ -57,7 +57,7 @@
* *
*******************************************************************************
*/
int HashProbe(TREE * RESTRICT tree, int ply, int depth, int side, int alpha,
int HashProbe(TREE *tree, int ply, int depth, int side, int alpha,
int beta, int *value) {
HASH_ENTRY *htable;
HPATH_ENTRY *ptable;
Expand Down Expand Up @@ -235,7 +235,7 @@ int HashProbe(TREE * RESTRICT tree, int ply, int depth, int side, int alpha,
* *
*******************************************************************************
*/
void HashStore(TREE * RESTRICT tree, int ply, int depth, int side, int type,
void HashStore(TREE *tree, int ply, int depth, int side, int type,
int value, int bestmove) {
HASH_ENTRY *htable, *replace = 0;
HPATH_ENTRY *ptable;
Expand Down Expand Up @@ -366,7 +366,7 @@ void HashStore(TREE * RESTRICT tree, int ply, int depth, int side, int type,
* *
*******************************************************************************
*/
void HashStorePV(TREE * RESTRICT tree, int side, int ply) {
void HashStorePV(TREE *tree, int side, int ply) {
HASH_ENTRY *htable, *replace;
uint64_t temp_hashkey, word1;
int entry, draft, replace_draft, age;
Expand Down
2 changes: 1 addition & 1 deletion src/history.c
Expand Up @@ -21,7 +21,7 @@
* *
*******************************************************************************
*/
void History(TREE * RESTRICT tree, int ply, int depth, int side, int move,
void History(TREE *tree, int ply, int depth, int side, int move,
int searched[]) {
int i, index, mindex;
/*
Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Expand Up @@ -952,7 +952,7 @@ void InitializeMasks(void) {
/*
masks to determine if a pawn has nearby neighbors or not.
*/
#if !defined(INLINEASM)
#if defined(NO_INTRIN)
/*
msb[0] = 64;
lsb[0] = 16;
Expand Down
4 changes: 2 additions & 2 deletions src/inline.h
Expand Up @@ -71,14 +71,14 @@ __forceinline int PopCnt(uint64_t a) {
#endif

__forceinline int MSB(uint64_t a) {
int v;
unsigned long v;

_BitScanReverse64(&v, a);
return v;
}

__forceinline int LSB(uint64_t a) {
int v;
unsigned long v;

_BitScanForward64(&v, a);
return v;
Expand Down
4 changes: 2 additions & 2 deletions src/input.c
Expand Up @@ -15,7 +15,7 @@
* *
*******************************************************************************
*/
int InputMove(TREE * RESTRICT tree, int ply, int wtm, int silent,
int InputMove(TREE *tree, int ply, int wtm, int silent,
int ponder_list, char *text) {
unsigned moves[220], *mv, *mvp, *goodmove = 0;
int piece = -1, capture, promote, give_check;
Expand Down Expand Up @@ -346,7 +346,7 @@ int InputMove(TREE * RESTRICT tree, int ply, int wtm, int silent,
* *
*******************************************************************************
*/
int InputMoveICS(TREE * RESTRICT tree, int ply, int wtm, int silent,
int InputMoveICS(TREE *tree, int ply, int wtm, int silent,
int ponder_list, char *text) {
unsigned moves[220], *mv, *mvp, *goodmove = 0;
int piece = -1, promote;
Expand Down
2 changes: 1 addition & 1 deletion src/iterate.c
Expand Up @@ -46,7 +46,7 @@ int Iterate(int wtm, int search_type, int root_list_done) {
ROOT_MOVE temp_rm;
int i, alpha, beta, current_rm = 0, force_print = 0;
int value = 0, twtm, correct, correct_count, npc, cpl, max;
unsigned int idle_time;
uint32_t idle_time;
char buff[32];
#if (CPUS > 1) && defined(UNIX)
pthread_t pt;
Expand Down
4 changes: 2 additions & 2 deletions src/make.c
Expand Up @@ -21,7 +21,7 @@
* *
*******************************************************************************
*/
void MakeMove(TREE * RESTRICT tree, int ply, int side, int move) {
void MakeMove(TREE *tree, int ply, int side, int move) {
uint64_t bit_move;
int piece, from, to, captured, promote, enemy = Flip(side), cpiece;
#if defined(DEBUG)
Expand Down Expand Up @@ -241,7 +241,7 @@ void MakeMove(TREE * RESTRICT tree, int ply, int side, int move) {
* *
*******************************************************************************
*/
void MakeMoveRoot(TREE * RESTRICT tree, int side, int move) {
void MakeMoveRoot(TREE *tree, int side, int move) {
int player;

/*
Expand Down
10 changes: 5 additions & 5 deletions src/movgen.c
Expand Up @@ -13,7 +13,7 @@
* *
*******************************************************************************
*/
unsigned *GenerateCaptures(TREE * RESTRICT tree, int ply, int side,
unsigned *GenerateCaptures(TREE *tree, int ply, int side,
unsigned *move) {
uint64_t target, piecebd, moves, promotions, pcapturesl, pcapturesr;
int from, to, temp, common, enemy = Flip(side);
Expand Down Expand Up @@ -160,7 +160,7 @@ unsigned *GenerateCaptures(TREE * RESTRICT tree, int ply, int side,
* *
*******************************************************************************
*/
unsigned *GenerateChecks(TREE * RESTRICT tree, int side, unsigned *move) {
unsigned *GenerateChecks(TREE *tree, int side, unsigned *move) {
uint64_t temp_target, target, piecebd, moves;
uint64_t padvances1, blockers, checkers;
int from, to, promote, temp, enemy = Flip(side);
Expand Down Expand Up @@ -438,7 +438,7 @@ unsigned *GenerateChecks(TREE * RESTRICT tree, int side, unsigned *move) {
* *
*******************************************************************************
*/
unsigned *GenerateCheckEvasions(TREE * RESTRICT tree, int ply, int side,
unsigned *GenerateCheckEvasions(TREE *tree, int ply, int side,
unsigned *move) {
uint64_t target, targetc, targetp, piecebd, moves, empty, checksqs;
uint64_t padvances1, padvances2, pcapturesl, pcapturesr, padvances1_all;
Expand Down Expand Up @@ -675,7 +675,7 @@ unsigned *GenerateCheckEvasions(TREE * RESTRICT tree, int ply, int side,
* *
*******************************************************************************
*/
unsigned *GenerateNoncaptures(TREE * RESTRICT tree, int ply, int side,
unsigned *GenerateNoncaptures(TREE *tree, int ply, int side,
unsigned *move) {
uint64_t target, piecebd, moves;
uint64_t padvances1, padvances2, pcapturesl, pcapturesr;
Expand Down Expand Up @@ -852,7 +852,7 @@ unsigned *GenerateNoncaptures(TREE * RESTRICT tree, int ply, int side,
* *
*******************************************************************************
*/
int PinnedOnKing(TREE * RESTRICT tree, int side, int square) {
int PinnedOnKing(TREE *tree, int side, int square) {
int ray, enemy = Flip(side);

/*
Expand Down
8 changes: 4 additions & 4 deletions src/next.c
Expand Up @@ -13,7 +13,7 @@
* *
*******************************************************************************
*/
int NextMove(TREE * RESTRICT tree, int ply, int depth, int side, int in_check) {
int NextMove(TREE *tree, int ply, int depth, int side, int in_check) {
unsigned *movep, *bestp;
int hist, bestval, possible;

Expand Down Expand Up @@ -388,7 +388,7 @@ int NextMove(TREE * RESTRICT tree, int ply, int depth, int side, int in_check) {
* *
*******************************************************************************
*/
int NextRootMove(TREE * RESTRICT tree, TREE * RESTRICT mytree, int side) {
int NextRootMove(TREE *tree, TREE *mytree, int side) {
uint64_t total_nodes;
int which, i, t;

Expand Down Expand Up @@ -565,7 +565,7 @@ int NextRootMoveParallel(void) {
* *
*******************************************************************************
*/
int Exclude(TREE * RESTRICT tree, int ply, int move) {
int Exclude(TREE *tree, int ply, int move) {
unsigned *i;

if (tree->next_status[ply].exclude > &tree->next_status[ply].done[0])
Expand All @@ -586,7 +586,7 @@ int Exclude(TREE * RESTRICT tree, int ply, int move) {
* *
*******************************************************************************
*/
void NextSort(TREE * RESTRICT tree, int ply) {
void NextSort(TREE *tree, int ply) {
unsigned temp, *movep, *tmovep;

/*
Expand Down
10 changes: 5 additions & 5 deletions src/option.c
Expand Up @@ -18,7 +18,7 @@
* *
*******************************************************************************
*/
int Option(TREE * RESTRICT tree) {
int Option(TREE *tree) {
int v;

/*
Expand Down Expand Up @@ -862,7 +862,7 @@ int Option(TREE * RESTRICT tree) {
************************************************************
*/
else if (OptionMatch("hash", *args)) {
size_t old_hash_size = hash_table_size, new_hash_size;
uint64_t old_hash_size = hash_table_size, new_hash_size;

if (thinking || pondering)
return 2;
Expand Down Expand Up @@ -2992,12 +2992,12 @@ int Option(TREE * RESTRICT tree) {
Print(32, " %s |\n", DisplayEvaluation(egb, 1));
mgb = tree->score_mg;
egb = tree->score_eg;
EvaluatePassedPawns(tree, black, game_wtm);
EvaluatePassedPawns(tree, black);
mgb = tree->score_mg - mgb;
egb = tree->score_eg - egb;
mgw = tree->score_mg;
egw = tree->score_eg;
EvaluatePassedPawns(tree, white, game_wtm);
EvaluatePassedPawns(tree, white);
mgw = tree->score_mg - mgw;
egw = tree->score_eg - egw;
tb = (mgb * phase + egb * (62 - phase)) / 62;
Expand Down Expand Up @@ -3979,7 +3979,7 @@ int OptionMatch(char *command, char *input) {
return 0;
}

void OptionPerft(TREE * RESTRICT tree, int ply, int depth, int wtm) {
void OptionPerft(TREE *tree, int ply, int depth, int wtm) {
unsigned *mv;
#if defined(TRACE)
static char line[256];
Expand Down
2 changes: 1 addition & 1 deletion src/output.c
Expand Up @@ -13,7 +13,7 @@
* *
*******************************************************************************
*/
char *OutputMove(TREE * RESTRICT tree, int ply, int wtm, int move) {
char *OutputMove(TREE *tree, int ply, int wtm, int move) {
static char text_move[10], new_text[10];
unsigned *mvp;
char *text = text_move;
Expand Down
4 changes: 2 additions & 2 deletions src/probe.c
Expand Up @@ -33,7 +33,7 @@ typedef uint64_t INDEX;
# else
typedef unsigned long INDEX;
# endif
typedef unsigned int squaret;
typedef uint32_t squaret;

/* Those declarations necessary because Crafty is C, not C++ program */
# if defined (_MSC_VER)
Expand Down Expand Up @@ -77,7 +77,7 @@ extern int TB_FASTCALL L_TbtProbeTable(int, pcolor, INDEX);

# define PfnIndCalc PfnIndCalcFun
# define FRegistered FRegisteredFun
int EGTBProbe(TREE * RESTRICT tree, int ply, int wtm, int *score) {
int EGTBProbe(TREE *tree, int ply, int wtm, int *score) {
int rgiCounters[10], iTb, fInvert;
pcolor side;
squaret rgsqWhite[C_PIECES * 5 + 1], rgsqBlack[C_PIECES * 5 + 1];
Expand Down
4 changes: 2 additions & 2 deletions src/quiesce.c
Expand Up @@ -39,7 +39,7 @@
* *
*******************************************************************************
*/
int Quiesce(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta,
int Quiesce(TREE *tree, int ply, int wtm, int alpha, int beta,
int checks) {
unsigned *next, *movep;
int original_alpha = alpha, value, repeat;
Expand Down Expand Up @@ -285,7 +285,7 @@ int Quiesce(TREE * RESTRICT tree, int ply, int wtm, int alpha, int beta,
* *
*******************************************************************************
*/
int QuiesceEvasions(TREE * RESTRICT tree, int ply, int wtm, int alpha,
int QuiesceEvasions(TREE *tree, int ply, int wtm, int alpha,
int beta) {
int original_alpha, value, moves_searched = 0, order, repeat;

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/repeat.c
Expand Up @@ -31,7 +31,7 @@
* *
*******************************************************************************
*/
int Repeat(TREE * RESTRICT tree, int ply) {
int Repeat(TREE *tree, int ply) {
int where, count;

/*
Expand Down Expand Up @@ -85,7 +85,7 @@ int Repeat(TREE * RESTRICT tree, int ply) {
* *
*******************************************************************************
*/
int Repeat3x(TREE * RESTRICT tree) {
int Repeat3x(TREE *tree) {
int reps = 0, where;

/*
Expand Down
2 changes: 1 addition & 1 deletion src/resign.c
Expand Up @@ -17,7 +17,7 @@
* *
*******************************************************************************
*/
void ResignOrDraw(TREE * RESTRICT tree, int value) {
void ResignOrDraw(TREE *tree, int value) {
int v, result = 0;

/*
Expand Down
36 changes: 18 additions & 18 deletions src/search.c
Expand Up @@ -15,7 +15,7 @@
* *
*******************************************************************************
*/
int Search(TREE * RESTRICT tree, int ply, int depth, int wtm, int alpha,
int Search(TREE *tree, int ply, int depth, int wtm, int alpha,
int beta, int in_check, int do_null) {
int repeat = 0, value = 0, pv_node = alpha != beta - 1, n_depth;
int searched[256];
Expand Down Expand Up @@ -356,18 +356,18 @@ int Search(TREE * RESTRICT tree, int ply, int depth, int wtm, int alpha,
* At that point it simply returns the current negamax value to the caller *
* to handle as necessary. *
* *
* The "mode" flag indicates which of the following conditions apply here *
* The "smode" flag indicates which of the following conditions apply here *
* which directly controls parts of the search. *
* *
* mode = serial -> this is a serial search. *
* smode = serial -> this is a serial search. *
* *
* mode = parallel -> this is a parallel search, which implies that this *
* smode = parallel -> this is a parallel search, which implies that this *
* is a partial search which means we do NOT want to *
* do any trans/ref updating and we also need to take *
* care about locking things that are being updated *
* by more than one thread in parallel. *
* *
* When mode = parallel, this code performs the same function as the old *
* When smode = parallel, this code performs the same function as the old *
* SearchParallel() code, except that it is the main search loop for the *
* program, there is no longer any duplicated code. This is called by the *
* normal Search() function and by ThreadWait() where idle processes wait *
Expand All @@ -376,8 +376,8 @@ int Search(TREE * RESTRICT tree, int ply, int depth, int wtm, int alpha,
* *
*******************************************************************************
*/
int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
int alpha, int beta, int searched[], int in_check, int repeat, int mode) {
int SearchMoveList(TREE *tree, int ply, int depth, int wtm,
int alpha, int beta, int searched[], int in_check, int repeat, int smode) {
TREE *current;
int extend, reduce, check, original_alpha = alpha, t_beta;
int i, j, value = 0, pv_node = alpha != beta - 1, search_result, order;
Expand All @@ -404,7 +404,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
************************************************************
*/
tree->next_status[ply].phase = HASH;
if (mode == parallel) {
if (smode == parallel) {
current = tree->parent;
t_beta = alpha + 1;
} else {
Expand All @@ -431,21 +431,21 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
*/
while (1) {
if (ply == 1 && moves_done == 1 && alpha == original_alpha &&
mode == serial)
smode == serial)
break;
if (mode == parallel)
if (smode == parallel)
Lock(current->lock);
order = (ply > 1) ? NextMove(current, ply, depth, wtm, in_check)
: NextRootMove(current, tree, wtm);
if (mode == parallel) {
if (smode == parallel) {
tree->curmv[ply] = current->curmv[ply];
Unlock(current->lock);
}
if (!order)
break;
#if defined(TRACE)
if (ply <= trace_level)
Trace(tree, ply, depth, wtm, alpha, beta, "SearchMoveList", mode,
Trace(tree, ply, depth, wtm, alpha, beta, "SearchMoveList", smode,
current->phase[ply], order);
#endif
MakeMove(tree, ply, wtm, tree->curmv[ply]);
Expand Down Expand Up @@ -603,7 +603,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
search_result = IN_WINDOW;
if (value >= beta)
search_result = FAIL_HIGH;
if (mode == parallel && ply == 1)
if (smode == parallel && ply == 1)
search_result = FAIL_HIGH;
}
} while (0);
Expand Down Expand Up @@ -650,7 +650,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
}
}
#if (CPUS > 1)
if (mode == parallel) {
if (smode == parallel) {
Lock(lock_smp);
Lock(tree->parent->lock);
if (!tree->stop) {
Expand Down Expand Up @@ -701,7 +701,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
*/
} else if (search_result == IN_WINDOW) {
alpha = value;
if (ply == 1 && mode == serial) {
if (ply == 1 && smode == serial) {
int best;

//
Expand Down Expand Up @@ -830,7 +830,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
************************************************************
*/
#if (CPUS > 1)
if (mode == serial && moves_done && smp_threads &&
if (smode == serial && moves_done && smp_threads &&
ThreadSplit(tree, ply, depth, alpha, original_alpha, moves_done))
do {
tree->alpha = alpha;
Expand Down Expand Up @@ -875,7 +875,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
* *
************************************************************
*/
if (abort_search || tree->stop || mode == parallel)
if (abort_search || tree->stop || smode == parallel)
return alpha;
/*
************************************************************
Expand Down Expand Up @@ -930,7 +930,7 @@ int SearchMoveList(TREE * RESTRICT tree, int ply, int depth, int wtm,
* *
*******************************************************************************
*/
int SearchMove(TREE * RESTRICT tree, int ply, int depth, int wtm, int alpha,
int SearchMove(TREE *tree, int ply, int depth, int wtm, int alpha,
int t_beta, int beta, int extend, int reduce, int check) {
int value;
/*
Expand Down
4 changes: 2 additions & 2 deletions src/see.c
Expand Up @@ -20,7 +20,7 @@
* *
*******************************************************************************
*/
int SEE(TREE * RESTRICT tree, int wtm, int move) {
int SEE(TREE *tree, int wtm, int move) {
uint64_t attacks, temp = 0, toccupied = OccupiedSquares;
uint64_t bsliders =
Bishops(white) | Bishops(black) | Queens(white) | Queens(black);
Expand Down Expand Up @@ -114,7 +114,7 @@ int SEE(TREE * RESTRICT tree, int wtm, int move) {
* *
*******************************************************************************
*/
int SEEO(TREE * RESTRICT tree, int wtm, int move) {
int SEEO(TREE *tree, int wtm, int move) {
uint64_t attacks, temp = 0, toccupied = OccupiedSquares;
uint64_t bsliders =
Bishops(white) | Bishops(black) | Queens(white) | Queens(black);
Expand Down
Empty file modified src/tbconfig.h 100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion src/tbprobe.c 100755 → 100644
Expand Up @@ -31,7 +31,6 @@ SOFTWARE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef uint8_t bool;
#include "tbprobe.h"

#ifdef __cplusplus
Expand Down
Empty file modified src/tbprobe.h 100755 → 100644
Empty file.
16 changes: 8 additions & 8 deletions src/thread.c
Expand Up @@ -170,7 +170,7 @@
* *
*******************************************************************************
*/
int Split(TREE * RESTRICT tree) {
int Split(TREE *tree) {
TREE *child;
int tid, tstart, tend;

Expand Down Expand Up @@ -451,7 +451,7 @@ void *STDCALL ThreadInit(void *t) {
* *
*******************************************************************************
*/
int ThreadSplit(TREE * tree, int ply, int depth, int alpha, int o_alpha,
int ThreadSplit(TREE *tree, int ply, int depth, int alpha, int o_alpha,
int done) {
TREE *used;
int64_t tblocks;
Expand Down Expand Up @@ -555,7 +555,7 @@ int ThreadSplit(TREE * tree, int ply, int depth, int alpha, int o_alpha,
* *
*******************************************************************************
*/
void ThreadStop(TREE * RESTRICT tree) {
void ThreadStop(TREE *tree) {
int proc;

Lock(tree->lock);
Expand All @@ -577,7 +577,7 @@ void ThreadStop(TREE * RESTRICT tree) {
* *
*******************************************************************************
*/
void ThreadTrace(TREE * RESTRICT tree, int depth, int brief) {
void ThreadTrace(TREE *tree, int depth, int brief) {
int proc, i;

Lock(tree->lock);
Expand Down Expand Up @@ -654,7 +654,7 @@ void ThreadTrace(TREE * RESTRICT tree, int depth, int brief) {
* *
*******************************************************************************
*/
int ThreadWait(int tid, TREE * RESTRICT waiting) {
int ThreadWait(int tid, TREE *waiting) {
int value, tstart, tend;

/*
Expand Down Expand Up @@ -736,7 +736,7 @@ int ThreadWait(int tid, TREE * RESTRICT waiting) {
* *
*******************************************************************************
*/
void CopyFromParent(TREE * RESTRICT child) {
void CopyFromParent(TREE *child) {
TREE *parent = child->parent;
int i, ply;

Expand Down Expand Up @@ -804,7 +804,7 @@ void CopyFromParent(TREE * RESTRICT child) {
* *
*******************************************************************************
*/
void CopyToParent(TREE * RESTRICT parent, TREE * RESTRICT child, int value) {
void CopyToParent(TREE *parent, TREE *child, int value) {
int i, ply = parent->ply, which;

/*
Expand Down Expand Up @@ -885,7 +885,7 @@ void CopyToParent(TREE * RESTRICT parent, TREE * RESTRICT child, int value) {
* *
*******************************************************************************
*/
TREE *GetBlock(TREE * RESTRICT parent, int tid) {
TREE *GetBlock(TREE *parent, int tid) {
TREE *child;
static int warnings = 0;
int i, unused;
Expand Down
2 changes: 1 addition & 1 deletion src/time.c
Expand Up @@ -101,7 +101,7 @@ void TimeAdjust(int side, int time_used) {
* *
*******************************************************************************
*/
int TimeCheck(TREE * RESTRICT tree, int busy) {
int TimeCheck(TREE *tree, int busy) {
int time_used;
int i, ndone;

Expand Down
2 changes: 1 addition & 1 deletion src/unmake.c
Expand Up @@ -11,7 +11,7 @@
* *
*******************************************************************************
*/
void UnmakeMove(TREE * RESTRICT tree, int ply, int side, int move) {
void UnmakeMove(TREE *tree, int ply, int side, int move) {
uint64_t bit_move;
int piece, from, to, captured, promote, enemy = Flip(side);

Expand Down
72 changes: 36 additions & 36 deletions src/utility.c
Expand Up @@ -109,12 +109,12 @@ void BookClusterIn(FILE * file, int positions, BOOK_POSITION * buffer) {
perror("BookClusterIn fread error: ");
for (i = 0; i < positions; i++) {
buffer[i].position =
BookIn64((unsigned char *) (file_buffer + i * sizeof(BOOK_POSITION)));
BookIn64((uint8_t *) (file_buffer + i * sizeof(BOOK_POSITION)));
buffer[i].status_played =
BookIn32((unsigned char *) (file_buffer + i * sizeof(BOOK_POSITION) +
BookIn32((uint8_t *) (file_buffer + i * sizeof(BOOK_POSITION) +
8));
buffer[i].learn =
BookIn32f((unsigned char *) (file_buffer + i * sizeof(BOOK_POSITION) +
BookIn32f((uint8_t *) (file_buffer + i * sizeof(BOOK_POSITION) +
12));
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ void BookClusterOut(FILE * file, int positions, BOOK_POSITION * buffer) {
* *
*******************************************************************************
*/
float BookIn32f(unsigned char *ch) {
float BookIn32f(uint8_t *ch) {
union {
float fv;
int iv;
Expand All @@ -171,7 +171,7 @@ float BookIn32f(unsigned char *ch) {
* *
*******************************************************************************
*/
int BookIn32(unsigned char *ch) {
int BookIn32(uint8_t *ch) {
return ch[3] << 24 | ch[2] << 16 | ch[1] << 8 | ch[0];
}

Expand All @@ -184,7 +184,7 @@ int BookIn32(unsigned char *ch) {
* *
*******************************************************************************
*/
uint64_t BookIn64(unsigned char *ch) {
uint64_t BookIn64(uint8_t *ch) {
return (uint64_t) ch[7] << 56 | (uint64_t) ch[6] << 48 | (uint64_t)
ch[5] << 40 | (uint64_t) ch[4] << 32 | (uint64_t) ch[3]
<< 24 | (uint64_t) ch[2] << 16 | (uint64_t) ch[1] << 8 | (uint64_t)
Expand All @@ -200,7 +200,7 @@ uint64_t BookIn64(unsigned char *ch) {
* *
*******************************************************************************
*/
unsigned char *BookOut32(int val) {
uint8_t *BookOut32(int val) {
convert_buff[3] = val >> 24 & 0xff;
convert_buff[2] = val >> 16 & 0xff;
convert_buff[1] = val >> 8 & 0xff;
Expand All @@ -217,7 +217,7 @@ unsigned char *BookOut32(int val) {
* *
*******************************************************************************
*/
unsigned char *BookOut32f(float val) {
uint8_t *BookOut32f(float val) {
union {
float fv;
int iv;
Expand All @@ -240,7 +240,7 @@ unsigned char *BookOut32f(float val) {
* *
*******************************************************************************
*/
unsigned char *BookOut64(uint64_t val) {
uint8_t *BookOut64(uint64_t val) {
convert_buff[7] = val >> 56 & 0xff;
convert_buff[6] = val >> 48 & 0xff;
convert_buff[5] = val >> 40 & 0xff;
Expand Down Expand Up @@ -816,7 +816,7 @@ char *DisplayEvaluationKibitz(int value, int wtm) {
* *
*******************************************************************************
*/
char *DisplayPath(TREE * RESTRICT tree, int wtm, PATH * pv) {
char *DisplayPath(TREE *tree, int wtm, PATH * pv) {
static char buffer[4096];
int i, t_move_number;

Expand Down Expand Up @@ -868,7 +868,7 @@ char *DisplayPath(TREE * RESTRICT tree, int wtm, PATH * pv) {
* *
*******************************************************************************
*/
void DisplayFail(TREE * RESTRICT tree, int type, int level, int wtm, int time,
void DisplayFail(TREE *tree, int type, int level, int wtm, int time,
int move, int value, int force) {
char buffer[4096], *fh_indicator;

Expand Down Expand Up @@ -934,12 +934,12 @@ void DisplayFail(TREE * RESTRICT tree, int type, int level, int wtm, int time,
* *
*******************************************************************************
*/
void DisplayPV(TREE * RESTRICT tree, int level, int wtm, int time, PATH * pv,
void DisplayPV(TREE *tree, int level, int wtm, int time, PATH * pv,
int force) {
char buffer[4096], *buffp, *bufftemp;
char blanks[40] = { " " };
int i, len, t_move_number, nskip = 0, twtm = wtm, pv_depth = pv->pathd;;
unsigned int idle_time;
uint32_t idle_time;

/*
************************************************************
Expand Down Expand Up @@ -1046,7 +1046,7 @@ void DisplayPV(TREE * RESTRICT tree, int level, int wtm, int time, PATH * pv,
* *
*******************************************************************************
*/
char *DisplayHHMMSS(unsigned int time) {
char *DisplayHHMMSS(uint32_t time) {
static char out[32];

time = time / 100;
Expand All @@ -1063,7 +1063,7 @@ char *DisplayHHMMSS(unsigned int time) {
* *
*******************************************************************************
*/
char *DisplayHHMM(unsigned int time) {
char *DisplayHHMM(uint32_t time) {
static char out[10];

time = time / 6000;
Expand Down Expand Up @@ -1118,7 +1118,7 @@ char *DisplayKMB(uint64_t val, int type) {
* *
*******************************************************************************
*/
char *DisplayTime(unsigned int time) {
char *DisplayTime(uint32_t time) {
static char out[10];

if (time < 6000)
Expand Down Expand Up @@ -1146,7 +1146,7 @@ char *DisplayTime(unsigned int time) {
* *
*******************************************************************************
*/
char *Display2Times(unsigned int time) {
char *Display2Times(uint32_t time) {
int ttime, c, spaces;
static char out[20], tout[10];

Expand Down Expand Up @@ -1187,7 +1187,7 @@ char *Display2Times(unsigned int time) {
* *
*******************************************************************************
*/
char *DisplayTimeKibitz(unsigned int time) {
char *DisplayTimeKibitz(uint32_t time) {
static char out[10];

if (time < 6000)
Expand All @@ -1207,7 +1207,7 @@ char *DisplayTimeKibitz(unsigned int time) {
* *
*******************************************************************************
*/
char *FormatPV(TREE * RESTRICT tree, int wtm, PATH pv) {
char *FormatPV(TREE *tree, int wtm, PATH pv) {
int i, t_move_number;
static char buffer[4096];

Expand Down Expand Up @@ -1308,7 +1308,7 @@ int GameOver(int wtm) {
* *
*******************************************************************************
*/
unsigned int ReadClock(void) {
uint32_t ReadClock(void) {
#if defined(UNIX)
struct timeval timeval;
struct timezone timezone;
Expand All @@ -1317,7 +1317,7 @@ unsigned int ReadClock(void) {
gettimeofday(&timeval, &timezone);
return timeval.tv_sec * 100 + (timeval.tv_usec / 10000);
#else
return (unsigned int) GetTickCount() / 10;
return (uint32_t) GetTickCount() / 10;
#endif
}

Expand All @@ -1329,7 +1329,7 @@ unsigned int ReadClock(void) {
* *
*******************************************************************************
*/
int FindBlockID(TREE * RESTRICT which) {
int FindBlockID(TREE *which) {
int i;

for (i = 0; i <= smp_max_threads * 64; i++)
Expand All @@ -1348,7 +1348,7 @@ int FindBlockID(TREE * RESTRICT which) {
* *
*******************************************************************************
*/
int InvalidPosition(TREE * RESTRICT tree) {
int InvalidPosition(TREE *tree) {
int error = 0, wp, wn, wb, wr, wq, wk, bp, bn, bb, br, bq, bk;

wp = PopCnt(Pawns(white));
Expand Down Expand Up @@ -1470,8 +1470,8 @@ int KingPawnSquare(int pawn, int king, int queen, int ptm) {
* *
*******************************************************************************
*/
int Mated(TREE * RESTRICT tree, int ply, int wtm) {
unsigned int rmoves[256], *mvp, *lastm;
int Mated(TREE *tree, int ply, int wtm) {
uint32_t rmoves[256], *mvp, *lastm;
int temp = 0;

/*
Expand Down Expand Up @@ -1645,7 +1645,7 @@ void Print(int vb, char *fmt, ...) {
* *
*******************************************************************************
*/
unsigned int Random32(void) {
uint32_t Random32(void) {
/*
random numbers from Mathematica 2.0.
SeedRandom = 1;
Expand Down Expand Up @@ -1683,7 +1683,7 @@ unsigned int Random32(void) {
j = 55 - 1;
if (--k < 0)
k = 55 - 1;
return (unsigned int) ul;
return (uint32_t) ul;
}

/*
Expand All @@ -1697,7 +1697,7 @@ unsigned int Random32(void) {
*/
uint64_t Random64(void) {
uint64_t result;
unsigned int r1, r2;
uint32_t r1, r2;

r1 = Random32();
r2 = Random32();
Expand Down Expand Up @@ -1849,7 +1849,7 @@ int ReadInput(void) {
* *
*******************************************************************************
*/
int ReadChessMove(TREE * RESTRICT tree, FILE * input, int wtm, int one_move) {
int ReadChessMove(TREE *tree, FILE * input, int wtm, int one_move) {
int move = 0, status;
static char text[128];
char *tmove;
Expand Down Expand Up @@ -1884,7 +1884,7 @@ int ReadChessMove(TREE * RESTRICT tree, FILE * input, int wtm, int one_move) {
* *
*******************************************************************************
*/
int ReadNextMove(TREE * RESTRICT tree, char *text, int ply, int wtm) {
int ReadNextMove(TREE *tree, char *text, int ply, int wtm) {
char *tmove;
int move = 0;

Expand Down Expand Up @@ -2258,7 +2258,7 @@ void Kibitz(int level, int wtm, int depth, int time, int value,
* *
*******************************************************************************
*/
void Output(TREE * RESTRICT tree) {
void Output(TREE *tree) {
int wtm, i;

/*
Expand Down Expand Up @@ -2292,7 +2292,7 @@ void Output(TREE * RESTRICT tree) {
* *
*******************************************************************************
*/
void Trace(TREE * RESTRICT tree, int ply, int depth, int wtm, int alpha,
void Trace(TREE *tree, int ply, int depth, int wtm, int alpha,
int beta, const char *name, int mode, int phase, int order) {
int i;

Expand Down Expand Up @@ -2341,7 +2341,7 @@ int StrCnt(char *string, char testchar) {
* *
*******************************************************************************
*/
int ValidMove(TREE * RESTRICT tree, int ply, int wtm, int move) {
int ValidMove(TREE *tree, int ply, int wtm, int move) {
int btm = Flip(wtm);

/*
Expand Down Expand Up @@ -2467,7 +2467,7 @@ int ValidMove(TREE * RESTRICT tree, int ply, int wtm, int move) {
* *
*******************************************************************************
*/
int VerifyMove(TREE * RESTRICT tree, int ply, int wtm, int move) {
int VerifyMove(TREE *tree, int ply, int wtm, int move) {
unsigned moves[256], *mv, *mvp;

/*
Expand Down Expand Up @@ -2555,7 +2555,7 @@ static void WinNumaInit(void) {
// so ProcessorMask[0] would always be node for thread 0
dwCPU =
pSetThreadIdealProcessor(GetCurrentThread(), MAXIMUM_PROCESSORS);
printf("Current ideal CPU is %llu\n", dwCPU);
printf("Current ideal CPU is %lu\n", dwCPU);
pSetThreadIdealProcessor(GetCurrentThread(), dwCPU);
if ((((DWORD) - 1) != dwCPU) && (MAXIMUM_PROCESSORS != dwCPU)
&& !(ullProcessorMask[0] & (1u << dwCPU))) {
Expand Down Expand Up @@ -2588,7 +2588,7 @@ pthread_t NumaStartThread(void *func, void *args) {
if (ulNumaNode > ulNumaNodes)
ulNumaNode = 0;
ullMask = ullProcessorMask[ulNumaNode];
printf("Starting thread on node " PRId64 " CPU mask %I64d\n", ulNumaNode,
printf("Starting thread on node " PRId64 " CPU mask %ld\n", ulNumaNode,
ullMask);
SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) ullMask);
hThread = (HANDLE) _beginthreadex(0, 0, func, args, CREATE_SUSPENDED, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/validate.c
Expand Up @@ -21,7 +21,7 @@
* *
*******************************************************************************
*/
void ValidatePosition(TREE * RESTRICT tree, int ply, int move, char *caller) {
void ValidatePosition(TREE *tree, int ply, int move, char *caller) {
uint64_t temp, temp1, temp_occ;
uint64_t temp_occx;
int i, square, error = 0;
Expand Down