From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31574 invoked by alias); 18 Oct 2011 08:07:53 -0000 Received: (qmail 31562 invoked by uid 22791); 18 Oct 2011 08:07:52 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_WR X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 18 Oct 2011 08:07:05 +0000 From: "vagran.ast at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug inline-asm/50772] New: Inline assembler "A" constrain works non-expectedly on 64-bits target Date: Tue, 18 Oct 2011 08:07:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: inline-asm X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: vagran.ast at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg01748.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50772 Bug #: 50772 Summary: Inline assembler "A" constrain works non-expectedly on 64-bits target Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: inline-asm AssignedTo: unassigned@gcc.gnu.org ReportedBy: vagran.ast@gmail.com As per documentation "A" constrain of inline assembler should accept/return 64-bits value in eax:edx registers pair. However it doesn't work on 64-bits target, the value of just %rdx register is used instead. Use case example: rdmsr and wrmsr x86 instruction use eax:edx pair in both 32 and 64 bits mode. The following code will not work on 64-bits target: static inline u64 rdmsr(u32 msr) { u64 rc; ASM ( "rdmsr" : "=A"(rc) : "c"(msr) ); return rc; } Value in %rdx will be used as the result, %rax value will be discarded. The same situation when "A" constrain is used as input. It is not a major problem, it can be easily worked around by additional instructions in inline assembler block. But IMHO it should be fixed either in the compiler code (preferably) or in documentation (mention that it is not supported on 64-bits target).