<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Nicolas,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 14, 2021 at 6:36 PM Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <br>
Ah! Got it!<br>
The generated code is incorrect!<br>
Source:<br>
<br>
            leadingZeroCount = 0<br>
                ifTrue:<br>
                    ["highBit is not defined for negative Integer"<br>
                    self primitiveFail]<br>
                ifFalse:<br>
                    ["Nice bit trick: 1-based high-bit is (32 - clz) -<br>
1 to account for tag bit.<br>
                    This is like two-complement - clz - 1 on 5 bits,<br>
or in other words a bit-invert operation clz ^16r1F"<br>
                    self pop: 1 thenPushInteger: (leadingZeroCount<br>
bitXor: (BytesPerWord * 8 - 1))].<br>
            ^self].<br>
<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">The source I have looks like:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default">                      "Note: in gcc, result is undefined if input is zero (for compatibility with BSR fallback when no CLZ instruction available).</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>but input is never zero because we pass the oop with tag bits set, so we are safe"</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>objectMemory wordSize = 4</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                              </span>ifTrue: [leadingZeroCount := self __builtin_clz: integerReceiverOop]</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                           </span>ifFalse: [leadingZeroCount := self __builtin_clzll: integerReceiverOop].</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>leadingZeroCount = 0 ifTrue: "highBit is not defined for negative Integer"</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                           </span>[self primitiveFail].</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>"Nice bit trick: 1-based high-bit is (32 - clz) - 1 to account for tag bit.</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">                       </span> This is like two-complement - clz - 1 on 5 bits, or in other words a bit-invert operation clz ^16r1F"</div><div class="gmail_default" style="font-size:small"><span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>self pop: 1 thenPushInteger: (leadingZeroCount bitXor: (BytesPerWord * 8 - 1))</div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small">so the problem is not in the generator.  Did you fix this and not publish?</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
Generated:<br>
<br>
        if (leadingZeroCount == 0) {<br>
<br>
                /* highBit is not defined for negative Integer */<br>
                /* begin primitiveFail */<br>
                if (!GIV(primFailCode)) {<br>
                        GIV(primFailCode) = 1;<br>
                }<br>
        }<br>
        /* begin pop:thenPushInteger: */<br>
        longAtput((sp = GIV(stackPointer) + ((0) * BytesPerWord)),<br>
(((usqInt)(leadingZeroCount ^ ((BytesPerWord * 8) - 1)) << 3) | 1));<br>
        GIV(stackPointer) = sp;<br>
<br>
The ifFalse: branch has been gobbled...<br>
Hence with always push (0 bitXor: 16r3F) as small integer in place of<br>
the receiver, the fail the primitive...<br>
The fallback code proceeds with 16r3F and answers 6... Correct.<br>
<br>
WE MUST FIX THE GENERATOR ASAP !<br>
<br>
Le ven. 15 janv. 2021 à 03:15, Nicolas Cellier<br>
<<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>> a écrit :<br>
><br>
> Hi all,<br>
> I got this on uptodate Mingw Win 64 bits Squeak.cog.spur VM:<br>
><br>
> (1to: 8) collect: [:i|-2942842961920 highBitOfMagnitude]<br>
> -> #(6 6 42 42 42 42 42 42)<br>
><br>
> That is correct once jitted, but wrong first two times...<br>
> I just can't understand when/how it fails by reading the code...<br>
> Any clue?<br>
><br>
> Nicolas<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="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></div></div></div>