From patchwork Thu Nov 21 23:23:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 293273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5BD9E2C00D0 for ; Fri, 22 Nov 2013 10:24:18 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=jxwR55u+vQ8cj9Q3 +GR6Jutpk43GmaiIodSJXqMfEVyvjCZ1tI0+liReBBqSlkofuYFv5AA2Rl3Dz6Eh ZZl3z2SQR0Rs2OnSAhW2bMJVK2VnOVUw7VKnb5eqNYP2hs/J3Ld8+lm1LrDvb8R5 LXgWwtLIZx8+vCQKB2axGa99BeA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=wcAGtgEaYMRAZ6nCtKZ9g3 Ra9Xs=; b=AAm/vOEQKeAzDdfH9hjagwPk+CsSfI/ulzCdSF5Yeq5nhEPFoFAwy6 7H9/oo1NREIa4LMAUe4vpN1vsctZrRz70y8r2YrvdmTEpuLzc+h95Q2Z7JmV+vk2 Xs+rcKAvDqYim5C7rUXJ00hVwlZVPrL1wv8NdZKiMf8NYNIrBLaF8= Received: (qmail 31708 invoked by alias); 21 Nov 2013 23:24:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31699 invoked by uid 89); 21 Nov 2013 23:24:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, SPF_PASS autolearn=no version=3.3.2 X-HELO: arjuna.pair.com Received: from Unknown (HELO arjuna.pair.com) (209.68.5.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 21 Nov 2013 23:24:06 +0000 Received: (qmail 43626 invoked by uid 3006); 21 Nov 2013 23:23:58 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 21 Nov 2013 23:23:58 -0000 Date: Thu, 21 Nov 2013 18:23:58 -0500 (EST) From: Hans-Peter Nilsson To: Andrew MacLeod cc: "Joseph S. Myers" , gcc-patches@gcc.gnu.org Subject: Re: Implement C11 _Atomic In-Reply-To: <528E2CB6.7020104@redhat.com> Message-ID: References: <528E1C0A.7020907@redhat.com> <528E2CB6.7020104@redhat.com> User-Agent: Alpine 2.02 (BSF 1266 2009-07-14) MIME-Version: 1.0 X-IsSubscribed: yes 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 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; } _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; } 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. */