1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Laura-Core: a fast and efficient move generator for chess engines.
Copyright (C) 2024-2025 HansTibberio <hanstiberio@proton.me>
Laura-Core is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Laura-Core is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Laura-Core. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::;
// This implementation of PEXT bitboards is based on the work developed in Cozy-Chess, licensed under the MIT License.
// Copyright (c) 2021 analog-hors
// Source: https://github.com/analog-hors/cozy-chess/blob/master/types/src/sliders/pext.rs
// Includes pre-generated files containing the slider attack bitboards and the PEXT (Parallel Bit Extraction)
// data. These files are created at build time and are dynamically included into the current module at compile-time.
include!;
include!;
/// Executes the PEXT (Parallel Bit Extraction) operation on two 64-bit integers. This function uses the x86_64
/// architecture's intrinsic to perform the PEXT operation, which extracts specific bits from one integer according
/// to a mask and returns them in the result. This is used to efficiently compute attack bitboards based on blockers.
///
/// ## Safety:
/// This function uses a raw FFI call to access the `x86_64::_pext_u64` intrinsic, which is platform-specific and unsafe.
/// Represents a single PEXT entry for a slider piece's attack data. This structure is used to store the necessary
/// information for performing a PEXT operation to compute the attack bitboard of a slider piece (rook or bishop).
/// Contains the PEXT data for rook and bishop pieces. This structure stores precomputed information for each square
/// on the chessboard regarding the PEXT operations required to compute valid attacks for sliders (rooks and bishops).
///
/// The data is divided into two arrays, one for rooks and one for bishops, with each entry containing an `offset` and `mask`.
/// Additionally, the total size of the table is stored.
/// Computes the index of the attack bitboard for a slider piece (rook or bishop) based on the blocker positions
/// using the PEXT data.
/// Retrieves the attack bitboard for a rook from a given square, considering the positions of blockers.
///
/// This function uses the PEXT operation and precomputed data to efficiently calculate the attack bitboard for a
/// rook piece.
/// Retrieves the attack bitboard for a bishop from a given square, considering the positions of blockers.
///
/// This function is similar to `get_rook_attacks`, but is designed for bishop pieces. It uses the PEXT operation
/// to efficiently compute the attack bitboard for a bishop, considering the positions of blockers.