]> git.sesse.net Git - stockfish/blob - src/nnue/nnue_common.h
Avoid special casing for MinGW
[stockfish] / src / nnue / nnue_common.h
1 /*
2   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3   Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
4
5   Stockfish is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9
10   Stockfish is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // Constants used in NNUE evaluation function
20
21 #ifndef NNUE_COMMON_H_INCLUDED
22 #define NNUE_COMMON_H_INCLUDED
23
24 #if defined(USE_AVX2)
25 #include <immintrin.h>
26
27 #elif defined(USE_SSE41)
28 #include <smmintrin.h>
29
30 #elif defined(USE_SSSE3)
31 #include <tmmintrin.h>
32
33 #elif defined(USE_SSE2)
34 #include <emmintrin.h>
35
36 #elif defined(USE_NEON)
37 #include <arm_neon.h>
38 #endif
39
40 namespace Eval::NNUE {
41
42   // Version of the evaluation file
43   constexpr std::uint32_t kVersion = 0x7AF32F16u;
44
45   // Constant used in evaluation value calculation
46   constexpr int FV_SCALE = 16;
47   constexpr int kWeightScaleBits = 6;
48
49   // Size of cache line (in bytes)
50   constexpr std::size_t kCacheLineSize = 64;
51
52   // SIMD width (in bytes)
53   #if defined(USE_AVX2)
54   constexpr std::size_t kSimdWidth = 32;
55
56   #elif defined(USE_SSE2)
57   constexpr std::size_t kSimdWidth = 16;
58
59   #elif defined(USE_NEON)
60   constexpr std::size_t kSimdWidth = 16;
61   #endif
62
63   constexpr std::size_t kMaxSimdWidth = 32;
64
65   // Type of input feature after conversion
66   using TransformedFeatureType = std::uint8_t;
67   using IndexType = std::uint32_t;
68
69   // Round n up to be a multiple of base
70   template <typename IntType>
71   constexpr IntType CeilToMultiple(IntType n, IntType base) {
72     return (n + base - 1) / base * base;
73   }
74
75 }  // namespace Eval::NNUE
76
77 #endif // #ifndef NNUE_COMMON_H_INCLUDED