Skip to content

Commit 055a4c8

Browse files
committed
bpf: Update atomic instruction pseudo-C syntax
This patch updates the pseudo-C dialect templates for the BPF v3 atomic instructions. The templates match the strings emitted by clang -S for these instructions. The tests and documentation are updated accordingly. gas/ * doc/c-bpf.texi (BPF Instructions): Update entries for atomic and 32-bit atomic instructions. * testsuite/gas/bpf/atomic.s: Test AAND, AAND32, AOR, AOR32, AXOR, AXOR32, AFADD, AFADD32, AFAND, AFAND32, AFOR, AFOR32, AFXOR and AFXOR32 instructions. * testsuite/gas/bpf/atomic.d: Likewise. * testsuite/gas/bpf/atomic-be.d: Likewise. * testsuite/gas/bpf/atomic-pseudoc.s: Likewise. * testsuite/gas/bpf/atomic-pseudoc.d: Likewise. * testsuite/gas/bpf/atomic-be-pseudoc.d: Likewise. * testsuite/gas/bpf/atomic-v1.s: New test. * testsuite/gas/bpf/atomic-v1.d: Likewise. * testuiste/gas/bpf/atomic-v1-be.d: Likewise. * testuiste/gas/bpf/bpf.exp: Run new tests. opcodes/ * bpf-opc.c (bpf_opcodes): Update pseudo-C dialect templates for: BPF_INSN_AADD, BPF_INSN_AOR, BPF_INSN_AAND, BPF_INSN_AXOR, BPF_INSN_AFADD, BPF_INSN_AFOR, BPF_INSN_AFAND, BPF_INSN_AFXOR, BPF_INSN_AADD32, BPF_INSN_AOR32, BPF_INSN_AAND32, BPF_INSN_AXOR32, BPF_INSN_AFADD32, BPF_INSN_AFOR32, BPF_INSN_AFAND32, and BPF_INSN_AFXOR32 instructions.
1 parent 695776d commit 055a4c8

File tree

12 files changed

+171
-52
lines changed

12 files changed

+171
-52
lines changed

gas/doc/c-bpf.texi

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -750,43 +750,41 @@ for swapping 64-bit quantities and another for 32-bit quantities.
750750

751751
@table @code
752752
@item aadd [rd + offset16], rs
753-
@itemx *(u64 *)(rd + offset16) = rs
753+
@itemx lock *(u64 *)(rd + offset16) = rs
754754
Atomic add instruction.
755755

756756
@item aor [rd + offset16], rs
757-
@itemx *(u64 *) (rd + offset16) |= rs
757+
@itemx lock *(u64 *) (rd + offset16) |= rs
758758
Atomic or instruction.
759759

760760
@item aand [rd + offset16], rs
761-
@itemx *(u64 *) (rd + offset16) &= rs
761+
@itemx lock *(u64 *) (rd + offset16) &= rs
762762
Atomic and instruction.
763763

764764
@item axor [rd + offset16], rs
765-
@itemx *(u64 *) (rd + offset16) ^= rs
766-
Atomic xor instruction
767-
@item xaddw [%d+offset16],%s
768-
Exchange-and-add a 32-bit value at the specified location.
765+
@itemx lock *(u64 *) (rd + offset16) ^= rs
766+
Atomic xor instruction.
769767
@end table
770768

771769
@noindent
772770
The following variants perform fetching before the atomic operation.
773771

774772
@table @code
775-
@item afadd [dr + offset16], rs
776-
@itemx ???
773+
@item afadd [rd + offset16], rs
774+
@itemx rs = atomic_fetch_add ((u64 *)(rd + offset16), rs)
777775
Atomic fetch-and-add instruction.
778776

779-
@item afor [dr + offset16], rs
780-
@itemx ???
777+
@item afor [rd + offset16], rs
778+
@itemx rs = atomic_fetch_or ((u64 *)(rd + offset16), rs)
781779
Atomic fetch-and-or instruction.
782780

