<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 28, 2020 at 3:47 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"> <div dir="ltr"><div>Hi Eliot,</div><div>it is in VMMaker inbox,</div><div><a rel="nofollow" href="https://source.squeak.org/VMMakerInbox/VMMaker.oscog-nice.2679.diff" target="_blank">https://source.squeak.org/VMMakerInbox/VMMaker.oscog-nice.2679.diff</a></div><div>The recursive method is #alignmentOfStructSpec:OfLength:StartingAt: called by #registerTypeForStructSpecs:#OfLength: called by #ffiCalloutTo: procAddr:in:</div><div><br></div><div>The last one has <inline: true>.</div><div>I had the idea to put an <inline: false> in #registerTypeForStructSpecs:#OfLength: but thought it didn't work (by stepping thru debugger)...</div><div>But now that you say it, I rechecked the generated code and it worked, thanks!<br></div></div></blockquote><div><br></div><div>Cool!!</div><div><br></div><br>BTW, on the issue of getting 32-bit results too.  I think I'm right in thinking that provided one collects the result by virtue of having the relevant field in the struct typed as either float or double, then the data will get written to either xmm0low or xmm1low, depending on whether this is the first or second field of the struct.  So then we can access the register and convert from 32 bits to 64-bits if required.  i.e. we only need the four combinations of long x double, long x double for the struct, but if either of the fields is actually typed as float, we can fix up the result after the fact by reading the relevant field via the 32-bit accessor.  So once we have the return struct loaded, to convert the 32-bit float result to a double for each field we would do something like</div><div class="gmail_quote"><br>    union { float f; double d; } pun;<br>    memcpy(&pun,&retStruct.doubles[0],sizeof(double));<br>    retStruct.doubles[0] = pun.f;</div><div class="gmail_quote"><br></div><div class="gmail_quote"><br><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"><div dir="ltr"><div></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 29 janv. 2020 à 00:14, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>> a écrit :<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"> <div dir="ltr"><div dir="ltr"><div dir="ltr">H Nicolas,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 28, 2020 at 2:55 PM Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">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"> <div dir="ltr">Hi all,<br>I have practically solved <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/443" target="_blank">https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/443</a> for passing/returning struct by value on X64SysV FFI.<br><br>I still have a few cases of packed struct or union to handle, but I know how to handle them and finish the job.<br><br>Practically, but not yet... There is an issue that I can't easily solve: slang inlining.<br><br>The generated code works on fast VM, but not debug nor assert...<br>It does not work because #ffiCalloutTo:SpecOnStack:in: is not inlined.<br>Since it uses sender's alloca as stack pointer (where FFI argVector was marshalled), it obviously will mess the stack if not inlined!<br><br>The code is not inlined because a sub-function sends a recursive message .<br>Unfortunately I have to check struct alignment for correctly determining the type of 8-byte registers, and algorithm for checking struct alignment is recursive because we must first check alignment of sub-struct....<br><br>Having a recursive function should not be a problem, just don't inline it, but invoke it.<br>Unfortunately, our strategy is to inline only sends that can be completely inlined (and recursively for every sub-send).<br></div></blockquote><div><br></div><div>What's the recursive function?  That should be marked as not inalienable (<inline: #false>.  And <span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium">#ffiCalloutTo:SpecOnStack:in: should be marked as <inline: true> or <inline: #always>.</span></div><div> </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"><div dir="ltr">So I'm currently blocked...<br></div></blockquote><div><br></div><div>We could pair later on today or early (my time) tomorrow.  Right now I'm busy with my day job and so can't spend significant time right now.  Feel free to email me the change set to look at too.</div><div> </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"><div dir="ltr">I'd like to specify to not inquire further sends that explicitely refuse to be inlined, maybe in the unless block in checkForCompletenessIn:<br><br>parseTree<br>        nodesDo:<br>            [:node|<br>             ...snip...]<br>        unless:<br>            [:node|<br>            node isSend<br><div>            and: [node selector == #cCode:inSmalltalk:</div><div>               <b> or: [node explicitelyRefuseToBeInlined</b><br></div><div>                or: [aCodeGen isAssertSelector: node selector]]]].</div><div><br></div><div>Thoughts?<br></div><br></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><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>
</blockquote></div>
</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>