1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-06-28 00:19:50 +00:00

Remove popcount16() (#2038)

This is a non-functional simplification / code-style change.

This popcount16 method does nothing but initialize the PopCnt16 arrays.

This can be done in a single bitset line, which is less lines and more clear. Performance for this code is moot.

No functional change.
This commit is contained in:
protonspring 2019-03-10 03:53:39 -06:00 committed by Marco Costalba
parent acc47e8b79
commit b8efa0daac

View file

@ -19,6 +19,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <bitset>
#include "bitboard.h" #include "bitboard.h"
#include "misc.h" #include "misc.h"
@ -49,14 +50,6 @@ namespace {
Bitboard BishopTable[0x1480]; // To store bishop attacks Bitboard BishopTable[0x1480]; // To store bishop attacks
void init_magics(Bitboard table[], Magic magics[], Direction directions[]); void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
// popcount16() counts the non-zero bits using SWAR-Popcount algorithm
unsigned popcount16(unsigned u) {
u -= (u >> 1) & 0x5555U;
u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
u = ((u >> 4) + u) & 0x0F0FU;
return (u * 0x0101U) >> 8;
}
} }
@ -85,7 +78,7 @@ const std::string Bitboards::pretty(Bitboard b) {
void Bitboards::init() { void Bitboards::init() {
for (unsigned i = 0; i < (1 << 16); ++i) for (unsigned i = 0; i < (1 << 16); ++i)
PopCnt16[i] = (uint8_t)popcount16(i); PopCnt16[i] = std::bitset<16>(i).count();
for (Square s = SQ_A1; s <= SQ_H8; ++s) for (Square s = SQ_A1; s <= SQ_H8; ++s)
SquareBB[s] = (1ULL << s); SquareBB[s] = (1ULL << s);