public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Roland McGrath <roland@hack.frob.com>
Cc: libc-ports@sourceware.org
Subject: Re: [PATCH roland/arm-atomic-warn] Fiddle ARM atomic.h to avoid -Wvolatile-register-var warnings.
Date: Wed, 08 Aug 2012 22:02:00 -0000	[thread overview]
Message-ID: <5022E1E4.7040801@twiddle.net> (raw)
In-Reply-To: <20120808204442.9B9F82C085@topped-with-meat.com>

On 08/08/2012 01:44 PM, Roland McGrath wrote:
> +   We use the union trick rather than simply using __typeof (...) in the
> +   declarations of A_OLDVAL et al because when NEWVAL or OLDVAL is of the
> +   form *PTR and PTR has a 'volatile ... *' type, then __typeof (*PTR) has
> +   a 'volatile ...' type and this triggers -Wvolatile-register-var to
> +   complain about 'register volatile ... asm ("reg")'.  */
>  #elif defined __thumb2__
>  /* Thumb-2 has ldrex/strex.  However it does not have barrier instructions,
>     so we still need to use the kernel helper.  */
>  #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
> -  ({ register __typeof (oldval) a_oldval asm ("r0");			      \
> -     register __typeof (oldval) a_newval asm ("r1") = (newval);		      \
> +  ({ union { __typeof (oldval) a; uint32_t v; } oldval_arg = { .a = (oldval) };\
> +     union { __typeof (newval) a; uint32_t v; } newval_arg = { .a = (newval) };\
> +     register uint32_t a_oldval asm ("r0");				      \
> +     register uint32_t a_newval asm ("r1") = newval_arg.v;		      \
>       register __typeof (mem) a_ptr asm ("r2") = (mem);			      \
> -     register __typeof (oldval) a_tmp asm ("r3");			      \
> -     register __typeof (oldval) a_oldval2 asm ("r4") = (oldval);	      \
> +     register uint32_t a_tmp asm ("r3");				      \
> +     register uint32_t a_oldval2 asm ("r4") = oldval_arg.v;		      \
>       __asm__ __volatile__						      \
>  	     ("0:\tldr\t%[tmp],[%[ptr]]\n\t"				      \

Is it really worth working so hard to avoid the gcc builtins?
Yes, gcc before 4.7 doesn't have __atomic to avoid the extra
barriers, but at least 4.7 and later will.

May I ask what gcc version you're targeting, anyway?


r~

  parent reply	other threads:[~2012-08-08 22:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-08 20:44 Roland McGrath
2012-08-08 20:52 ` Joseph S. Myers
2012-08-08 22:02 ` Richard Henderson [this message]
2012-08-08 22:13   ` Roland McGrath

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=5022E1E4.7040801@twiddle.net \
    --to=rth@twiddle.net \
    --cc=libc-ports@sourceware.org \
    --cc=roland@hack.frob.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.
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).