Ok, I was probably too optimistic, since I wrongly referred two 32-bit imuls per direction. Still even with one imul you have some shifts around. Processing two lines in parallel (for bishop or rook) relaxes the dependencies, and the 32-bit shifts are nops in 32-bit mode, so Collapsed Files for diagonals, anti-diagonal and ranks seems very competitive, even if compiler don't emit or al, ah. I think it is worth a try if you focus on 32-bit machines.Gian-Carlo Pascutto wrote:Ah, really? I would have expected that the 32 bit folded kindergarten (1 mul per direction) would be faster than a series of dependent shifts.Gerd Isenberg wrote:Sure, imul64 on 32-bit is a call with three imuls. But Piotr's proposal seems even a faster solution than a dedicated 2 times 32-bit mul approach.Gian-Carlo Pascutto wrote: In any case there is no need to do 64 bit multiplies with Kindergarten.
Kindergarten bitboards without multiplying
Moderators: hgm, Rebel, chrisw
-
- Posts: 2250
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: Kindergarten bitboards without multiplying
-
- Posts: 2250
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: Kindergarten bitboards without multiplying
Ok, is something similar available for gcc/linux?Gian-Carlo Pascutto wrote:Still doesn't guarantee it stays on the same CPU. Again: use QueryPerformanceCounter or get burned.Gerd Isenberg wrote: Sure, GetTickCount() resolution is far to coarse for that purpose, but you may try cpuid with eax zero before rdtsc, to make sure it doesn't executed out of order.
-
- Posts: 1243
- Joined: Sat Dec 13, 2008 7:00 pm
Re: Kindergarten bitboards without multiplying
gettimeofday()
If you really absolutely need nanoseconds, there is clock_gettime().
If you really absolutely need nanoseconds, there is clock_gettime().
-
- Posts: 838
- Joined: Thu Jul 05, 2007 5:03 pm
- Location: British Columbia, Canada
Re: Kindergarten bitboards without multiplying
Unless I misunderstand something, the shifts are not dependent on each other (but combining the result together is).Gian-Carlo Pascutto wrote:Ah, really? I would have expected that the 32 bit folded kindergarten (1 mul per direction) would be faster than a series of dependent shifts.Gerd Isenberg wrote:Sure, imul64 on 32-bit is a call with three imuls. But Piotr's proposal seems even a faster solution than a dedicated 2 times 32-bit mul approach.Gian-Carlo Pascutto wrote: In any case there is no need to do 64 bit multiplies with Kindergarten.
-
- Posts: 1243
- Joined: Sat Dec 13, 2008 7:00 pm
Re: Kindergarten bitboards without multiplying
The second shift is operating on the result of the first shift. The first shift is operating on the result of the operation just before it.wgarvin wrote: Unless I misunderstand something, the shifts are not dependent on each other (but combining the result together is).
-
- Posts: 838
- Joined: Thu Jul 05, 2007 5:03 pm
- Location: British Columbia, Canada
Re: Kindergarten bitboards without multiplying
Okay, I see what you mean now. I misunderstood that code.Gian-Carlo Pascutto wrote:The second shift is operating on the result of the first shift. The first shift is operating on the result of the operation just before it.wgarvin wrote: Unless I misunderstand something, the shifts are not dependent on each other (but combining the result together is).
I guess the shifts are a bit expensive, but not as expensive as doing 2 or more 32-bit multiplies.
-
- Posts: 2250
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: Kindergarten bitboards without multiplying
Two shifts plus "or" are about the same as 32-bit mul on current cpus >= K8, core2. The advantage of 32-bit mode is one safes the shift right 32. One of the seldom cases where 32-bit mode is advantageous for bitboardswgarvin wrote:Okay, I see what you mean now. I misunderstood that code.Gian-Carlo Pascutto wrote:The second shift is operating on the result of the first shift. The first shift is operating on the result of the operation just before it.wgarvin wrote: Unless I misunderstand something, the shifts are not dependent on each other (but combining the result together is).
I guess the shifts are a bit expensive, but not as expensive as doing 2 or more 32-bit multiplies.
To get the 2* six inner bits collapsedFilesIndex into eax might be 6 cycles each, the same for two indices in parallel:
Code: Select all
; input edx:eax masked rank, dia or antidia
; output eax
or eax, edx 1
mov edx, eax 1
shr eax, 16 1
or eax, edx 1
or al, ah 1
and eax, 2*63 1
Code: Select all
; input edx:eax masked rank, dia or antidia
; output eax
or eax, edx ; folded 1
imul eax, 0x01010101 111
shr eax, 24 1
and eax, 2*63 1