public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sustrik <sustrik@imatix.com>
To: gcc-help@gcc.gnu.org
Subject: Should it be reported as a bug? (-O2 and cmpxchg instruction)
Date: Fri, 15 Feb 2008 10:56:00 -0000	[thread overview]
Message-ID: <47B56FAA.6040504@imatix.com> (raw)

Hi all,

I've encountered a problem with gcc inline assembly.

Following code, when optimised with -O2 gives following machine code:

            __asm__ volatile (
                "lock; cmpxchgl %1, %3\n\t"
                "jz 1f\n\t"
                "mov %2, %%eax\n\t"
                "lock; xchgl %%eax, %3\n\t"
                "1:\n\t"
                : "=a" (oldval)
                : "r" (thenval_), "r" (elseval_), "m" (value), "0" (0)
                : "memory", "cc");

 4031a0:   31 c0                   xor    %eax,%eax
  4031a2:   f0 0f b1 55 40          lock cmpxchg %edx,0x40(%rbp)
  4031a7:   74 06                   je     4031af
  4031a9:   89 c0                   mov    %eax,%eax
  4031ab:   f0 87 45 40             lock xchg %eax,0x40(%rbp)

Note that %2 maps to %%eax (mov %2, %%eax --> mov %eax,%eax). This 
shouldn't happen given that cmpxchg modifies the value of %%eax.

Any idea whether this should be considered a bug and reported as such?

GCC version info:

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v 
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr 
--enable-shared --with-system-zlib --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --enable-nls 
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release 
x86_64-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Martin

             reply	other threads:[~2008-02-15 10:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-15 10:56 Martin Sustrik [this message]
2008-02-15 11:00 ` Andrew Haley
2008-02-15 11:21   ` Martin Sustrik
2008-02-15 11:22     ` Andrew Haley
2008-02-15 11:31       ` Martin Sustrik
2008-02-15 11:44         ` Andrew Haley
2008-02-15 12:05           ` Martin Sustrik
2008-02-15 13:45             ` Andrew Haley
2008-02-15 14:37               ` Martin Sustrik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47B56FAA.6040504@imatix.com \
    --to=sustrik@imatix.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).