/* last modified 01/18/09 */
/*
*******************************************************************************
* *
* This module is designed for the most efficient compiling, as it includes *
* all of the source files into one large wad so that the compiler can see *
* all function calls and inline whatever is appropriate. The includes are *
* loosely ordered so that the most common functions occur first, to help *
* with cache layout when the code is actually loaded. *
* *
*******************************************************************************
*/
#define TB_HAVE_THREADS
# ifdef TB_HAVE_THREADS
# ifndef _WIN32 // Pierre-Marie Baty -- fixed include guard
# define LOCK_T pthread_mutex_t
# define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
# define LOCK(x) pthread_mutex_lock(&(x))
# define UNLOCK(x) pthread_mutex_unlock(&(x))
# else
# define LOCK_T HANDLE
# define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
# define LOCK(x) WaitForSingleObject(x, INFINITE)
# define UNLOCK(x) ReleaseMutex(x)
# endif
# else /* !TB_HAVE_THREADS */
# define LOCK_T int
# define LOCK_INIT(x)
/* NOP */
# define LOCK(x)
/* NOP */
# define UNLOCK(x)
/* NOP */
# endif
int __builtin_clzll (unsigned long long x)
{
// Returns the number of leading 0-bits in x, starting at the most significant bit position.
// If x is zero, the result is undefined.
// This uses a binary search (counting down) algorithm from Hacker's Delight.
unsigned long long y;
int n = 64;
y = x >> 32; if (y != 0) { n = n - 32; x = y; }
y = x >> 16; if (y != 0) { n = n - 16; x = y; }
y = x >> 8; if (y != 0) { n = n - 8; x = y; }
y = x >> 4; if (y != 0) { n = n - 4; x = y; }
y = x >> 2; if (y != 0) { n = n - 2; x = y; }
y = x >> 1; if (y != 0) return (n - 2);
return (n - (int) x);
}
int __builtin_ctzll (unsigned long long x)
{
// Returns the number of trailing 0-bits in x, starting at the least significant bit position.
// If x is zero, the result is undefined.
// This uses a binary search algorithm from Hacker's Delight.
int n = 1;
if ((x & 0x00000000FFFFFFFF) == 0) { n = n + 32; x = x >> 32; }
if ((x & 0x000000000000FFFF) == 0) { n = n + 16; x = x >> 16; }
if ((x & 0x00000000000000FF) == 0) { n = n + 8; x = x >> 8; }
if ((x & 0x000000000000000F) == 0) { n = n + 4; x = x >> 4; }
if ((x & 0x0000000000000003) == 0) { n = n + 2; x = x >> 2; }
return (n - (x & 1));
}
int __builtin_popcountll (unsigned long long x)
{
// counts the number of 1-bits in x
x = (x & 0x5555555555555555ULL) + ((x >> 1) & 0x5555555555555555ULL);
x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL);
x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x >> 4) & 0x0F0F0F0F0F0F0F0FULL);
return (int) ((x * 0x0101010101010101ULL) >> 56);
}
#define __builtin_bswap32 _byteswap_ulong
#include "iterate.c"
#include "search.c"
#include "movgen.c"
#include "make.c"
#include "unmake.c"
#include "thread.c"
#include "repeat.c"
#include "next.c"
#include "history.c"
#include "quiesce.c"
#include "evaluate.c"
#include "hash.c"
#include "attacks.c"
#include "see.c"
#include "utility.c"
#include "tbprobe.c"
#include "book.c"
#include "autotune.c"
#include "analyze.c"
#include "annotate.c"
#include "bench.c"
#include "data.c"
#include "drawn.c"
#include "edit.c"
#include "epd.c"
#include "epdglue.c"
#include "evtest.c"
#include "init.c"
#include "input.c"
#include "interrupt.c"
#include "learn.c"
#include "main.c"
#include "option.c"
#include "output.c"
#include "ponder.c"
#include "resign.c"
#include "root.c"
#include "setboard.c"
#include "test.c"
#include "time.c"
#include "validate.c"