Computer Chess Club Archives


Search

Terms

Messages

Subject: Bitboard stuff

Author: Russell Reagan

Date: 21:02:06 06/22/04


Assume we are using a 32-bit machine. Let's say that I have a simple macro that
takes a bitboard and returns a given 8-bit rank of that bitboard. Something like
this:

#define GetRank(b,sq) ((b >> (sq & 56)) & 255)

Let's say I write this as a function:

unsigned GetRank (Bitboard b, int square)
{
    return (b >> (square & 56)) & 255;
}

In this situation (and any others like it), the return value will always be an
8-bit value. Is there any reason to prefer that the return type be unsigned char
(8-bit) or unsigned int (32-bit)?

The only potential issues I can think of are:

1. Converting between types. I don't think this matters as long as the types are
both unsigned. I think the only time this matters is when you are converting
from (say) an 8-bit signed value to a (say) 32-bit signed value, since a sign
extension is required.

2. Cache issues. By using a smaller type (8-bit in this case), is there any
chance that this will help the cache store more data per cache line? I know that
if you have a big array of values that can be either 8-bit or 32-bit values,
then choosing the 8-bit values would probably help, but in the case of the
return value, I don't think this would make any difference on the effectiveness
of the cache.

3. Register issues. Since the return value will only require one byte of a
register, can the compiler can use the other three bytes for something?



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.