the goal is to test if an integer value can fit in a 61bits Small Integer or not.
The way to do it, is as in `isIntegerValue:`
We check that most significant 4 bits are all 0 or all 1.
This is achieved by shifting `>> 60`.
we should then have `xxxx0000 `or `xxxx1111`
then we add `1`
we should have `xxxx0001 `or `xxxx0000`
we thus test:
`& 0b1111 <= 1 `=> SmallInteger
`& 0b1111 > 1` => NotSmallInteger
Unfortunately, the JIT have it right once:
genJumpIsSmallIntegerValue: aRegister scratch: scratchReg
"Generate a test for aRegister containing an integer value in the SmallInteger range, and a jump if so, answering the jump.
c.f. Spur64BitMemoryManager>>isIntegerValue:"
<returnTypeC: #'AbstractInstruction *'>
^cogit
MoveR: aRegister R: scratchReg;
ArithmeticShiftRightCq: 63 - objectMemory numTagBits R: scratchReg;
AddCq: 1 R: scratchReg;
AndCq: 1 << (objectMemory numTagBits + 1) - 1 R: scratchReg; "sign and top numTags bits must be the same"
CmpCq: 1 R: scratchReg;
JumpLessOrEqual: 0
but wrong once:
genJumpNotSmallIntegerValue: aRegister scratch: scratchReg
"Generate a test for aRegister containing an integer value outside the SmallInteger range, and a jump if so, answering the jump.
c.f. Spur64BitMemoryManager>>isIntegerValue:"
<returnTypeC: #'AbstractInstruction *'>
^cogit
MoveR: aRegister R: scratchReg;
ArithmeticShiftRightCq: 64 - objectMemory numTagBits R: scratchReg;
AddCq: 1 R: scratchReg;
AndCq: 1 << (objectMemory numTagBits + 1) - 1 R: scratchReg; "sign and top numTags bits must be the same"
CmpCq: 1 R: scratchReg;
JumpGreater: 0
64 should be 63, or we only test highest 3 bits...
Fortunately, this is only used in genPrimitiveDivide...
Unfortunately, this triggers the `(self deny: SmallInteger minVal / -1 = SmallInteger minVal)` bug...
That's not the first time that this bug happens, I already reported it in the past, but it seems that we did not capitalize this test case (or it is not jitted?).
If you accept a short method in Object:
testDiv
| si |
si := -1152921504606846976.
^si / -1
then force the jitter with a bench:
[self assert: 0 testDiv isLarge] bench
then you'll trigger it...
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/415
Branch: refs/heads/Cog
Home: https://github.com/OpenSmalltalk/opensmalltalk-vm
Commit: 20a361a0f8d434a8bb71db69ff3d06a63f839ace
https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/20a361a0f8d434a8bb…
Author: Nicolas Cellier <nicolas.cellier.aka.nice(a)gmail.com>
Date: 2019-08-22 (Thu, 22 Aug 2019)
Changed paths:
M spur64src/vm/cointerpmt.c
M spur64src/vm/cointerpmt.h
M spur64src/vm/gcc3x-cointerpmt.c
M spurlowcodestack64src/vm/gcc3x-interp.c
M spurlowcodestack64src/vm/interp.c
Log Message:
-----------
Forgot to generate code for MT variant (64bits only)
Code is generated from source VMMaker.oscog-nice.2541
Branch: refs/heads/Cog
Home: https://github.com/OpenSmalltalk/opensmalltalk-vm
Commit: e839adea0f2a8e2c8e04706b24283c996aeff1ae
https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/e839adea0f2a8e2c8e…
Author: Nicolas Cellier <nicolas.cellier.aka.nice(a)gmail.com>
Date: 2019-08-22 (Thu, 22 Aug 2019)
Changed paths:
M nsspur64src/vm/cogit.h
M nsspur64src/vm/cogitX64SysV.c
M nsspur64src/vm/cogitX64WIN64.c
M nsspur64src/vm/cointerp.c
M nsspur64src/vm/cointerp.h
M nsspur64src/vm/gcc3x-cointerp.c
M nsspurstack64src/vm/gcc3x-interp.c
M nsspurstack64src/vm/interp.c
M spur64src/vm/cogit.h
M spur64src/vm/cogitX64SysV.c
M spur64src/vm/cogitX64WIN64.c
M spur64src/vm/cointerp.c
M spur64src/vm/cointerp.h
M spur64src/vm/gcc3x-cointerp.c
M spur64src/vm/interp.h
M spurlowcode64src/vm/cogit.h
M spurlowcode64src/vm/cogitX64SysV.c
M spurlowcode64src/vm/cogitX64WIN64.c
M spurlowcode64src/vm/cointerp.c
M spurlowcode64src/vm/cointerp.h
M spurlowcode64src/vm/gcc3x-cointerp.c
M spursista64src/vm/cogit.h
M spursista64src/vm/cogitX64SysV.c
M spursista64src/vm/cogitX64WIN64.c
M spursista64src/vm/cointerp.c
M spursista64src/vm/cointerp.h
M spursista64src/vm/gcc3x-cointerp.c
M spurstack64src/vm/gcc3x-interp.c
M spurstack64src/vm/interp.c
Log Message:
-----------
Fix issue #417
Note that mixed arithmetic operations involving Integer >= (2^52) will no longer fail the primitives in Spur64
The new mechanism does handle all the exact mixed arithmetic comparisons primitively, regaining some speed in those cases.
Also 5 = 5.0 is now handled primitively and quite boosted (it was only for boxed float).