Skip to content
New issue

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

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

Already on GitHub? # to your account

Optimizations #33

Merged
merged 11 commits into from
Jan 10, 2019
Merged

Optimizations #33

merged 11 commits into from
Jan 10, 2019

Conversation

GunshipPenguin
Copy link
Owner

@GunshipPenguin GunshipPenguin commented Dec 30, 2018

Implement a variety of small optimizations (and a few small enhancements to existing features).

  • Remove incrementally updated bitboards from Board class that could be calculated on the fly quicker
  • Take advantage of branch prediction by surrounding code that only needs to be executed from time to time in conditionals
  • Add Board::_movePiece() and use it instead of _removePiece() + addPiece() to save a few CPU instructions
  • Bulk count leaves in perft calculations
  • Don't use C++ exceptions, instead add a new [[ noreturn ]] fatal() function and compile with -fno-exceptions
  • Improve showbb.py script to accept Python expressions rather than only single hex/decimal numbers
  • Improve output of printboard and printmoves

Together, these optimizations improve raw perft speed by roughly 10%.

- Remove incrementially updated _notOccupied bitboard from Board
  instead generate it on demand with ~_occupied
- Remove _attackable[2] bitboards from Board, instead generate
  them on demand with _allPieces[color] & ~_pieces[color][KING]
- Only call _updateCastlingRightsForMove() if castling rights
  are nonzero
- Only clear the en passant target square if it's not already
  clear
- Add Board::_movePiece(), which saves a few instructions vs.
  using _removePiece() and then _addPiece()

These changes noticeably increase perft speed (~10%)
@GunshipPenguin GunshipPenguin merged commit 897a303 into master Jan 10, 2019
@GunshipPenguin GunshipPenguin deleted the optimizations branch January 10, 2019 06:18
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant