From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24957 invoked by alias); 14 Oct 2002 15:46:06 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 24939 invoked by uid 71); 14 Oct 2002 15:46:05 -0000 Date: Mon, 14 Oct 2002 08:46:00 -0000 Message-ID: <20021014154605.24934.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Zack Weinberg Subject: Re: c/8221: return value of a function is forgotten Reply-To: Zack Weinberg X-SW-Source: 2002-10/txt/msg00545.txt.bz2 List-Id: The following reply was made to PR c/8221; it has been noted by GNATS. From: Zack Weinberg To: c.kaliszyk@zodiac.mimuw.edu.pl Cc: gcc-gnats@gcc.gnu.org, cek@wp.pl Subject: Re: c/8221: return value of a function is forgotten Date: Mon, 14 Oct 2002 08:43:14 -0700 On Mon, Oct 14, 2002 at 08:44:09AM -0000, c.kaliszyk@zodiac.mimuw.edu.pl wrote: > inline int getcputime(void) { > int i; > __asm__( > "rdtsc > movl %%eax, %0" > : :"g" (i) :"ax", "dx"); > return i; > } This asm statement claims that I is an input to the instruction, and that there aren't any outputs. Thus, GCC assumes that I is not modified by the asm. The correct way to write getcputime() would be static inline unsigned int getcputime(void) { unsigned int i; asm volatile ("rdtsc" : "=a" (i) : : "edx"); return i; } The key change is to put the I parameter in the _first_ block of asm operands, and add a leading = to its constraint. That tells the compiler that I contains an output. Changing "g" to "a" in the constraint tells GCC that the output appears in %eax, which obviates the need for the move instruction you wrote. This also means you need not (must not) clobber edx. All the other changes are also necessary. I leave as an exercise for you to figure out why I made them. zw