Include 4men syzygy in an engine

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Fabio Gobbato
Posts: 217
Joined: Fri Apr 11, 2014 10:45 am
Full name: Fabio Gobbato

Re: Include 4men syzygy in an engine

Post by Fabio Gobbato »

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: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Include 4men syzygy in an engine

Post by mar »

Fabio Gobbato wrote: Sat Dec 07, 2019 12:52 pm 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