Micro-optimize integer-length on fixnums on x86-64.
authorStas Boukarev <stassats@gmail.com>
Tue, 30 Apr 2013 19:32:43 +0000 (23:32 +0400)
committerStas Boukarev <stassats@gmail.com>
Tue, 30 Apr 2013 19:32:43 +0000 (23:32 +0400)
commit33391df7f217210a8017296f6bf2da8c9f60769f
tree2055e90b1b58c498c5df9a1569505f71992793fd
parent68991b9cf496d21d872246942c27edb83fdeb22d
Micro-optimize integer-length on fixnums on x86-64.

INTEGER-LENGTH is implemented by using the BSR instruction, which
returns the position of the first 1-bit from the right. And that needs
to be incremented to get the width of the integer, and BSR doesn't
work on 0, so it needs a branch to handle 0.

But fixnums are tagged by being shifted left n-fixnum-tag-bits times,
untagging by shifting right n-fixnum-tag-bits-1 times (and if
n-fixnum-tag-bits = 1, no shifting is required), will make the
resulting integer one bit wider, making the increment unnecessary.
Then, to avoid calling BSR on 0, OR the result with 1. That sets the
first bit to 1, and if all other bits are 0, BSR will return 0,
which is the correct value for INTEGER-LENGTH.
NEWS
src/compiler/x86-64/arith.lisp