<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">
<blockquote style="border-left-width: 3px; border-left-style: solid; border-color: rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);" itemscope="" itemtype="https://schemas.microsoft.com/QuotedText">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="caret-color:rgb(31, 73, 125);color:rgb(31, 73, 125);font-family:Calibri, sans-serif;background-color:rgb(255, 255, 255);display:inline !important">__fp16 is a pure storage format. You cannot pass it by value, because only<span class="Apple-converted-space"> </span></span><a href="https://gitlab.com/x86-psABIs/x86-64-ABI" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable" style="margin:0px;font-family:Calibri, sans-serif">ABI</a><span style="caret-color:rgb(31, 73, 125);color:rgb(31, 73, 125);font-family:Calibri, sans-serif;background-color:rgb(255, 255, 255);display:inline !important"><span class="Apple-converted-space"> </span>permissive
 types can be passed by value while __fp16 is not one of them.</span><br>
</div>
</blockquote>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="caret-color: rgb(31, 73, 125); color: rgb(0, 0, 0); font-family: calibri, arial, helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important; font-size: 12pt;">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></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="caret-color:rgb(31, 73, 125);color:rgb(31, 73, 125);font-family:Calibri, sans-serif;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="caret-color:rgb(31, 73, 125);color:rgb(31, 73, 125);font-family:Calibri, sans-serif;background-color:rgb(255, 255, 255);display:inline !important"><a href="https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point" id="LPlnk173766">https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point</a><br>
</span></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);">
Cheers,<br>
Sjoerd.</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of Wang, Pengfei via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> 05 March 2021 06:28<br>
<b>To:</b> Jason Hafer <jhafer@mathworks.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] Is it legal to pass a half by value on x86_64?</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:Wingdings}
@font-face
        {font-family:SimSun}
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:"Segoe UI"}
@font-face
        {}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
p.x_MsoListParagraph, li.x_MsoListParagraph, div.x_MsoListParagraph
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
span.x_EmailStyle22
        {font-family:"Calibri",sans-serif;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
ol
        {margin-bottom:0in}
ul
        {margin-bottom:0in}
-->
</style>
<div lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:#1F497D">Hi Jason,</span></p>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><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></p>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:#1F497D"> </span></p>
<ul type="disc" style="margin-top:0in">
<li class="x_MsoListParagraph" style="color:#1F497D; margin-left:0in"><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><span style="font-size:12.0pt"></span></li></ul>
<p class="x_MsoNormal"><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></p>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:#1F497D"> </span></p>
<div>
<p class="x_MsoNormal"><span style="color:#1F497D">Thanks</span></p>
<p class="x_MsoNormal"><span style="color:#1F497D">Pengfei</span></p>
</div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:#1F497D"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_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:46 AM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Cc:</b> Jason Hafer <jhafer@mathworks.com><br>
<b>Subject:</b> [llvm-dev] Is it legal to pass a half by value on x86_64?</p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">Hello,</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" 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></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" 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></p>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">  %6 = alloca half</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">  store half %4, half* %6, align 1</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">  ...</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">  ret void</span></p>
</div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">}</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" 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></p>
</div>
<div>
<p class="x_MsoNormal" 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></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">While investigating I noticed clang gave me the error below:</span></p>
<div>
<p class="x_MsoNormal" 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></p>
</div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" 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></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">Thank you in advance!</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">Cheers,</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-size:12.0pt; color:black">JP</span></p>
</div>
</div>
</div>
</body>
</html>