<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi again,</div><div><br></div><div>I see this horrible generated code:</div><div><br></div><div>    /* Spur64BitMemoryManager>>#integerValueOf: */<br>sqInt<br>integerValueOf(sqInt oop)<br>{<br>    return ((((usqInt) oop >> 63)) == 1<br>        ? ((((((-(numTagBits())) < 0) ? ((usqInt) oop >> -(-(numTagBits()))) : ((usqInt) oop << (-(numTagBits()))))) & 0x1FFFFFFFFFFFFFFFLL) - 0x1FFFFFFFFFFFFFFFLL) - 1<br>        : (((-(numTagBits())) < 0) ? ((usqInt) oop >> -(-(numTagBits()))) : ((usqInt) oop << (-(numTagBits())))));<br>}</div><div><br></div><div>which of course generates a (false positive) warning:</div><div><br></div><div>Avertissement    C4293    '<<' : compteur de décalage négatif ou trop important, comportement non défini    SqueakCogSpur    X:\Smalltalk\opensmalltalk-vm\spur64src\vm\cointerp.c    41564    <br></div><div><br></div><div>Slang is:</div><div><br></div><div>integerValueOf: oop<br>    "Translator produces 'oop >> 3'"<br>    ^(oop bitShift: -63) = 1 "tests top bit"<br>        ifTrue: "negative"<br>            [((oop bitShift: self numTagBits negated) bitAnd: 16r1FFFFFFFFFFFFFFF) - 16r1FFFFFFFFFFFFFFF - 1  "Faster than -16r4000000000000000 (a LgInt)"]<br>        ifFalse: "positive"<br>            [oop bitShift: self numTagBits negated]</div><div><br></div><div>We see that the constant -63 has been translated into a directed (right) shift, but the other constant (numTagBits) not so, either because constant substitution is not aggressive enough, or because negated made an expression of the constant...</div><div><br></div><div>However, the intention is ALWAYS to perform a directed shift (to the right) so the code could be expressed to make both intention AND generated code clear (and warning-free):</div><div><br></div><div>integerValueOf: oop<br>    "Translator produces 'oop >> 3'"<br>    ^(oop >> 63) = 1 "tests top bit"<br>        ifTrue: "negative"<br>            [((oop >> self numTagBits) bitAnd: 16r1FFFFFFFFFFFFFFF) - 16r1FFFFFFFFFFFFFFF - 1  "Faster than -16r4000000000000000 (a LgInt)"]<br>        ifFalse: "positive"<br>            [oop >> self numTagBits]</div><div><br></div><div>Why use bitShift: then? Is it a problem of speed for the VM simulator?</div><div><br></div></div></div></div></div></div>