Skip to content

Commit

Permalink
Added bit rotation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluemer committed Apr 13, 2017
1 parent f8f9aac commit 2dc1f29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/BitBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class BitBoard

bool m_isBlacksTurn = true;

/* Class member functions */

// These are basic 32 bit rotation functions
// Details here: http://stackoverflow.com/questions/776508/best-practices-for-circular-shift-rotate-operations-in-c
uint32_t const rotl32 (uint32_t n, unsigned int c);
uint32_t const rotr32 (uint32_t n, unsigned int c);

public:

};
Expand Down
18 changes: 18 additions & 0 deletions src/BitBoard.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
#include <cstdint>
#include <limits.h>
#include "BitBoard.h"

uint32_t const BitBoard::rotl32 (uint32_t n, unsigned int c)
{
const unsigned int mask = (CHAR_BIT*sizeof(n)-1);

c &= mask; // avoid undef behaviour with NDEBUG. 0 overhead for most types / compilers
return (n<<c) | (n>>( (-c)&mask ));
}

uint32_t const BitBoard::rotr32 (uint32_t n, unsigned int c)
{
const unsigned int mask = (CHAR_BIT*sizeof(n)-1);

c &= mask; // avoid undef behaviour with NDEBUG. 0 overhead for most types / compilers
return (n>>c) | (n<<( (-c)&mask ));
}

0 comments on commit 2dc1f29

Please sign in to comment.