Message ID | alpine.BSF.2.02.1311211758050.26167@arjuna.pair.com |
---|---|
State | New |
Headers | show |
On 11/21/2013 06:23 PM, Hans-Peter Nilsson wrote: > 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! > > All we need is a way to communicate the atomic property to the type within the libstdc++ template... We cant use _Atomic there :-P I originally had created an __attribute__ ((atomic)) whch you could apply to the atomic template type and get the same behaviour as _Atomic, Im not sure if there is another way or not. The atomic template is generic, so I couldn't think of any special macro wizardry we could define... Andrew
On Thu, 21 Nov 2013, Hans-Peter Nilsson wrote: > with this/these patches > at least I'll be able to tell people that _Atomic for C11 works. Oh right, gcc still doesn't remove target-introduced "manual" alignment checks (when expanding atomic intrinsics), but at least gcc makes sure it's aligned on stack, when options doesn't say it's aligned. And a.c:plugh2 doesn't seem to perform an atomic assignment, but just assignment through an _Atomic-aligned stack temporary. Might be my C11-ignorance showing. (Without the patches layout and alignment is all broken.) brgds, H-P
On Thu, 21 Nov 2013, Hans-Peter Nilsson wrote: > Oh right, gcc still doesn't remove target-introduced "manual" > alignment checks (when expanding atomic intrinsics), but at > least gcc makes sure it's aligned on stack, when options doesn't > say it's aligned. And a.c:plugh2 doesn't seem to perform an > atomic assignment, but just assignment through an > _Atomic-aligned stack temporary. Might be my C11-ignorance > showing. It appears to me on x86_64 to produce an __atomic_store_4 to *x (in the GIMPLE dumps, what happens after that is a matter for the back end). Note that atomic variable initialization is *not* atomic (see 7.17.2.1 - in general ATOMIC_VAR_INIT needs using with the initializer, or the initialization needs to be carried out with atomic_init, though GCC doesn't require that). (In C11, the effect of a plain initialization without ATOMIC_VAR_INIT is I think that the initializer is evaluated for its side effects, but if the variable gets used as either rvalue or lvalue without one of the special forms of initialization being used first then the behavior is undefined. The idea is to support implementations with extra bits in atomic objects used for locking purposes.) So no atomic store to y is expected - although there are atomic loads from y.
On 11/21/2013 06:40 PM, Hans-Peter Nilsson wrote: > On Thu, 21 Nov 2013, Hans-Peter Nilsson wrote: >> with this/these patches >> at least I'll be able to tell people that _Atomic for C11 works. > Oh right, gcc still doesn't remove target-introduced "manual" > alignment checks (when expanding atomic intrinsics), but at > least gcc makes sure it's aligned on stack, when options doesn't > say it's aligned. And a.c:plugh2 doesn't seem to perform an > atomic assignment, but just assignment through an > _Atomic-aligned stack temporary. Might be my C11-ignorance > showing. > > (Without the patches layout and alignment is all broken.) > > brgds, H-P The target hook patch is checked into mainline, revision 205273. Andrew
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. */