Skip to content

Commit

Permalink
fix various cases of undefined behaviour to make the comparison testi…
Browse files Browse the repository at this point in the history
…ng easier
  • Loading branch information
panstromek committed Feb 20, 2022
1 parent 7be5d71 commit 3416efd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
48 changes: 24 additions & 24 deletions bitbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ static const unsigned int high_flip[56] = {
#endif

#define bbFlips_Right_high(pos, mask) \
contig = right_contiguous[(opp_bits_high >> (pos + 1)) & mask]; \
fl = right_flip[contig] << (pos + 1); \
t = -(int)(my_bits_high & fl) >> 31; \
contig = right_contiguous[(opp_bits_high >> (pos + 1u)) & mask]; \
fl = right_flip[contig] << (pos + 1u); \
t = ((int)(-(unsigned int)(my_bits_high & fl))) >> 31u; \
my_bits_high |= fl & t; \
flipped = contig & t

Expand Down Expand Up @@ -544,22 +544,22 @@ static const unsigned int high_flip[56] = {


#define bbFlips_Down_2_3(pos, vec, maskh) \
if (opp_bits_low & (1 << (pos + vec))) { \
if (opp_bits_low & (1 << (pos + vec * 2))) { \
t = (opp_bits_high >> (pos + vec * 3 - 32)) & 1; \
contig = 2 + t; \
t &= (opp_bits_high >> (pos + vec * 4 - 32)); \
if (opp_bits_low & (1u << (pos + vec))) { \
if (opp_bits_low & (1u << (pos + vec * 2u))) { \
t = (opp_bits_high >> (pos + vec * 3u - 32u)) & 1u; \
contig = 2u + t; \
t &= (opp_bits_high >> (pos + vec * 4u - 32u)); \
contig += t; \
t &= (opp_bits_high >> (pos + vec * 5 - 32)); \
t &= (opp_bits_high >> (pos + vec * 5u - 32u)); \
contig += t; \
t = lsb_mask[contig - 2] & maskh; \
if (my_bits_high & t) { \
my_bits_high |= t; \
my_bits_low |= (1 << (pos + vec)) | (1 << (pos + vec * 2)); \
my_bits_low |= (1u << (pos + vec)) | (1u << (pos + vec * 2u)); \
flipped += contig; \
} \
} else { \
t = (my_bits_low >> (pos + vec * 2)) & 1; \
t = (my_bits_low >> (pos + vec * 2u)) & 1u; \
my_bits_low |= t << (pos + vec); \
flipped += t; \
} \
Expand Down Expand Up @@ -679,17 +679,17 @@ static const unsigned int high_flip[56] = {


#define bbFlips_Down_1_3(pos, vec, maskh) \
if (opp_bits_low & (1 << (pos + vec))) { \
t = (opp_bits_high >> (pos + vec * 2 - 32)) & 1; \
if (opp_bits_low & (1u << (pos + vec))) { \
t = (opp_bits_high >> (pos + vec * 2u - 32u)) & 1u; \
contig = 1 + t; \
t &= (opp_bits_high >> (pos + vec * 3 - 32)); \
t &= (opp_bits_high >> (pos + vec * 3u - 32u)); \
contig += t; \
t &= (opp_bits_high >> (pos + vec * 4 - 32)); \
t &= (opp_bits_high >> (pos + vec * 4u - 32u)); \
contig += t; \
t = lsb_mask[contig - 1] & maskh; \
t = lsb_mask[contig - 1u] & maskh; \
if (my_bits_high & t) { \
my_bits_high |= t; \
my_bits_low |= 1 << (pos + vec); \
my_bits_low |= 1u << (pos + vec); \
flipped += contig; \
} \
}
Expand Down Expand Up @@ -795,10 +795,10 @@ static const unsigned int high_flip[56] = {
#endif

#define bbFlips_Up_0_3(pos, vec, mask) \
if (opp_bits_low & (1 << (pos + 32 - vec))) { \
t = (opp_bits_low >> (pos + 32 - vec * 2)) & 1; \
if (opp_bits_low & (1u << (pos + 32u - vec))) { \
t = (opp_bits_low >> (pos + 32u - vec * 2u)) & 1u; \
contig = 1 + t; \
t &= (opp_bits_low >> (pos + 32 - vec * 3)); \
t &= (opp_bits_low >> (pos + 32u - vec * 3u)); \
contig += t; \
fl = msb_mask[contig] & mask; \
t = -(int)(my_bits_low & fl) >> 31; \
Expand Down Expand Up @@ -1021,7 +1021,7 @@ TestFlips_bitboard_a8( unsigned int my_bits_high, unsigned int my_bits_low, unsi
unsigned int t, fl;

/* Right */
bbFlips_Right_high(24, 0x3F);
bbFlips_Right_high(24u, 0x3Fu);
/* Up right */
bbFlips_Up_3_3(24, 7, 0x00020408u, 0x10204080u);
/* Up */
Expand Down Expand Up @@ -1115,7 +1115,7 @@ TestFlips_bitboard_h2( unsigned int my_bits_high, unsigned int my_bits_low, unsi
/* Down left */
bbFlips_Down_2_3(15, 7, 0x02040810u);
/* Down */
bbFlips_Down_2_3(15, 8, 0x80808080u);
bbFlips_Down_2_3(15u, 8u, 0x80808080u);

my_bits_low |= 0x00008000u;
bb_flips.high = my_bits_high;
Expand Down Expand Up @@ -1339,7 +1339,7 @@ TestFlips_bitboard_h3( unsigned int my_bits_high, unsigned int my_bits_low, unsi
/* Down left */
bbFlips_Down_1_3(23, 7, 0x04081020u);
/* Down */
bbFlips_Down_1_3(23, 8, 0x80808080u);
bbFlips_Down_1_3(23u, 8u, 0x80808080u);
/* Up */
bbFlips_Up_1_low(23, 8);
/* Up left */
Expand Down Expand Up @@ -1553,7 +1553,7 @@ TestFlips_bitboard_h5( unsigned int my_bits_high, unsigned int my_bits_low, unsi
/* Down */
bbFlips_Down_2_high(7, 8, 0x00808000u);
/* Up */
bbFlips_Up_0_3(7, 8, 0x80808080u);
bbFlips_Up_0_3(7u, 8u, 0x80808080u);
/* Up left */
bbFlips_Up_0_3(7, 9, 0x40201008u);

Expand Down
2 changes: 1 addition & 1 deletion end.c
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,7 @@ setup_end( void ) {
if ( dir_mask[pos] & (1 << k) ) {
unsigned int neighbor = shift + dir_shift[k];
if ( neighbor < 32 )
neighborhood_mask[pos].low |= (1 << neighbor);
neighborhood_mask[pos].low |= ((unsigned int)1 << ((unsigned int)neighbor));
else
neighborhood_mask[pos].high |= (1 << (neighbor - 32));
}
Expand Down
4 changes: 2 additions & 2 deletions myrandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ my_srandom(int x)
my_state[ 0 ] = x;
for (i = 1; i < my_rand_deg; i++)
{
my_state[i] = 1103515245*my_state[i - 1] + 12345;
my_state[i] = ((unsigned int)1103515245)*((unsigned int)my_state[i - 1]) + ((unsigned int )12345);
}
my_fptr = &my_state[my_rand_sep];
my_rptr = &my_state[0];
Expand Down Expand Up @@ -348,7 +348,7 @@ my_random(void)
}
else
{
*my_fptr += *my_rptr;
*my_fptr = ((unsigned int)*my_fptr) + ((unsigned int)*my_rptr);
i = (*my_fptr >> 1)&0x7fffffff; /* chucking least random bit */
if (++my_fptr >= my_end_ptr )
{
Expand Down
2 changes: 1 addition & 1 deletion patterns.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ transformation_setup( void ) {
static void
add_single( int mask, int pos ) {
if ( mask < 32 )
depend_lo[pos] |= 1 << mask;
depend_lo[pos] |= ((unsigned int )1) << ((unsigned int)mask);
else
depend_hi[pos] |= 1 << (mask - 32);
}
Expand Down
2 changes: 1 addition & 1 deletion stable.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ count_stable( int color,

common_stable.low = edge_stable[edge_a1h1];

common_stable.high = (edge_stable[edge_a8h8] << 24);
common_stable.high = (((unsigned int)edge_stable[edge_a8h8]) << (unsigned int)24);

t = edge_stable[edge_a1a8];
common_stable.low |= ((t & 0x0F) * 0x00204081) & 0x01010101;
Expand Down
8 changes: 4 additions & 4 deletions thordb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2522,18 +2522,18 @@ init_move_masks( void ) {
for ( i = 0; i < 4; i++ )
for ( j = 0, pos = 10 * i + 11; j < 8; j++, pos++ ) {
index = 8 * i + j;
move_mask_lo[pos] = (1 << index);
move_mask_lo[pos] = (((unsigned int)1) << ((unsigned int)index));
move_mask_hi[pos] = 0;
unmove_mask_lo[pos] = ~(1 << index);
unmove_mask_lo[pos] = ~(((unsigned int)1) << ((unsigned int)index));
unmove_mask_hi[pos] = ~0;
}
for ( i = 0; i < 4; i++ )
for ( j = 0, pos = 10 * i + 51; j < 8; j++, pos++ ) {
index = 8 * i + j;
move_mask_lo[pos] = 0;
move_mask_hi[pos] = (1 << index);
move_mask_hi[pos] = (((unsigned int)1) << ((unsigned int)index));
unmove_mask_lo[pos] = ~0;
unmove_mask_hi[pos] = ~(1 << index);
unmove_mask_hi[pos] = ~(((unsigned int)1) << ((unsigned int)index));
}
}

Expand Down

0 comments on commit 3416efd

Please sign in to comment.