Numbers. (but completely different)
Ned Konz
ned at bike-nomad.com
Fri Apr 9 15:05:52 UTC 2004
On Thursday 08 April 2004 10:43 pm, Alan Grimes wrote:
> I was going through the posting I just made and squinting really hard at
> what the VM was _REALLY_ doing I came across something that starteled me
> out of my chair...
>
> I had assumed that the basic integer format was a basic two's complement
> number only shifted to the left one bit...
> To my shock and disbeleif I found that it's stored in a magnitude+sign
> format, EGADS!!!
>
That's a surprise to me.
As the comment in ObjectMemory says:
SmallIntegers are tagged with a low-order bit equal to 1, and an immediate
31-bit 2s-complement signed value in the rest of the word.
> ^obj >> 1 + obj bitAnd: maxInt.
Which could be more concisely put in C (and better compiled) as (assuming obj
is an int):
obj / 2
or the inverse:
(obj << 1) +1
> Admittedly, we'll sometimes have to do range checks and promote as
> necessary but that doesn't really worry me.
But we *always* have to do the range checks.
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|