783-
@item afand [dr + offset16], rs
784-
@itemx ???
781+
@item afand [rd + offset16], rs
782+
@itemx rs = atomic_fetch_and ((u64 *)(rd + offset16), rs)
785783
Atomic fetch-and-and instruction.
786784

787-
@item afxor [dr + offset16], rs
788-
@itemx ???
789-
Atomic fetch-and-or instruction
785+
@item afxor [rd + offset16], rs
786+
@itemx rs = atomic_fetch_xor ((u64 *)(rd + offset16), rs)
787+
Atomic fetch-and-or instruction.
790788
@end table
791789

792790
The above instructions were introduced in the V3 of the BPF
@@ -805,19 +803,19 @@ for swapping 32-bit quantities and another for 32-bit quantities.
805803

806804
@table @code
807805
@item aadd32 [rd + offset16], rs
808-
@itemx *(u32 *)(rd + offset16) = rs
806+
@itemx lock *(u32 *)(rd + offset16) = rs
809807
Atomic add instruction.
810808

811809
@item aor32 [rd + offset16], rs
812-
@itemx *(u32 *) (rd + offset16) |= rs
810+
@itemx lock *(u32 *) (rd + offset16) |= rs
813811
Atomic or instruction.
814812

815813
@item aand32 [rd + offset16], rs
816-
@itemx *(u32 *) (rd + offset16) &= rs
814+
@itemx lock *(u32 *) (rd + offset16) &= rs
817815
Atomic and instruction.
818816

819817
@item axor32 [rd + offset16], rs
820-
@itemx *(u32 *) (rd + offset16) ^= rs
818+
@itemx lock *(u32 *) (rd + offset16) ^= rs
821819
Atomic xor instruction
822820
@end table
823821

@@ -826,19 +824,19 @@ The following variants perform fetching before the atomic operation.
826824

827825
@table @code
828826
@item afadd32 [dr + offset16], rs
829-
@itemx ???
827+
@itemx ws = atomic_fetch_add ((u32 *)(rd + offset16), ws)
830828
Atomic fetch-and-add instruction.
831829

832830
@item afor32 [dr + offset16], rs
833-
@itemx ???
831+
@itemx ws = atomic_fetch_or ((u32 *)(rd + offset16), ws)
834832
Atomic fetch-and-or instruction.
835833

836834
@item afand32 [dr + offset16], rs
837-
@itemx ???
835+
@itemx ws = atomic_fetch_and ((u32 *)(rd + offset16), ws)
838836
Atomic fetch-and-and instruction.
839837

840838
@item afxor32 [dr + offset16], rs
841-
@itemx ???
839+
@itemx ws = atomic_fetch_xor ((u32 *)(rd + offset16), ws)
842840
Atomic fetch-and-or instruction
843841
@end table
844842

gas/testsuite/gas/bpf/atomic-be-pseudoc.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,21 @@
88
Disassembly of section .text:
99

