[LLVMbugs] [Bug 9848] New: _mm_andnot_si64() is broken

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 5 08:19:24 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=9848

           Summary: _mm_andnot_si64() is broken
           Product: new-bugs
           Version: 2.9
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: yottui at yahoo.co.jp
                CC: llvmbugs at cs.uiuc.edu


clang++ 2.9 generates a wrong code with _mm_andnot_si64().
Ths source register and the destination register are swapped in PANDN.

--- begin test case (andnot.cpp) ---
#include <mmintrin.h>

__m64 max_pu16(__m64 lhs, __m64 rhs)
{
    __m64 sign = _mm_set1_pi16((short)0x8000);
    __m64 ls   = _mm_xor_si64(lhs, sign);
    __m64 rs   = _mm_xor_si64(rhs, sign);
    __m64 mask = _mm_cmpgt_pi16(ls, rs);
    __m64 gt   = _mm_and_si64(mask, lhs);
    __m64 le   = _mm_andnot_si64(mask, rhs);

    return _mm_or_si64(gt, le);
}
--- end test case ---

--- begin output ---
$ clang++ -O -S -mmmx -mno-sse -mno-sse2 -D _mm_malloc andnot.cpp

$ cat andnot.s
    .def     __Z8max_pu16Dv1_xS_;
    .scl    2;
    .type    32;
    .endef
    .text
    .globl    __Z8max_pu16Dv1_xS_
    .align    16, 0x90
__Z8max_pu16Dv1_xS_:
    subl    $68, %esp
    movl    84(%esp), %eax ; rhs[1]
    movl    %eax, 44(%esp) ;   -> 44(esp)
    movl    80(%esp), %eax ; rhs[0]
    movl    %eax, 40(%esp) ;   -> 40(esp)
    movl    76(%esp), %eax ; lhs[1]
    movl    %eax, 52(%esp) ;   -> 52(esp)
    movl    72(%esp), %eax ; lhs[0]
    movl    %eax, 48(%esp) ;   -> 48(esp)
    movl    $-2147450880, 60(%esp) ; 0x8000 -> 60(esp)
    movl    $-2147450880, 56(%esp) ; 0x8000 -> 56(esp)
    movq    56(%esp), %mm0 ; 0x8000 -> mm0
    movq    40(%esp), %mm1 ; rhs -> mm1
    movq    %mm1, %mm2     ; rhs -> mm2
    pxor    %mm0, %mm2     ; 0x8000 ^ rhs -> mm2 = rs
    movq    48(%esp), %mm3 ; lhs -> mm3
    pxor    %mm3, %mm0     ; lhs ^ 0x8000 -> mm0 = ls
    pcmpgtw    %mm2, %mm0     ; rs < ls
    movq    %mm0, 8(%esp)  ;              ->  8(esp) = mask
    movl    8(%esp), %eax  ;  8(esp)      -> eax
    movl    12(%esp), %ecx ; 12(esp)      -> ecx
    movl    %ecx, 20(%esp) ; ecx          -> 20(esp)
    movl    %eax, 16(%esp) ; eax          -> 16(esp)
    movq    16(%esp), %mm0 ; mask         -> mm0
    pandn    %mm0, %mm1     ; mask & ~rhs  -> mm1 = le !!!!!! wrong code !!!!!
    pand    %mm3, %mm0     ; lhs  & mask  -> mm0 = gt
    por    %mm1, %mm0         ; le | gt -> mm0
    movq    %mm0, (%esp)
    movl    (%esp), %eax
    movl    4(%esp), %edx
    addl    $68, %esp
    ret
--- end output ---

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list