<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-03-08 22:10 GMT+01:00 Esteban Lorenzano <span dir="ltr">&lt;<a href="mailto:estebanlm@gmail.com" target="_blank">estebanlm@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On 08 Mar 2016, at 21:38, Nicolas Cellier &lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>&gt; wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">IMO the right fix would be to force coercion here:<br><span><br>                                                        ifTrue:[interpreterProxy signed64BitIntegerFor: (</span><span>self cCoerceSimple: value to: #sqLong)]<br></span></div></div></blockquote><div><br></div><div>why? </div></div></div></blockquote><div><div><br></div>I recommend writing simple programs like below, compile and run:<br><br></div><div>#include &lt;stdio.h&gt;<br></div><div>int main() {<br></div><div>    int x=-1;<br></div><div>    unsigned long long y;<br></div><div>   y = (signed) x;<br></div><div>   printf(&quot; y &lt;- (signed) x :%llx\n&quot;, y);<br><div>   y = (unsigned) x;<br></div>   printf(&quot; y &lt;- (unsigned) x :%llx\n&quot;, y);<br>}<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div>forcing a coercion to &quot;unsigned int” while we always use sqTypes didn’t feel correct… also long32At will always answer an sqLong, that’s why I thought simpler approach was to remove a coercion instead adding two… </div><br></div></div></blockquote> <br></div><div class="gmail_quote">I wouldn&#39;t trust it too much. What is long32At doing exactly?<br>I can see two versions of it in platforms/Cross/vm/sqMemoryAccess.h ...<br><br>#define long32At    intAt<br># define intAt(oop)                    intAtPointer(atPointerArg(oop))<br># define intAtPointer(ptr)            ((sqInt)(*((int *)(ptr))))<br><br></div><div class="gmail_quote">In this case, there will be sign promotion and (ref integerAt: 1 size: 4 signed: false) will be broken on 64bits VM...<br><br></div><div class="gmail_quote">But with the other #if #else branch:<br><br>static inline sqInt intAt(sqInt oop)                          { return intAtPointer(pointerForOop(oop)); }<br>static inline sqInt intAtPointer(char *ptr)            { return (sqInt)(*((unsigned int *)ptr)); }<br><br></div><div class="gmail_quote">there won&#39;t be any sign promotion, and this time the problem will be with (ref integerAt: 1 size: 4 signed: true)on 64 bits VM<br><br></div><div class="gmail_quote">So the 32 high bits of long32 SHOULD be UNTRUSTED and that&#39;s why we need to force (int) or (unsigned int) cast in 64 bits VM.<br></div><div class="gmail_quote">It&#39;s a mistake to have long32 returning a sqInt, it should return a 32bits int.<br>Currently, int would fit for supported platform, but to be future proof, it should have been int32_t<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">In my own VM brand I have defined unsignedLong32At to be sure to avoid these nasty horrible things...<br></div><div class="gmail_quote">Most of the time handling unsigned is the right thing to do, they have well defined, least surprising behavior.<br><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span><br></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span>But maybe we can avoid signed64/unsigned64 and use signedMachineInteger and positiveMachineInteger when byteSize = bytePerWord...<br></span></div></div></blockquote></div><br><div>that, I have no idea, maybe :)</div></div></blockquote><div><br></div><div>It&#39;s just an optimization for avoiding unecessary 64bits ops.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Esteban</div></div><br></blockquote></div><br></div></div>