public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hp@bitrange.com>
To: Andrew MacLeod <amacleod@redhat.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>, gcc-patches@gcc.gnu.org
Subject: Re: Implement C11 _Atomic
Date: Fri, 22 Nov 2013 02:57:00 -0000	[thread overview]
Message-ID: <alpine.BSF.2.02.1311211758050.26167@arjuna.pair.com> (raw)
In-Reply-To: <528E2CB6.7020104@redhat.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 737 bytes --]

On Thu, 21 Nov 2013, Andrew MacLeod wrote:
> I can bootstrap and check this on x86 to make sure it doesnt affect anything,
> and you can fool with it and see if you can get your desired results with your
> port.

Success!

For the record, tested together with the attached patch for the
CRIS ports, both regularly (not finished, but done with the C
testsuite part and no regressions there), as well as manually
for the attached test-programs, compiling and inspecting output
for different sub-targets and checking that data layout,
alignment and size is as intended.

Too bad about the libstdc++ atomics, but with this/these patches
at least I'll be able to tell people that _Atomic for C11 works.

Thanks to the both of you!

brgds, H-P

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1377 bytes --]

Index: config/cris/cris.c
===================================================================
--- config/cris/cris.c	(revision 205225)
+++ config/cris/cris.c	(working copy)
@@ -93,6 +93,8 @@ static int cris_reg_overlap_mentioned_p 
 static enum machine_mode cris_promote_function_mode (const_tree, enum machine_mode,
 						     int *, const_tree, int);
 
+static unsigned int cris_atomic_align_for_mode (enum machine_mode);
+
 static void cris_print_base (rtx, FILE *);
 
 static void cris_print_index (rtx, FILE *);
@@ -227,6 +229,9 @@ int cris_cpu_version = CRIS_DEFAULT_CPU_
 #undef TARGET_PROMOTE_FUNCTION_MODE
 #define TARGET_PROMOTE_FUNCTION_MODE cris_promote_function_mode
 
+#undef TARGET_ATOMIC_ALIGN_FOR_MODE
+#define TARGET_ATOMIC_ALIGN_FOR_MODE cris_atomic_align_for_mode
+
 #undef TARGET_STRUCT_VALUE_RTX
 #define TARGET_STRUCT_VALUE_RTX cris_struct_value_rtx
 #undef TARGET_SETUP_INCOMING_VARARGS
@@ -4018,6 +4023,14 @@ cris_promote_function_mode (const_tree t
     return mode;
   return CRIS_PROMOTED_MODE (mode, *punsignedp, type);
 } 
+
+/* Atomic types require alignment to be at least the "natural" size. */
+
+static unsigned int
+cris_atomic_align_for_mode (enum machine_mode mode)
+{
+  return GET_MODE_BITSIZE (mode);
+}
 
 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
    time being.  */

