<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>The following passes everything through XMM0:<br>
</p>
<div style="color: #000000;background-color: #fffffe;font-family:
Consolas, ">
<div>
<div style="color: #000000;background-color:
#fffffe;font-family: Consolas, ">
<div><span style="color: #0000ff;">#include</span><span
style="color: #000000;"> </span><span style="color:
#0000ff;"><</span><span style="color: #a31515;">cmath</span><span
style="color: #0000ff;">></span></div>
<div><span style="color: #0000ff;">#include</span><span
style="color: #000000;"> </span><span style="color:
#0000ff;"><</span><span style="color: #a31515;">emmintrin.h</span><span
style="color: #0000ff;">></span></div>
<br>
<div><span style="color: #0000ff;">double</span><span
style="color: #000000;"> Mod(</span><span style="color:
#0000ff;">__m128d</span><span style="color: #000000;"> z)</span></div>
<div><span style="color: #000000;">{</span></div>
<div><span style="color: #000000;"> </span><span
style="color: #0000ff;">return</span><span style="color:
#000000;"> sqrt((z[</span><span style="color: #09885a;">0</span><span
style="color: #000000;">]*z[</span><span style="color:
#09885a;">0</span><span style="color: #000000;">])+(z[</span><span
style="color: #09885a;">1</span><span style="color:
#000000;">]*z[</span><span style="color: #09885a;">1</span><span
style="color: #000000;">]));</span></div>
<div><span style="color: #000000;">}</span></div>
<br>
<div><span style="color: #0000ff;">int</span><span
style="color: #000000;"> main()</span></div>
<div><span style="color: #000000;">{</span></div>
<div><span style="color: #000000;"> </span><span
style="color: #0000ff;">__m128d</span><span style="color:
#000000;"> z;</span></div>
<div><span style="color: #000000;"> z[</span><span
style="color: #09885a;">0</span><span style="color:
#000000;">] = </span><span style="color: #09885a;">0</span><span
style="color: #000000;">; z[</span><span style="color:
#09885a;">1</span><span style="color: #000000;">] = </span><span
style="color: #09885a;">1</span><span style="color:
#000000;">;</span></div>
<div><span style="color: #000000;"> </span><span
style="color: #0000ff;">double</span><span style="color:
#000000;"> d = Mod(z);</span></div>
<div><span style="color: #000000;">}</span></div>
</div>
<span style="color: #000000;"></span></div>
<div><span style="color: #000000;"><br>
</span></div>
</div>
<div class="moz-cite-prefix">I will admit that it's very fiddly to
get right. All of my attempts to map an anonymous struct to
__m128d via a union (so you could call z.re and z.im rather than
access the array elements) were unsuccessful. C++ is not very
friendly with vector types and you have to go out of your way to
get the compiler to be efficient with them, but the System V ABI
does support utilising the full vector registers.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">It took me a while to work out how
passing a record type with two single-precision elements into just
XMM0 is correct, but this is because the record type as a whole
has a size of eight bytes, and gets passed as a single argument of
class SSE. If the function parameters are instead two separate
arguments, then they get passed individually through XMM0 and
XMM1. It seems you have to interpret this document very literally
to get it right: <a class="moz-txt-link-freetext" href="https://www.uclibc.org/docs/psABI-x86_64.pdf">https://www.uclibc.org/docs/psABI-x86_64.pdf</a><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Gareth aka. Kit<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 27/10/2019 08:13, Florian Klämpfl
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:5af2c3ab-57cb-948d-e8ff-06303230cfc1@freepascal.org">Am
23.10.19 um 22:36 schrieb J. Gareth Moreton:
<br>
<blockquote type="cite">So I did a bit of reading after finding
the "mpx-linux64-abi.pdf" document. As I suspected, the System
V ABI is like vectorcall when it comes to using the XMM
registers... only the types __m128, __float128 and __Decimal128
use the "SSEUP" class and hence use the entire register. The
types are opaque, but both their size and alignment are 16
bytes, so I think anything that abides by those rules can be
considered equivalent.
<br>
<br>
If the complex type is unaligned, the two fields get their own
XMM register. If aligned, they both go into %xmm0. At least
that is what I gathered from reading the document - it's a
little unclear sometimes.
<br>
</blockquote>
<br>
I briefly tested with god bolt (<a class="moz-txt-link-freetext" href="https://godbolt.org/">https://godbolt.org/</a>): records of
two double are passed in two xmm registers regardless of the
alignment, two floats (so single) are passed in one xmm register.
<br>
_______________________________________________
<br>
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<br>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
<br>
<br>
</blockquote>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #D3D4DE;">
<tr>
<td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
<td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>
</td>
</tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>