1010
0+ <.text>:
11-
0: db 12 1e ef 00 00 00 00 \*\(u64\*\)\(r1\+0x1eef\)\+=r2
12-
8: c3 12 1e ef 00 00 00 00 \*\(u32\*\)\(r1\+0x1eef\)\+=r2
11+
0: db 12 1e ef 00 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\+=r2
12+
8: c3 12 1e ef 00 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\+=r2
13+
10: db 12 1e ef 00 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\+=r2
14+
18: c3 12 1e ef 00 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\+=r2
15+
20: db 12 1e ef 00 00 00 50 lock \*\(u64\*\)\(r1\+0x1eef\)\&=r2
16+
28: c3 12 1e ef 00 00 00 50 lock \*\(u32\*\)\(r1\+0x1eef\)\&=r2
17+
30: db 12 1e ef 00 00 00 40 lock \*\(u64\*\)\(r1\+0x1eef\)\|=r2
18+
38: c3 12 1e ef 00 00 00 40 lock \*\(u32\*\)\(r1\+0x1eef\)\|=r2
19+
40: db 12 1e ef 00 00 00 a0 lock \*\(u64\*\)\(r1\+0x1eef\)\^=r2
20+
48: c3 12 1e ef 00 00 00 a0 lock \*\(u32\*\)\(r1\+0x1eef\)\^=r2
21+
50: db 12 1e ef 00 00 00 01 r2=atomic_fetch_add\(\(u64\*\)\(r1\+0x1eef\),r2\)
22+
58: c3 12 1e ef 00 00 00 01 w2=atomic_fetch_add\(\(u32\*\)\(r1\+0x1eef\),w2\)
23+
60: db 12 1e ef 00 00 00 51 r2=atomic_fetch_and\(\(u64\*\)\(r1\+0x1eef\),r2\)
24+
68: c3 12 1e ef 00 00 00 51 w2=atomic_fetch_and\(\(u32\*\)\(r1\+0x1eef\),w2\)
25+
70: db 12 1e ef 00 00 00 41 r2=atomic_fetch_or\(\(u64\*\)\(r1\+0x1eef\),r2\)
26+
78: c3 12 1e ef 00 00 00 41 w2=atomic_fetch_or\(\(u32\*\)\(r1\+0x1eef\),w2\)
27+
80: db 12 1e ef 00 00 00 a1 r2=atomic_fetch_xor\(\(u64\*\)\(r1\+0x1eef\),r2\)
28+
88: c3 12 1e ef 00 00 00 a1 w2=atomic_fetch_xor\(\(u32\*\)\(r1\+0x1eef\),w2\)

gas/testsuite/gas/bpf/atomic-be.d

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
#as: -EB -mdialect=normal
22
#source: atomic.s
3-
#objdump: -dr -M hex,v1
3+
#objdump: -dr -M hex
44
#name: eBPF atomic instructions, big endian
55

66
.*: +file format .*bpf.*
77

88
Disassembly of section .text:
99

1010
0+ <.text>:
11-
0: db 12 1e ef 00 00 00 00 xadddw \[%r1\+0x1eef\],%r2
12-
8: c3 12 1e ef 00 00 00 00 xaddw \[%r1\+0x1eef\],%r2
11+
0: db 12 1e ef 00 00 00 00 aadd \[%r1\+0x1eef\],%r2
12+
8: c3 12 1e ef 00 00 00 00 aadd32 \[%r1\+0x1eef\],%r2
13+
10: db 12 1e ef 00 00 00 50 aand \[%r1\+0x1eef\],%r2
14+
18: c3 12 1e ef 00 00 00 50 aand32 \[%r1\+0x1eef\],%r2
15+
20: db 12 1e ef 00 00 00 40 aor \[%r1\+0x1eef\],%r2
16+
28: c3 12 1e ef 00 00 00 40 aor32 \[%r1\+0x1eef\],%r2
17+
30: db 12 1e ef 00 00 00 a0 axor \[%r1\+0x1eef\],%r2
18+
38: c3 12 1e ef 00 00 00 a0 axor32 \[%r1\+0x1eef\],%r2
19+
40: db 12 1e ef 00 00 00 01 afadd \[%r1\+0x1eef\],%r2
20+
48: c3 12 1e ef 00 00 00 01 afadd32 \[%r1\+0x1eef\],%r2
21+
50: db 12 1e ef 00 00 00 51 afand \[%r1\+0x1eef\],%r2
22+
58: c3 12 1e ef 00 00 00 51 afand32 \[%r1\+0x1eef\],%r2
23+
60: db 12 1e ef 00 00 00 41 afor \[%r1\+0x1eef\],%r2
24+
68: c3 12 1e ef 00 00 00 41 afor32 \[%r1\+0x1eef\],%r2
25+
70: db 12 1e ef 00 00 00 a1 afxor \[%r1\+0x1eef\],%r2
26+
78: c3 12 1e ef 00 00 00 a1 afxor32 \[%r1\+0x1eef\],%r2

gas/testsuite/gas/bpf/atomic-pseudoc.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,21 @@
88
Disassembly of section .text:
99

