<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection">
<div dir="auto">Hi:<br />
<br />
I am trying to implement interval arithmetic through llvm. I have a problem with the rounding mode with llvm.experimental.constrained.cos<br />
<br />
I have two pieces of codes:<br />
<br />
<em style="color:#bbbbbb;font-size: 12px">; Function Attrs: norecurse nounwind readnone ssp uwtable</em><span style="font-size: 12px"><br /></span><strong style="color:#b877db;font-size: 12px">define</strong><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">@cosine_down</em><span style="color:#bbbbbb;font-size: 12px">(</span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> returned) local_unnamed_addr #</span><span style="color:#f09483;font-size: 12px">0</span><span style="color:#bbbbbb;font-size: 12px"> {</span><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#bbbbbb;font-size: 12px">; call the llvm intrinsic to perform downward cosine</em><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">%2</em><span style="color:#bbbbbb;font-size: 12px"> = </span><strong style="color:#b877db;font-size: 12px">call</strong><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">@llvm.experimental.constrained.cos</em><span style="color:#bbbbbb;font-size: 12px">(</span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">%0</em><span style="color:#bbbbbb;font-size: 12px">, </span><strong style="color:#b877db;font-size: 12px">metadata</strong><span style="color:#bbbbbb;font-size: 12px"> !</span><span style="color:#fab795;font-size: 12px">"round</span><span style="color:#25b0bc;font-size: 12px">.d</span><span style="color:#fab795;font-size: 12px">ownward"</span><span style="color:#bbbbbb;font-size: 12px">, </span><strong style="color:#b877db;font-size: 12px">metadata</strong><span style="color:#bbbbbb;font-size: 12px"> !</span><span style="color:#fab795;font-size: 12px">"fpexcept</span><span style="color:#25b0bc;font-size: 12px">.s</span><span style="color:#fab795;font-size: 12px">trict"</span><span style="color:#bbbbbb;font-size: 12px">)</span><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">ret</strong><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">%2</em><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px">}</span><span style="font-size: 12px"><br /></span><span style="font-size: 12px"><br /></span><em style="color:#bbbbbb;font-size: 12px">; Function Attrs: norecurse nounwind readnone ssp uwtable</em><span style="font-size: 12px"><br /></span><strong style="color:#b877db;font-size: 12px">define</strong><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">@cosine_up</em><span style="color:#bbbbbb;font-size: 12px">(</span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> returned) local_unnamed_addr #</span><span style="color:#f09483;font-size: 12px">0</span><span style="color:#bbbbbb;font-size: 12px"> {</span><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#bbbbbb;font-size: 12px">; call the llvm intrinsic to perform upward cosine</em><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">%2</em><span style="color:#bbbbbb;font-size: 12px"> = </span><strong style="color:#b877db;font-size: 12px">call</strong><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">@llvm.experimental.constrained.cos</em><span style="color:#bbbbbb;font-size: 12px">(</span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">%0</em><span style="color:#bbbbbb;font-size: 12px">, </span><strong style="color:#b877db;font-size: 12px">metadata</strong><span style="color:#bbbbbb;font-size: 12px"> !</span><span style="color:#fab795;font-size: 12px">"round</span><span style="color:#25b0bc;font-size: 12px">.u</span><span style="color:#fab795;font-size: 12px">pward"</span><span style="color:#bbbbbb;font-size: 12px">, </span><strong style="color:#b877db;font-size: 12px">metadata</strong><span style="color:#bbbbbb;font-size: 12px"> !</span><span style="color:#fab795;font-size: 12px">"fpexcept</span><span style="color:#25b0bc;font-size: 12px">.s</span><span style="color:#fab795;font-size: 12px">trict"</span><span style="color:#bbbbbb;font-size: 12px">)</span><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">ret</strong><span style="color:#bbbbbb;font-size: 12px"> </span><strong style="color:#b877db;font-size: 12px">double</strong><span style="color:#bbbbbb;font-size: 12px"> </span><em style="color:#fac29a;font-size: 12px">%2</em><span style="font-size: 12px"><br /></span><span style="color:#bbbbbb;font-size: 12px">}</span><span style="font-size: 12px"><br /></span><span style="font-size: 12px"><br /></span><span style="color:#d5dade">When calling the function on a test number</span><span style="color:#bbbbbb;font-size: 12px">: </span><span style="color:#f09483;font-size: 12px">0.79358805865013693</span><span style="font-size: 12px"><br /></span><span style="font-size: 12px"><br /></span><span style="color:#d5dade">The two functions return the same value: </span>0.7012920012119437<span style="color:#d5dade">. </span><br />
<br />
<span style="color:#d5dade">Ideally, the two functions will give me the upper and lower bound of where the true value will lie within, so maybe </span>0.7012920012119436 to 0.7012920012119438, but it seems like even with the upward and downward rounding mode that’s not the case.<br />
<br />
I noted on the page <a href="https://llvm.org/docs/LangRef.html#llvm-experimental-constrained-cos-intrinsic" target="_blank">https://llvm.org/docs/LangRef.html#llvm-experimental-constrained-cos-intrinsic</a> it says <span style="color:#000000;background-color:#ffffff;font-family:Lucida Grande, Lucida Sans Unicode, Geneva, Verdana, sans-serif">This function returns the cosine of the specified operand, returning the same values as the libm </span><code>cos</code><span style="color:#000000;background-color:#ffffff;font-family:Lucida Grande, Lucida Sans Unicode, Geneva, Verdana, sans-serif"> functions would</span><br />
<br />
<span style="color:#d5dade;background-color:rgba(0, 0, 0, 0)">So does this mean that constrained cos does not care about the rounding mode but instead will just return the same value?</span></div>
</div>
<div name="messageSignatureSection"><br />
<div class="matchFont">Thank you
<div>Xuan Tang</div>
</div>
</div>
</body>
</html>