From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25230 invoked by alias); 19 Aug 2008 16:58:42 -0000 Received: (qmail 25222 invoked by uid 22791); 19 Aug 2008 16:58:42 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 19 Aug 2008 16:57:30 +0000 Received: from zps77.corp.google.com (zps77.corp.google.com [172.25.146.77]) by smtp-out.google.com with ESMTP id m7JGtptw030813; Tue, 19 Aug 2008 17:55:51 +0100 Received: from localhost.localdomain.google.com (dhcp-172-18-118-203.corp.google.com [172.18.118.203]) (authenticated bits=0) by zps77.corp.google.com with ESMTP id m7JGtnVC013293 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 19 Aug 2008 09:55:50 -0700 To: Jeroen Demeyer Cc: gcc-help@gcc.gnu.org Subject: Re: Inline assembly constraints question References: <48A937FE.30100@cage.ugent.be> From: Ian Lance Taylor Date: Tue, 19 Aug 2008 16:59:00 -0000 In-Reply-To: <48A937FE.30100@cage.ugent.be> (Jeroen Demeyer's message of "Mon\, 18 Aug 2008 10\:51\:10 +0200") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes 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-08/txt/msg00177.txt.bz2 Jeroen Demeyer writes: > I have a C++ program (i386 target) which has a piece of inline > assembly with the following constraints: > > asm(/* Some asm code */ > : "=&rm" (n0), "=&r" (n1), "=&r" (n2) > : "2" (n0), "1" (n1), "g" (n2), "cI" (s) > ); > > When compiled with g++ 4.1.2 (CXXFLAGS=-O2 -march=pentium4) the > operands %0 and %5 get the same memory address, even though they refer > to distinct variables (n0 and n2). So, is this a bug in g++ 4.1.2 or > am I doing something wrong? g++ 3.4.6 and g++ 4.3.1 generate correct > code, but that does not really prove anything. It would help to see the types of the variables. Is n2 a pointer? Also it would help to see the actual values that wind up getting passed in. With "=%rm" you are telling gcc that it is OK to pass a memory address. And "g" accepts any operand. That gives gcc a lot of flexibility. If it does wind up passing in a memory operand for both, though, it seems to me that they should not overlap. I think more details would help. For example, run gcc with the -dg option, look at FILENAME.xxx.greg, and show us the insn corresponding to the asm statement. > In particular I would like to know: > 1) Is it allowed to put matching (digit) constraints referring to > different variables? This is what I do with %2. The same register is > used as input for variable n0 and as output for variable n2. Yes, that is fine. > 2) Is there a way to specify some kind of 'earlyclobber' (&) modifier > with a memory constraint? How can I prevent gcc from putting an input > variable and an unrelated output variable in the same memory location? The simple way is to force one or both of them into registers. Ian