<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
p.xmsonormal, li.xmsonormal, div.xmsonormal
        {mso-style-name:x_msonormal;
        margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.xapple-converted-space
        {mso-style-name:x_apple-converted-space;}
p.xxmsonormal, li.xxmsonormal, div.xxmsonormal
        {mso-style-name:x_xmsonormal;
        margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.xxmsolistparagraph, li.xxmsolistparagraph, div.xxmsolistparagraph
        {mso-style-name:x_xmsolistparagraph;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:660818971;
        mso-list-template-ids:-688592638;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:4.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt;color:#1F497D">Hi Jason,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;color:#1F497D">The different behavior between Linux and Windows comes form the difference of the calling conversion. Windows uses 4 registers for arguments passing which Linux uses 6.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;color:#1F497D"><a href="https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-160#parameter-passing">https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-160#parameter-passing</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;color:#1F497D"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:#1F497D">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Pengfei<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>Jason Hafer via llvm-dev<br>
<b>Sent:</b> Friday, March 5, 2021 10:21 PM<br>
<b>To:</b> Craig Topper <craig.topper@gmail.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] Is it legal to pass a half by value on x86_64?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black;background:white">Hi All,</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black">Thank you very much for all the great information.  This is awesome! <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black">To circle back on Craig's questions.<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black;background:white">I did notice LLVM 11 behave very differently.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black;background:white">** Per: </span><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">What does "incorrect math operations" mean? </span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">The half is passed to the function as a float.  The function does operations with other half numbers.  On Windows when
 we don't get the float to half conversation the input is always truncated to 0.0.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">** Per: "Do you have a more complete IR file for Windows that I can take a look at?"</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">I can get you our IR if you want, but I think it is more convoluted than required.  I was working
 on a unit test and I think all one needs to see the anomaly is:</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">define void @foo(i8, i8, i8, i8, half) {
<o:p></o:p></span></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">; CHECK-I686:    callq __gnu_f2h_ieee<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  %6 = alloca half<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  store half %4, half* %6, align 1<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  ret void<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">}<br>
<br>
x86_64-pc-windows gives:<br>
push rax <o:p></o:p></span></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_stackalloc 8<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_endprologue<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">movss xmm0, dword ptr [rsp + 48] # xmm0 = mem[0],zero,zero,zero<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">movss dword ptr [rsp + 4], xmm0 # 4-byte Spill<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">pop rax<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">ret<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_handlerdata<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.text<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_endproc<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black">What I find extremely interesting is the behavior seems has something to do with the stack?  For dropping the inputs by one then even Windows will generate the conversion.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">define void @foo(i8, i8, i8, half) {
<o:p></o:p></span></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">; CHECK-I686:    callq __gnu_f2h_ieee<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  %5 = alloca half<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  store half %3, half* %5, align 1<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  ret void<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">}</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">x86_64-pc-windows gives:</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">sub rsp, 40<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_stackalloc 40<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_endprologue<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">movabs rax, offset __gnu_f2h_ieee<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">movaps xmm0, xmm3<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">call rax<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">mov word ptr [rsp + 38], ax<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">add rsp, 40<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">ret<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_handlerdata<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.text<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">.seh_endproc<o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">** If interested, here is a dissection of our real asm.<br>
For both Windows and Linux our IR calls c2_foo() with a half(2): <o:p></o:p></span></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">...<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">call void @c2_foo(i8* %S_6, [21 x i8*]* %ptr_gvar_instance_7, %emlrtStack* %c2_b_st_, [18 x float]* @15, half 0xH4000,
 [18 x i8]* %t10)<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">They both register this in c2_foo as:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">...<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  %c2_in2_ = alloca half<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">  store half %c2_in2, half* %c2_in2_, align 1<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">When we compile them, they both send 0x40000000 to c2_foo (a single).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">The Linux c2_foo() asm addresses this with a float2half conversion:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">...<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 448], rdi<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 440], rsi<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 432], rdx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 424], rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> movabs rcx, offset __gnu_f2h_ieee     # <---Convert Here<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 336], r8 # 8-byte Spill<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> call rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov word ptr [rsp + 422], ax<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rcx, qword ptr [rsp + 336] # 8-byte Reload<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 408], rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 392], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 384], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 376], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 368], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rdx, qword ptr [rsp + 432]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 360], rdx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rdx, qword ptr [rsp + 432]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rdx, qword ptr [rdx + 8]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 352], rdx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rdx, qword ptr [rsp + 440]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rdx, qword ptr [rdx + 56]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 344], rdx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov dword ptr [rsp + 400], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> jmp .LBB9_9<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">The Windows c2_foo() asm is missing this conversion but treats the value as if it has been converted.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white">...<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rax, qword ptr [rsp + 424]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> movss xmm0, dword ptr [rsp + 416] # xmm0 = mem[0],zero,zero,zero  # <-- moves the data like it wants to convert but
 never does<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 344], rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 336], rdx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 328], r8<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 320], r9<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 304], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 296], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 288], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 280], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rcx, qword ptr [rsp + 328]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 272], rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rcx, qword ptr [rsp + 328]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rcx, qword ptr [rcx + 8]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 264], rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rcx, qword ptr [rsp + 336]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov rcx, qword ptr [rcx + 56]<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 256], rcx<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov dword ptr [rsp + 312], 0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> mov qword ptr [rsp + 248], rax # 8-byte Spill<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white"><span style="font-size:11.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"> movss dword ptr<br>
