From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1963 invoked by alias); 15 Feb 2008 11:31:00 -0000 Received: (qmail 1954 invoked by uid 22791); 15 Feb 2008 11:30:59 -0000 X-Spam-Check-By: sourceware.org Received: from chrocht.moloch.sk (HELO mail.moloch.sk) (62.176.169.44) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 15 Feb 2008 11:30:40 +0000 Received: from [62.176.172.198] (ildyko.moloch.sk [62.176.172.198]) by mail.moloch.sk (Postfix) with ESMTP id 94F4B340F141; Fri, 15 Feb 2008 12:30:37 +0100 (CET) Message-ID: <47B577DD.4080802@imatix.com> Date: Fri, 15 Feb 2008 11:31:00 -0000 From: Martin Sustrik User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: Andrew Haley CC: gcc-help@gcc.gnu.org Subject: Re: Should it be reported as a bug? (-O2 and cmpxchg instruction) References: <47B56FAA.6040504@imatix.com> <47B5709B.10407@redhat.com> <47B57583.7030206@imatix.com> <47B575EF.3050200@redhat.com> In-Reply-To: <47B575EF.3050200@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-02/txt/msg00180.txt.bz2 Andrew Haley wrote: > Please don't top-post. > > Martin Sustrik wrote: >> Andrew, >> >> Thanks for prompt response. However, I am not sure how to use the >> earlyclobber modifier - this is actually the first gcc inline asembly >> code I've ever written. >> >> Do you mean that I should add '&' sign to every operand in input >> operand list, or should I add the sign when using the operands or what? > > Use "=&a" on the first operand. Ok, I've modified the code this way: __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"); However, the generated code is exactly the same as before. > >> >> The problem, AFAICS, is that cmpxchg modifies eax although eax is not >> an explicit operand of the instruction. Therefore optimiser has no >> idea that it is modified and acts as if it was unchanged :( >> >> Martin >> >> Andrew Haley wrote: >>> Martin Sustrik wrote: >>>> 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? >>> >>> Look for "earlyclobber" in the section Constraint Modifier Characters >>> >>> Andrew. >> >