Skip to content

Commit 3a288b4

Browse files
authored
Merge pull request #23 from winapiadmin/pr_forceinline
Uses FORCEINLINE for critical-performance functions, and optimized pawn move generation
2 parents 4a37611 + d13ab31 commit 3a288b4

9 files changed

Lines changed: 214 additions & 435 deletions

File tree

.github/workflows/cmake-multi-platform.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ jobs:
6161
run: cmake --build ${{ steps.vars.outputs.dir }} --config ${{ matrix.build_type }}
6262

6363
- name: Test
64-
working-directory: ${{ steps.vars.outputs.dir }}
65-
shell: bash
66-
run: |
67-
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
68-
ctest --build-config ${{ matrix.build_type }} --verbose
69-
else
70-
ctest --verbose
71-
fi
64+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
65+
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
66+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
67+
run: ctest --build-config ${{ matrix.build_type }} --verbose

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ build/
99
!.gitignore
1010
CMakePresets.json
1111
CMakeSettings.json
12-
*.s
12+
*.s

CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

77
# --- Compiler tuning ---
8-
set(ASAN_ENABLED OFF CACHE BOOL "Whether to enable ASan or not")
8+
set(SAN_ENABLED OFF CACHE BOOL "Whether to enable ASan or not")
99
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
1010
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
1111
# clang-cl: forward GCC/Clang style constexpr flags via /clang:
@@ -24,24 +24,12 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
2424
-march=native -mtune=native
2525
-ftemplate-backtrace-limit=0
2626
)
27-
if (ASAN_ENABLED)
28-
add_compile_options(-fsanitize=address)
29-
add_link_options(-fsanitize=address)
30-
endif()
3127
endif()
3228
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3329
add_compile_options(-fconstexpr-ops-limit=2000000000 -fconstexpr-depth=1024 -march=native -mtune=native -ftemplate-backtrace-limit=0)
34-
if (ASAN_ENABLED)
35-
add_compile_options(-fsanitize=address)
36-
add_link_options(-fsanitize=address)
37-
endif()
3830
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
3931
set(ARCH_FLAG "/arch:AVX2" CACHE STRING "MSVC architecture flag (/arch:SSE2, /arch:AVX, /arch:AVX2, /arch:AVX512)")
4032
add_compile_options(/constexpr:steps2000000000 /constexpr:depth1024 ${ARCH_FLAG})
41-
if (ASAN_ENABLED)
42-
add_compile_options(/fsanitize=address)
43-
add_link_options(/fsanitize=address)
44-
endif()
4533
endif()
4634

4735
add_compile_definitions(GENERATE_AT_RUNTIME)

bitboard.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#if defined(_MSC_VER)
55
#include <intrin.h>
66
#endif
7-
7+
#include <immintrin.h>
88
namespace chess {
99
// -------------------------------
1010
// constexpr fallbacks
@@ -43,7 +43,7 @@ constexpr int msb_constexpr(Bitboard x) noexcept {
4343
#if defined(__GNUG__) || defined(__clang__)
4444
[[gnu::const]]
4545
#endif
46-
inline constexpr int popcount(Bitboard x) noexcept {
46+
__FORCEINLINE constexpr int popcount(Bitboard x) noexcept {
4747
#if defined(__GNUG__) || defined(__clang__)
4848
if (!is_constant_evaluated())
4949
return __builtin_popcountll(x);
@@ -57,7 +57,7 @@ inline constexpr int popcount(Bitboard x) noexcept {
5757
#if defined(__GNUG__) || defined(__clang__)
5858
[[gnu::const]]
5959
#endif
60-
inline constexpr int lsb(Bitboard x) noexcept {
60+
__FORCEINLINE constexpr int lsb(Bitboard x) noexcept {
6161
#if defined(__GNUG__) || defined(__clang__)
6262
if (!is_constant_evaluated())
6363
return __builtin_ctzll(x);
@@ -74,7 +74,7 @@ inline constexpr int lsb(Bitboard x) noexcept {
7474
#if defined(__GNUG__) || defined(__clang__)
7575
[[gnu::const]]
7676
#endif
77-
inline constexpr int msb(Bitboard x) noexcept {
77+
__FORCEINLINE constexpr int msb(Bitboard x) noexcept {
7878
#if defined(__GNUG__) || defined(__clang__)
7979
if (!is_constant_evaluated())
8080
return 63 - __builtin_clzll(x);
@@ -91,13 +91,17 @@ inline constexpr int msb(Bitboard x) noexcept {
9191
// -------------------------------
9292
// destructive variants
9393
// -------------------------------
94-
inline int pop_lsb(Bitboard &b) noexcept {
94+
__FORCEINLINE int pop_lsb(Bitboard &b) noexcept {
9595
int c = lsb(b);
96+
#ifndef __BMI2__
9697
b &= b - 1;
98+
#else
99+
b = _blsr_u64(b);
100+
#endif
97101
return c;
98102
}
99103

100-
inline int pop_msb(Bitboard &b) noexcept {
104+
__FORCEINLINE int pop_msb(Bitboard &b) noexcept {
101105
int c = msb(b);
102106
b &= ~(1ULL << c);
103107
return c;

examples/perft_with_tt.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,17 @@ template <int DEPTH, bool EnableDiv=false, typename T=EnginePiece> void benchmar
113113
double avgTime = totalTime / N_RUNS;
114114
double avgMnps = (nodes / avgTime) / 1'000'000.0;
115115

116-
std::cout << "Average: " << avgTime << " s, " << avgMnps << " Mnps\n";
116+
std::cout << "Average: " << avgTime << " s, " << avgMnps << " Mnps (nodes="<<(nodes/N_RUNS)<<")\n";
117117
}
118118

119119

120120
int main() {
121-
_Position<ContiguousMappingPiece> pos("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1");
121+
_Position<EnginePiece> pos;
122122

123123
#ifdef TT_ENABLED
124124
tt.resize(1 << 28);
125125
#endif
126-
benchmark<3, true, ContiguousMappingPiece>(pos);
127-
126+
benchmark<7, true, EnginePiece>(pos);
128127
// Movelist moves;
129128
// pos.template legals(moves);
130129
// for (const Move &m : moves) {

0 commit comments

Comments
 (0)