Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movegen speedup via magic bitboards #640

Merged
merged 19 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ if not get_option('popcnt')
add_project_arguments('-DNO_POPCNT', language : 'cpp')
endif

if not get_option('pext')
add_project_arguments('-DNO_PEXT', language : 'cpp')
endif

executable('lc0', 'src/main.cc',
files, include_directories: includes, dependencies: deps, install: true)

Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ option('popcnt',
value: true,
description: 'Use the popcnt instruction')

option('pext',
type: 'boolean',
value: false,
description: 'Use the pext instruction')

option('gtest',
type: 'boolean',
value: true,
Expand Down
18 changes: 11 additions & 7 deletions src/chess/bitboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class BitBoard {
return board_ == other.board_;
}

bool operator!=(const BitBoard& other) const {
return board_ != other.board_;
}

BitIterator<BoardSquare> begin() const { return board_; }
BitIterator<BoardSquare> end() const { return 0; }

Expand All @@ -195,7 +199,7 @@ class BitBoard {
}

// Applies a mask to the bitboard (intersects).
BitBoard& operator*=(const BitBoard& a) {
BitBoard& operator&=(const BitBoard& a) {
board_ &= a.board_;
return *this;
}
Expand All @@ -206,10 +210,15 @@ class BitBoard {
}

// Returns union (bitwise OR) of two boards.
friend BitBoard operator+(const BitBoard& a, const BitBoard& b) {
friend BitBoard operator|(const BitBoard& a, const BitBoard& b) {
return {a.board_ | b.board_};
}

// Returns intersection (bitwise AND) of two boards.
friend BitBoard operator&(const BitBoard& a, const BitBoard& b) {
return {a.board_ & b.board_};
}

// Returns bitboard with one bit reset.
friend BitBoard operator-(const BitBoard& a, const BoardSquare& b) {
return {a.board_ & ~(1ULL << b.as_int())};
Expand All @@ -220,11 +229,6 @@ class BitBoard {
return {a.board_ & ~b.board_};
}

// Returns intersection (bitwise AND) of two boards.
friend BitBoard operator*(const BitBoard& a, const BitBoard& b) {
return {a.board_ & b.board_};
}

private:
std::uint64_t board_ = 0;
};
Expand Down
Loading