[Vm-dev] Does a signed int64 fits in SmallInteger?

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Apr 29 20:33:48 UTC 2015


Before I forget it, I have this trick ready for a year or so that
might serve in my LargeInteger plugin which use int64 a lot.

If SmallInteger are on 31 bits, then the 34 most significant bits of
the int64 must be the same...
since we are tricky, we just test 33 bits:
    (((usqLong)(x)) + 0x40000000ULL) & 0xFFFFFFFF80000000ULL == 0

And when SmallInt is 61bits long (Spur64), the 4 most significant bits
must be the same
we just test 3 bits:
    (((usqLong)(x)) + 0x1000000000000000UL) & 0xE000000000000000UL == 0

Indeed:
    2r0000 + 1 -> 0001
    2r1111 + 1 -> 0000
Any other combination will be > 1 and have one of the most significant
3 bits != 0
So we just have to test the first 3 bits

It's almost how #isIntegerValue: is done currently in Spur 64 but with
one more op and a test on 4 most significant bits...
 (intValue >> 60 + 1 bitAnd: 16rF) <= 1

Nicolas


More information about the Vm-dev mailing list