X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftypes.h;h=ade9a620a47d5d70e63a71887f8310403a6f7c69;hp=d4ebec9f06fe977fa0d5df482fecab850af063f3;hb=de1dc4f2de7d22c9ea1b33b9caee276651ef7c6d;hpb=e40b06a0503b44bae5508a371d961914828214b6 diff --git a/src/types.h b/src/types.h index d4ebec9f..ade9a620 100644 --- a/src/types.h +++ b/src/types.h @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2008-2013 Marco Costalba, Joona Kiiski, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ /// | only in 64-bit mode. For compiling requires hardware with /// | popcnt support. +#include #include #include #include @@ -55,10 +56,11 @@ # include // Intel and Microsoft header for _mm_prefetch() # endif +#define CACHE_LINE_SIZE 64 #if defined(_MSC_VER) || defined(__INTEL_COMPILER) -# define CACHE_LINE_ALIGNMENT __declspec(align(64)) +# define CACHE_LINE_ALIGNMENT __declspec(align(CACHE_LINE_SIZE)) #else -# define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64))) +# define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(CACHE_LINE_SIZE))) #endif #if defined(_MSC_VER) @@ -211,7 +213,7 @@ enum Depth { DEPTH_ZERO = 0 * ONE_PLY, DEPTH_QS_CHECKS = -1 * ONE_PLY, DEPTH_QS_NO_CHECKS = -2 * ONE_PLY, - DEPTH_QS_RECAPTURES = -5 * ONE_PLY, + DEPTH_QS_RECAPTURES = -7 * ONE_PLY, DEPTH_NONE = -127 * ONE_PLY }; @@ -266,7 +268,7 @@ inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); } /// 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(((s + 32768) & ~0xffff) / 0x10000); } +inline Value mg_value(Score s) { return Value(((s + 0x8000) & ~0xffff) / 0x10000); } /// On Intel 64 bit we have a small speed regression with the standard conforming /// version, so use a faster code in this case that, although not 100% standard @@ -323,29 +325,9 @@ inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); } -/// Weight score v by score w trying to prevent overflow -inline Score apply_weight(Score v, Score w) { - return make_score((int(mg_value(v)) * mg_value(w)) / 0x100, - (int(eg_value(v)) * eg_value(w)) / 0x100); -} - #undef ENABLE_OPERATORS_ON #undef ENABLE_SAFE_OPERATORS_ON -namespace Zobrist { - - extern Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; - extern Key enpassant[FILE_NB]; - extern Key castle[CASTLE_RIGHT_NB]; - extern Key side; - extern Key exclusion; - - void init(); -} - -CACHE_LINE_ALIGNMENT - -extern Score pieceSquareTable[PIECE_NB][SQUARE_NB]; extern Value PieceValue[PHASE_NB][PIECE_NB]; extern int SquareDistance[SQUARE_NB][SQUARE_NB]; @@ -391,7 +373,8 @@ inline PieceType type_of(Piece p) { } inline Color color_of(Piece p) { - return p == NO_PIECE ? NO_COLOR : Color(p >> 3); + assert(p != NO_PIECE); + return Color(p >> 3); } inline bool is_ok(Square s) { @@ -439,12 +422,12 @@ inline int square_distance(Square s1, Square s2) { return SquareDistance[s1][s2]; } -inline char file_to_char(File f) { - return char(f - FILE_A + int('a')); +inline char file_to_char(File f, bool tolower = true) { + return char(f - FILE_A + (tolower ? 'a' : 'A')); } inline char rank_to_char(Rank r) { - return char(r - RANK_1 + int('1')); + return char(r - RANK_1 + '1'); } inline Square pawn_push(Color c) { @@ -473,7 +456,7 @@ inline Move make_move(Square from, Square to) { template inline Move make(Square from, Square to, PieceType pt = KNIGHT) { - return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12)) ; + return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12)); } inline bool is_ok(Move m) { @@ -487,21 +470,4 @@ inline const std::string square_to_string(Square s) { return ch; } -/// Our insertion sort implementation, works with pointers and iterators and is -/// guaranteed to be stable, as is needed. -template -void sort(K first, K last) -{ - T tmp; - K p, q; - - for (p = first + 1; p < last; p++) - { - tmp = *p; - for (q = p; q != first && *(q-1) < tmp; --q) - *q = *(q-1); - *q = tmp; - } -} - #endif // !defined(TYPES_H_INCLUDED)