[LLVMdev] GCC Atomic NAND implementation

Cameron McInally cameron.mcinally at nyu.edu
Tue Jul 12 16:44:28 PDT 2011


Hey Guys,


I have a newbie question about supporting the GNU atomic
builtin, __sync_fetch_and_nand. It appears that LLVM 29 produces X86
assembly like the GCC versions below v4.4, i.e.


NEGATE and AND

        notq    %rax

        movq    48(%rsp), %rcx

        andq    %rcx, %rax


I'm looking to produce X86 assembly like GCC v4.4 and greater, i.e.


NOT AND

        movq    48(%rsp), %rcx

        andq    %rcx, %rax

        notq    %rax


I currently have custom code to make the switch between implementations, but
it's invasive at best. Has the newer implementation already been written and
I missed it? If so, could someone please point me to that code? If not, are
there any plans in the near future to support the newer GCC implementation?


mcinally/MERGE_29> cat llvm.c

#include <stdio.h>


typedef int16_t T;


T a = 10;


int main() {

    volatile T *p = &a;

    T x = 2;

    int failed = 0;


    printf( "Testing %d bit objects\n", sizeof( T ) * 8 );


    *p = 15;  /* Or any value with the 2nd bit set */

    __sync_fetch_and_nand(p,x);

    if ( ~*p != 2 ) {

      failed = 1;

    }


    if ( !failed ) printf( "Test PASSED\n" );

    else printf( "Test FAILED\n" );

    return 0;

}


Thanks,

Cameron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110712/aba51511/attachment.html>


More information about the llvm-dev mailing list