<br>
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Wang, Pengfei <<a href="mailto:pengfei.wang@intel.com">pengfei.wang@intel.com</a>><br>
<b>Sent:</b> Friday, March 5, 2021 7:30 AM<br>
<b>To:</b> Sjoerd Meijer <<a href="mailto:Sjoerd.Meijer@arm.com">Sjoerd.Meijer@arm.com</a>>; Jason Hafer <<a href="mailto:jhafer@mathworks.com">jhafer@mathworks.com</a>><br>
<b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> RE: Is it legal to pass a half by value on x86_64?</span> <o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:#1F497D">I guess it’s designed for language portability. You can use this type across different platforms. Nevertheless, I’m not a FE expert, so I cannot think out other intentions.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:12.0pt;color:#1F497D">The _Float16 is a primitive type in the latest x86 ABI, but there’s no X86 target that supports it yet. So you cannot use it on X86 by now. I think that’s the difference from __fp16 and why
 should use it.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:12.0pt;color:#1F497D">We also have some discussion here.
<a href="https://reviews.llvm.org/D97318">https://reviews.llvm.org/D97318</a></span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:12.0pt;color:#1F497D"> </span><o:p></o:p></p>
<div>
<p class="xmsonormal"><span style="color:#1F497D">Thanks</span><o:p></o:p></p>
<p class="xmsonormal"><span style="color:#1F497D">Pengfei</span><o:p></o:p></p>
</div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:#1F497D"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="xmsonormal"><b>From:</b> Sjoerd Meijer <<a href="mailto:Sjoerd.Meijer@arm.com">Sjoerd.Meijer@arm.com</a>>
<br>
<b>Sent:</b> Friday, March 5, 2021 5:49 PM<br>
<b>To:</b> Jason Hafer <<a href="mailto:jhafer@mathworks.com">jhafer@mathworks.com</a>>; Wang, Pengfei <<a href="mailto:pengfei.wang@intel.com">pengfei.wang@intel.com</a>><br>
<b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: Is it legal to pass a half by value on x86_64?<o:p></o:p></p>
</div>
</div>
<p class="xmsonormal"> <o:p></o:p></p>
<blockquote style="border:none;border-left:solid #C8C8C8 2.25pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:#1F497D;background:white">__fp16 is a pure storage format. You cannot pass it by value, because only<span class="xapple-converted-space"> </span></span><span style="font-size:12.0pt;color:black"><a href="https://gitlab.com/x86-psABIs/x86-64-ABI" target="_blank">ABI</a></span><span class="xapple-converted-space"><span style="font-size:12.0pt;color:#1F497D;background:white"> </span></span><span style="font-size:12.0pt;color:#1F497D;background:white">permissive
 types can be passed by value while __fp16 is not one of them.</span><o:p></o:p></p>
