Author: Bo Persson
Date: 04:30:15 04/21/00
Go up one level in this thread
On April 20, 2000 at 16:09:43, Flemming Rodler wrote:
>>>PS: I still hope someone can show me how to inline assembler under gcc.
>>
>>Hopefully this helps (and works! :) :
>>
>>#define firstone(b) \
>>({ int __value; long long int __arg = (b); \
>> asm ("bsfl %1,%0\n\t" \
>> "jnz 1f\n\t" \
>> "bsfl 4+%1,%0\n\t"\
>> "jz 2f\n\t" \
>> "addl $32,%0\n\t" \
>> "jmp 1f\n\t" \
>> "2:\n\t" \
>> "movl $64,%0\n\t" \
>> "1:\n\t" \
>> : "=r" (__value) \
>> : "o" (__arg) ); \
>> __value; })
>>
>>best wishes,
>>Andrzej Nagorko
>
>Thanks. I just tried it out, and it seems to work fine. Nice that it returns 64
>if there are no 1's in b. The execution time varies with the postion of the
>first 1. Not only depending in which half of the long long it resides in so the
>bsfl instruction have varying execution times. Maybe it a lookup table is
>faster? I will try later today.
>
>Thanks
>Flemming
The execution time varies becuase you have an AMD processor. On an Intel
PII/PIII, the BSF instruction will run in 1 or 2 clock ticks regardless of the
number of bits set!
Bo Persson
bop@malmo.mail.telia.com
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.