[llvm-dev] constrained cosine rounding mode behavior

Xuan Tang via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 8 20:55:13 PDT 2020


Hi:

I am trying to implement interval arithmetic through llvm. I have a problem with the rounding mode with llvm.experimental.constrained.cos

I have two pieces of codes:

; Function Attrs: norecurse nounwind readnone ssp uwtable
define double @cosine_down(double returned) local_unnamed_addr #0 {
  ; call the llvm intrinsic to perform downward cosine
  %2 = call double @llvm.experimental.constrained.cos(double %0, metadata !"round.downward", metadata !"fpexcept.strict")
  ret double %2
}

; Function Attrs: norecurse nounwind readnone ssp uwtable
define double @cosine_up(double returned) local_unnamed_addr #0 {
  ; call the llvm intrinsic to perform upward cosine
  %2 = call double @llvm.experimental.constrained.cos(double %0, metadata !"round.upward", metadata !"fpexcept.strict")
  ret double %2
}

When calling the function on a test number: 0.79358805865013693

The two functions return the same value: 0.7012920012119437.

Ideally, the two functions will give me the upper and lower bound of where the true value will lie within, so maybe 0.7012920012119436 to 0.7012920012119438, but it seems like even with the upward and downward rounding mode that’s not the case.

I noted on the page https://llvm.org/docs/LangRef.html#llvm-experimental-constrained-cos-intrinsic it says  This function returns the cosine of the specified operand, returning the same values as the libm cos functions would

So does this mean that constrained cos does not care about the rounding mode but instead will just return the same value?

Thank you
Xuan Tang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200908/19278381/attachment.html>


More information about the llvm-dev mailing list