Why is my code slower on 64-bit machines than 32-bit?

Discussion of chess software programming and technical issues.

Moderator: Ras

monk64

Why is my code slower on 64-bit machines than 32-bit?

Post by monk64 »

I have some chess engine code I've written and I ran some benchmarks on it. The benchmark simply generates 1,000,000 Zobrist keys and runs through my eval routine 1,000,000 on the same position (without any transpo table or any other hashing). It's all pretty standard bitboard stuff, built by reading examples on the Wiki.

On a 32-bit Pentium 4 HT 2.4Ghz box, I get this:

1,000,000 hash keys took 0.531496 seconds
1,000,000 scores took 1.044043 seconds

Nothing special about the compile flags:

CFLAGS = -O3 -Wall -pedantic -std=c99

The binary is

ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

running on

Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux

Now I took the code over to a 64-bit x86_64 box, and recompiled it:

ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), not stripped

Slightly different version of the OS but pretty similar:

Linux 2.6.9-89.0.18.ELsmp #1 SMP Tue Dec 15 14:10:51 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

The box is a 3.0Ghz Pentium 4 HT and is generally newer than the 32-bit box.

The code, however, runs 2.5 times slower:

1,000,000 hash keys took 1.435741 seconds
1,000,000 scores took 2.142182 seconds

I'd thought the 64-bit processor would make a difference...the other way ;-)

The only code change I played with was the typedef for the bitboard (same typedef for the hash key):

On 32-bit:

typedef unsigned long long int BITBOARD;

On 64-bit, I tried both "unsigned long long" and "unsigned long" but the number did not change.

Now, I realize code doesn't magically run faster just because you recompile it to 64-bits - I've certainly experienced that in my professional life.

But in the case of chess engines, I would think the benefits of 64-bit would be great: slinging 64-bit bitboards around natively, more CPU registers, etc.

So, I'm a little confused...

I can work up a publishable example if someone wants to see the specific code. It's all single-threaded at this point, btw.
Dann Corbit
Posts: 12803
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Why is my code slower on 64-bit machines than 32-bit?

Post by Dann Corbit »

What do you see when you type
gcc --version
on the two machines?
monk64

Re: Why is my code slower on 64-bit machines than 32-bit?

Post by monk64 »

Looks like the 64-bit box is a little older version-wise.

GCC versions:

64-bit (CentOS 4.8):

$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)


32-bit (CentOS 5.4):

$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
Dann Corbit
Posts: 12803
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Why is my code slower on 64-bit machines than 32-bit?

Post by Dann Corbit »

Your 64 bit GCC compiler is a fossil.
alpha123
Posts: 660
Joined: Sat Dec 05, 2009 5:13 am
Location: Colorado, USA

Re: Why is my code slower on 64-bit machines than 32-bit?

Post by alpha123 »

gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)
:shock:

Um, 2.5x slower is pretty good.....

Peter
monk64

Re: Why is my code slower on 64-bit machines than 32-bit?

Post by monk64 »

Dann Corbit wrote:Your 64 bit GCC compiler is a fossil.
I guess so! upgrading it to 4.1.2 produced:

1,000,000 hash keys took 0.170033 seconds
1,000,000 scores took 0.315351 seconds


:-)