</div>
</blockquote>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black;background:white">Yep. Any specific reason to use a pure storage format? The native type is _Float16 and would give some benefits, but this is not yet supported on x86, see also:</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
</div>
<div>
<p class="xmsonormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;color:#1F497D;background:white"><a href="https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point">https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point</a></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">Cheers,<br>
Sjoerd.</span><o:p></o:p></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="1" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="xmsonormal"><b><span style="color:black">From:</span></b><span style="color:black"> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>> on behalf of Wang, Pengfei via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<b>Sent:</b> 05 March 2021 06:28<br>
<b>To:</b> Jason Hafer <<a href="mailto:jhafer@mathworks.com">jhafer@mathworks.com</a>><br>
<b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] Is it legal to pass a half by value on x86_64?</span>
<o:p></o:p></p>
<div>
<p class="xmsonormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D">Hi Jason,</span><o:p></o:p></p>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D">__fp16 is a pure storage format. You cannot pass it by value, because only
<a href="https://gitlab.com/x86-psABIs/x86-64-ABI">ABI</a> permissive types can be passed by value while __fp16 is not one of them.</span><o:p></o:p></p>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D"> </span><o:p></o:p></p>
<ul style="margin-top:0in" type="disc">
<li class="xxmsolistparagraph" style="color:#1F497D;margin-top:0in;margin-bottom:0in;mso-list:l0 level1 lfo1">
<span style="font-size:12.0pt;color:black">if "<span style="background:white">define void @foo(i8, i8, i8, i8, half) " is even legal to use</span></span><o:p></o:p></li></ul>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D">half as a target independent type is legal for LLVM. It’s not legal for unsupported target like X86. The behavior depends on how we lowering it. But I don’t know why there’s differences between
 Linux and Windows. Maybe because “__gnu_f2h_ieee” is a Linux only function?</span><o:p></o:p></p>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D"> </span><o:p></o:p></p>
<div>
<p class="xxmsonormal"><span style="color:#1F497D">Thanks</span><o:p></o:p></p>
<p class="xxmsonormal"><span style="color:#1F497D">Pengfei</span><o:p></o:p></p>
</div>
<p class="xxmsonormal"><span style="font-size:12.0pt;color:#1F497D"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="xxmsonormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Jason Hafer via llvm-dev<br>
<b>Sent:</b> Friday, March 5, 2021 10:46 AM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<b>Cc:</b> Jason Hafer <<a href="mailto:jhafer@mathworks.com">jhafer@mathworks.com</a>><br>
<b>Subject:</b> [llvm-dev] Is it legal to pass a half by value on x86_64?<o:p></o:p></p>
</div>
</div>
<p class="xxmsonormal"> <o:p></o:p></p>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">Hello,</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">I am attempting to understand an anomaly I am seeing when dealing with half on Windows and could use some help.</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">Using LLVM 8 or 10, if I have IR of the flavor below:<br>
define void @foo(i8, i8, i8, i8, half) { </span><o:p></o:p></p>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">  %6 = alloca half</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">  store half %4, half* %6, align 1</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">  ...</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">  ret void</span><o:p></o:p></p>
</div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">}</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">Using x86_64-pc-linux, we convert the float passed in with __gnu_f2h_ieee.</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">Using x86_64-pc-windows I do not get the conversion, so we end up with incorrect math operations.</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">While investigating I noticed clang gave me the error below:</span><o:p></o:p></p>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:black">error: parameters cannot have __fp16 type; did you forget * ?<br>
void foo(int dc1, int dc2,int dc3,int dc4, __fp16 in)</span><o:p></o:p></p>
</div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">So, this got me wondering if "<span style="background:white">define void @foo(i8, i8, i8, i8, half) " is even legal to use or if I should rather pass by ref?  I have
 yet to find documentation to convince me one way or the other.  Thus, I was hoping someone here might be able to shed some light on the issue.</span></span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">Thank you in advance!</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">Cheers,</span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal" style="background:white"><span style="font-size:12.0pt;color:black">JP</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>