A Neat Trick

Discussion of chess software programming and technical issues.

Moderator: Ras

Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: A Neat Trick

Post by Michael Sherwin »

Just for completeness is this code now at least correct?

Code: Select all

sq = ts - ((epbit[t][ply[t] - 1] & (one << ts)) >> (ts - 3));
          target = board[t][sq];
More simple pseudo code.

Code: Select all

sq = ts - ((epbit & (1ull << ts)) >> (ts - 3));
          target = board[sq];
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: A Neat Trick

Post by Michael Sherwin »

@hgm, Benchmarks of shift instructions comparing Intel vs AMD reveals that even ten year old AMD chips run circles around even the latest Intel chips. So my question about your solution is wouldn't it be better to use a shift instruction rather than a multiply.

Code: Select all

sq = ts ^ ((u64)(epbitboard == one<<ts) << 3);
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Terje
Posts: 347
Joined: Tue Nov 19, 2019 4:34 am
Location: https://github.com/TerjeKir/weiss
Full name: Terje Kirstihagen

Re: A Neat Trick

Post by Terje »

Michael Sherwin wrote: Sun Apr 12, 2020 11:27 pm @hgm, Benchmarks of shift instructions comparing Intel vs AMD reveals that even ten year old AMD chips run circles around even the latest Intel chips. So my question about your solution is wouldn't it be better to use a shift instruction rather than a multiply.

Code: Select all

sq = ts ^ ((u64)(epbitboard == one<<ts) << 3);
If you multiply by a constant that's a power of 2 the compiler will output shifts instead.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: A Neat Trick

Post by Michael Sherwin »

Terje wrote: Mon Apr 13, 2020 1:26 am
Michael Sherwin wrote: Sun Apr 12, 2020 11:27 pm @hgm, Benchmarks of shift instructions comparing Intel vs AMD reveals that even ten year old AMD chips run circles around even the latest Intel chips. So my question about your solution is wouldn't it be better to use a shift instruction rather than a multiply.

Code: Select all

sq = ts ^ ((u64)(epbitboard == one<<ts) << 3);
If you multiply by a constant that's a power of 2 the compiler will output shifts instead.
Oh okay, I think I knew that, duh (to me). Thanks for the reminder! :D
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through