1010
0+ <.text>:
11-
0: db 21 ef 1e 00 00 00 00 \*\(u64\*\)\(r1\+0x1eef\)\+=r2
12-
8: c3 21 ef 1e 00 00 00 00 \*\(u32\*\)\(r1\+0x1eef\)\+=r2
11+
0: db 21 ef 1e 00 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\+=r2
12+
8: c3 21 ef 1e 00 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\+=r2
13+
10: db 21 ef 1e 00 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\+=r2
14+
18: c3 21 ef 1e 00 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\+=r2
15+
20: db 21 ef 1e 50 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\&=r2
16+
28: c3 21 ef 1e 50 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\&=r2
17+
30: db 21 ef 1e 40 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\|=r2
18+
38: c3 21 ef 1e 40 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\|=r2
19+
40: db 21 ef 1e a0 00 00 00 lock \*\(u64\*\)\(r1\+0x1eef\)\^=r2
20+
48: c3 21 ef 1e a0 00 00 00 lock \*\(u32\*\)\(r1\+0x1eef\)\^=r2
21+
50: db 21 ef 1e 01 00 00 00 r2=atomic_fetch_add\(\(u64\*\)\(r1\+0x1eef\),r2\)
22+
58: c3 21 ef 1e 01 00 00 00 w2=atomic_fetch_add\(\(u32\*\)\(r1\+0x1eef\),w2\)
23+
60: db 21 ef 1e 51 00 00 00 r2=atomic_fetch_and\(\(u64\*\)\(r1\+0x1eef\),r2\)
24+
68: c3 21 ef 1e 51 00 00 00 w2=atomic_fetch_and\(\(u32\*\)\(r1\+0x1eef\),w2\)
25+
70: db 21 ef 1e 41 00 00 00 r2=atomic_fetch_or\(\(u64\*\)\(r1\+0x1eef\),r2\)
26+
78: c3 21 ef 1e 41 00 00 00 w2=atomic_fetch_or\(\(u32\*\)\(r1\+0x1eef\),w2\)
27+
80: db 21 ef 1e a1 00 00 00 r2=atomic_fetch_xor\(\(u64\*\)\(r1\+0x1eef\),r2\)
28+
88: c3 21 ef 1e a1 00 00 00 w2=atomic_fetch_xor\(\(u32\*\)\(r1\+0x1eef\),w2\)
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
# Test for eBPF ADDW and ADDDW pseudo-C instructions
1+
# Test for eBPF atomic pseudo-C instructions.
22
.text
3-
*(u64 *)(r1 + 7919) += r2
4-
*(u32 *)(r1 + 7919) += r2
3+
lock *(u64 *)(r1 + 0x1eef) += r2
4+
lock *(u32 *)(r1 + 0x1eef) += r2
5+
lock *(u64*)(r1+0x1eef)+=r2
6+
lock *(u32*)(r1+0x1eef)+=r2
7+
lock *(u64*)(r1+0x1eef)&=r2
8+
lock *(u32*)(r1+0x1eef)&=r2
9+
lock *(u64*)(r1+0x1eef)|=r2
10+
lock *(u32*)(r1+0x1eef)|=r2
11+
lock *(u64*)(r1+0x1eef)^=r2
12+
lock *(u32*)(r1+0x1eef)^=r2
13+
r2 = atomic_fetch_add((u64*)(r1+0x1eef),r2)
14+
w2 = atomic_fetch_add((u32*)(r1+0x1eef),w2)
15+
r2 = atomic_fetch_and((u64*)(r1+0x1eef),r2)
16+
w2 = atomic_fetch_and((u32*)(r1+0x1eef),w2)
17+
r2 = atomic_fetch_or((u64*)(r1+0x1eef),r2)
18+
w2 = atomic_fetch_or((u32*)(r1+0x1eef),w2)
19+
r2 = atomic_fetch_xor((u64*)(r1+0x1eef),r2)
20+
w2 = atomic_fetch_xor((u32*)(r1+0x1eef),w2)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#as: -EB -mdialect=normal
2+
#source: atomic-v1.s
3+
#objdump: -dr -M hex,v1
4+
#name: eBPF atomic instructions, big endian
5+
6+
.*: +file format .*bpf.*
7+
8+
Disassembly of section .text:
9+
10+
0+ <.text>:
11+
0: db 12 1e ef 00 00 00 00 xadddw \[%r1\+0x1eef\],%r2
12+
8: c3 12 1e ef 00 00 00 00 xaddw \[%r1\+0x1eef\],%r2

