Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: assembly--not really that fast

Author: leonid

Date: 11:07:11 01/13/02

Go up one level in this thread


On January 13, 2002 at 10:22:52, Robert Hyatt wrote:

>On January 13, 2002 at 07:05:02, Ed Schröder wrote:
>
>>On January 13, 2002 at 05:35:06, Tom Kerrigan wrote:
>>
>>>On January 13, 2002 at 05:10:44, David Dory wrote:
>>>
>>>>On January 13, 2002 at 01:53:02, emerson tan wrote:
>>>>
>>>>>What's the best computer language to program a chess software in terms of speed
>>>>>of execution? Is it FORTRAN? C++? C? or any other language I dont know? What are
>>>>>the advantages and disadvantages of each language? What languages does FRITZ,
>>>>>SHREDDER, REBEL, TIGER, JUNIOR, HIARCS, CRAFTY, CHESSMATER AND OTHER FAMOUS
>>>>>PROGRAMS USE?
>>>>>
>>>>>Thanks
>>>>
>>>>Most of the top amateur and pro programs are written in C. Many sprinkle in some
>>>>assembly language in very time-critical sections. Some very good programs have
>>>>been written in assembly - which is blazingly fast. Unfortunately when the
>>>
>>>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.
>>>
>>>Another problem with assembly is that it's hard to keep current. Assembly that
>>>ran well on Pentiums does not necessarily run well on Pentium Pros. I know that
>>>Fritz was bitten by this problem--the engine was written in assembly and
>>>optimized for the Pentium when the PPro came out, and it actually ran slower on
>>>an equally-clocked PPro. A C program can just be recompiled with a PPro-suited
>>>compiler and get performance gains from the new processor.
>>>
>>>-Tom
>>
>>
>>I have to disagree, I have a MSVC6 version of Rebel and it runs 30% slower than
>>the ASM version.
>>
>>Ed
>
>
>I've always sais that the people that say that C is just as fast as assembly
>simply don't know "how to do it right".  Cray has the _best_ optimizing
>FORTRAN compiler on the planet, _bar_ _none_.  Yet the assembly version of
>Cray Blitz was roughly 5x faster when we started and even at the end of the
>project it was still 3x faster.
>
>There are several reasons:
>
>1.  You know more about the program than the compiler.  No bounds-checking
>on "switch" type statements is necessary.
>
>2.  you know whether a value can be positive, negative, or both.  The
>compiler can't.
>
>3.  you know whether a value can exceed (say) 127 or not.  The compiler can't.
>
>4.  You know how many registers the CPU has and can design code around that,
>while C doesn't give you such control.
>
>5.  you know exactly which registers procedure "x" will destroy, so you don't
>have to save everything before calling it.  If you are careful, you don't have
>to save _anything_.
>
>the list goes on and on.
>
>In the case of the Cray, we could do some tricky things in assembly that the
>compiler simply couldn't do, particularly dealing with vectors and the vector
>hardware.  IE we could use vector values as temporary registers.  We didn't
>have to continually save/restore stuff as procedure calls were made because
>we didn't use _any_ "library functions" whatsoever in the search itself.
>
>I would be more than happy to take on _any_ compiler, given a program as
>complex as a chess engine.  And the compiler simply won't have a chance.
>
>Of course, there _are_ good reasons for using C.  Portability and ease of
>change to name just two...
>
>But for absolutely max speed, there is only one answer...

Thanks for excellent and interesting explanation!

Leonid.



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.