Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question for the Crafty/Compiler experts

Author: Robert Hyatt

Date: 08:14:30 02/19/04

Go up one level in this thread


On February 19, 2004 at 08:38:43, Dieter Buerssner wrote:

>While looking at your code:
>
>int static __inline__ FirstOne(BITBOARD word) {
>  int dummy, dummy2;
>       asm ("movl    $-1, %1"             "\n\t"
>            "bsr     %3, %0"              "\n\t"
>            "cmovz   %1, %0"              "\n\t"
>            "bsr     %2, %1"              "\n\t"
>	    "setnz   %b3"                 "\n\t"
>	    "addl    $32,%1"              "\n\t"
>	    "testb   %b3, %b3"            "\n\t"
>            "cmovz   %0, %1"              "\n\t"
>            "movl    $63, %0"             "\n\t"
>            "subl    %1, %0"              "\n\t"
>  : "=&q" (dummy), "=&q" (dummy2)
>  : "q" ((int) (word>>32)), "q" ((int) word)
>  : "cc");
>  return (dummy);
>}

Where did that come from?  That is not what I am using, so I now see why we are
seeing different results.  That was an experiment to write a FirstOne() with no
jumps, just to see what happened.  Here is the current code (inlinex86.h):

int static __inline__ FirstOne(BITBOARD word) {
  int dummy, dummy2;
       asm ("        movl    $63, %0"     "\n\t"
            "        bsr     %2, %1"      "\n\t"
            "        jnz     1f"          "\n\t"
            "        bsr     %3, %1"      "\n\t"
            "        jnz     2f"          "\n\t"
            "        movl    $64, %0"     "\n\t"
            "        jmp     3f"          "\n\t"
            "1:      addl    $32,%1"      "\n\t"
            "2:      subl    %1, %0"      "\n\t"
            "3:"
  : "=&q" (dummy), "=&q" (dummy2)
  : "q" ((int) (word>>32)), "q" ((int) word)
  : "cc");
  return (dummy);
}

This has more jumps, but the other did two bsf/bsr's each time and then used
cmovxx to choose between the results.  This is what is in the current version of
crafty on my ftp machine.  And this is what I used when I said the inline was
faster than the old external asm that required a call.

>
>This seems risky. You are changing %3 by setnz %b3 without notifying the
>compiler. It is probably better, to have another output var dummy3, to notify
>the compiler of this. Perhaps the & for dummy2 is not needed, because the input
>is already consumed, when you first need it..

It was dangerous, and I had fixed that a while back, but I never really used
that code in a production version that I know of.  Where did you find this?  IE
if it is in any of the released...  wait a minute.  This was probably in older
versions but it was not used as there was no include for it.  The new version
has a specific include for this header file now, but it also has the non-cmovxx
firstone/lastone asm too.



>
>Regards,
>Dieter



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.