mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Refactoring atomics as llsc?
Date: Thu, 21 May 2015 13:08:23 -0400	[thread overview]
Message-ID: <20150521170823.GF17573@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LNX.2.11.1505211516540.22867@monopod.intra.ispras.ru>

On Thu, May 21, 2015 at 03:21:21PM +0300, Alexander Monakov wrote:
> On Thu, 21 May 2015, Szabolcs Nagy wrote:
> > > Fortunately, there seems to be a clean solution: load them via asm
> > > that looks like
> > > 
> > > static inline int v6_compat() {
> > > 	int r;
> > > 	__asm__ ( "..." : "=r"(r) );
> > > 	return r;
> > > }
> > > 
> > > where the "..." is asm to perform the load. Since this asm is not
> > > volatile and has no inputs, it can be CSE'd and treated like an
> > > attribute-const function. Strictly speaking this doesn't prevent
> > > reordering to the very beginning of program execution, before the
> > > runtime atomic selection is initialized, but I don't think that's a
> > > serious practical concern. It's certainly not a concern with dynamic
> > > linking since nothing can be reordered back into dynamic-linker-time,
> > > and the atomics would be initialized there. For static-linking LTO
> > > this may require some more thought for formal correctness.
> > 
> > does gcc cse that?
> > 
> > why is it guaranteed that r will be always the same?
> 
> The asm is not volatile, so the compiler can use its constraints to move it
> like any other instruction.  In this case there's only one input and output
> register, and no clobbers.
> 
> > (and how can gcc know the cost of the asm? it seems to
> > me that would be needed to determine if it's worth keeping
> > r in a reg or just rerun the asm every time)
> 
> While obviously any sort of exact cost can not be known, GCC uses the line
> count of the asm, iirc, as an estimation of the number of instructions.

Interesting. So can you use ; instead of \n for semantic purposes
controlling GCC's decision making? ;-)

Rich


  reply	other threads:[~2015-05-21 17:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20  5:11 Rich Felker
2015-05-20  5:33 ` Timo Teras
2015-05-20  6:19   ` Rich Felker
2015-05-20  6:36   ` Rich Felker
2015-05-21  4:12 ` Rich Felker
2015-05-21 12:06   ` Szabolcs Nagy
2015-05-21 12:21     ` Alexander Monakov
2015-05-21 17:08       ` Rich Felker [this message]
2015-05-21 17:07     ` Rich Felker

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=20150521170823.GF17573@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).