Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
96 pmbaty 1
/*
2
  Copyright (c) 2011-2013 Ronald de Man
3
*/
4
 
5
#ifndef TBCORE_H
6
#define TBCORE_H
7
 
8
#ifndef _WIN32
9
#include <pthread.h>
10
#define SEP_CHAR ':'
11
#define FD int
12
#define FD_ERR -1
13
#else
14
#include <windows.h>
15
#define SEP_CHAR ';'
16
#define FD HANDLE
17
#define FD_ERR INVALID_HANDLE_VALUE
18
#endif
19
 
20
#ifndef _WIN32
21
#define LOCK_T pthread_mutex_t
22
#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
23
#define LOCK(x) pthread_mutex_lock(&(x))
24
#define UNLOCK(x) pthread_mutex_unlock(&(x))
25
#else
26
#define LOCK_T HANDLE
27
#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
28
#define LOCK(x) WaitForSingleObject(x, INFINITE)
29
#define UNLOCK(x) ReleaseMutex(x)
30
#endif
31
 
32
#ifndef _MSC_VER
33
#define BSWAP32(v) __builtin_bswap32(v)
34
#define BSWAP64(v) __builtin_bswap64(v)
35
#else
36
#define BSWAP32(v) _byteswap_ulong(v)
37
#define BSWAP64(v) _byteswap_uint64(v)
38
#endif
39
 
40
#define WDLSUFFIX ".rtbw"
41
#define DTZSUFFIX ".rtbz"
42
#define WDLDIR "RTBWDIR"
43
#define DTZDIR "RTBZDIR"
44
#define TBPIECES 6
45
 
46
typedef unsigned long long uint64;
47
typedef unsigned int uint32;
48
typedef unsigned char ubyte;
49
typedef unsigned short ushort;
50
 
51
const ubyte WDL_MAGIC[4] = { 0x71, 0xe8, 0x23, 0x5d };
52
const ubyte DTZ_MAGIC[4] = { 0xd7, 0x66, 0x0c, 0xa5 };
53
 
54
#define TBHASHBITS 10
55
 
56
struct TBHashEntry;
57
 
58
typedef uint64 base_t;
59
 
60
struct PairsData {
61
  char *indextable;
62
  ushort *sizetable;
63
  ubyte *data;
64
  ushort *offset;
65
  ubyte *symlen;
66
  ubyte *sympat;
67
  int blocksize;
68
  int idxbits;
69
  int min_len;
70
  base_t base[1]; // C++ complains about base[]...
71
};
72
 
73
struct TBEntry {
74
  char *data;
75
  uint64 key;
76
  uint64 mapping;
77
  ubyte ready;
78
  ubyte num;
79
  ubyte symmetric;
80
  ubyte has_pawns;
81
}
82
#ifndef _WIN32
83
__attribute__((__may_alias__))
84
#endif
85
;
86
 
87
struct TBEntry_piece {
88
  char *data;
89
  uint64 key;
90
  uint64 mapping;
91
  ubyte ready;
92
  ubyte num;
93
  ubyte symmetric;
94
  ubyte has_pawns;
95
  ubyte enc_type;
96
  struct PairsData *precomp[2];
97
  int factor[2][TBPIECES];
98
  ubyte pieces[2][TBPIECES];
99
  ubyte norm[2][TBPIECES];
100
};
101
 
102
struct TBEntry_pawn {
103
  char *data;
104
  uint64 key;
105
  uint64 mapping;
106
  ubyte ready;
107
  ubyte num;
108
  ubyte symmetric;
109
  ubyte has_pawns;
110
  ubyte pawns[2];
111
  struct {
112
    struct PairsData *precomp[2];
113
    int factor[2][TBPIECES];
114
    ubyte pieces[2][TBPIECES];
115
    ubyte norm[2][TBPIECES];
116
  } file[4];
117
};
118
 
119
struct DTZEntry_piece {
120
  char *data;
121
  uint64 key;
122
  uint64 mapping;
123
  ubyte ready;
124
  ubyte num;
125
  ubyte symmetric;
126
  ubyte has_pawns;
127
  ubyte enc_type;
128
  struct PairsData *precomp;
129
  int factor[TBPIECES];
130
  ubyte pieces[TBPIECES];
131
  ubyte norm[TBPIECES];
132
  ubyte flags; // accurate, mapped, side
133
  ushort map_idx[4];
134
  ubyte *map;
135
};
136
 
137
struct DTZEntry_pawn {
138
  char *data;
139
  uint64 key;
140
  uint64 mapping;
141
  ubyte ready;
142
  ubyte num;
143
  ubyte symmetric;
144
  ubyte has_pawns;
145
  ubyte pawns[2];
146
  struct {
147
    struct PairsData *precomp;
148
    int factor[TBPIECES];
149
    ubyte pieces[TBPIECES];
150
    ubyte norm[TBPIECES];
151
  } file[4];
152
  ubyte flags[4];
153
  ushort map_idx[4][4];
154
  ubyte *map;
155
};
156
 
157
struct TBHashEntry {
158
  uint64 key;
159
  struct TBEntry *ptr;
160
};
161
 
162
struct DTZTableEntry {
163
  uint64 key1;
164
  uint64 key2;
165
  struct TBEntry *entry;
166
};
167
 
168
#endif
169