<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-11-01 2:06 GMT+01:00 Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr">Hi Nicolas,<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 31, 2016 at 3:38 PM, Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@<wbr>gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-10-31 22:42 GMT+01:00  <span dir="ltr">&lt;<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:<br>
<a href="http://source.squeak.org/VMMaker/VMMaker.oscog-eem.1972.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/VMMak<wbr>er/VMMaker.oscog-eem.1972.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: VMMaker.oscog-eem.1972<br>
Author: eem<br>
Time: 31 October 2016, 2:42:12.362675 pm<br>
UUID: 0e6a54ad-d62f-4b69-9f0d-7b66f8<wbr>350984<br>
Ancestors: VMMaker.oscog-eem.1971<br>
<br>
Redo fixing extB sign extension in NewsqueakV4 &amp; SistaV1 extPushIntegerBytecode &amp; extUnconditionalJump in interpreter and Cogit using bitShift: 8 instead of &lt;&lt; 8.  Slang seems to generate the correct code with bitAShift:, but not with &lt;&lt;.<br>
<br></blockquote><div><br></div><div>Hi Eliot,<br></div><div>it would have worked if you would have used bitOr: instead of +<br>I&#39;d say bitOr: better fits the intention:<br></div><div>you want to assemble the bits, you do not really want to perform arithmetic here.<br></div></div></div></div></blockquote><div><br></div><div>OK, but in 2&#39;s complement they do the same thing, so + sdeems just as good for me.</div><div> </div></div></div></div></blockquote><div>Not when we mix negative with positive obviously...<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div>Also, the result we are after is a signed int, so consider that &lt;&lt; is doing the right thing, it gives you a signed int.<br></div></div></div></div></blockquote><div><br></div><div>That&#39;s not what Slang generated.  It generated a cast to usqInt.</div></div></div></div></blockquote><div><br></div><div>No, in fact &lt;&lt; generates signed left shift.<br></div><div>But it does so carefully, to make sure that C compiler do not detect UB (which can happen in case of sign overflow).<br></div><div>That is, it first convert to usqInt, then shift, then convert the result back to sqInt.<br></div><div>In this case, even the overflow is well defined, and we can write things like<br></div><div>    ( (somePositiveConstant &lt;&lt; shiftVariable ) &lt; 0 ) ifTrue: [...]<br></div><div>without fear that the produced C code will be removed by compiler...<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>The expression you propose is unsigned. It works OK in this context, because we assign immediately to a signed int.<br>But for a more general usage, it could deceive the inliner (for example if variable is automatically typed or eliminated...)<br></div></div></div></div></blockquote><div><br></div><div>Well, we have signed right shifts, but no signed left shifts.  What I really want is a signed left shift but chose not to introduce e.g. &lt;&lt;&lt;.  For me I would make left shift maintain the signedness of the left-hand, generating a warning if the type couldn&#39;t be determined.  That&#39;s closest to what Smalltalk does.</div><div><br></div></div></div></div></blockquote><div>again, &lt;&lt; currently generates signed left shift.<br></div><div>That&#39;s why we need bitOr: rather than +<br><br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
=============== Diff against VMMaker.oscog-eem.1971 ===============<br>
<br>
Item was changed:<br>
  ----- Method: SimpleStackBasedCogit&gt;&gt;genExtP<wbr>ushIntegerBytecode (in category &#39;bytecode generators&#39;) -----<br>
  genExtPushIntegerBytecode<br>
        &quot;NewsqueakV4:   229             11100101        iiiiiiii        Push Integer #iiiiiiii (+ Extend B * 256, where bbbbbbbb = sddddddd, e.g. -32768 = i=0, a=0, s=1)<br>
        SistaV1:                232             11101000        iiiiiiii        Push Integer #iiiiiiii (+ Extend B * 256, where bbbbbbbb = sddddddd, e.g. -32768 = i=0, a=0, s=1)&quot;<br>
        | value |<br>
+       value := byte1 + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) bitShift: 8).<br>
-       value := byte1 + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) &lt;&lt; 8).<br>
        extB := 0.<br>
        ^self genPushLiteral: (objectMemory integerObjectOf: value)!<br>
