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

Eliot Miranda eliot.miranda at gmail.com
Wed Apr 29 20:57:17 UTC 2015


On Wed, Apr 29, 2015 at 1:33 PM, Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:

>
> 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
>

And we're using the same trick on the ARM 32x32=>64 multiply.


> 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


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20150429/826948e7/attachment.htm


More information about the Vm-dev mailing list