linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Nikita Danilov <Nikita@Namesys.COM>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org
Subject: Re: const versus __attribute__((const))
Date: Tue, 9 Dec 2003 02:59:52 +0000	[thread overview]
Message-ID: <20031209025952.GA26439@mail.shareable.org> (raw)
In-Reply-To: <3FD4C375.2060803@zytor.com>

H. Peter Anvin wrote:
> Actually, the reason it doesn't use it for the inlines is because it 
> doesn't need to -- it already has full visibility, so it doesn't need it 
> to be spelled out.

Until a few minutes ago, I disagreed.  I thought GCC wouldn't
eliminate calls to inline functions which contain an inline asm, such
as current_thread_info().

But having just looked, multiple calls to current_thread_info() are
eliminated.  GCC inspects the arguments of the inline asm which is the
body of this function, and concludes that the asm itself is to be
optimised like a const function, depending only on its input operands.

In fact to get GCC to _not_ optimise away inline asms, or even to
behave like "pure" (allowing memory to be read) instead of "const",
they must be declared volatile, or have no outputs.  Putting "memory"
in the clobber list says only that the asm clobbers memory, not that
it reads memory.

It would be nice to have a way to declare an asm like "pure" not
"const", so that it's allowed to read memory but multiple calls can be
eliminated; I don't know of a way to express that.

-- Jamie

  reply	other threads:[~2003-12-09  3:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-08 15:46 const versus __attribute__((const)) Arnd Bergmann
2003-12-08 17:50 ` H. Peter Anvin
2003-12-08 18:27   ` Nikita Danilov
2003-12-08 18:31     ` H. Peter Anvin
2003-12-09  2:59       ` Jamie Lokier [this message]
2003-12-09  3:21         ` H. Peter Anvin
2003-12-09  3:49           ` Jamie Lokier
2003-12-09  5:37             ` H. Peter Anvin
2003-12-09  7:26               ` Linus Torvalds
2003-12-09  7:40                 ` H. Peter Anvin
2003-12-09 11:56                   ` Arnd Bergmann
2003-12-09 15:42                     ` H. Peter Anvin
2003-12-09 16:44                       ` Linus Torvalds
2003-12-09 16:51                         ` H. Peter Anvin
2003-12-09 19:15                           ` Jamie Lokier
2003-12-09  7:19             ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2003-12-08  1:19 H. Peter Anvin
2003-12-08 12:32 ` Nikita Danilov

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=20031209025952.GA26439@mail.shareable.org \
    --to=jamie@shareable.org \
    --cc=Nikita@Namesys.COM \
    --cc=arnd@arndb.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.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: link
Be 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 NNTP newsgroup(s).