<p>the goal is to test if an integer value can fit in a 61bits Small Integer or not.<br>
The way to do it, is as in <code>isIntegerValue:</code></p>
<p>We check that most significant 4 bits are all 0 or all 1.<br>
This is achieved by shifting <code>>> 60</code>.<br>
we should then have <code>xxxx0000 </code>or <code>xxxx1111</code><br>
then we add <code>1</code><br>
we should have <code>xxxx0001 </code>or <code>xxxx0000</code><br>
we thus test:<br>
<code>& 0b1111 <= 1 </code>=> SmallInteger<br>
<code>& 0b1111 > 1</code> => NotSmallInteger</p>
<p>Unfortunately, the JIT have it right once:</p>
<pre><code>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
</code></pre>
<p>but wrong once:</p>
<pre><code>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
</code></pre>
<p>64 should be 63, or we only test highest 3 bits...</p>
<p>Fortunately, this is only used in genPrimitiveDivide...<br>
Unfortunately, this triggers the <code>(self deny: SmallInteger minVal / -1 = SmallInteger minVal)</code> bug...</p>
<p>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?).<br>
If you accept a short method in Object:</p>
<pre><code>testDiv
    | si |
    si := -1152921504606846976.
    ^si / -1
</code></pre>
<p>then force the jitter with a bench:</p>
<pre><code>[self assert: 0 testDiv isLarge] bench
</code></pre>
<p>then you'll trigger it...</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/415?email_source=notifications&email_token=AIJPEW3JURXUBOPFWOJWRLDQFQO3RA5CNFSM4IN2ACMKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HGJTTMA">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AIJPEWZWGLAUGZPDQJP4K2DQFQO3RANCNFSM4IN2ACMA">mute the thread</a>.<img src="https://github.com/notifications/beacon/AIJPEW27UYE7HYYGAI3TOPDQFQO3RA5CNFSM4IN2ACMKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HGJTTMA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/415?email_source=notifications\u0026email_token=AIJPEW3JURXUBOPFWOJWRLDQFQO3RA5CNFSM4IN2ACMKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HGJTTMA",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/415?email_source=notifications\u0026email_token=AIJPEW3JURXUBOPFWOJWRLDQFQO3RA5CNFSM4IN2ACMKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HGJTTMA",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>