Page 1 of 1
Little-Endian or Big-Endian?
Posted: Sun Dec 06, 2015 6:12 am
by MathAddict
I was wondering if it is better to have little-endian representation of squares(a1=0,h8=63) or big-endian(h1=0,a8=63).
Currently I am using big-endian but I see that engines like Stockfish use little-endian so I was wondering if little-endian can be optimized to be faster.
Re: Little-Endian or Big-Endian?
Posted: Sun Dec 06, 2015 1:41 pm
by thevinenator
it is a matter of personal choice. i originally had my code in what you are calling "big endian", because it was easier to display boards on the console since the looping was going from 0 to 63 and the white piece were usually shown on the bottom of the board display. But as time went on, it got confusing when i examined or tried code from other developers who mostly use the "little endian" style. It wasn't too much work to switch and it all seems to be working now.
Re: Little-Endian or Big-Endian?
Posted: Sun Dec 06, 2015 5:13 pm
by hyatt
The issue is bit numbering. Intel hardware (BSF/BSR) counts LSB as 0, MSB as 63. You should use that numbering scheme to avoid any sort of translation such as the 63 - N I did since I originally numbered the bits to match the Cray architecture. For simplicity I use a1=0, h1=7, a8=56, h8=63, makes move input and output translation a "direct process"...
Makes the bit boards a bit "backward" to visualize since rightmost bit = leftmost square, but then everything else is a direct map.