Moderator: Andres Valverde
Steve Maughan wrote:I think I recall that Fruit has a 16 x 16 board representation. And I think I remeber someone, probably Fabian, saying that this gives the benefits of post-box and x88. Having recently given this some thought I'm not sure how this can be the case. I cannot find a mask such that a simple '&' (or any other) operation will give a simple on/off board result (i.e. x88 approach), while still allowing [Square - 33] to be always a valid array index (i.e. postbox approach).
What am I missing? Can anyone explain the 16 x 16 approach?
typedef struct {
uint8 board_[256];
uint8 *board;
} position_t
void initialise_position(position_t *pos) {
pos->board = pos->board_ + 64; /* 64 = index of first square on the "real board" */
}
if(pos->board[sq] == OUTSIDE) { ... }
if(sq & 0x88) { ... }
typedef struct {
int board-[256];
int *board;
};
typedef struct {
uint8 board_[256];
uint8 *board;
} position_t
void initialise_position(position_t *pos) {
pos->board = pos->board_ + 64; /* 64 = index of first square on the "real board" */
}
if(pos->board[sq] == OUTSIDE) { ... }
if(sq & 0x88) { ... }
Dieter B?r?ner wrote:
This sounds a bit less efficient (on x86 hardware) than the functional equivilant
#define A1_OFFSET 64
#define BOARD(sq) board_[(sq) + A1_OFFSET]
Using the pointer needs one indirection more, to access the value. Constant offsets (almost) don't need any time. On x86 they will just change the used upcode. For offsets > 127 (or so, I don't remember the details), the upcode gets a bit longer, however - so the program may use a bit more of code space, and might be less cache friendly. Also, accessing data through a pointer can make things harder for the optimizer.
Dieter B?r?ner wrote:
- Code: Select all
if(sq & 0x88) { ... }
>In practice, I have found that the first method is almost always a tiny bit faster
A surprise to me. The 0x88 method is just one typical test upcode (which any machine will have, althoug some RISC type machines may need to put 0x88 into an register first - on x86 the constant is inside the upcode).
The mailbox methods needs a memory access (most probably from cache), which just sounds slower.
Steve Maughan wrote:I think the reason why it's faster is that in most cases you need to do the memory access anyway i.e. once you've establish that the square is on the board you then need to make sure it's not one of your pieces, which is a memory access. The 0x88 metthod is only faster if the square proves to be off the board.
Dieter B?r?ner wrote:
This sounds a bit less efficient (on x86 hardware) than the functional equivilant
#define A1_OFFSET 64
#define BOARD(sq) board_[(sq) + A1_OFFSET]
uint8 * const Board = &Board_[offset];
Dieter B?r?ner wrote:A surprise to me. The 0x88 method is just one typical test upcode (which any machine will have, althoug some RISC type machines may need to put 0x88 into an register first - on x86 the constant is inside the upcode).
The mailbox methods needs a memory access (most probably from cache), which just sounds slower.
if (board[sq] & IS_WHITE_PIECE) {...}
uint8 * const Board = &Board_[offset];
Steve Maughan wrote:I think I recall that Fruit has a 16 x 16 board representation. And I think I remeber someone, probably Fabian, saying that this gives the benefits of post-box and x88. Having recently given this some thought I'm not sure how this can be the case. I cannot find a mask such that a simple '&' (or any other) operation will give a simple on/off board result (i.e. x88 approach), while still allowing [Square - 33] to be always a valid array index (i.e. postbox approach).
What am I missing? Can anyone explain the 16 x 16 approach?
Thanks,
Steve
Uri Blass wrote:I wonder if the board representation is very important.
I simply use info[64] as the board representation when
0=a1,1=b1,...7=h1,...63=h8
info[x]=0(8) means white(black) pawn at square x respectively.
info[x]=1(9) means white(black) knight at square x.
...
info[x]=5(13) means white king at square x.
info[x]=22 means empty square.
Did someone try that method and how much faster are the alternatives?
Dieter B?r?ner wrote:This sounds a bit less efficient (on x86 hardware) than the functional equivilant
- Code: Select all
#define A1_OFFSET 64
#define BOARD(sq) board_[(sq) + A1_OFFSET]
quote="Fabien LetouzeyI changed from 16x12 (Fruit 1.5) to 16x16 (2.0) only to have a symmetric treatment of files and ranks.
May I ask why you're interested in treating files and ranks symmetrically?
Steve Maughan wrote:May I ask why you're interested in treating files and ranks symmetrically?
Steve
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 12 guests