<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">Hi All,</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<div style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Thank you very much for all the great information.  This is awesome! </div>
<div style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
To circle back on Craig's questions.</div>
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">I did notice LLVM 11 behave very differently.</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">** Per: <span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;">What
 does "incorrect math operations" mean?<span> </span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>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></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span><br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>**
 Per: "<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); display: inline !important;">Do you have a more complete IR file for Windows that I can take a look at?</span>"</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>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:<br>
<br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>define
 void @foo(i8, i8, i8, i8, half) {
<div>; CHECK-I686:    callq __gnu_f2h_ieee</div>
<div><br>
</div>
<div>  %6 = alloca half</div>
<div>  store half %4, half* %6, align 1</div>
<div>  ret void</div>
}<br>
<br>
x86_64-pc-windows gives:<br>
push rax
<div>.seh_stackalloc 8</div>
<div>.seh_endprologue</div>
<div>movss xmm0, dword ptr [rsp + 48] # xmm0 = mem[0],zero,zero,zero</div>
<div>movss dword ptr [rsp + 4], xmm0 # 4-byte Spill</div>
<div>pop rax</div>
<div>ret</div>
<div>.seh_handlerdata</div>
<div>.text</div>
<div>.seh_endproc</div>
<br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
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.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span><br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>define
 void @foo(i8, i8, i8, half) {
<div>; CHECK-I686:    callq __gnu_f2h_ieee</div>
<div><br>
</div>
<div>  %5 = alloca half</div>
<div>  store half %3, half* %5, align 1</div>
<div>  ret void</div>
}<br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span><br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); display: inline !important;">x86_64-pc-windows
 gives:</span><br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>
<div>sub rsp, 40</div>
<div>.seh_stackalloc 40</div>
<div>.seh_endprologue</div>
<div>movabs rax, offset __gnu_f2h_ieee</div>
<div>movaps xmm0, xmm3</div>
<div>call rax</div>
<div>mov word ptr [rsp + 38], ax</div>
<div>add rsp, 40</div>
<div>ret</div>
<div>.seh_handlerdata</div>
<div>.text</div>
<div>.seh_endproc</div>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span><br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="margin: 0px; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); display: inline !important;"><span>**
 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):
<div>...</div>
<div>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)</div>
<div><br>
</div>
<div>They both register this in c2_foo as:</div>
<div>...</div>
<div>  %c2_in2_ = alloca half</div>
<div>  store half %c2_in2, half* %c2_in2_, align 1</div>
<div><br>
</div>
<div>When we compile them, they both send 0x40000000 to c2_foo (a single).</div>
<div>The Linux c2_foo() asm addresses this with a float2half conversion:</div>
<div>...</div>
<div> mov qword ptr [rsp + 448], rdi</div>
<div> mov qword ptr [rsp + 440], rsi</div>
<div> mov qword ptr [rsp + 432], rdx</div>
<div> mov qword ptr [rsp + 424], rcx</div>
<div> movabs rcx, offset __gnu_f2h_ieee     # <---Convert Here</div>
<div> mov qword ptr [rsp + 336], r8 # 8-byte Spill</div>
<div> call rcx</div>
<div> mov word ptr [rsp + 422], ax</div>
<div> mov rcx, qword ptr [rsp + 336] # 8-byte Reload</div>
<div> mov qword ptr [rsp + 408], rcx</div>
<div> mov qword ptr [rsp + 392], 0</div>
<div> mov qword ptr [rsp + 384], 0</div>
<div> mov qword ptr [rsp + 376], 0</div>
<div> mov qword ptr [rsp + 368], 0</div>
<div> mov rdx, qword ptr [rsp + 432]</div>
<div> mov qword ptr [rsp + 360], rdx</div>
<div> mov rdx, qword ptr [rsp + 432]</div>
<div> mov rdx, qword ptr [rdx + 8]</div>
<div> mov qword ptr [rsp + 352], rdx</div>
<div> mov rdx, qword ptr [rsp + 440]</div>
<div> mov rdx, qword ptr [rdx + 56]</div>
<div> mov qword ptr [rsp + 344], rdx</div>
<div> mov dword ptr [rsp + 400], 0</div>
<div> jmp .LBB9_9</div>
<div><br>
</div>
<div>The Windows c2_foo() asm is missing this conversion but treats the value as if it has been converted.</div>
<div>...</div>
<div> mov rax, qword ptr [rsp + 424]</div>
<div> movss xmm0, dword ptr [rsp + 416] # xmm0 = mem[0],zero,zero,zero  # <-- moves the data like it wants to convert but never does</div>
<div> mov qword ptr [rsp + 344], rcx</div>
<div> mov qword ptr [rsp + 336], rdx</div>
<div> mov qword ptr [rsp + 328], r8</div>
<div> mov qword ptr [rsp + 320], r9</div>
<div> mov qword ptr [rsp + 304], 0</div>
<div> mov qword ptr [rsp + 296], 0</div>
<div> mov qword ptr [rsp + 288], 0</div>
<div> mov qword ptr [rsp + 280], 0</div>
<div> mov rcx, qword ptr [rsp + 328]</div>
<div> mov qword ptr [rsp + 272], rcx</div>
<div> mov rcx, qword ptr [rsp + 328]</div>
<div> mov rcx, qword ptr [rcx + 8]</div>
<div> mov qword ptr [rsp + 264], rcx</div>
<div> mov rcx, qword ptr [rsp + 336]</div>
<div> mov rcx, qword ptr [rcx + 56]</div>
<div> mov qword ptr [rsp + 256], rcx</div>
<div> mov dword ptr [rsp + 312], 0</div>
<div> mov qword ptr [rsp + 248], rax # 8-byte Spill</div>
 movss dword ptr<br>
