Compare commits

...

12 Commits

Author SHA1 Message Date
Marco Costalba e0a8b36436 Stockfish 1.6.2
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-30 13:25:20 +01:00
Marco Costalba 8d724220a7 Better fix for gcc optimization issue
According to the standard, compiler is free to choose
the enum type as long as can keep its data.
Also cast to short and right shift are implementation
defined in case of a signed integer.

Normally all the compilers implement this stuff in
the "usual" way, but gcc with -O3 and -O2 pushes
aggressively the language to its limits to squeeze
even the last bit of speed. And this broke our
not 100% standard conforming code.

The fix is to rewrite the Score enum and the 16 bits
word extracting functions in a way that is 100% standard
compliant and with no speed regression on gcc and also on
the other compilers.

Verified it works on all compilers and with equivalent
functionality.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-30 13:25:02 +01:00
Marco Costalba 0973cc2ef6 Score enum should be at least 32 bits
The compiler is allowed to chose the size of an enum variable
based on the values it is expected to store. So force the compiler
to use at least a 32 bit integer type for the Score.

MSVC and Intel do not change, while gcc under -O3 is affected
by this change.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-27 19:45:19 +01:00
Marco Costalba 3f14f9a478 Revert small pop_1st_bit() optimization
We cannot cast a pointer type to an unrelated pointer type.
This is a violation of the strict aliasing rules.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-27 14:07:08 +01:00
Marco Costalba aa86d81f79 Remove a bogus assert
It is not clear why is not true, even in single thread
case, but as a matter of fact it is not!

So remove it.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-27 13:54:46 +01:00
Marco Costalba b884351cc7 Use THREAD_MAX instead of hardcoded 8
This will allow to change THREAD_MAX value in the future.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-27 13:52:29 +01:00
Marco Costalba 4d9e9ac3d4 Restore development version
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-27 08:35:44 +01:00
Marco Costalba 3dc9f95225 Set maximum hash table size to 2GB
We cannot allocate more then 2 GB, so let the limit
reflect this.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-27 00:44:08 +01:00
Marco Costalba bc0871acbc Stockfish 1.6.1
Workaround a gcc optimization bug.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-26 19:39:22 +01:00
Marco Costalba 2643f1552f Workaround optimization bug in gcc
Unfortunatly we need to slow down to -O1 to be sure
it works always.

