Skip to content

Commit b8efa0d

Browse files
protonspringmcostalba
authored andcommitted
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.
1 parent acc47e8 commit b8efa0d

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/bitboard.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include <algorithm>
22+
#include <bitset>
2223

2324
#include "bitboard.h"
2425
#include "misc.h"
@@ -49,14 +50,6 @@ namespace {
4950
Bitboard BishopTable[0x1480]; // To store bishop attacks
5051

5152
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);
52-
53-
// popcount16() counts the non-zero bits using SWAR-Popcount algorithm
54-
unsigned popcount16(unsigned u) {
55-
u -= (u >> 1) & 0x5555U;
56-
u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
57-
u = ((u >> 4) + u) & 0x0F0FU;
58-
return (u * 0x0101U) >> 8;
59-
}
6053
}
6154

6255

@@ -85,7 +78,7 @@ const std::string Bitboards::pretty(Bitboard b) {
8578
void Bitboards::init() {
8679

8780
for (unsigned i = 0; i < (1 << 16); ++i)
88-
PopCnt16[i] = (uint8_t)popcount16(i);
81+
PopCnt16[i] = std::bitset<16>(i).count();
8982

9083
for (Square s = SQ_A1; s <= SQ_H8; ++s)
9184
SquareBB[s] = (1ULL << s);

0 commit comments

Comments
 (0)