Include 4men syzygy in an engine

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, Dann Corbit, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Fabio Gobbato
Posts: 158
Joined: Fri Apr 11, 2014 8:45 am
Full name: Fabio Gobbato
Contact:

Re: Include 4men syzygy in an engine

Post by Fabio Gobbato » Sat Dec 07, 2019 11:52 am

I've found the problem!

In init_table there is this code:

Code: Select all

  for (int t = 0; t < num; t++) {
    data = (uint8_t *)(((uintptr_t)data + 0x3f) & ~0x3f);
    ei[t].precomp->data = data;
    data += size[t][0][2];
    if (split) {
      data = (uint8_t *)(((uintptr_t)data + 0x3f) & ~0x3f);
      ei[num + t].precomp->data = data;
      data += size[t][1][2];
    }
  }
The pointer arithmetic suppose that the files in memory are aligned with 64 bytes, that it's true with mmap but not with malloc or with a global array.
Now that it works the probe with the 4men tb in ram is very very fast.

mar
Posts: 2225
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Include 4men syzygy in an engine

Post by mar » Sat Dec 07, 2019 12:32 pm

Fabio Gobbato wrote:
Sat Dec 07, 2019 11:52 am
I've found the problem!

In init_table there is this code:

Code: Select all

  for (int t = 0; t < num; t++) {
    data = (uint8_t *)(((uintptr_t)data + 0x3f) & ~0x3f);
    ei[t].precomp->data = data;
    data += size[t][0][2];
    if (split) {
      data = (uint8_t *)(((uintptr_t)data + 0x3f) & ~0x3f);
      ei[num + t].precomp->data = data;
      data += size[t][1][2];
    }
  }
The pointer arithmetic suppose that the files in memory are aligned with 64 bytes, that it's true with mmap but not with malloc or with a global array.
Now that it works the probe with the 4men tb in ram is very very fast.
You're lucky that the masking is done on a signed integer that is sign-extended first before conversion to a (potentially) 64-bit value.
Had you used ~0x3fu the program would break badly in 64-bit mode.

Anyway good that you found the problem. I was wondering because the code you posted should've worked, I wouldn't guess an aligment issue but it makes sense.
Martin Sedlak

Post Reply