]> git.sesse.net Git - stockfish/blob - src/types.h
Retire HistoryMax
[stockfish] / src / types.h
1 /*
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
5
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.
10
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.
15
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/>.
18 */
19
20 #if !defined(TYPES_H_INCLUDED)
21 #define TYPES_H_INCLUDED
22
23 #if !defined(_MSC_VER)
24
25 #include <inttypes.h>
26
27 #else
28
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
32
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;
41
42 #endif // !defined(_MSC_VER)
43
44 // Hash keys
45 typedef uint64_t Key;
46
47 // Bitboard type
48 typedef uint64_t Bitboard;
49
50 #include <cstdlib>
51
52 ////
53 //// Configuration
54 ////
55
56 //// For Linux and OSX configuration is done automatically using Makefile.
57 //// To get started type "make help".
58 ////
59 //// For windows part of the configuration is detected automatically, but
60 //// some switches need to be set manually:
61 ////
62 //// -DNDEBUG       | Disable debugging mode. Use always.
63 ////
64 //// -DNO_PREFETCH  | Disable use of prefetch asm-instruction. A must if you want the
65 ////                | executable to run on some very old machines.
66 ////
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.
70 ////
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.
74
75 // Automatic detection for 64-bit under Windows
76 #if defined(_WIN64)
77 #define IS_64BIT
78 #endif
79
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)
83 #define USE_BSFQ
84 #endif
85
86 // Intel header for _mm_popcnt_u64() intrinsic
87 #if defined(USE_POPCNT) && defined(_MSC_VER) && defined(__INTEL_COMPILER)
88 #include <nmmintrin.h>
89 #endif
90
91 // Cache line alignment specification
92 #if defined(_MSC_VER) || defined(__INTEL_COMPILER)
93 #define CACHE_LINE_ALIGNMENT __declspec(align(64))
94 #else
95 #define CACHE_LINE_ALIGNMENT  __attribute__ ((aligned(64)))
96 #endif
97
98 // Define a __cpuid() function for gcc compilers, for Intel and MSVC
99 // is already available as an intrinsic.
100 #if defined(_MSC_VER)
101 #include <intrin.h>
102 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
103 inline void __cpuid(int CPUInfo[4], int InfoType)
104 {
105   int* eax = CPUInfo + 0;
106   int* ebx = CPUInfo + 1;
107   int* ecx = CPUInfo + 2;
108   int* edx = CPUInfo + 3;
109
110   *eax = InfoType;
111   *ecx = 0;
112   __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
113                   : "0" (*eax), "2" (*ecx));
114 }
115 #else
116 inline void __cpuid(int CPUInfo[4], int)
117 {
118    CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
119 }
120 #endif
121
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))
127 #else
128 #define FORCE_INLINE  inline
129 #endif
130
131 // Operators used by enum types like Depth, Piece, Square and so on.
132
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); }
146
147 #endif // !defined(TYPES_H_INCLUDED)