<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 2, 2018 at 3:44 PM, Guido Chari <span dir="ltr"><<a href="mailto:charig@gmail.com" target="_blank">charig@gmail.com</a>></span> wrote:<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 dir="ltr">Hi Eliot,<br><div class="gmail_extra"><br><div class="gmail_quote">2018-02-28 16:03 GMT+01:00 Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></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>
Hi Javier,<br>
<br>
<br>
> On Feb 28, 2018, at 5:16 AM, Javier Pimás <<a href="mailto:elpochodelagente@gmail.com" target="_blank">elpochodelagente@gmail.com</a>> wrote:<br>
><br>
> Hi! This time I'm investigating how cog jit handles pointers to objects in native code. In x86-32 its easier because you have immediates of the size of a pointer, but in x64 the immediates are restricted to 32bits (and I think less in arm).<br>
<br>
That's not quite right.  On x86_64 instructions can load 64-bit constants into registers.  What is restricted is loading/storing through a 64-bit immediate address.  That can only be done to/from %rax.  So when loading an arbitrary register from memory the JIT often generates sequences like:<br>
<br>
    xchgq %r15,%rax<br>
    moveq 123456789AB0,%rax<br>
    xchgq %r15,%rax<br>
<br>
> So I wonder how people works around that, if using a movabs instruction every time you need a pointer or if doing something else. I found a mail in the list dated from 2011 (titled "questions about cog internals") where you (Eliot) said that pointers were inlined in jit code, but I don't know if that's still the case.<br>
<br>
Yes.  The easy way to see this is to use in-image compilation.  e.g. in a VMMaker.oscog image (scripts to build them being in the image directory) run the following with a Transcript open:<br>
<br>
StackToRegisterMappingCogit<br>
    genAndDis: Object>>#printOn: "includes 'a ' and 'an '"<br>
    options: #(ObjectMemory Spur64BitCoMemoryManager)<br>
<br>
and the generated machine code method will be output to the transcript.<br></blockquote><div><br></div><div>There are plenty of scripts. I ran a few that failed while loading code. Could you point us to the one you are using?</div></div></div></div></blockquote><div><br></div><div>My normal workflow from loading is to run StackVMSimulator from VM simulation workspace, then Cog Simulator from VM simulation workspace, then in-image compilation from In-image compilation workspace. I frequently pick up a new image and annoy Eliot if it does not work, so normally things should be working. Sometimes the last one does not work if the first ones are not run first. In any case in-image compilation requires a VM with a processor simulator external plugins (else it fails on prim New CPU). To build such a VM go in the build folder and follow HowToBuild file instructions, especially the section on Bochs.</div><div><br></div><div>StackVMSimulator script looks like<br></div><div><br></div><div><div>| cos |</div><div>cos := StackInterpreterSimulator newWithOptions: #( ...</div></div><div> </div><div>CogSimulator <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">script looks like</span></div><div><div>| cos |</div><div><span style="white-space:pre">      </span>cos := CogVMSimulator newWithOptions: #(...</div></div><div><br></div><div>In-image compilation are the scripts using #genAndDis:options: </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 dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> Looking at the slang code I found CogOutOfLineLiteralsX64Compile<wbr>r, but it seems it is not used (yet?).<br>
<br>
Yes, we should implement this and see how it compares.  It's not particularly compelling in x86_64 because we can load 64-bit immediates inline but performance might differ significantly.<br>
<br>
> Cheers!<br>
> Pocho<br>
<span class="gmail-m_-2552738113379117191m_5200049313112914963HOEnZb"><font color="#888888">><br>
> --<br>
> Javier Pimás<br>
> Ciudad de Buenos Aires<br>
</font></span></blockquote></div><br></div></div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span style="font-size:12.8px">Clément Béra</span><div style="font-size:12.8px">Pharo consortium engineer</div><div style="font-size:12.8px"><a href="https://clementbera.wordpress.com/" target="_blank">https://clementbera.wordpress.com/</a><br></div><div style="font-size:12.8px"><span style="line-height:16px">Bâtiment B 40, avenue Halley 59650 </span><span style="font-weight:bold;line-height:16px">Villeneuve d'Ascq</span></div></div></div>
</div></div>