Skip to content
Snippets Groups Projects
Commit db189d02 authored by David Faust's avatar David Faust
Browse files

bpf: add v3 atomic instructions

This patch adds support for the general atomic operations introduced in
eBPF v3. In addition to the existing atomic add instruction, this adds:
 - Atomic and, or, xor
 - Fetching versions of these operations (including add)
 - Atomic exchange
 - Atomic compare-and-exchange

To control emission of these instructions, a new target option
-m[no-]v3-atomics is added. This option is enabled by -mcpu=v3
and above.

Support for these instructions was recently added in binutils.

gcc/

	* config/bpf/bpf.opt (mv3-atomics): New option.
	* config/bpf/bpf.cc (bpf_option_override): Handle it here.
	* config/bpf/bpf.h (enum_reg_class): Add R0 class.
	(REG_CLASS_NAMES): Likewise.
	(REG_CLASS_CONTENTS): Likewise.
	(REGNO_REG_CLASS): Handle R0.
	* config/bpf/bpf.md (UNSPEC_XADD): Rename to UNSPEC_AADD.
	(UNSPEC_AAND): New unspec.
	(UNSPEC_AOR): Likewise.
	(UNSPEC_AXOR): Likewise.
	(UNSPEC_AFADD): Likewise.
	(UNSPEC_AFAND): Likewise.
	(UNSPEC_AFOR): Likewise.
	(UNSPEC_AFXOR): Likewise.
	(UNSPEC_AXCHG): Likewise.
	(UNSPEC_ACMPX): Likewise.
	(atomic_add<mode>): Use UNSPEC_AADD and atomic type attribute.
	Move to...
	* config/bpf/atomic.md: ...Here. New file.
	* config/bpf/constraints.md (t): New constraint for R0.
	* doc/invoke.texi (eBPF Options): Document -mv3-atomics.

gcc/testsuite/

	* gcc.target/bpf/atomic-cmpxchg-1.c: New test.
	* gcc.target/bpf/atomic-cmpxchg-2.c: New test.
	* gcc.target/bpf/atomic-fetch-op-1.c: New test.
	* gcc.target/bpf/atomic-fetch-op-2.c: New test.
	* gcc.target/bpf/atomic-fetch-op-3.c: New test.
	* gcc.target/bpf/atomic-op-1.c: New test.
	* gcc.target/bpf/atomic-op-2.c: New test.
	* gcc.target/bpf/atomic-op-3.c: New test.
	* gcc.target/bpf/atomic-xchg-1.c: New test.
	* gcc.target/bpf/atomic-xchg-2.c: New test.
parent 7931a1de
No related branches found
No related tags found
No related merge requests found
Showing
with 593 additions and 19 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment