Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Interesting Assembly (OT)

Author: Matt Taylor

Date: 06:03:42 01/04/03

Go up one level in this thread


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



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.