]> git.sesse.net Git - stockfish/commit
Guard against UB in lsb/msb
authorlucasart <lucas.braesch@gmail.com>
Tue, 29 Mar 2016 12:37:42 +0000 (20:37 +0800)
committerJoona Kiiski <joona@zoox.com>
Thu, 31 Mar 2016 12:22:37 +0000 (13:22 +0100)
commitf256388e0808b45d8468b088cdc141a41feac3fb
tree3521dbc47e7d5f83cd3b01da4939eaade3dfb70d
parentdb4b0d8b7db8db15c16a71212990354094f00b0d
Guard against UB in lsb/msb

lsb(b) and msb(b) are undefined when b == 0. This can lead to subtle bugs, where
the resulting code behaves differently on different configurations:
- It can be the home grown software LSB/MSB
- It can be the compiler generated software LSB/MSB (when using compiler
  intrinsics without the right compiler flags to allow compiler to use hardware
  LSB/MSB). Which of course depends on the compiler.
- It can be hardware LSB/MSB generated by the compiler.
- Not to mention that hardware LSB/MSB can return different value on different
  hardware when b == 0.

No functional change

Resolves #610
src/bitboard.cpp
src/bitboard.h