mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Oleg Endo <oleg.endo@t-online.de>
To: Rich Felker <dalias@libc.org>, gcc@gcc.gnu.org
Cc: musl@lists.openwall.com
Subject: Re: SH runtime switchable atomics - proposed design
Date: Thu, 21 Jan 2016 08:08:18 +0900	[thread overview]
Message-ID: <1453331298.3681.58.camel@t-online.de> (raw)
In-Reply-To: <20160119202851.GA18720@brightrain.aerifal.cx>

On Tue, 2016-01-19 at 15:28 -0500, Rich Felker wrote:
> I've been working on the new version of runtime-selected SH atomics
> for musl, and I think what I've got might be appropriate for GCC's
> generated atomics too. I know Oleg was not very excited about doing
> this on the gcc side from a cost/benefit perspective

I am just not keen on making this the default atomic model for SH.
If you have a system built around this atomic model and want to add it
to GCC, please send in patches.  Just a few comments below...

> Inputs:
> - R0: Memory address to operate on
> - R1: Address of implementation function, loaded from a global
> - R2: Comparison value
> - R3: Value to set on success
> 
> Outputs:
> - R3: Old value read, ==R2 iff cas succeeded.

> Preserved: R0, R2.
> 
> Clobbered: R1, PR, T.

The T bit is obviously the result of the cas operation.  So you could
use it as an output directly instead of the implicit R3 == R2
condition.

> 
> This call (performed from __asm__ for musl, but gcc would do it as SH
> "SFUNC") is highly compact/convenient for inlining because it avoids
> clobbering any of the argument registers that are likely to already
> be
> in use by the caller, and it preserves the important values that are
> likely to be reused after the cas operation.
> 
> For J2 and future J4, the function pointer just points to:
> 
> 	rts
> 	 cas.l r2,r3,@r0
> 

> and the only costs vs an inline cas.l are loading the address of the
> function (done in the caller; involves GOT access) and clobbering R1
> and PR.
> 
> This is still a draft design and the version in musl is subject to
> change at any time since it's not a public API/ABI, but I think it
> could turn into something useful to have on the gcc side with a
> -matomic-model=libfunc option or similar. Other ABI considerations
> for
> gcc use would be where to store the function pointer and how to
> initialize it. To be reasonably efficient with FDPIC the caller needs
> to be responsible for loading the function pointer (and it needs to
> always point to code, not a function descriptor) so that the callee
> does not need a GOT pointer passed in.

Obviously the ABI has been constructed around the J-core's cas.l
instruction.  Do you have plans to add other atomic operations (like
arithmetic)?  If not, then I'd suggest to name the atomic model
"libfunc-musl-cas".

Cheers,
Oleg


  parent reply	other threads:[~2016-01-20 23:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19 20:28 Rich Felker
2016-01-19 20:51 ` Rich Felker
2016-01-20 23:08 ` Oleg Endo [this message]
2016-01-21  1:22   ` Rich Felker
2016-01-21 11:22     ` Torvald Riegel
2016-01-21 11:32     ` Oleg Endo

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=1453331298.3681.58.camel@t-online.de \
    --to=oleg.endo@t-online.de \
    --cc=dalias@libc.org \
    --cc=gcc@gcc.gnu.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).