This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Aarch64][2/3] Use the atomic compare-and-swap instructions when available.
- From: James Greenhalgh <james dot greenhalgh at arm dot com>
- To: Matthew Wahab <matthew dot wahab at foss dot arm dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 12 Aug 2015 12:18:26 +0100
- Subject: Re: [Aarch64][2/3] Use the atomic compare-and-swap instructions when available.
- Authentication-results: sourceware.org; auth=none
- References: <55CB1C0D dot 6070405 at foss dot arm dot com> <55CB1CBD dot 9030204 at foss dot arm dot com>
On Wed, Aug 12, 2015 at 11:15:25AM +0100, Matthew Wahab wrote:
> ARMv8.1 adds instructions for atomic compare-and-swap with optional memory
> ordering specifiers. This patch adds the compare-and-swap instructions and
> changes the atomic_compare_and_swap patterns to use them
>
> The changes to the atomic_compare_and_swap pattern makes the new
> instructions available as an alternative for the existing expander, to
> be used when the target supports them. The existing expander is reused
> so that it can generate code needed to meet the requirements of the
> atomic_compare_and_swap name.
>
> Using the atomic CAS instructions, the code generated for a call to
> __atomic_compare_exchange (ptr, expected, desired, weak, smodel, fmodel)
> becomes:
>
> mov r, r1
> cas<smo><sz> r, r2, [r0]
> cmp r, r1
> cset r0, eq
> cbnz r0, L
> strb r, [r1]
> L:
> ret
>
> where
> r0 = ptr, r1 = *expected, r2 = *desired,
> r is some temporary.
> mo is one of {'', 'a', 'l', 'al'}, depending on smodel
> sz is one of {'', 'b', 'h'} depending on the data size.
>
> Tested the series for aarch64-none-linux-gnu with native bootstrap and make
> check and for aarch64-none-elf with cross-compiled check-gcc. Also tested
> aarch64-none-elf with cross-compiled check-gcc on an emulator that supports
> ARMv8.1.
>
> Ok for trunk?
> Matthew
OK, but please fix up the testcases Andrew mentioned for those configuring
their toolchains/test runs with a default -mcpu or -march which targets
these instructions. I would just hardwire them
(with dg-additional-options) to -march=armv8-a.
Thanks,
James
> 2015-08-12 Matthew Wahab <matthew.wahab@arm.com>
>
> * config/aarch64/aarch64-protos.h
> (aarch64_gen_atomic_cas): Declare.
> * config/aarch64/aarch64.c (aarch64_expand_compare_and_swap):
> Choose appropriate instruction pattern for the target.
> (aarch64_gen_atomic_cas): New.
> * config/aarch64/atomics.md (UNSPECV_ATOMIC_CAS): New.
> (atomic_compare_and_swap<mode>_1): Rename to
> aarch64_compare_and_swap<mode>. Fix some indentation.
> (aarch64_compare_and_swap<mode>_lse): New.
> (aarch64_atomic_cas<mode>): New.
>