Skip to content

Commit 69726f4

Browse files
committed
Remove defined(IS_64BIT) in init_sliding_attacks()
No functional change bith in 32 and 64 bits. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
1 parent f3e0b32 commit 69726f4

3 files changed

Lines changed: 33 additions & 42 deletions

File tree

src/bitboard.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,27 +451,19 @@ namespace {
451451

452452
void init_sliding_attacks(Bitboard attacks[], int attackIndex[], Bitboard mask[],
453453
const int shift[], const Bitboard mult[], int deltas[][2]) {
454+
Bitboard b, v;
455+
int i, j, index;
454456

455-
for (int i = 0, index = 0; i < 64; i++)
457+
for (i = index = 0; i < 64; i++)
456458
{
457459
attackIndex[i] = index;
458460
mask[i] = sliding_attacks(i, 0, deltas, 1, 6, 1, 6);
459-
460-
#if defined(IS_64BIT)
461-
int j = (1 << (64 - shift[i]));
462-
#else
463-
int j = (1 << (32 - shift[i]));
464-
#endif
461+
j = 1 << ((CpuIs64Bit ? 64 : 32) - shift[i]);
465462

466463
for (int k = 0; k < j; k++)
467464
{
468-
Bitboard b = index_to_bitboard(k, mask[i]);
469-
470-
#if defined(IS_64BIT)
471-
Bitboard v = b * mult[i];
472-
#else
473-
unsigned v = int(b) * int(mult[i]) ^ int(b >> 32) * int(mult[i] >> 32);
474-
#endif
465+
b = index_to_bitboard(k, mask[i]);
466+
v = CpuIs64Bit ? b * mult[i] : unsigned(b * mult[i] ^ (b >> 32) * (mult[i] >> 32));
475467
attacks[index + (v >> shift[i])] = sliding_attacks(i, b, deltas, 0, 7, 0, 7);
476468
}
477469
index += j;

src/bitcount.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,4 @@ inline int count_1s<CNT_POPCNT>(Bitboard b) {
9696
#endif
9797
}
9898

99-
100-
/// cpu_has_popcnt() detects support for popcnt instruction at runtime
101-
inline bool cpu_has_popcnt() {
102-
103-
int CPUInfo[4] = {-1};
104-
__cpuid(CPUInfo, 0x00000001);
105-
return (CPUInfo[2] >> 23) & 1;
106-
}
107-
108-
109-
/// CpuHasPOPCNT is a global constant initialized at startup that
110-
/// is set to true if CPU on which application runs supports popcnt
111-
/// hardware instruction. Unless USE_POPCNT is not defined.
112-
#if defined(USE_POPCNT)
113-
const bool CpuHasPOPCNT = cpu_has_popcnt();
114-
#else
115-
const bool CpuHasPOPCNT = false;
116-
#endif
117-
118-
119-
/// CpuIs64Bit is a global constant initialized at compile time that
120-
/// is set to true if CPU on which application runs is a 64 bits.
121-
#if defined(IS_64BIT)
122-
const bool CpuIs64Bit = true;
123-
#else
124-
const bool CpuIs64Bit = false;
125-
#endif
126-
12799
#endif // !defined(BITCOUNT_H_INCLUDED)

src/types.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,31 @@ inline void operator-= (T& d1, const T d2) { d1 = d1 - d2; } \
146146
inline void operator*= (T& d, int i) { d = T(int(d) * i); } \
147147
inline void operator/= (T& d, int i) { d = T(int(d) / i); }
148148

149+
150+
/// cpu_has_popcnt() detects support for popcnt instruction at runtime
151+
inline bool cpu_has_popcnt() {
152+
153+
int CPUInfo[4] = {-1};
154+
__cpuid(CPUInfo, 0x00000001);
155+
return (CPUInfo[2] >> 23) & 1;
156+
}
157+
158+
/// CpuHasPOPCNT is a global constant initialized at startup that
159+
/// is set to true if CPU on which application runs supports popcnt
160+
/// hardware instruction. Unless USE_POPCNT is not defined.
161+
#if defined(USE_POPCNT)
162+
const bool CpuHasPOPCNT = cpu_has_popcnt();
163+
#else
164+
const bool CpuHasPOPCNT = false;
165+
#endif
166+
167+
168+
/// CpuIs64Bit is a global constant initialized at compile time that
169+
/// is set to true if CPU on which application runs is a 64 bits.
170+
#if defined(IS_64BIT)
171+
const bool CpuIs64Bit = true;
172+
#else
173+
const bool CpuIs64Bit = false;
174+
#endif
175+
149176
#endif // !defined(TYPES_H_INCLUDED)

0 commit comments

Comments
 (0)