[llvm-dev] constrained cosine rounding mode behavior

Craig Topper via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 8 22:28:29 PDT 2020


Hi Xuan Tang,

The rounding mode argument to the intrinsic is supposed to be a hint to the
compiler to tell us what the rounding mode has been changed to. In theory
we could use this to constant fold the intrinsic with correct rounding but
I don't think much of that is implemented. The compiler does not add any
code to change the rounding mode in the hardware floating point unit in
response to the intrinsic. It's up to the user to call something like
fesetround in libm to change the rounding mode in hardware. Changing the
rounding mode in hardware could have an effect on the result returned by
the cos library function that we will ultimately call, but I don't know for
sure.

~Craig


On Tue, Sep 8, 2020 at 8:55 PM Xuan Tang via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200908/ad7ef5c1/attachment.html>


More information about the llvm-dev mailing list