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?
- helmut
On 15 April 2013 11:31, Helmut Rohregger helmut.rohregger@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.
- helmut
Am 15.04.2013 11:40, schrieb Igor Stasenko:
On 15 April 2013 11:31, Helmut Rohregger helmut.rohregger@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.
On 15 April 2013 11:46, Helmut Rohregger helmut.rohregger@gmail.com wrote:
Am 15.04.2013 11:40, schrieb Igor Stasenko:
On 15 April 2013 11:31, Helmut Rohregger helmut.rohregger@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.
Am 15.04.2013 11:55, schrieb Igor Stasenko:
On 15 April 2013 11:46, Helmut Rohregger helmut.rohregger@gmail.com wrote:
Am 15.04.2013 11:40, schrieb Igor Stasenko:
On 15 April 2013 11:31, Helmut Rohregger helmut.rohregger@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.
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@gmail.com
Am 15.04.2013 11:55, schrieb Igor Stasenko:
On 15 April 2013 11:46, Helmut Rohregger helmut.rohregger@gmail.com
wrote:
Am 15.04.2013 11:40, schrieb Igor Stasenko:
On 15 April 2013 11:31, Helmut Rohregger <helmut.rohregger@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.
Hi Nicolas,
Am 15.04.2013 19:22, schrieb Nicolas Cellier:
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.
ok, i have assumed, that "positive32BitIntegerFor" will return a small integer because of "32 bit" in its name :-) well, it does return a 32 bit integer but if to big for small integer, a largePositiveInteger gets built...
The balance between purity and efficiency I guess...
this makes sense! thank you!
Nicolas
2013/4/15 Helmut Rohregger <helmut.rohregger@gmail.com mailto:helmut.rohregger@gmail.com>
Am 15.04.2013 11:55, schrieb Igor Stasenko: On 15 April 2013 11:46, Helmut Rohregger <helmut.rohregger@gmail.com <mailto:helmut.rohregger@gmail.com>> wrote: Am 15.04.2013 11:40, schrieb Igor Stasenko: On 15 April 2013 11:31, Helmut Rohregger <helmut.rohregger@gmail.com <mailto:helmut.rohregger@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.
vm-dev@lists.squeakfoundation.org