[pypy-dev] Re: OT: abs(x) with 4 assembly insns
bob at redivi.com
Mon Sep 29 15:23:44 CEST 2003
On Monday, Sep 29, 2003, at 09:13 America/New_York, Christian Tismer
> Michael Hudson wrote:
>> Christian Tismer <tismer at tismer.com> writes:
>>> Hmm. 4 insns.
>> Or you can cheat, and remember that you saw something like this in
>> some psyco header file somewhere...
> No, I couldn't. Armin was referring to it, and I wanted
> to find out by myself. He told me about the exhaustive
> search, which I found funny.
>> /* as you can check the following takes the absolute value of (say)
>> EAX: \
>> ADD EAX, EAX
>> SBB EAX, sourcecopy
>> SBB EDX, EDX
>> XOR EAX, EDX
>> (note: although the idea is not original, the above code might be
>> original as it has been found by an exhaustive search on *all*
>> short codes :-)
> Actually, the above is not correct since it needs
> 5 insns. Armin didn't count the sourcecopy.
> My solution really has four insns, but it is
> cheating since it *needs* the register eax.
>> I don't know x86 assembler, so I have no idea which of the two code
>> sequences are actually likely to run quicker on a modern processor.
> I guess they are almost the same speed.
Ah, the joys of x86. It's amazing that so many people still use such a
braindead ISA :)
More information about the Pypy-dev