From: Rob Kennedy on
Skybuck Flying wrote:
> "Wojciech Mula" <wojciech_mula(a)poczta.null.onet.pl.invalid> wrote in message
> news:20080504190913.938d1fff.wojciech_mula(a)poczta.null.onet.pl.invalid...
>> "Skybuck Flying" <BloodyShame(a)hotmail.com> wrote:
>>
>>> function FastGetBit( Value : longword; BitPosition : longword ) :
>>> boolean;
>>> asm
>>> bt eax, edx // latency: 1
>>> mov eax, 0 // latency: 1
>>> adc eax, 0 // latency: 1
>>> end;
>> You can replace mov/adc with single setc eax -- this instruction
>> has 1 cycle latency on modern CPUs.
>
> No, there is a little problem with that solution.
>
> setxx only sets a single byte.

Why is that a problem? That's exactly the size of your function's return
type.

> The delphi 2007 compiler uses the setxx solution and for some reason it is
> forced to output:
>
> "and 127" as well.
>
> Which is an extra instruction.

Based on your later message in this thread, it looks as though Delphi
really adds that as part of converting a Boolean to a LongWord. It has
nothing to do with the code in your function. Delphi would add the "and
127" part to the result of your function call no matter what code you
put in your function since Delphi doesn't do interprocedural analysis,
especially not for inline assembler.

--
Rob
 | 
Pages: 1
Prev: my 3d gallery art
Next: OS - Processor interaction