]> git.sesse.net Git - stockfish/blob - src/types.h
Retire some unused functions in bitboard.h
[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 #include <cstdlib>
24
25 #if defined(_MSC_VER)
26
27 // Disable some silly and noisy warning from MSVC compiler
28 #pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
29 #pragma warning(disable: 4127) // Conditional expression is constant
30
31 // MSVC does not support <inttypes.h>
32 typedef   signed __int8    int8_t;
33 typedef unsigned __int8   uint8_t;
34 typedef   signed __int16  int16_t;
35 typedef unsigned __int16 uint16_t;
36 typedef   signed __int32  int32_t;
37 typedef unsigned __int32 uint32_t;
38 typedef   signed __int64  int64_t;
39 typedef unsigned __int64 uint64_t;
40
41 #else
42
43 #include <inttypes.h>
44
45 #endif
46
47 // Our hash key and bitboard types
48 typedef uint64_t Key;
49 typedef uint64_t Bitboard;
50
51 #define Min(x, y) (((x) < (y)) ? (x) : (y))
52 #define Max(x, y) (((x) < (y)) ? (y) : (x))
53
54 ////
55 //// Configuration
56 ////
57
58 //// For Linux and OSX configuration is done automatically using Makefile.
59 //// To get started type "make help".
60 ////
61 //// For windows part of the configuration is detected automatically, but
62 //// some switches need to be set manually:
63 ////
64 //// -DNDEBUG       | Disable debugging mode. Use always.
65 ////
66 //// -DNO_PREFETCH  | Disable use of prefetch asm-instruction. A must if you want the
67 ////                | executable to run on some very old machines.
68 ////
69 //// -DUSE_POPCNT   | Add runtime support for use of popcnt asm-instruction.
70 ////                | Works only in 64-bit mode. For compiling requires hardware
71 ////                | with popcnt support. Around 4% speed-up.
72 ////
73 //// -DOLD_LOCKS    | By default under Windows are used the fast Slim Reader/Writer (SRW)
74 ////                | Locks and Condition Variables: these are not supported by Windows XP
75 ////                | and older, to compile for those platforms you should enable OLD_LOCKS.
76
77 // Automatic detection for 64-bit under Windows
78 #if defined(_WIN64)
79 #define IS_64BIT
80 #endif
81
82 // Automatic detection for use of bsfq asm-instruction under Windows.
83 // Works only in 64-bit mode. Does not work with MSVC.
84 #if defined(_WIN64) && defined(__INTEL_COMPILER)
85 #define USE_BSFQ
86 #endif
87
88 // Intel header for _mm_popcnt_u64() intrinsic
89 #if defined(USE_POPCNT) && defined(_MSC_VER) && defined(__INTEL_COMPILER)
90 #include <nmmintrin.h>
91 #endif
92
93 // Cache line alignment specification
94 #if defined(_MSC_VER) || defined(__INTEL_COMPILER)
95 #define CACHE_LINE_ALIGNMENT __declspec(align(64))
96 #else
97 #define CACHE_LINE_ALIGNMENT  __attribute__ ((aligned(64)))
98 #endif
99
100 // Define a __cpuid() function for gcc compilers, for Intel and MSVC
101 // is already available as an intrinsic.
102 #if defined(_MSC_VER)
103 #include <intrin.h>
104 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
105 inline void __cpuid(int CPUInfo[4], int InfoType)
106 {
107   int* eax = CPUInfo + 0;
108   int* ebx = CPUInfo + 1;
109   int* ecx = CPUInfo + 2;
110   int* edx = CPUInfo + 3;
111
112   *eax = InfoType;
113   *ecx = 0;
114   __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
115                   : "0" (*eax), "2" (*ecx));
116 }
117 #else
118 inline void __cpuid(int CPUInfo[4], int)
119 {
120    CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
121 }
122 #endif
123
124 // Define FORCE_INLINE macro to force inlining overriding compiler choice
125 #if defined(_MSC_VER)
126 #define FORCE_INLINE  __forceinline
127 #elif defined(__GNUC__)
128 #define FORCE_INLINE  inline __attribute__((always_inline))
129 #else
130 #define FORCE_INLINE  inline
131 #endif
132
133 // Operators used by enum types like Depth, Piece, Square and so on.
134
135 #define ENABLE_OPERATORS_ON(T) \
136 inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } \
137 inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); } \
138 inline T operator* (int i, const T d) {  return T(i * int(d)); } \
139 inline T operator* (const T d, int i) {  return T(int(d) * i); } \
140 inline T operator/ (const T d, int i) { return T(int(d) / i); } \
141 inline T operator- (const T d) { return T(-int(d)); } \
142 inline T operator++ (T& d, int) {d = T(int(d) + 1); return d; } \
143 inline T operator-- (T& d, int) { d = T(int(d) - 1); return d; } \
144 inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; } \
145 inline void operator-= (T& d1, const T d2) { d1 = d1 - d2; } \
146 inline void operator*= (T& d, int i) { d = T(int(d) * i); } \
147 inline void operator/= (T& d, int i) { d = T(int(d) / i); }
148
149 #endif // !defined(TYPES_H_INCLUDED)