<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 28, 2018 at 12:03 PM, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Javier,<br>
<span class=""><br>
<br>
> On Feb 28, 2018, at 5:16 AM, Javier Pimás <<a href="mailto:elpochodelagente@gmail.com">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>
</span>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>
<span class=""><br></span></blockquote><div><br></div><div>yes, I meant a solution like this. You also need a scratch register if you want to push a pointer but it's not a huge problem.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> 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>
</span>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></blockquote><div><br></div><div>Nice! I'll try it</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
and the generated machine code method will be output to the transcript.<br>
<span class=""><br>
> Looking at the slang code I found CogOutOfLineLiteralsX64Compile<wbr>r, but it seems it is not used (yet?).<br>
<br>
</span>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>
<div class="HOEnZb"><div class="h5"><br>
> Cheers!<br>
> Pocho<br>
><br>
> --<br>
> Javier Pimás<br>
> Ciudad de Buenos Aires<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Javier Pimás<br>Ciudad de Buenos Aires</div></div>
</div></div>