[pypy-dev] Re: OT: abs(x) with 4 assembly insns
tismer at tismer.com
Mon Sep 29 15:13:57 CEST 2003
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.
ciao - chris
Christian Tismer :^) <mailto:tismer at tismer.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Pypy-dev