<br>
Item was changed:<br>
  ----- Method: SimpleStackBasedCogit&gt;&gt;genExtU<wbr>nconditionalJump (in category &#39;bytecode generators&#39;) -----<br>
  genExtUnconditionalJump<br>
        &quot;242            11110010        i i i i i i i i Jump i i i i i i i i (+ Extend B * 256, where bbbbbbbb = sddddddd, e.g. -32768 = i=0, a=0, s=1)&quot;<br>
        | distance target |<br>
+       distance := byte1 + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) bitShift: 8).<br>
-       distance := byte1 + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) &lt;&lt; 8).<br>
        self assert: distance = (self v4: (self generatorAt: byte0)<br>
                                                                Long: bytecodePC<br>
                                                                Branch: (extA ~= 0 ifTrue: [1] ifFalse: [0]) + (extB ~= 0 ifTrue: [1] ifFalse: [0])<br>
                                                                Distance: methodObj).<br>
        extB := 0.<br>
        target := distance + 2 + bytecodePC.<br>
        distance &lt; 0 ifTrue:<br>
                [^self genJumpBackTo: target].<br>
        self genJumpTo: target.<br>
        &quot;The bytecode must be mapped since it can be either forward or backward, and<br>
          backwards branches must be mapped. So if forward, we need to map.&quot;<br>
        self annotateBytecode: self lastOpcode.<br>
        ^0!<br>
<br>
Item was changed:<br>
  ----- Method: SimpleStackBasedCogit&gt;&gt;v4:Long<wbr>:Branch:Distance: (in category &#39;span functions&#39;) -----<br>
  v4: descriptor Long: pc Branch: nExts Distance: aMethodObj<br>
        &quot;242            11110010        i i i i i i i i Jump i i i i i i i i (+ Extend B * 256, where bbbbbbbb = sddddddd, e.g. -32768 = i=0, a=0, s=1)&quot;<br>
        &lt;var: #descriptor type: #&#39;BytecodeDescriptor *&#39;&gt;<br>
        | extBValue |<br>
        self assert: nExts &gt;= 0.<br>
        self parseV4Exts: nExts priorTo: pc in: aMethodObj into: [:ea :eb| extBValue := eb].<br>
        ^(objectMemory fetchByte: pc + 1 ofObject: aMethodObj)<br>
+       + (extBValue bitShift: 8)!<br>
-       + (extBValue &lt;&lt; 8)!<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreter&gt;&gt;extPushInteg<wbr>erBytecode (in category &#39;stack bytecodes&#39;) -----<br>
  extPushIntegerBytecode<br>
        &quot;229            11100101        i i i i i i i i Push Integer #iiiiiiii (+ Extend B * 256, where bbbbbbbb = sddddddd, e.g. -32768 = i=0, a=0, s=1)&quot;<br>
        | value |<br>
+       value := self fetchByte + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) bitShift: 8).<br>
-       value := self fetchByte + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) &lt;&lt; 8).<br>
        self fetchNextBytecode.<br>
        extB := 0.<br>
        self internalPush: (objectMemory integerObjectOf: value)!<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreter&gt;&gt;extUnconditi<wbr>onalJump (in category &#39;jump bytecodes&#39;) -----<br>
  extUnconditionalJump<br>
        &quot;242            11110010        i i i i i i i i Jump i i i i i i i i (+ Extend B * 256, where bbbbbbbb = sddddddd, e.g. -32768 = i=0, a=0, s=1)&quot;<br>
        | byte offset |<br>
        byte := self fetchByte.<br>
+       offset := byte + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) bitShift: 8).<br>
-       offset := byte + ((extB &gt; 127 ifTrue: [extB - 256] ifFalse: [extB]) &lt;&lt; 8).<br>
        extB := 0.<br>
        localIP := localIP + offset.<br>
        self ifBackwardsCheckForEvents: offset.<br>
        self fetchNextBytecode!<br>
<br>
</blockquote></div><br></div></div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_-1127952739195797670gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>
<br></blockquote></div><br></div></div>