public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37908]  New: atomic NAND op generate wrong code; __sync_nand_and_fetch, __sync_fetch_and_nand
@ 2008-10-24  3:38 kokseng at ieee dot org
  2008-10-24  7:45 ` [Bug middle-end/37908] [4.2/4.3/4.4 regression] " ubizjak at gmail dot com
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: kokseng at ieee dot org @ 2008-10-24  3:38 UTC (permalink / raw)
  To: gcc-bugs

Hello,

I discovered a failure relating to atomic NAND operation on  x86 platform,
which can be confirmed using the included test-case.  The test was done with
gcc 4.2.4, using 8-, 16-, 32- and 64-bit data width.  Test cases on other logic
atomic operators passes all width-size except NAND.  I have read through the
assembly code generated and confirm that some wrong codes are generated when
no-optimization and -O.


I ) Test case : 

/*
        Compile using:
                gcc -c -march=i686 test.c 

        To get assembly listing:
                gcc -S -march=i686 test.c

        To get mix c and assembly listing:
                gcc -c -g -Wa,-a,-ad -march=i686 test.c > test-xxx.lst
*/

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned long long QWORD;


int main(void)
{

        WORD xLoc;  /* change xLoc type to BYTE, WORD, DWORD, QWORD to test
different data-width */
        typeof(xLoc)    xIn, xOut, xExpect, i = 1; 
        xLoc = xIn = (typeof(xIn)) ~ (1<<i); 
        xExpect = (typeof(xIn)) ~(xIn & ((typeof(xIn)) 0x7F)); 
        /* Both __sync_nand_and_fetch and __sync_fetch_and_nand have the same
problem */
        xOut = __sync_nand_and_fetch(&xLoc, (typeof(xIn)) 0x7F);
        if (xOut!=xExpect) 
                printf("__sync_nand_and_fetch():; wrong result; i(%d) xIn(%x)
xExpect(%x) xOut(%x) xLoc(%x)\n", 
                        i, xIn, xExpect, xOut, xLoc);

        return 0;
}

II )  Output of gcc -v -save-temps

gcc -o test_bug -v -save-temps -march=i686 test_nand_bug.c

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2.4/configure --prefix=/opt/gcc-4.2.4
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu
Thread model: posix
gcc version 4.2.4
 /opt/gcc-4.2.4/libexec/gcc/i686-pc-linux-gnu/4.2.4/cc1 -E -quiet -v
test_nand_bug.c -march=i686 -fpch-preprocess -o test_nand_bug.i
ignoring nonexistent directory
"/opt/gcc-4.2.4/lib/gcc/i686-pc-linux-gnu/4.2.4/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /opt/gcc-4.2.4/include
 /opt/gcc-4.2.4/lib/gcc/i686-pc-linux-gnu/4.2.4/include
 /usr/include
End of search list.
 /opt/gcc-4.2.4/libexec/gcc/i686-pc-linux-gnu/4.2.4/cc1 -fpreprocessed
test_nand_bug.i -quiet -dumpbase test_nand_bug.c -march=i686 -auxbase
test_nand_bug -version -o test_nand_bug.s
GNU C version 4.2.4 (i686-pc-linux-gnu)
        compiled by GNU C version 4.2.4.
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32052
Compiler executable checksum: 383821529167afc2e47a93836e3831a4
 as -V -Qy -o test_nand_bug.o test_nand_bug.s
GNU assembler version 2.13.90.0.18 (i386-redhat-linux) using BFD version
2.13.90.0.18 20030206
 /opt/gcc-4.2.4/libexec/gcc/i686-pc-linux-gnu/4.2.4/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o test_bug /usr/lib/crt1.o
/usr/lib/crti.o /opt/gcc-4.2.4/lib/gcc/i686-pc-linux-gnu/4.2.4/crtbegin.o
-L/opt/gcc-4.2.4/lib/gcc/i686-pc-linux-gnu/4.2.4
-L/opt/gcc-4.2.4/lib/gcc/i686-pc-linux-gnu/4.2.4/../../.. test_nand_bug.o -lgcc
-lgcc_eh -lc -lgcc -lgcc_eh
/opt/gcc-4.2.4/lib/gcc/i686-pc-linux-gnu/4.2.4/crtend.o /usr/lib/crtn.o


-- 
           Summary: atomic NAND op generate wrong code;
                    __sync_nand_and_fetch, __sync_fetch_and_nand
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kokseng at ieee dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37908


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2008-12-10  9:57 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-24  3:38 [Bug c/37908] New: atomic NAND op generate wrong code; __sync_nand_and_fetch, __sync_fetch_and_nand kokseng at ieee dot org
2008-10-24  7:45 ` [Bug middle-end/37908] [4.2/4.3/4.4 regression] " ubizjak at gmail dot com
2008-10-24  7:46 ` ubizjak at gmail dot com
2008-10-24 10:43 ` jakub at gcc dot gnu dot org
2008-10-24 12:19 ` kokseng at ieee dot org
2008-10-24 16:48 ` ubizjak at gmail dot com
2008-10-29  7:11 ` ubizjak at gmail dot com
2008-10-29  9:39 ` kokseng at ieee dot org
2008-10-29 10:57 ` ubizjak at gmail dot com
2008-11-03 11:25 ` [Bug middle-end/37908] " jakub at gcc dot gnu dot org
2008-11-05 13:23 ` ubizjak at gmail dot com
2008-11-17 11:21 ` uros at gcc dot gnu dot org
2008-11-21  7:31 ` uros at gcc dot gnu dot org
2008-11-21 17:30 ` howarth at nitro dot med dot uc dot edu
2008-11-21 17:30 ` howarth at nitro dot med dot uc dot edu
2008-11-21 17:31 ` howarth at nitro dot med dot uc dot edu
2008-12-01 13:51 ` uros at gcc dot gnu dot org
2008-12-10  9:57 ` ubizjak at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).