public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Zack Weinberg <zack@codesourcery.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: c/8221: return value of a function is forgotten Date: Mon, 14 Oct 2002 08:46:00 -0000 [thread overview] Message-ID: <20021014154605.24934.qmail@sources.redhat.com> (raw) The following reply was made to PR c/8221; it has been noted by GNATS. From: Zack Weinberg <zack@codesourcery.com> 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
next reply other threads:[~2002-10-14 15:46 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-10-14 8:46 Zack Weinberg [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-10-14 8:54 zack 2002-10-14 2:16 Andrew Pinski 2002-10-14 1:46 c.kaliszyk
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=20021014154605.24934.qmail@sources.redhat.com \ --to=zack@codesourcery.com \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@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: linkBe 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).