[LLVMdev] Which floating-point comparison?

Russell Wallace russell.wallace at gmail.com
Mon Mar 29 02:10:07 PDT 2010


That works, thanks! It turns out that x86/SSE at least handles both
equally well, but the ordered version is what C uses.

On Sun, Mar 28, 2010 at 6:38 PM, Jeffrey Yasskin <jyasskin at google.com> wrote:
> On Sun, Mar 28, 2010 at 7:45 AM, Russell Wallace
> <russell.wallace at gmail.com> wrote:
>> I notice llvm provides both ordered and unordered variants of
>> floating-point comparison. Which of these is the right one to use by
>> default? I suppose the two criteria would be, in order of importance:
>>
>> 1. Which is more efficient (more directly maps to typical hardware)?
>
> You can figure this out by looking at the output of llc:
>
> $ cat test.ll
> define i1 @less(double %x, double %y) nounwind readnone {
> entry:
>  %0 = fcmp ult double %x, %y                     ; <i1> [#uses=1]
>  ret i1 %0
> }
> $ Debug/bin/llc  <test.ll
>        .section        __TEXT,__text,regular,pure_instructions
>        .globl  _less
>        .align  4, 0x90
> _less:                                  ## @less
> ## BB#0:                                ## %entry
>        movsd   4(%esp), %xmm0
>        ucomisd 12(%esp), %xmm0
>        sbbb    %al, %al
>        andb    $1, %al
>        ret
>
>> 2. Which is more familiar (more like the way C and Fortran do it)?
>
> You can use http://llvm.org/demo/ to figure that out.
>




More information about the llvm-dev mailing list