[-- Attachment #3: Type: TEXT/PLAIN, Size: 1731 bytes --]

struct r0 {
  char a;
  int b;
};

struct l0 {
  char a;
  int b __attribute__((__aligned__(4)));
};

struct a0 {
  char a;
  _Atomic int b;
};

#define test(name, cond) typedef int test_ ## name [-!(cond)]

struct a0 ag;
struct l0 lg;
struct r0 rg;

struct a0 ai = {0, 1};
struct l0 li = {1, 2};
struct r0 ri = {2, 3};

extern struct a0 ae;
extern struct l0 le;
extern struct r0 re;

void foo(void)
{
  struct a0 al;
  struct l0 ll;
  struct r0 rl;
  test(a_al_ge_4, __alignof__(al) >= 4);
  test(a_al_ge_ll, __alignof__(al) >= __alignof__(ll));
  test(a_al_ge_rl, __alignof__(al) >= __alignof__(rl));
  test(a_ag_ge_4, __alignof__(ag) >= 4);
  test(a_ag_ge_lg, __alignof__(ag) >= __alignof__(lg));
  test(a_ag_ge_rg, __alignof__(ag) >= __alignof__(rg));
  test(a_ai_ge_4, __alignof__(ai) >= 4);
  test(a_ai_ge_li, __alignof__(ai) >= __alignof__(li));
  test(a_ai_ge_ri, __alignof__(ai) >= __alignof__(ri));
  test(a_ae_ge_4, __alignof__(ae) >= 4);
  test(a_ae_ge_le, __alignof__(ae) >= __alignof__(le));
  test(a_ae_ge_re, __alignof__(ae) >= __alignof__(re));

  test(s_al_ge_4, sizeof(al) >= 8);
  test(s_al_ge_ll, sizeof(al) >= sizeof(ll));
  test(s_al_ge_rl, sizeof(al) >= sizeof(rl));
  test(s_ag_ge_4, sizeof(ag) >= 8);
  test(s_ag_ge_lg, sizeof(ag) >= sizeof(lg));
  test(s_ag_ge_rg, sizeof(ag) >= sizeof(rg));
  test(s_ai_ge_4, sizeof(ai) >= 8);
  test(s_ai_ge_lg, sizeof(ai) >= sizeof(li));
  test(s_ai_ge_rg, sizeof(ai) >= sizeof(ri));
  test(s_ae_ge_4, sizeof(ae) >= 8);
  test(s_ae_ge_le, sizeof(ae) >= sizeof(le));
  test(s_ae_ge_re, sizeof(ae) >= sizeof(re));

  test(ab_eq_4, __builtin_offsetof(struct a0, b) == 4);
  al = ai;
  al.b++;
  ae = al;
}

[-- Attachment #4: Type: TEXT/PLAIN, Size: 311 bytes --]

_Atomic int foo;
int bar;
void baz(void)
{
  foo++;
}
void foobar(void)
{
  bar++;
}

void xyzzy(int *x)
{
  (*x)++;
}

void plugh(_Atomic int *x)
{
  (*x)++;
}

void xyzzy1(int *x)
{
  int y = *x;
  *x = y+1;
}

void plugh2(_Atomic int *x)
{
  _Atomic int y = *x;
  *x = y+1;
}

  parent reply	other threads:[~2013-11-21 23:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-06  0:44 Joseph S. Myers
2013-11-06 22:42 ` Andrew MacLeod
2013-11-07 17:16 ` Uros Bizjak
2013-11-07 17:24 ` Jakub Jelinek
2013-11-07 18:10   ` Uros Bizjak
2013-11-07 18:44     ` Joseph S. Myers
2013-11-07 18:47       ` Uros Bizjak
2013-11-07 18:55         ` Joseph S. Myers
     [not found]           ` <CAFULd4ZrAEECG+pptH8cRaWznioaM9VXS4TetpEvkWj--n7H1w@mail.gmail.com>
2013-11-07 21:02             ` Joseph S. Myers
2013-11-07 21:08               ` Uros Bizjak
2013-11-07 22:25                 ` Uros Bizjak
2013-11-07 22:43                   ` Joseph S. Myers
2013-11-08 10:09       ` Uros Bizjak
2013-11-08 13:33         ` Joseph S. Myers
2013-11-21 13:19 ` Hans-Peter Nilsson
2013-11-21 18:03   ` Andrew MacLeod
2013-11-21 18:20     ` Hans-Peter Nilsson
2013-11-21 18:30       ` Andrew MacLeod
2013-11-21 18:49         ` Joseph S. Myers
2013-11-21 18:58           ` Andrew MacLeod
2013-11-21 19:24         ` Hans-Peter Nilsson
2013-11-22  2:57         ` Hans-Peter Nilsson [this message]
2013-11-22  3:03           ` Andrew MacLeod
2013-11-22  3:32           ` Hans-Peter Nilsson
2013-11-22  3:32             ` Joseph S. Myers
2013-11-22 19:12             ` Andrew MacLeod
2013-11-22 20:01               ` Hans-Peter Nilsson
2013-11-08 13:28 Dominique Dhumieres
2013-11-08 13:34 ` Joseph S. Myers
2013-11-08 13:43   ` Dominique Dhumieres

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=alpine.BSF.2.02.1311211758050.26167@arjuna.pair.com \
    --to=hp@bitrange.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.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).