HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
bitboard-attacks-x86-bmi2.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2023-2025 Sami Kiminki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_ATTACKS_X86_BMI2_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_ATTACKS_X86_BMI2_H_INCLUDED
19
20#include "pgnreader-config.h"
21
22#include "bitboard-tables.h"
24
25#include <array>
26#include <cinttypes>
27#include <immintrin.h>
28
29static_assert(HAVE_X86_BMI2, "This file should be included only when PDEP/PEXT is available");
30
32{
33
37{
38public:
40 static inline SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
41 {
42 const std::uint64_t pextMask { ctBitBoardTables.bmi2BishopMasks[static_cast<SquareUnderlyingType>(sq)] };
43 const std::uint64_t *pextData { ctBitBoardTables.bmi2BishopOffsets[static_cast<SquareUnderlyingType>(sq)] };
44
45 return SquareSet {
46 pextData[
47 _pext_u64(
48 static_cast<std::uint64_t>(occupancyMask),
49 pextMask)] };
50 }
51
53 static inline SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
54 {
55 const std::uint64_t pextMask { ctBitBoardTables.bmi2RookMasks[static_cast<SquareUnderlyingType>(sq)] };
56 const std::uint64_t *pextData { ctBitBoardTables.bmi2RookOffsets[static_cast<SquareUnderlyingType>(sq)] };
57
58 return SquareSet {
59 pextData[
60 _pext_u64(
61 static_cast<std::uint64_t>(occupancyMask),
62 pextMask)] };
63 }
64};
65
66}
67
68#endif
Slider attacks implementation using PEXT/PDEP.
Definition bitboard-attacks-x86-bmi2.h:37
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-x86-bmi2.h:53
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-x86-bmi2.h:40
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
std::uint_fast8_t SquareUnderlyingType
Underlying type of Square
Definition chessboard-types.h:38
Square
Named square.
Definition chessboard-types.h:122
Definition chessboard-types-squareset.h:30
const BitBoardTables ctBitBoardTables
Various bitboard attack and other tables.