[Vm-dev] primitiveBitShift

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Mon Apr 15 17:22:42 UTC 2013


If you look at the terminal instructions in primitiveBitShift you'll see:

    self push: (self positive32BitIntegerFor: shifted)

If you inquire a bit, you will see that positive32BitIntegerFor: will
create a LargePositiveInteger instead of failing the primitive.
The balance between purity and efficiency I guess...

Nicolas


2013/4/15 Helmut Rohregger <helmut.rohregger at gmail.com>

>
> Am 15.04.2013 11:55, schrieb Igor Stasenko:
>
>    On 15 April 2013 11:46, Helmut Rohregger <helmut.rohregger at gmail.com>
>> wrote:
>>
>>> Am 15.04.2013 11:40, schrieb Igor Stasenko:
>>>
>>>     On 15 April 2013 11:31, Helmut Rohregger <helmut.rohregger at gmail.com
>>>> >
>>>> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> i am interested in the implementations of primitives in the VMMaker
>>>>> package
>>>>> and found some code, which i think may be implemented incorrectly.
>>>>> Maybe some of you can help me out and correct me if i am wrong.
>>>>>
>>>>> Its located in InterpreterPrimitives>>#**primitiveBitShift
>>>>> (VMMaker-dtl.319):
>>>>> the code: "self success: integerArgument <= 31" checks, if we lose bits
>>>>> by
>>>>> shifting to the left. This is because of processing SmallIntegers here,
>>>>> isn't it? But a "1 bitShift: 31" will produce a LargePositiveInteger
>>>>> instead
>>>>> of a SmallInteger. In fact a left shift of 30 will produce a
>>>>> LargePositiveInteger too.
>>>>>
>>>>> I know the code works, because the resulting object gets checked being
>>>>> a
>>>>> SmallInteger and fails if not. But the correct check would be "self
>>>>> success:
>>>>> integerArgument <= 29", isn't it?
>>>>> What do you think?
>>>>>
>>>>>  hmm., how do you know if shifted result will fit into smallint, if you
>>>> don't check both operands?
>>>>
>>>> "1 << 29 " fits
>>>> "SmallInteger maxVal << 29 " doesnt.
>>>> even
>>>> "SmallInteger maxVal << 1 " doesnt.
>>>>
>>>
>>> but " x << 30 " does never fit, no matter which value 'x' has.
>>>
>> 0 << 30 = 0.
>> fits.
>>
>>
>>  hehe i know.
> and "0 << SmallInteger maxVal" fits too, but will fail with the
> implemented primitive.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20130415/b8ec99cb/attachment.htm


More information about the Vm-dev mailing list