mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 08:37:44 +00:00
+20
-20
@@ -8,13 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
#include "tbcore.h"
|
#include "tbcore.h"
|
||||||
@@ -68,7 +68,7 @@ static FD open_tb(const char *str, const char *suffix)
|
|||||||
strcat(file, "/");
|
strcat(file, "/");
|
||||||
strcat(file, str);
|
strcat(file, str);
|
||||||
strcat(file, suffix);
|
strcat(file, suffix);
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
fd = open(file, O_RDONLY);
|
fd = open(file, O_RDONLY);
|
||||||
#else
|
#else
|
||||||
fd = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL,
|
fd = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||||
@@ -81,7 +81,7 @@ static FD open_tb(const char *str, const char *suffix)
|
|||||||
|
|
||||||
static void close_tb(FD fd)
|
static void close_tb(FD fd)
|
||||||
{
|
{
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
close(fd);
|
close(fd);
|
||||||
#else
|
#else
|
||||||
CloseHandle(fd);
|
CloseHandle(fd);
|
||||||
@@ -93,7 +93,7 @@ static char *map_file(const char *name, const char *suffix, uint64 *mapping)
|
|||||||
FD fd = open_tb(name, suffix);
|
FD fd = open_tb(name, suffix);
|
||||||
if (fd == FD_ERR)
|
if (fd == FD_ERR)
|
||||||
return NULL;
|
return NULL;
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
fstat(fd, &statbuf);
|
fstat(fd, &statbuf);
|
||||||
*mapping = statbuf.st_size;
|
*mapping = statbuf.st_size;
|
||||||
@@ -124,7 +124,7 @@ static char *map_file(const char *name, const char *suffix, uint64 *mapping)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
static void unmap_file(char *data, uint64 size)
|
static void unmap_file(char *data, uint64 size)
|
||||||
{
|
{
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
@@ -779,10 +779,10 @@ static uint64 calc_factors_piece(int *factor, int num, int order, ubyte *norm, u
|
|||||||
f = 1;
|
f = 1;
|
||||||
for (i = norm[0], k = 0; i < num || k == order; k++) {
|
for (i = norm[0], k = 0; i < num || k == order; k++) {
|
||||||
if (k == order) {
|
if (k == order) {
|
||||||
factor[0] = f;
|
factor[0] = static_cast<int>(f);
|
||||||
f *= pivfac[enc_type];
|
f *= pivfac[enc_type];
|
||||||
} else {
|
} else {
|
||||||
factor[i] = f;
|
factor[i] = static_cast<int>(f);
|
||||||
f *= subfactor(norm[i], n);
|
f *= subfactor(norm[i], n);
|
||||||
n -= norm[i];
|
n -= norm[i];
|
||||||
i += norm[i];
|
i += norm[i];
|
||||||
@@ -804,13 +804,13 @@ static uint64 calc_factors_pawn(int *factor, int num, int order, int order2, uby
|
|||||||
f = 1;
|
f = 1;
|
||||||
for (k = 0; i < num || k == order || k == order2; k++) {
|
for (k = 0; i < num || k == order || k == order2; k++) {
|
||||||
if (k == order) {
|
if (k == order) {
|
||||||
factor[0] = f;
|
factor[0] = static_cast<int>(f);
|
||||||
f *= pfactor[norm[0] - 1][file];
|
f *= pfactor[norm[0] - 1][file];
|
||||||
} else if (k == order2) {
|
} else if (k == order2) {
|
||||||
factor[norm[0]] = f;
|
factor[norm[0]] = static_cast<int>(f);
|
||||||
f *= subfactor(norm[norm[0]], 48 - norm[0]);
|
f *= subfactor(norm[norm[0]], 48 - norm[0]);
|
||||||
} else {
|
} else {
|
||||||
factor[i] = f;
|
factor[i] = static_cast<int>(f);
|
||||||
f *= subfactor(norm[i], n);
|
f *= subfactor(norm[i], n);
|
||||||
n -= norm[i];
|
n -= norm[i];
|
||||||
i += norm[i];
|
i += norm[i];
|
||||||
@@ -984,7 +984,7 @@ static struct PairsData *setup_pairs(unsigned char *data, uint64 tb_size, uint64
|
|||||||
d->min_len = min_len;
|
d->min_len = min_len;
|
||||||
*next = &data[12 + 2 * h + 3 * num_syms + (num_syms & 1)];
|
*next = &data[12 + 2 * h + 3 * num_syms + (num_syms & 1)];
|
||||||
|
|
||||||
int num_indices = (tb_size + (1ULL << idxbits) - 1) >> idxbits;
|
uint64 num_indices = (tb_size + (1ULL << idxbits) - 1) >> idxbits;
|
||||||
size[0] = 6ULL * num_indices;
|
size[0] = 6ULL * num_indices;
|
||||||
size[1] = 2ULL * num_blocks;
|
size[1] = 2ULL * num_blocks;
|
||||||
size[2] = (1ULL << blocksize) * real_num_blocks;
|
size[2] = (1ULL << blocksize) * real_num_blocks;
|
||||||
@@ -1163,7 +1163,7 @@ static int init_table_dtz(struct TBEntry *entry)
|
|||||||
if (ptr->flags & 2) {
|
if (ptr->flags & 2) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
ptr->map_idx[i] = (data + 1 - ptr->map);
|
ptr->map_idx[i] = static_cast<ushort>(data + 1 - ptr->map);
|
||||||
data += 1 + data[0];
|
data += 1 + data[0];
|
||||||
}
|
}
|
||||||
data += ((uintptr_t)data) & 0x01;
|
data += ((uintptr_t)data) & 0x01;
|
||||||
@@ -1197,7 +1197,7 @@ static int init_table_dtz(struct TBEntry *entry)
|
|||||||
if (ptr->flags[f] & 2) {
|
if (ptr->flags[f] & 2) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
ptr->map_idx[f][i] = (data + 1 - ptr->map);
|
ptr->map_idx[f][i] = static_cast<ushort>(data + 1 - ptr->map);
|
||||||
data += 1 + data[0];
|
data += 1 + data[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1230,11 +1230,11 @@ static ubyte decompress_pairs(struct PairsData *d, uint64 idx)
|
|||||||
if (!d->idxbits)
|
if (!d->idxbits)
|
||||||
return d->min_len;
|
return d->min_len;
|
||||||
|
|
||||||
uint32 mainidx = idx >> d->idxbits;
|
uint32 mainidx = static_cast<uint32>(idx >> d->idxbits);
|
||||||
int litidx = (idx & ((1 << d->idxbits) - 1)) - (1 << (d->idxbits - 1));
|
int litidx = (idx & ((1ULL << d->idxbits) - 1)) - (1ULL << (d->idxbits - 1));
|
||||||
uint32 block = *(uint32 *)(d->indextable + 6 * mainidx);
|
uint32 block = *(uint32 *)(d->indextable + 6 * mainidx);
|
||||||
if (!LittleEndian)
|
if (!LittleEndian)
|
||||||
block = __builtin_bswap32(block);
|
block = BSWAP32(block);
|
||||||
|
|
||||||
ushort idxOffset = *(ushort *)(d->indextable + 6 * mainidx + 4);
|
ushort idxOffset = *(ushort *)(d->indextable + 6 * mainidx + 4);
|
||||||
if (!LittleEndian)
|
if (!LittleEndian)
|
||||||
@@ -1260,7 +1260,7 @@ static ubyte decompress_pairs(struct PairsData *d, uint64 idx)
|
|||||||
|
|
||||||
uint64 code = *((uint64 *)ptr);
|
uint64 code = *((uint64 *)ptr);
|
||||||
if (LittleEndian)
|
if (LittleEndian)
|
||||||
code = __builtin_bswap64(code);
|
code = BSWAP64(code);
|
||||||
|
|
||||||
ptr += 2;
|
ptr += 2;
|
||||||
bitcnt = 0; // number of "empty bits" in code
|
bitcnt = 0; // number of "empty bits" in code
|
||||||
@@ -1270,7 +1270,7 @@ static ubyte decompress_pairs(struct PairsData *d, uint64 idx)
|
|||||||
sym = offset[l];
|
sym = offset[l];
|
||||||
if (!LittleEndian)
|
if (!LittleEndian)
|
||||||
sym = ((sym & 0xff) << 8) | (sym >> 8);
|
sym = ((sym & 0xff) << 8) | (sym >> 8);
|
||||||
sym += ((code - base[l]) >> (64 - l));
|
sym += static_cast<int>((code - base[l]) >> (64 - l));
|
||||||
if (litidx < (int)symlen[sym] + 1) break;
|
if (litidx < (int)symlen[sym] + 1) break;
|
||||||
litidx -= (int)symlen[sym] + 1;
|
litidx -= (int)symlen[sym] + 1;
|
||||||
code <<= l;
|
code <<= l;
|
||||||
@@ -1279,7 +1279,7 @@ static ubyte decompress_pairs(struct PairsData *d, uint64 idx)
|
|||||||
bitcnt -= 32;
|
bitcnt -= 32;
|
||||||
uint32 tmp = *ptr++;
|
uint32 tmp = *ptr++;
|
||||||
if (LittleEndian)
|
if (LittleEndian)
|
||||||
tmp = __builtin_bswap32(tmp);
|
tmp = BSWAP32(tmp);
|
||||||
code |= ((uint64)tmp) << bitcnt;
|
code |= ((uint64)tmp) << bitcnt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-3
@@ -5,7 +5,7 @@
|
|||||||
#ifndef TBCORE_H
|
#ifndef TBCORE_H
|
||||||
#define TBCORE_H
|
#define TBCORE_H
|
||||||
|
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#define SEP_CHAR ':'
|
#define SEP_CHAR ':'
|
||||||
#define FD int
|
#define FD int
|
||||||
@@ -17,16 +17,22 @@
|
|||||||
#define FD_ERR INVALID_HANDLE_VALUE
|
#define FD_ERR INVALID_HANDLE_VALUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __WIN32__
|
#ifndef _WIN32
|
||||||
#define LOCK_T pthread_mutex_t
|
#define LOCK_T pthread_mutex_t
|
||||||
#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
|
#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
|
||||||
#define LOCK(x) pthread_mutex_lock(&(x))
|
#define LOCK(x) pthread_mutex_lock(&(x))
|
||||||
#define UNLOCK(x) pthread_mutex_unlock(&(x))
|
#define UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||||
|
|
||||||
|
#define BSWAP32(v) __builtin_bswap32(v)
|
||||||
|
#define BSWAP64(v) __builtin_bswap64(v)
|
||||||
#else
|
#else
|
||||||
#define LOCK_T HANDLE
|
#define LOCK_T HANDLE
|
||||||
#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
|
#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
|
||||||
#define LOCK(x) WaitForSingleObject(x, INFINITE)
|
#define LOCK(x) WaitForSingleObject(x, INFINITE)
|
||||||
#define UNLOCK(x) ReleaseMutex(x)
|
#define UNLOCK(x) ReleaseMutex(x)
|
||||||
|
|
||||||
|
#define BSWAP32(v) _byteswap_ulong(v)
|
||||||
|
#define BSWAP64(v) _byteswap_uint64(v)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WDLSUFFIX ".rtbw"
|
#define WDLSUFFIX ".rtbw"
|
||||||
@@ -70,7 +76,11 @@ struct TBEntry {
|
|||||||
ubyte num;
|
ubyte num;
|
||||||
ubyte symmetric;
|
ubyte symmetric;
|
||||||
ubyte has_pawns;
|
ubyte has_pawns;
|
||||||
} __attribute__((__may_alias__));
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
__attribute__((__may_alias__))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
struct TBEntry_piece {
|
struct TBEntry_piece {
|
||||||
char *data;
|
char *data;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
this code to other chess engines.
|
this code to other chess engines.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "../position.h"
|
#include "../position.h"
|
||||||
#include "../movegen.h"
|
#include "../movegen.h"
|
||||||
#include "../bitboard.h"
|
#include "../bitboard.h"
|
||||||
@@ -144,7 +146,11 @@ static int probe_wdl_table(Position& pos, int *success)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Memory barrier to ensure ptr->ready = 1 is not reordered.
|
// Memory barrier to ensure ptr->ready = 1 is not reordered.
|
||||||
|
#ifdef _WIN32
|
||||||
|
_ReadWriteBarrier();
|
||||||
|
#else
|
||||||
__asm__ __volatile__ ("" ::: "memory");
|
__asm__ __volatile__ ("" ::: "memory");
|
||||||
|
#endif
|
||||||
ptr->ready = 1;
|
ptr->ready = 1;
|
||||||
}
|
}
|
||||||
UNLOCK(TB_mutex);
|
UNLOCK(TB_mutex);
|
||||||
|
|||||||
Reference in New Issue
Block a user