From: Skybuck Flying on
Hello,

To load the carry flag into a register I use:

mov eax, 0
adc eax, 0

I was wondering is there a faster way to load the carry flag into a register
?

Maybe there is a single instruction for it ?

Bye,
Skybuck.


From: Frank Kotler on
Skybuck Flying wrote:
> Hello,
>
> To load the carry flag into a register I use:
>
> mov eax, 0
> adc eax, 0
>
> I was wondering is there a faster way to load the carry flag into a register
> ?
>
> Maybe there is a single instruction for it ?

"setc al", perhaps? Dunno how the speed would compare. Still need to
zero eax first, if you need "all of eax".

Best,
Frank
From: Robert Redelmeier on
In alt.lang.asm Skybuck Flying <spam(a)hotmail.com> wrote in part:
> To load the carry flag into a register I use:
>
> mov eax, 0
> adc eax, 0
>
> I was wondering is there a faster way to load the carry flag
> into a register? Maybe there is a single instruction for it ?

SBB EAX, EAX ?

Then you get 0 or FF..FF

-- Robert

From: Skybuck Flying on
Hmm it's one instruction shorter but it doesn't appear to be faster:

function GetBitInt( BaseAddress : pointer; BitIndex : longword ) : byte;
asm
bt [eax], edx
setc al
// mov eax, 0
// adc eax, 0
end;

The three instruction version appears to be faster on X2 3800+ ?:

function GetBitInt( BaseAddress : pointer; BitIndex : longword ) : byte;
asm
bt [eax], edx
mov eax, 0
adc eax, 0
end;

Kinda strange.

Thanks anyway.

Bye,
Skybuck.


From: Skybuck Flying on
Yeah, I thought about that too, dismissed it because of different results,
but now that I think about it again, negative values or all bits set values
might be usuable as well.

However the sbb version seems to be slower than the three instructions
version:

function GetBitInt( BaseAddress : pointer; BitIndex : longword ) : byte;
asm
bt [eax], edx
sbb eax, eax
end;

Kinda strange.

Some possibilities:

1. Maybe I am not measuring it right ?
2. Maybe other software is influencing the testing, maybe they don't use adc
so maybe processor has some micro ops available for it or so ?
3. Maybe it's an alignment issue. Maybe the three instruction version loads
faster from memory ??? or for some reason gets executed faster.

function GetBitInt( BaseAddress : pointer; BitIndex : longword ) : byte;
asm
bt [eax], edx
mov eax, 0
adc eax, eax
end;

Bye,
Skybuck.