Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: assembly--not really that fast

Author: Scott Gasch

Date: 11:26:32 01/14/02

Go up one level in this thread


>
>Assembly used to be blazingly fast, back when compilers weren't very good and
>microprocessors were simpler, but it has lost a lot of its advantages.
>
>It is now extremely difficult to write assembly that's faster than compiled C.
>There are so many rules about how to schedule instructions and align data for
>good performance that only a computer can keep up with them all. I've
>participated in contests with highly regarded assembly language programmers and
>Visual C++ usually outperforms their hand-written code by ~20%. This is often
>because the humans forget or aren't aware of some obscure rule about aligning
>data or instructions.
>

Hey Tom,

I have to disagree also.  I am a totally inexperienced assembly language
programmer.  I've spent a lot of time debugging x86 assembly language so I am
reasonable familiar it.  But I've never really coded much in assembly besides a
random function here or there.

Well one day I happened to be hunting a bug in my chess engine and had the
occation to look at my GetAttacks (part of SEE) routine disassembled.  I was
shocked.  The code was utter garbage.  Often the compiler would load a value
from memory that it already had sitting in a register.  Identifiers that could
have been made pure register variables were written back and forth from memory
all over the place.  This was with maximum optimization turned on in the
compiler!

So I rewrote the function in assembly.  I did this by taking the MSVC assembly
the code gen spat out, printing it out, and optimizing it by hand.  The end
result was about 40% less instructions.  The engine ran, overall, about 20%
faster when I was done.  (My GetAttacks is called very often, #2 in my
profiler hitlist).

Anyway, I am sure compilers do a great job in some places.  And coding the
entire engine in assembly would be very tedious.  But in this case at least the
code generated by the compiler could be rewritten by an inexperienced assembly
language programmer in a short period of time for a dramatic speedup.

Scott




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.