[Newcompiler] Optimizing compiled methods for performance [was: A
day optimizing]
bryce at kampjes.demon.co.uk
bryce at kampjes.demon.co.uk
Thu May 31 19:12:24 UTC 2007
Mathieu Suen writes:
> What is tag checking?
> Mth
Tag checking means checking that the argument is a SmallInteger.
SmallIntegers have 1 as their lowest bit while pointers to objects
have 0 as their lowest bit so to check an argument is an integer we
check to see if it's lowest bit is 1. To detag means to remove the 1
tag bit.
The fast case for a general SmallInteger addition is:
bitTest arg1 0
jumpIfUnset failureBlock
sub 1 arg1
bitTest arg2 0
jumpIfUnset failureBlock
sub 1 arg2
add arg1 arg2
jumpOverflow failureBlock
add 1 arg2
Both arg1 and arg2 would need to be in registers that are not used
after the bytecode otherwise move instructions are nessisary.
It's possible to remove one of the subs used to detag and the
add at the end which retags. This is because the tag will transfer
through the addition.
So to add a 1 (which tagged is 3) constant just requires:
bitTest arg1 0
jumpIfUnset failureBlock
add 3 arg1
jumpOverflow failureBlock
If either argument is not a SmallInteger or the addition overflows
a full message send is performed which will deal with those cases.
When interpreting the branch mispredict overhead from decoding the
bytecodes is likely to dominate so the efficiency of the addition
sequence doesn't matter so long as it's tolerable. The VM uses a less
efficient method of checking for oveflow but it probably doesn't
matter on desktop out of order CPUs.
Bryce
More information about the Newcompiler
mailing list