[libc][NFC] Remove extra ; in exhaustive_test.h. (#124216)
[llvm-project.git] / llvm / test / MC / BPF / insn-unit.s
blobe0a4864837798955a575cd4d48c9386ec77fdd2a
1 # RUN: llvm-mc -triple bpfel -filetype=obj -o %t %s
2 # RUN: llvm-objdump --no-print-imm-hex -d -r %t | FileCheck --check-prefixes CHECK,CHECK-64 %s
3 # RUN: llvm-objdump --no-print-imm-hex --mattr=+alu32 -d -r %t | FileCheck --check-prefixes CHECK,CHECK-32 %s
5 // ======== BPF_LD Class ========
6 // Some extra whitespaces are deliberately added to test the parser.
8 r0 = * (u8 *)skb[0] // BPF_LD | BPF_ABS | BPF_B
9 r0 = *(u16 *)skb[2] // BPF_LD | BPF_ABS | BPF_H
10 r0 = * (u32*)skb[4] // BPF_LD | BPF_ABS | BPF_W
11 // CHECK: 30 00 00 00 00 00 00 00 r0 = *(u8 *)skb[0]
12 // CHECK: 28 00 00 00 02 00 00 00 r0 = *(u16 *)skb[2]
13 // CHECK: 20 00 00 00 04 00 00 00 r0 = *(u32 *)skb[4]
15 r0 = * (u8 *)skb[r0] // BPF_LD | BPF_IND | BPF_B
16 r0 = * (u16 *)skb[r1] // BPF_LD | BPF_IND | BPF_H
17 r0 = *(u32 *)skb[r2] // BPF_LD | BPF_IND | BPF_W
18 // CHECK: 50 00 00 00 00 00 00 00 r0 = *(u8 *)skb[r0]
19 // CHECK: 48 10 00 00 00 00 00 00 r0 = *(u16 *)skb[r1]
20 // CHECK: 40 20 00 00 00 00 00 00 r0 = *(u32 *)skb[r2]
22 r9 = 0xffffffff ll // BPF_LD | BPF_DW | BPF_IMM
23 r9 = 8589934591 ll // BPF_LD | BPF_DW | BPF_IMM
24 r9 = 0x1ffffffff ll // BPF_LD | BPF_DW | BPF_IMM
25 r9 = dummy_map ll // BPF_LD | BPF_DW | BPF_IMM
26 // CHECK: 18 09 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 r9 = 4294967295 ll
27 // CHECK: 18 09 00 00 ff ff ff ff 00 00 00 00 01 00 00 00 r9 = 8589934591 ll
28 // CHECK: 18 09 00 00 ff ff ff ff 00 00 00 00 01 00 00 00 r9 = 8589934591 ll
29 // CHECK: 18 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r9 = 0 ll
30 // CHECK: 0000000000000060: R_BPF_64_64 dummy_map
32 // ======== BPF_LDX Class ========
33 r5 = *(u8 *)(r0 + 0) // BPF_LDX | BPF_B
34 r6 = *(u16 *)(r1 + 8) // BPF_LDX | BPF_H
35 r7 = *(u32 *)(r2 + 16) // BPF_LDX | BPF_W
36 r8 = *(u64 *)(r3 - 30) // BPF_LDX | BPF_DW
37 // CHECK-64: 71 05 00 00 00 00 00 00 w5 = *(u8 *)(r0 + 0)
38 // CHECK-64: 69 16 08 00 00 00 00 00 w6 = *(u16 *)(r1 + 8)
39 // CHECK-64: 61 27 10 00 00 00 00 00 w7 = *(u32 *)(r2 + 16)
40 // CHECK-32: 71 05 00 00 00 00 00 00 w5 = *(u8 *)(r0 + 0)
41 // CHECK-32: 69 16 08 00 00 00 00 00 w6 = *(u16 *)(r1 + 8)
42 // CHECK-32: 61 27 10 00 00 00 00 00 w7 = *(u32 *)(r2 + 16)
43 // CHECK: 79 38 e2 ff 00 00 00 00 r8 = *(u64 *)(r3 - 30)
45 // ======== BPF_STX Class ========
46 *(u8 *)(r0 + 0) = r7 // BPF_STX | BPF_B
47 *(u16 *)(r1 + 8) = r8 // BPF_STX | BPF_H
48 *(u32 *)(r2 + 16) = r9 // BPF_STX | BPF_W
49 *(u64 *)(r3 - 30) = r10 // BPF_STX | BPF_DW
50 // CHECK-64: 73 70 00 00 00 00 00 00 *(u8 *)(r0 + 0) = w7
51 // CHECK-64: 6b 81 08 00 00 00 00 00 *(u16 *)(r1 + 8) = w8
52 // CHECK-64: 63 92 10 00 00 00 00 00 *(u32 *)(r2 + 16) = w9
53 // CHECK-32: 73 70 00 00 00 00 00 00 *(u8 *)(r0 + 0) = w7
54 // CHECK-32: 6b 81 08 00 00 00 00 00 *(u16 *)(r1 + 8) = w8
55 // CHECK-32: 63 92 10 00 00 00 00 00 *(u32 *)(r2 + 16) = w9
56 // CHECK: 7b a3 e2 ff 00 00 00 00 *(u64 *)(r3 - 30) = r10
58 lock *(u32 *)(r2 + 16) += r9 // BPF_STX | BPF_W | BPF_XADD
59 lock *(u64 *)(r3 - 30) += r10 // BPF_STX | BPF_DW | BPF_XADD
60 // CHECK-64: c3 92 10 00 00 00 00 00 lock *(u32 *)(r2 + 16) += w9
61 // CHECK-32: c3 92 10 00 00 00 00 00 lock *(u32 *)(r2 + 16) += w9
62 // CHECK: db a3 e2 ff 00 00 00 00 lock *(u64 *)(r3 - 30) += r10
64 callx r2
65 // CHECK: 8d 02 00 00 00 00 00 00 callx r2
67 // ======== BPF_JMP Class ========
68 may_goto Llabel0 // BPF_JCOND | BPF_K
69 if r1 & r2 goto Llabel0 // BPF_JSET | BPF_X
70 if r1 & 0xffff goto Llabel0 // BPF_JSET | BPF_K
71 // CHECK: e5 00 1e 00 00 00 00 00 may_goto +30
72 // CHECK: 4d 21 1d 00 00 00 00 00 if r1 & r2 goto +29
73 // CHECK: 45 01 1c 00 ff ff 00 00 if r1 & 65535 goto +28
75 goto Llabel0 // BPF_JA
76 call 1 // BPF_CALL
77 exit // BPF_EXIT
78 // CHECK: 05 00 1b 00 00 00 00 00 goto +27
79 // CHECK: 85 00 00 00 01 00 00 00 call 1
80 // CHECK: 95 00 00 00 00 00 00 00 exit
82 if r0 == r1 goto Llabel0 // BPF_JEQ | BPF_X
83 if r3 != r4 goto Llabel0 // BPF_JNE | BPF_X
84 // CHECK: 1d 10 18 00 00 00 00 00 if r0 == r1 goto +24
85 // CHECK: 5d 43 17 00 00 00 00 00 if r3 != r4 goto +23
87 if r1 > r2 goto Llabel0 // BPF_JGT | BPF_X
88 if r2 >= r3 goto Llabel0 // BPF_JGE | BPF_X
89 if r4 s> r5 goto Llabel0 // BPF_JSGT | BPF_X
90 if r5 s>= r6 goto Llabel0 // BPF_JSGE | BPF_X
91 // CHECK: 2d 21 16 00 00 00 00 00 if r1 > r2 goto +22
92 // CHECK: 3d 32 15 00 00 00 00 00 if r2 >= r3 goto +21
93 // CHECK: 6d 54 14 00 00 00 00 00 if r4 s> r5 goto +20
94 // CHECK: 7d 65 13 00 00 00 00 00 if r5 s>= r6 goto +19
96 if r6 < r7 goto Llabel0 // BPF_JLT | BPF_X
97 if r7 <= r8 goto Llabel0 // BPF_JLE | BPF_X
98 if r8 s< r9 goto Llabel0 // BPF_JSLT | BPF_X
99 if r9 s<= r10 goto Llabel0 // BPF_JSLE | BPF_X
100 // CHECK: ad 76 12 00 00 00 00 00 if r6 < r7 goto +18
101 // CHECK: bd 87 11 00 00 00 00 00 if r7 <= r8 goto +17
102 // CHECK: cd 98 10 00 00 00 00 00 if r8 s< r9 goto +16
103 // CHECK: dd a9 0f 00 00 00 00 00 if r9 s<= r10 goto +15
105 if r0 == 0 goto Llabel0 // BPF_JEQ | BPF_K
106 if r3 != -1 goto Llabel0 // BPF_JNE | BPF_K
107 // CHECK: 15 00 0e 00 00 00 00 00 if r0 == 0 goto +14
108 // CHECK: 55 03 0d 00 ff ff ff ff if r3 != -1 goto +13
110 if r1 > 64 goto Llabel0 // BPF_JGT | BPF_K
111 if r2 >= 0xffffffff goto Llabel0 // BPF_JGE | BPF_K
112 if r4 s> 0xffffffff goto Llabel0 // BPF_JSGT | BPF_K
113 if r5 s>= 0x7fffffff goto Llabel0 // BPF_JSGE | BPF_K
114 // CHECK: 25 01 0c 00 40 00 00 00 if r1 > 64 goto +12
115 // CHECK: 35 02 0b 00 ff ff ff ff if r2 >= -1 goto +11
116 // CHECK: 65 04 0a 00 ff ff ff ff if r4 s> -1 goto +10
117 // CHECK: 75 05 09 00 ff ff ff 7f if r5 s>= 2147483647 goto +9
119 if r6 < 0xff goto Llabel0 // BPF_JLT | BPF_K
120 if r7 <= 0xffff goto Llabel0 // BPF_JLE | BPF_K
121 if r8 s< 0 goto Llabel0 // BPF_JSLT | BPF_K
122 if r9 s<= -1 goto Llabel0 // BPF_JSLE | BPF_K
123 // CHECK: a5 06 08 00 ff 00 00 00 if r6 < 255 goto +8
124 // CHECK: b5 07 07 00 ff ff 00 00 if r7 <= 65535 goto +7
125 // CHECK: c5 08 06 00 00 00 00 00 if r8 s< 0 goto +6
126 // CHECK: d5 09 05 00 ff ff ff ff if r9 s<= -1 goto +5
128 // ======== BPF_ALU64 Class ========
129 r0 += r1 // BPF_ADD | BPF_X
130 r1 -= r2 // BPF_SUB | BPF_X
131 r2 *= r3 // BPF_MUL | BPF_X
132 r3 /= r4 // BPF_DIV | BPF_X
133 r4 %= r5 // BPF_MOD | BPF_X
134 // CHECK: 0f 10 00 00 00 00 00 00 r0 += r1
135 // CHECK: 1f 21 00 00 00 00 00 00 r1 -= r2
136 // CHECK: 2f 32 00 00 00 00 00 00 r2 *= r3
137 // CHECK: 3f 43 00 00 00 00 00 00 r3 /= r4
138 // CHECK: 9f 54 00 00 00 00 00 00 r4 %= r5
140 Llabel0 :
141 r2 = -r2 // BPF_NEG
142 r4 |= r5 // BPF_OR | BPF_X
143 r5 &= r6 // BPF_AND | BPF_X
144 r6 <<= r7 // BPF_LSH | BPF_X
145 r7 >>= r8 // BPF_RSH | BPF_X
146 r8 ^= r9 // BPF_XOR | BPF_X
147 r9 = r10 // BPF_MOV | BPF_X
148 r10 s>>= r0 // BPF_ARSH | BPF_X
149 // CHECK: <Llabel0>:
150 // CHECK: 87 02 00 00 00 00 00 00 r2 = -r2
151 // CHECK: 4f 54 00 00 00 00 00 00 r4 |= r5
152 // CHECK: 5f 65 00 00 00 00 00 00 r5 &= r6
153 // CHECK: 6f 76 00 00 00 00 00 00 r6 <<= r7
154 // CHECK: 7f 87 00 00 00 00 00 00 r7 >>= r8
155 // CHECK: af 98 00 00 00 00 00 00 r8 ^= r9
156 // CHECK: bf a9 00 00 00 00 00 00 r9 = r10
157 // CHECK: cf 0a 00 00 00 00 00 00 r10 s>>= r0
159 r1 = be16 r1 // BPF_END | BPF_TO_BE
160 r2 = be32 r2 // BPF_END | BPF_TO_BE
161 r3 = be64 r3 // BPF_END | BPF_TO_BE
162 // CHECK: dc 01 00 00 10 00 00 00 r1 = be16 r1
163 // CHECK: dc 02 00 00 20 00 00 00 r2 = be32 r2
164 // CHECK: dc 03 00 00 40 00 00 00 r3 = be64 r3
166 r0 += 1 // BPF_ADD | BPF_K
167 r1 -= 0x1 // BPF_SUB | BPF_K
168 r2 *= -4 // BPF_MUL | BPF_K
169 r3 /= 5 // BPF_DIV | BPF_K
170 r4 %= 5 // BPF_MOD | BPF_K
171 // CHECK: 07 00 00 00 01 00 00 00 r0 += 1
172 // CHECK: 17 01 00 00 01 00 00 00 r1 -= 1
173 // CHECK: 27 02 00 00 fc ff ff ff r2 *= -4
174 // CHECK: 37 03 00 00 05 00 00 00 r3 /= 5
175 // CHECK: 97 04 00 00 05 00 00 00 r4 %= 5
177 r4 |= 0xff // BPF_OR | BPF_K
178 r5 &= 0xFF // BPF_AND | BPF_K
179 r6 <<= 63 // BPF_LSH | BPF_K
180 r7 >>= 32 // BPF_RSH | BPF_K
181 r8 ^= 0 // BPF_XOR | BPF_K
182 r9 = 1 // BPF_MOV | BPF_K
183 r9 = 0xffffffff // BPF_MOV | BPF_K
184 r10 s>>= 64 // BPF_ARSH | BPF_K
185 // CHECK: 47 04 00 00 ff 00 00 00 r4 |= 255
186 // CHECK: 57 05 00 00 ff 00 00 00 r5 &= 255
187 // CHECK: 67 06 00 00 3f 00 00 00 r6 <<= 63
188 // CHECK: 77 07 00 00 20 00 00 00 r7 >>= 32
189 // CHECK: a7 08 00 00 00 00 00 00 r8 ^= 0
190 // CHECK: b7 09 00 00 01 00 00 00 r9 = 1
191 // CHECK: b7 09 00 00 ff ff ff ff r9 = -1
192 // CHECK: c7 0a 00 00 40 00 00 00 r10 s>>= 64