int opEquals(Object), and other legacy ints (!)
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Jul 30 17:29:45 PDT 2006
Bruno Medeiros wrote:
> And uuuh.., I've checked gcc's generated code for a C++'s Eq1, and it
> was only 2 instructions too, CMP and SETE ! :
>
> Eq1:
> ...
> cmp EAX,0Ch[ECX]
> sete EAX;
>
> (http://www.cs.tut.fi/~siponen/upros/intel/instr/sete_setz.html)
> It seems to me perfectly valid, is there any problem here?
Interesting instruction. Seems to have the exact semantics needed for
these situations. You'd almost think CPU designers care about what
people want to do with their products :P.
> What does the original Eq1 even do? :
Step by step:
> mov ECX,0Ch[EAX]
(You skipped this one) Loads this.bar into ECX.
> sub ECX,0Ch[EDX]
Subtracts foo.bar from ECX.
> cmp ECX,1 // Huh?
Among other things, sets borrow (aka carry) flag if ECX == 0 (i.e. if
foo.bar == this.bar), clears it otherwise.
> sbb EAX,EAX
Subtracts (EAX + borrow) from EAX, setting it to either -1 (if carry ==
1) or 0 (if carry == 0).
> neg EAX
Negates EAX.
A bit weird at first glance, but it works as advertised :).
But indeed, a cmp/sete combo seems to do the same in less instructions.
More information about the Digitalmars-d-bugs
mailing list