From 2bfe61c33b99bd5ebb2e4616a6e8ac5790ff4c4f Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 7 Apr 2014 16:02:24 +0200 Subject: [PATCH] Add PEXT software implementation For development/debug purposes. No functional change. --- src/bitboard.cpp | 17 +++++++++++++++++ src/bitboard.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index bfacc412..27ba6574 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -79,6 +79,23 @@ namespace { } } + +/// Intel PEXT (parallel extraction) software implementation +Bitboard pext(Bitboard b, Bitboard mask) { + + Bitboard res = 0; + + for (Bitboard bb = 1; mask; bb += bb) + { + if (b & mask & -mask) + res |= bb; + + mask &= mask - 1; + } + return res; +} + + /// lsb()/msb() finds the least/most significant bit in a non-zero bitboard. /// pop_lsb() finds and clears the least significant bit in a non-zero bitboard. diff --git a/src/bitboard.h b/src/bitboard.h index 3ff0408a..140867fa 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -23,6 +23,8 @@ #include "types.h" +extern Bitboard pext(Bitboard b, Bitboard mask); + namespace Bitboards { void init(); -- 2.39.2