Note that sometime it works also with -O2 or even -O3,
but user has to try himself.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-26 19:39:13 +01:00
Marco Costalba ba07b95ee0 Fix description of Score enum
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-26 19:39:04 +01:00
Marco Costalba ef58551a2d Fix a typo in ReducedStateInfo
It happened to work by accident because Score and
Value are both integer.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2009-12-26 19:38:53 +01:00
8 changed files with 38 additions and 25 deletions
+9 -7
View File
@@ -348,19 +348,21 @@ union b_union {
Square pop_1st_bit(Bitboard* bb) { Square pop_1st_bit(Bitboard* bb) {
b_union* u; b_union u;
Square ret; Square ret;
u = (b_union*)bb; u.b = *bb;
if (u->dw.l) if (u.dw.l)
{ {
ret = Square(BitTable[((u->dw.l ^ (u->dw.l - 1)) * 0x783a9b23) >> 26]); ret = Square(BitTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783a9b23) >> 26]);
u->dw.l &= (u->dw.l - 1); u.dw.l &= (u.dw.l - 1);
*bb = u.b;
return ret; return ret;
} }
ret = Square(BitTable[((~(u->dw.h ^ (u->dw.h - 1))) * 0x783a9b23) >> 26]); ret = Square(BitTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783a9b23) >> 26]);
u->dw.h &= (u->dw.h - 1); u.dw.h &= (u.dw.h - 1);
*bb = u.b;
return ret; return ret;
} }
+4 -3
View File
@@ -251,9 +251,10 @@ namespace {
// in init_safety(). // in init_safety().
Value SafetyTable[100]; Value SafetyTable[100];
// Pawn and material hash tables, indexed by the current thread id // Pawn and material hash tables, indexed by the current thread id.
MaterialInfoTable* MaterialTable[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // Note that they will be initialized at 0 being global variables.
PawnInfoTable* PawnTable[8] = {0, 0, 0, 0, 0, 0, 0, 0}; MaterialInfoTable* MaterialTable[THREAD_MAX];
PawnInfoTable* PawnTable[THREAD_MAX];
// Sizes of pawn and material hash tables // Sizes of pawn and material hash tables
const int PawnTableSize = 16384; const int PawnTableSize = 16384;
+1 -1
View File
@@ -50,7 +50,7 @@ using namespace std;
/// Version number. If this is left empty, the current date (in the format /// Version number. If this is left empty, the current date (in the format
/// YYMMDD) is used as a version number. /// YYMMDD) is used as a version number.
static const string EngineVersion = "1.6"; static const string EngineVersion = "1.6.2";
static const string AppName = "Stockfish"; static const string AppName = "Stockfish";
static const string AppTag = ""; static const string AppTag = "";
+4 -4
View File
@@ -671,7 +671,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
Key pawnKey, materialKey; Key pawnKey, materialKey;
int castleRights, rule50, pliesFromNull; int castleRights, rule50, pliesFromNull;
Square epSquare; Square epSquare;
Value value; Score value;
Value npMaterial[2]; Value npMaterial[2];
}; };
@@ -969,7 +969,7 @@ void Position::do_castle_move(Move m) {
set_bit(&(byColorBB[us]), rto); set_bit(&(byColorBB[us]), rto);
set_bit(&(byTypeBB[ROOK]), rto); set_bit(&(byTypeBB[ROOK]), rto);
set_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares set_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
// Update board array // Update board array
Piece king = piece_of_color_and_type(us, KING); Piece king = piece_of_color_and_type(us, KING);
Piece rook = piece_of_color_and_type(us, ROOK); Piece rook = piece_of_color_and_type(us, ROOK);
@@ -1154,7 +1154,7 @@ void Position::undo_castle_move(Move m) {
assert(piece_on(kto) == piece_of_color_and_type(us, KING)); assert(piece_on(kto) == piece_of_color_and_type(us, KING));
assert(piece_on(rto) == piece_of_color_and_type(us, ROOK)); assert(piece_on(rto) == piece_of_color_and_type(us, ROOK));
// Remove pieces from destination squares: // Remove pieces from destination squares:
clear_bit(&(byColorBB[us]), kto); clear_bit(&(byColorBB[us]), kto);
clear_bit(&(byTypeBB[KING]), kto); clear_bit(&(byTypeBB[KING]), kto);
@@ -1162,7 +1162,7 @@ void Position::undo_castle_move(Move m) {
clear_bit(&(byColorBB[us]), rto); clear_bit(&(byColorBB[us]), rto);
clear_bit(&(byTypeBB[ROOK]), rto); clear_bit(&(byTypeBB[ROOK]), rto);
clear_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares clear_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
// Put pieces on source squares: // Put pieces on source squares:
set_bit(&(byColorBB[us]), kfrom); set_bit(&(byColorBB[us]), kfrom);
set_bit(&(byTypeBB[KING]), kfrom); set_bit(&(byTypeBB[KING]), kfrom);
-3
View File
@@ -1142,9 +1142,6 @@ namespace {
search_pv(pos, ss, alpha, beta, depth-2*OnePly, ply, threadID); search_pv(pos, ss, alpha, beta, depth-2*OnePly, ply, threadID);
ttMove = ss[ply].pv[ply]; ttMove = ss[ply].pv[ply];
tte = TT.retrieve(pos.get_key()); tte = TT.retrieve(pos.get_key());
// If tte->move() != MOVE_NONE then it equals ttMove
assert(!(tte && tte->move()) || tte->move() == ttMove);
} }
// Initialize a MovePicker object for the current position, and prepare // Initialize a MovePicker object for the current position, and prepare
+1 -1
View File
@@ -55,7 +55,7 @@ TranspositionTable::~TranspositionTable() {
void TranspositionTable::set_size(unsigned mbSize) { void TranspositionTable::set_size(unsigned mbSize) {
assert(mbSize >= 4 && mbSize <= 4096); assert(mbSize >= 4 && mbSize <= 2048);
unsigned newSize = 1024; unsigned newSize = 1024;
+2 -2
View File
@@ -122,8 +122,8 @@ namespace {
o["Randomness"] = Option(0, 0, 10); o["Randomness"] = Option(0, 0, 10);
o["Minimum Split Depth"] = Option(4, 4, 7); o["Minimum Split Depth"] = Option(4, 4, 7);
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8); o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
o["Threads"] = Option(1, 1, 8); o["Threads"] = Option(1, 1, THREAD_MAX);
o["Hash"] = Option(32, 4, 4096); o["Hash"] = Option(32, 4, 2048);
o["Clear Hash"] = Option(false, BUTTON); o["Clear Hash"] = Option(false, BUTTON);
o["New Game"] = Option(false, BUTTON); o["New Game"] = Option(false, BUTTON);
o["Ponder"] = Option(true); o["Ponder"] = Option(true);
+17 -4
View File
@@ -52,13 +52,26 @@ enum Value {
}; };
/// Score struct keeps a midgame and an endgame value in a single /// Score enum keeps a midgame and an endgame value in a single
/// ScoreValue 64 bit union. /// integer (enum), first LSB 16 bits are used to store endgame
/// value, while upper bits are used for midgame value.
enum Score {}; // Compiler is free to choose the enum type as long as can keep
// its data, so ensure Score to be an integer type.
enum Score { ENSURE_32_BITS_SIZE_P = (1 << 16), ENSURE_32_BITS_SIZE_N = -(1 << 16)};
// Extracting the _signed_ lower and upper 16 bits it not so trivial
// because according to the standard a simple cast to short is
// implementation defined and so is a right shift of a signed integer.
inline Value mg_value(Score s) { return Value(((int(s) + 32768) & ~0xffff) / 0x10000); }
// Unfortunatly on Intel 64 bit we have a small speed regression, so use a faster code in
// this case, although not 100% standard compliant it seems to work for Intel and MSVC.
#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); } inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
inline Value mg_value(Score s) { return Value((int(s) + 32768) >> 16); } #else
inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (int)(unsigned(s) & 0x8000u)); }
#endif
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); } inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }