2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4 Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
6 Stockfish is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Stockfish is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #if !defined(TYPES_H_INCLUDED)
21 #define TYPES_H_INCLUDED
23 #if !defined(_MSC_VER)
29 // Disable some silly and noisy warning from MSVC compiler
30 #pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
31 #pragma warning(disable: 4127) // Conditional expression is constant
33 typedef signed __int8 int8_t;
34 typedef unsigned __int8 uint8_t;
35 typedef signed __int16 int16_t;
36 typedef unsigned __int16 uint16_t;
37 typedef signed __int32 int32_t;
38 typedef unsigned __int32 uint32_t;
39 typedef signed __int64 int64_t;
40 typedef unsigned __int64 uint64_t;
42 #endif // !defined(_MSC_VER)
48 typedef uint64_t Bitboard;
56 //// For Linux and OSX configuration is done automatically using Makefile.
57 //// To get started type "make help".
59 //// For windows part of the configuration is detected automatically, but
60 //// some switches need to be set manually:
62 //// -DNDEBUG | Disable debugging mode. Use always.
64 //// -DNO_PREFETCH | Disable use of prefetch asm-instruction. A must if you want the
65 //// | executable to run on some very old machines.
67 //// -DUSE_POPCNT | Add runtime support for use of popcnt asm-instruction.
68 //// | Works only in 64-bit mode. For compiling requires hardware
69 //// | with popcnt support. Around 4% speed-up.
71 //// -DOLD_LOCKS | By default under Windows are used the fast Slim Reader/Writer (SRW)
72 //// | Locks and Condition Variables: these are not supported by Windows XP
73 //// | and older, to compile for those platforms you should enable OLD_LOCKS.
75 // Automatic detection for 64-bit under Windows
80 // Automatic detection for use of bsfq asm-instruction under Windows.
81 // Works only in 64-bit mode. Does not work with MSVC.
82 #if defined(_WIN64) && defined(__INTEL_COMPILER)
86 // Intel header for _mm_popcnt_u64() intrinsic
87 #if defined(USE_POPCNT) && defined(_MSC_VER) && defined(__INTEL_COMPILER)
88 #include <nmmintrin.h>
91 // Cache line alignment specification
92 #if defined(_MSC_VER) || defined(__INTEL_COMPILER)
93 #define CACHE_LINE_ALIGNMENT __declspec(align(64))
95 #define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
98 // Define a __cpuid() function for gcc compilers, for Intel and MSVC
99 // is already available as an intrinsic.
100 #if defined(_MSC_VER)
102 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
103 inline void __cpuid(int CPUInfo[4], int InfoType)
105 int* eax = CPUInfo + 0;
106 int* ebx = CPUInfo + 1;
107 int* ecx = CPUInfo + 2;
108 int* edx = CPUInfo + 3;
112 __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
113 : "0" (*eax), "2" (*ecx));
116 inline void __cpuid(int CPUInfo[4], int)
118 CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
122 // Define FORCE_INLINE macro to force inlining overriding compiler choice
123 #if defined(_MSC_VER)
124 #define FORCE_INLINE __forceinline
125 #elif defined(__GNUC__)
126 #define FORCE_INLINE inline __attribute__((always_inline))
128 #define FORCE_INLINE inline
131 // Operators used by enum types like Depth, Piece, Square and so on.
133 #define ENABLE_OPERATORS_ON(T) \
134 inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } \
135 inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); } \
136 inline T operator* (int i, const T d) { return T(i * int(d)); } \
137 inline T operator* (const T d, int i) { return T(int(d) * i); } \
138 inline T operator/ (const T d, int i) { return T(int(d) / i); } \
139 inline T operator- (const T d) { return T(-int(d)); } \
140 inline T operator++ (T& d, int) {d = T(int(d) + 1); return d; } \
141 inline T operator-- (T& d, int) { d = T(int(d) - 1); return d; } \
142 inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; } \
143 inline void operator-= (T& d1, const T d2) { d1 = d1 - d2; } \
144 inline void operator*= (T& d, int i) { d = T(int(d) * i); } \
145 inline void operator/= (T& d, int i) { d = T(int(d) / i); }
147 #endif // !defined(TYPES_H_INCLUDED)