Fun with De Bruijn

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Fun with De Bruijn

Post by stegemma »

vittyvirus wrote:
Henk wrote:I wanted to convert a bitboard position into a square position. So I decided to use a de Bruijn sequence to calculate row and colnr but it did not work. Finally it is working but what is wrong with using a simple Math.Log(bb, 2).
Wow! This is the fastest way I've heard of. I wonder why people are wasting their time with magic (debruijn) hashing based methods. They involve a lot of instructions compared to this: Math.Log(bb, 2)! Just one instruction!!! I haven't done benchmarks yet, but I predict it is 13.64 times faster than with debruijn hashing. Also, Math.Log(bb, 2) gives you the advantage of using 2, which is quite hardware friendly, and this method can even take advantages of floating point hardware intrinsics, and thus making it even faster. I don't think your idea is original, but still I'd appreciate you for making us know tjis revolutionary idea.
You've missed some smiling emoticon but of course you're just joking. In this case, only the experiment can tell us how this idea is good or not:

Code: Select all

with log2(): Nodes: 119060324, Time: 5891 ms, Nodes/s: 20207115
with intrinsic: Nodes: 119060324, Time: 2453 ms, Nodes/s: 48516839
But, despite from that, when I was about 15 I've wrote a program that solves the 8 queens problem on a Texas TI57 using the trick to call log10(position) to extract single queens in a 8 digit decimal number. Of course that calculator were very limited and it has only decimal number programming.

Maybe in the future log2(bitboard) would becomes the fastest way to scan for bits... who knows? ;)
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Fun with De Bruijn

Post by jwes »

vittyvirus wrote:
Henk wrote:I wanted to convert a bitboard position into a square position. So I decided to use a de Bruijn sequence to calculate row and colnr but it did not work. Finally it is working but what is wrong with using a simple Math.Log(bb, 2).
Wow! This is the fastest way I've heard of. I wonder why people are wasting their time with magic (debruijn) hashing based methods. They involve a lot of instructions compared to this: Math.Log(bb, 2)! Just one instruction!!! I haven't done benchmarks yet, but I predict it is 13.64 times faster than with debruijn hashing. Also, Math.Log(bb, 2) gives you the advantage of using 2, which is quite hardware friendly, and this method can even take advantages of floating point hardware intrinsics, and thus making it even faster. I don't think your idea is original, but still I'd appreciate you for making us know tjis revolutionary idea.
There is actually a reasonable implementation of this idea. Roughly, the idea is convert the bitboard to a double, extract the exponent, subtract a constant and you have the high bit. This may be competitive on machines without BSF.