<br>
<br>
</span></span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="margin: 0px; font-size: 15px; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"></span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size: 11pt;"><b>From:</b> Wang, Pengfei <pengfei.wang@intel.com><br>
<b>Sent:</b> Friday, March 5, 2021 7:30 AM<br>
<b>To:</b> Sjoerd Meijer <Sjoerd.Meijer@arm.com>; Jason Hafer <jhafer@mathworks.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> RE: Is it legal to pass a half by value on x86_64?</font>
<div> </div>
</div>
<div lang="EN-US" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);">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></p>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);">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></p>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);">We also have some discussion here.
<a href="https://reviews.llvm.org/D97318">
https://reviews.llvm.org/D97318</a></span></p>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);"> </span></p>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="color: rgb(31, 73, 125);">Thanks</span></p>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="color: rgb(31, 73, 125);">Pengfei</span></p>
</div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<b>From:</b> Sjoerd Meijer <Sjoerd.Meijer@arm.com> <br>
<b>Sent:</b> Friday, March 5, 2021 5:49 PM<br>
<b>To:</b> Jason Hafer <jhafer@mathworks.com>; Wang, Pengfei <pengfei.wang@intel.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: Is it legal to pass a half by value on x86_64?</p>
</div>
</div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
 </p>
<blockquote style="border:none #C8C8C8 1.0pt; 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="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125); background: white;">__fp16 is a pure storage format. You cannot pass it by value, because only<span class="x_apple-converted-space"> </span></span><span style="font-size: 12pt; color: black;"><a href="https://gitlab.com/x86-psABIs/x86-64-ABI" target="_blank">ABI</a></span><span class="x_apple-converted-space"><span style="font-size: 12pt; color: rgb(31, 73, 125); background: white;"> </span></span><span style="font-size: 12pt; color: rgb(31, 73, 125); background: white;">permissive
 types can be passed by value while __fp16 is not one of them.</span><span style="font-size: 12pt; color: black;"></span></p>
</div>
</blockquote>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; 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><span style="font-size: 12pt; color: black;"></span></p>
</div>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125); background: white;"><br>
<br>
</span><span style="font-size: 12pt; color: black;"></span></p>
</div>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125); 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><br>
<br>
</span><span style="font-size: 12pt; color: black;"></span></p>
</div>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: black;">Cheers,<br>
Sjoerd.</span></p>
</div>
<div class="x_MsoNormal" align="center" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<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>
</p>
<div>
<p class="x_MsoNormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
 </p>
</div>
</div>
<div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);">Hi Jason,</span></p>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);"> </span></p>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);">__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></p>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);"> </span></p>
<ul type="disc" style="margin-bottom: 0in;margin-top:0in">
<li class="x_xmsolistparagraph" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">
<span style="font-size: 12pt; color: black;">if "<span style="background: white;">define void @foo(i8, i8, i8, i8, half) " is even legal to use</span></span></li></ul>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);">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></p>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);"> </span></p>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="color: rgb(31, 73, 125);">Thanks</span></p>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="color: rgb(31, 73, 125);">Pengfei</span></p>
</div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<span style="font-size: 12pt; color: rgb(31, 73, 125);"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
<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?</p>
</div>
</div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">
 </p>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">Hello,</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">I am attempting to understand an anomaly I am seeing when dealing with half on Windows and could use some help.</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; 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></p>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">  %6 = alloca half</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">  store half %4, half* %6, align 1</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">  ...</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">  ret void</span></p>
</div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">}</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">Using x86_64-pc-linux, we convert the float passed in with __gnu_f2h_ieee.</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">Using x86_64-pc-windows I do not get the conversion, so we end up with incorrect math operations.</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">While investigating I noticed clang gave me the error below:</span></p>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; 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></p>
</div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; 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></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">Thank you in advance!</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">Cheers,</span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;"> </span></p>
</div>
<div>
<p class="x_xmsonormal" style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif; background: white;">
<span style="font-size: 12pt; color: black;">JP</span></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>