gas/testsuite/gas/bpf/atomic-v1.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#as: -EL -mdialect=normal
2+
#source: atomic-v1.s
3+
#objdump: -dr -M hex,v1
4+
#name: eBPF atomic instructions, little endian
5+
6+
.*: +file format .*bpf.*
7+
8+
Disassembly of section .text:
9+
10+
0+ <.text>:
11+
0: db 21 ef 1e 00 00 00 00 xadddw \[%r1\+0x1eef\],%r2
12+
8: c3 21 ef 1e 00 00 00 00 xaddw \[%r1\+0x1eef\],%r2

gas/testsuite/gas/bpf/atomic-v1.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Test for eBPF XADDW and XADDDW instructions.
3+
.text
4+
xadddw [%r1+0x1eef], %r2
5+
xaddw [%r1+0x1eef], %r2

gas/testsuite/gas/bpf/atomic.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ Disassembly of section .text:
1010
0+ <.text>:
1111
0: db 21 ef 1e 00 00 00 00 aadd \[%r1\+0x1eef\],%r2
1212
8: c3 21 ef 1e 00 00 00 00 aadd32 \[%r1\+0x1eef\],%r2
13+
10: db 21 ef 1e 50 00 00 00 aand \[%r1\+0x1eef\],%r2
14+
18: c3 21 ef 1e 50 00 00 00 aand32 \[%r1\+0x1eef\],%r2
15+
20: db 21 ef 1e 40 00 00 00 aor \[%r1\+0x1eef\],%r2
16+
28: c3 21 ef 1e 40 00 00 00 aor32 \[%r1\+0x1eef\],%r2
17+
30: db 21 ef 1e a0 00 00 00 axor \[%r1\+0x1eef\],%r2
18+
38: c3 21 ef 1e a0 00 00 00 axor32 \[%r1\+0x1eef\],%r2
19+
40: db 21 ef 1e 01 00 00 00 afadd \[%r1\+0x1eef\],%r2
20+
48: c3 21 ef 1e 01 00 00 00 afadd32 \[%r1\+0x1eef\],%r2
21+
50: db 21 ef 1e 51 00 00 00 afand \[%r1\+0x1eef\],%r2
22+
58: c3 21 ef 1e 51 00 00 00 afand32 \[%r1\+0x1eef\],%r2
23+
60: db 21 ef 1e 41 00 00 00 afor \[%r1\+0x1eef\],%r2
24+
68: c3 21 ef 1e 41 00 00 00 afor32 \[%r1\+0x1eef\],%r2
25+
70: db 21 ef 1e a1 00 00 00 afxor \[%r1\+0x1eef\],%r2
26+
78: c3 21 ef 1e a1 00 00 00 afxor32 \[%r1\+0x1eef\],%r2

gas/testsuite/gas/bpf/atomic.s

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
# Test for eBPF ADDW and ADDDW instructions
1+
# Test for eBPF atomic instructions
22
.text
33
aadd [%r1+0x1eef], %r2
44
aadd32 [%r1+0x1eef], %r2
5-
5+
aand [%r1+0x1eef], %r2
6+
aand32 [%r1+0x1eef], %r2
7+
aor [%r1+0x1eef], %r2
8+
aor32 [%r1+0x1eef], %r2
9+
axor [%r1+0x1eef], %r2
10+
axor32 [%r1+0x1eef], %r2
11+
12+
afadd [%r1+0x1eef], %r2
13+
afadd32 [%r1+0x1eef], %r2
14+
afand [%r1+0x1eef], %r2
15+
afand32 [%r1+0x1eef], %r2
16+
afor [%r1+0x1eef], %r2
17+
afor32 [%r1+0x1eef], %r2
18+
afxor [%r1+0x1eef], %r2
19+
afxor32 [%r1+0x1eef], %r2

0 commit comments

Comments
 (0)