Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
geko authored and geko committed Jun 18, 2015
1 parent 1cbc942 commit 0f0a139
Show file tree
Hide file tree
Showing 31 changed files with 2,354 additions and 2,367 deletions.
51 changes: 26 additions & 25 deletions src/Bits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,93 +18,94 @@

#include "Bits.h"
#include <iostream>

Bits::Bits() {
//LINK_ROOKS
LINK_ROOKS = (u64**) malloc(64 * sizeof(u64*));
for(int i = 0; i < 64; i++) {
LINK_ROOKS[i] = (u64*) malloc(64 * sizeof(u64));
LINK_ROOKS = (u64 **) malloc(64 * sizeof(u64 *));
for (int i = 0; i < 64; i++) {
LINK_ROOKS[i] = (u64 *) malloc(64 * sizeof(u64));
}
int from, to;
for(int i = 0; i < 64; i++) {
for(int j = 0; j < 64; j++) {
for (int i = 0; i < 64; i++) {
for (int j = 0; j < 64; j++) {
u64 t = 0;
if(RANK[i] & RANK[j]) { //rank
if (RANK[i] & RANK[j]) { //rank
from = min(i, j);
to = max(i, j);
for(int k = from + 1; k <= to - 1; k++) {
for (int k = from + 1; k <= to - 1; k++) {
t |= POW2[k];
}
} else if(FILE_[i] & FILE_[j]) { //file
} else if (FILE_[i] & FILE_[j]) { //file
from = min(i, j);
to = max(i, j);
for(int k = from + 8; k <= to - 8; k += 8) {
for (int k = from + 8; k <= to - 8; k += 8) {
t |= POW2[k];
}
}
if(!t) {
if (!t) {
t = 0xffffffffffffffffULL;
}
LINK_ROOKS[i][j] = t;
}
}
//DISTANCE
for(int i = 0; i < 64; i++) {
for(int j = 0; j < 64; j++) {
for (int i = 0; i < 64; i++) {
for (int j = 0; j < 64; j++) {
DISTANCE[i][j] = max(abs(RANK_AT[i] - FILE_AT[j]), abs(RANK_AT[j] - FILE_AT[i]));
}
}
///
u64 MASK_BIT_SET[64][64];
memset(MASK_BIT_SET, 0, sizeof(MASK_BIT_SET));
for(int i = 0; i < 64; i++) {
for(int j = 0; j < 64; j++) {
for (int i = 0; i < 64; i++) {
for (int j = 0; j < 64; j++) {
int a = min(i, j);
int b = max(i, j);
MASK_BIT_SET[i][i] = 0;
for(int e = a; e <= b; e++) {
for (int e = a; e <= b; e++) {
u64 r = (RANK[i] | POW2[i]) & (RANK[j] | POW2[j]);
if(r) {
if (r) {
MASK_BIT_SET[i][j] |= POW2[e] & r;
} else {
r = (FILE_[i] | POW2[i]) & (FILE_[j] | POW2[j]);
if(r) {
if (r) {
MASK_BIT_SET[i][j] |= POW2[e] & r;
} else {
r = (LEFT_DIAG[i] | POW2[i]) & (LEFT_DIAG[j] | POW2[j]);
if(r) {
if (r) {
MASK_BIT_SET[i][j] |= POW2[e] & r;
} else {
r = (RIGHT_DIAG[i] | POW2[i]) & (RIGHT_DIAG[j] | POW2[j]);
if(r) {
if (r) {
MASK_BIT_SET[i][j] |= POW2[e] & r;
}
}
}
}
}
if(i == j) {
if (i == j) {
MASK_BIT_SET[i][i] &= NOTPOW2[i];
}
}
}
for(int i = 0; i < 64; i++) {
for(int j = 0; j < 64; j++) {
for (int i = 0; i < 64; i++) {
for (int j = 0; j < 64; j++) {
MASK_BIT_SET_NOBOUND[i][j] = MASK_BIT_SET[i][j];
MASK_BIT_SET_NOBOUND[i][j] &= NOTPOW2[i];
MASK_BIT_SET_NOBOUND[i][j] &= NOTPOW2[j];
MASK_BIT_SET[i][j] &= NOTPOW2[i];
}
}
for(int i = 0; i < 64; i++) {
for(int j = 0; j < 64; j++) {
for (int i = 0; i < 64; i++) {
for (int j = 0; j < 64; j++) {
MASK_BIT_SET_COUNT[i][j] = bitCount(MASK_BIT_SET[i][j]);
MASK_BIT_SET_NOBOUND_COUNT[i][j] = bitCount(MASK_BIT_SET_NOBOUND[i][j]);
}
}
}

Bits::~Bits() {
for(int i = 0; i < 64; i++) {
for (int i = 0; i < 64; i++) {
free(LINK_ROOKS[i]);
}
free(LINK_ROOKS);
Expand Down
38 changes: 12 additions & 26 deletions src/Bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@

#ifndef _BITS_H_
#define _BITS_H_

#include "namespaces.h"

class Bits {
public:

Bits();

virtual ~Bits();

#ifdef HAS_POPCNT
static int bitCount(u64 bits) {
return __builtin_popcountll(bits);
}
#else

static int bitCount(u64 bits) {
int count = 0;
while(bits) {
while (bits) {
count++;
bits &= bits - 1;
}
return count;
}

#endif
protected:

Expand All @@ -46,15 +51,14 @@ class Bits {
char MASK_BIT_SET_COUNT[64][64];
char MASK_BIT_SET_NOBOUND_COUNT[64][64];

u64** LINK_ROOKS;
u64 **LINK_ROOKS;

template <int side, int shift>
template<int side, int shift>
static u64 shiftForward(const u64 bits) {
return side == WHITE ? bits <<shift : bits>> shift;
return side == WHITE ? bits << shift : bits >> shift;
}



#ifdef HAS_BSF
#if UINTPTR_MAX == 0xffffffffffffffff
static int BITScanForward(u64 bits) {
Expand All @@ -76,19 +80,9 @@ class Bits {
#else



static int BITScanForward(u64 bb) {
// @author Matt Taylor (2003)
static const int lsb_64_table[64] = {
63, 30, 3, 32, 59, 14, 11, 33,
60, 24, 50, 9, 55, 19, 21, 34,
61, 29, 2, 53, 51, 23, 41, 18,
56, 28, 1, 43, 46, 27, 0, 35,
62, 31, 58, 4, 5, 49, 54, 6,
15, 52, 12, 40, 7, 42, 45, 16,
25, 57, 48, 13, 10, 39, 8, 44,
20, 47, 38, 22, 17, 37, 36, 26
};
static const int lsb_64_table[64] = {63, 30, 3, 32, 59, 14, 11, 33, 60, 24, 50, 9, 55, 19, 21, 34, 61, 29, 2, 53, 51, 23, 41, 18, 56, 28, 1, 43, 46, 27, 0, 35, 62, 31, 58, 4, 5, 49, 54, 6, 15, 52, 12, 40, 7, 42, 45, 16, 25, 57, 48, 13, 10, 39, 8, 44, 20, 47, 38, 22, 17, 37, 36, 26};
unsigned int folded;
bb ^= bb - 1;
folded = (int) bb ^ (bb >> 32);
Expand All @@ -98,16 +92,7 @@ class Bits {

static int BITScanReverse(u64 bb) {
// authors Kim Walisch, Mark Dickinson
static const int index64[64] = {
0, 47, 1, 56, 48, 27, 2, 60,
57, 49, 41, 37, 28, 16, 3, 61,
54, 58, 35, 52, 50, 42, 21, 44,
38, 32, 29, 23, 17, 11, 4, 62,
46, 55, 26, 59, 40, 36, 15, 53,
34, 51, 20, 43, 31, 22, 10, 45,
25, 39, 14, 33, 19, 30, 9, 24,
13, 18, 8, 12, 7, 6, 5, 63
};
static const int index64[64] = {0, 47, 1, 56, 48, 27, 2, 60, 57, 49, 41, 37, 28, 16, 3, 61, 54, 58, 35, 52, 50, 42, 21, 44, 38, 32, 29, 23, 17, 11, 4, 62, 46, 55, 26, 59, 40, 36, 15, 53, 34, 51, 20, 43, 31, 22, 10, 45, 25, 39, 14, 33, 19, 30, 9, 24, 13, 18, 8, 12, 7, 6, 5, 63};
static const u64 debruijn64 = 0x03f79d71b4cb0a89ULL;
bb |= bb >> 1;
bb |= bb >> 2;
Expand All @@ -120,4 +105,5 @@ class Bits {

#endif
};

#endif
Loading

0 comments on commit 0f0a139

Please sign in to comment.