Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Interesting Assembly (OT)

Author: Robert Hyatt

Date: 10:01:56 01/04/03

Go up one level in this thread


On January 04, 2003 at 09:03:42, Matt Taylor wrote:

>On January 04, 2003 at 07:16:55, Graham Laight wrote:
>
>>On January 03, 2003 at 19:42:51, Matt Taylor wrote:
>>
>>>On January 03, 2003 at 13:37:25, Robert Hyatt wrote:
>>>
>>>>On January 03, 2003 at 10:00:51, Graham Laight wrote:
>>>>
>>>>
>>>>Here is a snippet of assembly produced by gcc, for the test
>>>>
>>>>if (x[1]==3 || x[1]==7) return(1);
>>>>else return(0);
>>>>
>>>>        movl    x+4, %eax
>>>>        cmpl    $3, %eax
>>>>        sete    %dl
>>>>        cmpl    $7, %eax
>>>>        sete    %al
>>>>        orl     %edx, %eax
>>>>        testl   $1, %eax
>>>>        sete    %al
>>>>        movzbl  %al, %eax
>>>>        ret
>>><snip>
>>>
>>>Very interesting. I tried the same snippet using VC 7 and every optimization I
>>>could find and got atrocious code:
>>>
>>>        movl	x+4, %eax
>>>        cmpl	$3, %eax
>>>        je	L73439
>>>        cmpl	$7, %eax
>>>        je	L73439
>>>
>>>        xorl	%eax, %eax
>>>        ret
>>>
>>>L73439:
>>>        movl	$1, %eax
>>>        ret
>>>
>>>
>>>I'm also suprised that GCC missed saving these two cycles:
>>>        movl    x+4, %eax
>>>        cmpl    $3, %eax
>>>        sete    %dl
>>>        cmpl    $7, %eax
>>>        sete    %al
>>>
>>>        ; Should be using partial registers to avoid stall on P6/P7
>>>        ;orl     %edx, %eax
>>>        orb     %dl, %al
>>>
>>>        ; Omit (redundant)
>>>        ;testl   $1, %eax
>>>        ;sete    %al
>>>
>>>        movzbl  %al, %eax
>>>        ret
>>>
>>>I guess there is still room for hand-tweaking assembly code, though it is
>>>obviously not worthwhile unless you need to start squeezing cycles out of code.
>>>
>>>-Matt
>>
>>Fritz is reputed to use assembly code inserts. It is worthwhile in a chess
>>program because so much depends on speed in loops (and recursions) which are
>>repeated a massive number of times.
>>
>>The downside is that Fritz would be the most difficult program to port to a
>>non-intel computer. At future world championships, I think that Fritz will have
>>trouble against competitors who have ported to unix boxes with a large number of
>>processors.
>>
>>-g
>
>Not necessarily. A lot of people think that assembly is mutually exclusive with
>portability. I always write my routines first in C (whenever -possible-), partly
>because it helps in writing the assembly. Keeping the C routine makes it trivial
>to port to other platforms. Just use preprocessor directives. You don't get the
>extra performance on the other platforms, but you wouldn't expect that anyway.
>:-)
>
>-Matt


There are clearly two issues here, from _lots_ of experience.

1.  writing in assembly _first_ is really a waste of time.  You want to write
in something that makes writing easy, so that you can test algorithms without
investing man-months of effort in something that you might/probably will throw
away.  I had 20K lines of assembly in Cray Blitz, but I also had FORTRAN code
that did the same thing, so that if we wanted to try something, we could compile
with FORTRAN-only, make the FORTRAN changes (much easier) and only after
deciding the new idea worked would we dive into the assembler and make the
comparable changes there.

2.  assembly has a _terrific_ effect on portability however.  IE our assembly
was 5x faster overall than the FORTRAN-only version of Cray Blitz, yet Cray
had arguably the best optimizing FORTRAN compiler in the entire world of
supercomputing (or any kind of computing for that matter).  Giving up a factor
of 5x would be quite a loss, until the assembly code for the new machine was
developed...

The disadvanatages of assembly are numerous, but the speed advantage can't be
overlooked...



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.