aboutsummaryrefslogtreecommitdiff
path: root/gas/doc/c-bpf.texi
blob: d99538f16a989f323d3bc9e3e7064190ff0c9d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
@c Copyright (C) 2019-2024 Free Software Foundation, Inc.
@c This is part of the GAS manual.
@c For copying conditions, see the file as.texinfo.

@ifset GENERIC
@page
@node BPF-Dependent
@chapter BPF Dependent Features
@end ifset

@ifclear GENERIC
@node Machine Dependencies
@chapter BPF Dependent Features
@end ifclear

@cindex BPF support
@menu
* BPF Options::                 BPF specific command-line options.
* BPF Special Characters::      Comments and statements.
* BPF Registers::               Register names.
* BPF Directives::		Machine directives.
* BPF Instructions::            Machine instructions.
@end menu

@node BPF Options
@section BPF Options
@cindex BPF options (none)
@cindex options for BPF (none)

@c man begin OPTIONS
@table @gcctabopt

@cindex @option{-EB} command-line option, BPF
@item -EB
This option specifies that the assembler should emit big-endian eBPF.

@cindex @option{-EL} command-line option, BPF
@item -EL
This option specifies that the assembler should emit little-endian
eBPF.

@cindex @option{-mdialect} command-line options, BPF
@item -mdialect=@var{dialect}
This option specifies the assembly language dialect to recognize while
assembling.  The assembler supports @option{normal} and
@option{pseudoc}.

@cindex @option{-misa-spec} command-line options, BPF
@item -misa-spec=@var{spec}
This option specifies the version of the BPF instruction set to use
when assembling.  The BPF ISA versions supported are @option{v1} @option{v2}, @option{v3} and @option{v4}.

The value @option{xbpf} can be specified to recognize extra
instructions that are used by GCC for testing purposes.  But beware
this is not valid BPF.

@cindex @option{-mno-relax} command-line options, BPF
@item -mno-relax
This option tells the assembler to not relax instructions.
@end table

Note that if no endianness option is specified in the command line,
the host endianness is used.
@c man end

@node BPF Special Characters
@section BPF Special Characters

@cindex line comment character, BPF
@cindex BPF line comment character
The presence of a @samp{#} or @samp{//} anywhere on a line indicates
the start of a comment that extends to the end of the line.

@cindex block comments, BPF
@cindex BPF block comments
The presence of the @samp{/*} sequence indicates the beginning of a
block (multi-line) comment, whose contents span until the next
@samp{*/} sequence.  It is not possible to nest block comments.

@cindex statement separator, BPF
Statements and assembly directives are separated by newlines and
@samp{;} characters.

@node BPF Registers
@section BPF Registers

@cindex BPF register names
@cindex register names, BPF
The eBPF processor provides ten general-purpose 64-bit registers,
which are read-write, and a read-only frame pointer register:

@noindent
In normal syntax:

@table @samp
@item %r0 .. %r9
General-purpose registers.
@item %r10
@itemx %fp
Read-only frame pointer register.
@end table

All BPF registers are 64-bit long.  However, in the Pseudo-C syntax
registers can be referred using different names, which actually
reflect the kind of instruction they appear on:

@noindent
In pseudoc syntax:

@table @samp
@item r0..r9
General-purpose register in an instruction that operates on its value
as if it was a 64-bit value.
@item w0..w9
General-purpose register in an instruction that operates on its value
as if it was a 32-bit value.
@item r10
Read-only frame pointer register.
@end table

@noindent
Note that in the Pseudo-C syntax register names are not preceded by
@code{%} characters.  A consequence of that is that in contexts like
instruction operands, where both register names and expressions
involving symbols are expected, there is no way to disambiguate
between them.  In order to keep things simple, this assembler does not
allow to refer to symbols whose names collide with register names in
instruction operands.

@node BPF Directives
@section BPF Directives

@cindex machine directives, BPF

The BPF version of @code{@value{AS}} supports the following additional
machine directives:

@table @code
@cindex @code{half} directive, BPF
@item .word
The @code{.half} directive produces a 16 bit value.

@cindex @code{word} directive, BPF
@item .word
The @code{.word} directive produces a 32 bit value.

@cindex @code{dword} directive, BPF
@item .dword
The @code{.dword} directive produces a 64 bit value.
@end table

@node BPF Instructions
@section BPF Instructions

@cindex BPF opcodes
@cindex opcodes for BPF
In the instruction descriptions below the following field descriptors
are used:

@table @code
@item rd
Destination general-purpose register whose role is to be the
destination of an operation.
@item rs
Source general-purpose register whose role is to be the source of an
operation.
@item disp16
16-bit signed PC-relative offset, measured in number of 64-bit words,
minus one.
@item disp32
32-bit signed PC-relative offset, measured in number of 64-bit words,
minus one.
@item offset16
Signed 16-bit immediate representing an offset in bytes.
@item disp16
Signed 16-bit immediate representing a displacement to a target,
measured in number of 64-bit words @emph{minus one}.
@item disp32
Signed 32-bit immediate representing a displacement to a target,
measured in number of 64-bit words @emph{minus one}.
@item imm32
Signed 32-bit immediate.
@item imm64
Signed 64-bit immediate.
@end table

@noindent
Note that the assembler allows to express the value for an immediate
using any numerical literal whose two's complement encoding fits in
the immediate field.  For example, @code{-2}, @code{0xfffffffe} and
@code{4294967294} all denote the same encoded 32-bit immediate, whose
value may be then interpreted by different instructions as either as a
negative or a positive number.

@subsection Arithmetic instructions

The destination register in these instructions act like an
accumulator.

Note that in pseudoc syntax these instructions should use @code{r}
registers.

@table @code
@item add rd, rs
@itemx add rd, imm32
@itemx rd += rs
@itemx rd += imm32
64-bit arithmetic addition.

@item sub rd, rs
@itemx sub rd, rs
@itemx rd -= rs
@itemx rd -= imm32
64-bit arithmetic subtraction.

@item mul rd, rs
@itemx mul rd, imm32
@itemx rd *= rs
@itemx rd *= imm32
64-bit arithmetic multiplication.

@item div rd, rs
@itemx div rd, imm32
@itemx rd /= rs
@itemx rd /= imm32
64-bit arithmetic integer division.

@item mod rd, rs
@itemx mod rd, imm32
@itemx rd %= rs
@itemx rd %= imm32
64-bit integer remainder.

@item and rd, rs
@itemx and rd, imm32
@itemx rd &= rs
@itemx rd &= imm32
64-bit bit-wise ``and'' operation.

@item or rd, rs
@itemx or rd, imm32
@itemx rd |= rs
@itemx rd |= imm32
64-bit bit-wise ``or'' operation.

@item xor rd, imm32
@itemx xor rd, rs
@itemx rd ^= rs
@itemx rd ^= imm32
64-bit bit-wise exclusive-or operation.

@item lsh rd, rs
@itemx ldh rd, imm32
@itemx rd <<= rs
@itemx rd <<= imm32
64-bit left shift, by @code{rs} or @code{imm32} bits.

@item rsh %d, %s
@itemx rsh rd, imm32
@itemx rd >>= rs
@itemx rd >>= imm32
64-bit right logical shift, by @code{rs} or @code{imm32} bits.

@item arsh rd, rs
@itemx arsh rd, imm32
@itemx rd s>>= rs
@itemx rd s>>= imm32
64-bit right arithmetic shift, by @code{rs} or @code{imm32} bits.

@item neg rd
@itemx rd = - rd
64-bit arithmetic negation.

@item mov rd, rs
@itemx mov rd, imm32
@itemx rd = rs
@itemx rd = imm32
Move the 64-bit value of @code{rs} in @code{rd}, or load @code{imm32}
in @code{rd}.

@item movs rd, rs, 8
@itemx rd = (s8) rs
Move the sign-extended 8-bit value in @code{rs} to @code{rd}.

@item movs rd, rs, 16
@itemx rd = (s16) rs
Move the sign-extended 16-bit value in @code{rs} to @code{rd}.

@item movs rd, rs, 32
@itemx rd = (s32) rs
Move the sign-extended 32-bit value in @code{rs} to @code{rd}.
@end table

@subsection 32-bit arithmetic instructions

The destination register in these instructions act as an accumulator.

Note that in pseudoc syntax these instructions should use @code{w}
registers.  It is not allowed to mix @code{w} and @code{r} registers
in the same instruction.

@table @code
@item add32 rd, rs
@itemx add32 rd, imm32
@itemx rd += rs
@itemx rd += imm32
32-bit arithmetic addition.

@item sub32 rd, rs
@itemx sub32 rd, imm32
@itemx rd -= rs
@itemx rd += imm32
32-bit arithmetic subtraction.

@item mul32 rd, rs
@itemx mul32 rd, imm32
@itemx rd *= rs
@itemx rd *= imm32
32-bit arithmetic multiplication.

@item div32 rd, rs
@itemx div32 rd, imm32
@itemx rd /= rs
@itemx rd /= imm32
32-bit arithmetic integer division.

@item mod32 rd, rs
@itemx mod32 rd, imm32
@itemx rd %= rs
@itemx rd %= imm32
32-bit integer remainder.

@item and32 rd, rs
@itemx and32 rd, imm32
@itemx rd &= rs
@itemx rd &= imm32
32-bit bit-wise ``and'' operation.

@item or32 rd, rs
@itemx or32 rd, imm32
@itemx rd |= rs
@itemx rd |= imm32
32-bit bit-wise ``or'' operation.

@item xor32 rd, rs
@itemx xor32 rd, imm32
@itemx rd ^= rs
@itemx rd ^= imm32
32-bit bit-wise exclusive-or operation.

@item lsh32 rd, rs
@itemx lsh32 rd, imm32
@itemx rd <<= rs
@itemx rd <<= imm32
32-bit left shift, by @code{rs} or @code{imm32} bits.

@item rsh32 rd, rs
@itemx rsh32 rd, imm32
@itemx rd >>= rs
@itemx rd >>= imm32
32-bit right logical shift, by @code{rs} or @code{imm32} bits.

@item arsh32 rd, rs
@itemx arsh32 rd, imm32
@itemx rd s>>= rs
@itemx rd s>>= imm32
32-bit right arithmetic shift, by @code{rs} or @code{imm32} bits.

@item neg32 rd
@itemx rd = - rd
32-bit arithmetic negation.

@item mov32 rd, rs
@itemx mov32 rd, imm32
@itemx rd = rs
@itemx rd = imm32
Move the 32-bit value of @code{rs} in @code{rd}, or load @code{imm32}
in @code{rd}.

@item mov32s rd, rs, 8
@itemx rd = (s8) rs
Move the sign-extended 8-bit value in @code{rs} to @code{rd}.

@item mov32s rd, rs, 16
@itemx rd = (s16) rs
Move the sign-extended 16-bit value in @code{rs} to @code{rd}.

@item mov32s rd, rs, 32
@itemx rd = (s32) rs
Move the sign-extended 32-bit value in @code{rs} to @code{rd}.
@end table

@subsection Endianness conversion instructions

@table @code
@item endle rd, 16
@itemx endle rd, 32
@itemx endle rd, 64
@itemx rd = le16 rd
@itemx rd = le32 rd
@itemx rd = le64 rd
Convert the 16-bit, 32-bit or 64-bit value in @code{rd} to
little-endian and store it back in @code{rd}.
@item endbe %d, 16
@itemx endbe %d, 32
@itemx endbe %d, 64
@itemx rd = be16 rd
@itemx rd = be32 rd
@itemx rd = be64 rd
Convert the 16-bit, 32-bit or 64-bit value in @code{rd} to big-endian
and store it back in @code{rd}.
@end table

@subsection Byte swap instructions

@table @code
@item bswap rd, 16
@itemx rd = bswap16 rd
Swap the least-significant 16-bit word in @code{rd} with the
most-significant 16-bit word.

@item bswap rd, 32
@itemx rd = bswap32 rd
Swap the least-significant 32-bit word in @code{rd} with the
most-significant 32-bit word.

@item bswap rd, 64
@itemx rd = bswap64 rd
Swap the least-significant 64-bit word in @code{rd} with the
most-significant 64-bit word.
@end table


@subsection 64-bit load and pseudo maps

@table @code
@item lddw rd, imm64
@itemx rd = imm64 ll
Load the given signed 64-bit immediate to the destination register
@code{rd}.
@end table

@subsection Load instructions for socket filters

The following instructions are intended to be used in socket filters,
and are therefore not general-purpose: they make assumptions on the
contents of several registers.  See the file
@file{Documentation/networking/filter.txt} in the Linux kernel source
tree for more information.

Absolute loads:

@table @code
@item ldabsw imm32
@itemx r0 = *(u32 *) skb[imm32]
Absolute 32-bit load.

@item ldabsh imm32
@itemx r0 = *(u16 *) skb[imm32]
Absolute 16-bit load.

@item ldabsb imm32
@itemx r0 = *(u8 *) skb[imm32]
Absolute 8-bit load.
@end table

Indirect loads:

@table @code
@item ldindw rs, imm32
@itemx r0 = *(u32 *) skb[rs + imm32]
Indirect 32-bit load.

@item ldindh rs, imm32
@itemx r0 = *(u16 *) skb[rs + imm32]
Indirect 16-bit load.

@item ldindb %s, imm32
@itemx r0 = *(u8 *) skb[rs + imm32]
Indirect 8-bit load.
@end table

@subsection Generic load/store instructions

General-purpose load and store instructions are provided for several
word sizes.

Load to register instructions:

@table @code
@item ldxdw rd, [rs + offset16]
@itemx rd = *(u64 *) (rs + offset16)
Generic 64-bit load.

@item ldxw rd, [rs + offset16]
@itemx rd = *(u32 *) (rs + offset16)
Generic 32-bit load.

@item ldxh rd, [rs + offset16]
@itemx rd = *(u16 *) (rs + offset16)
Generic 16-bit load.

@item ldxb rd, [rs + offset16]
@itemx rd = *(u8 *) (rs + offset16)
Generic 8-bit load.
@end table

Signed load to register instructions:

@table @code
@item ldxsdw rd, [rs + offset16]
@itemx rd = *(s64 *) (rs + offset16)
Generic 64-bit signed load.

@item ldxsw rd, [rs + offset16]
@itemx rd = *(s32 *) (rs + offset16)
Generic 32-bit signed load.

@item ldxsh rd, [rs + offset16]
@itemx rd = *(s16 *) (rs + offset16)
Generic 16-bit signed load.

@item ldxsb rd, [rs + offset16]
@itemx rd = *(s8 *) (rs + offset16)
Generic 8-bit signed load.
@end table

Store from register instructions:

@table @code
@item stxdw [rd + offset16], %s
@itemx *(u64 *) (rd + offset16)
Generic 64-bit store.

@item stxw [rd + offset16], %s
@itemx *(u32 *) (rd + offset16)
Generic 32-bit store.

@item stxh [rd + offset16], %s
@itemx *(u16 *) (rd + offset16)
Generic 16-bit store.

@item stxb [rd + offset16], %s
@itemx *(u8 *) (rd + offset16)
Generic 8-bit store.
@end table

Store from immediates instructions:

@table @code
@item stdw [rd + offset16], imm32
@itemx *(u64 *) (rd + offset16) = imm32
Store immediate as 64-bit.

@item stw [rd + offset16], imm32
@itemx *(u32 *) (rd + offset16) = imm32
Store immediate as 32-bit.

@item sth [rd + offset16], imm32
@itemx *(u16 *) (rd + offset16) = imm32
Store immediate as 16-bit.

@item stb [rd + offset16], imm32
@itemx *(u8 *) (rd + offset16) = imm32
Store immediate as 8-bit.
@end table

@subsection Jump instructions

eBPF provides the following compare-and-jump instructions, which
compare the values of the two given registers, or the values of a
register and an immediate, and perform a branch in case the comparison
holds true.

@table @code
@item ja disp16
@itemx goto disp16
Jump-always.

@item jal disp32
@itemx gotol disp32
Jump-always, long range.

@item jeq rd, rs, disp16
@itemx jeq rd, imm32, disp16
@itemx if rd == rs goto disp16
@itemx if rd == imm32 goto disp16
Jump if equal, unsigned.

@item jgt rd, rs, disp16
@itemx jgt rd, imm32, disp16
@itemx if rd > rs goto disp16
@itemx if rd > imm32 goto disp16
Jump if greater, unsigned.

@item jge rd, rs, disp16
@itemx jge rd, imm32, disp16
@itemx if rd >= rs goto disp16
@itemx if rd >= imm32 goto disp16
Jump if greater or equal.

@item jlt rd, rs, disp16
@itemx jlt rd, imm32, disp16
@itemx if rd < rs goto disp16
@itemx if rd < imm32 goto disp16
Jump if lesser.

@item jle rd , rs, disp16
@itemx jle rd, imm32, disp16
@itemx if rd <= rs goto disp16
@itemx if rd <= imm32 goto disp16
Jump if lesser or equal.

@item jset rd, rs, disp16
@itemx jset rd, imm32, disp16
@itemx if rd & rs goto disp16
@itemx if rd & imm32 goto disp16
Jump if signed equal.

@item jne rd, rs, disp16
@itemx jne rd, imm32, disp16
@itemx if rd != rs goto disp16
@itemx if rd != imm32 goto disp16
Jump if not equal.

@item jsgt rd, rs, disp16
@itemx jsgt rd, imm32, disp16
@itemx if rd s> rs goto disp16
@itemx if rd s> imm32 goto disp16
Jump if signed greater.

@item jsge rd, rs, disp16
@itemx jsge rd, imm32, disp16
@itemx if rd s>= rd goto disp16
@itemx if rd s>= imm32 goto disp16
Jump if signed greater or equal.

@item jslt rd, rs, disp16
@itemx jslt rd, imm32, disp16
@itemx if rd s< rs goto disp16
@itemx if rd s< imm32 goto disp16
Jump if signed lesser.

@item jsle rd, rs, disp16
@itemx jsle rd, imm32, disp16
@itemx if rd s<= rs goto disp16
@itemx if rd s<= imm32 goto disp16
Jump if signed lesser or equal.
@end table

A call instruction is provided in order to perform calls to other eBPF
functions, or to external kernel helpers:

@table @code
@item call disp32
@item call imm32
Jump and link to the offset @emph{disp32}, or to the kernel helper
function identified by @emph{imm32}.
@end table

Finally:

@table @code
@item exit
Terminate the eBPF program.
@end table

@subsection 32-bit jump instructions

eBPF provides the following compare-and-jump instructions, which
compare the 32-bit values of the two given registers, or the values of
a register and an immediate, and perform a branch in case the
comparison holds true.

These instructions are only available in BPF v3 or later.

@table @code
@item jeq32 rd, rs, disp16
@itemx jeq32 rd, imm32, disp16
@itemx if rd == rs goto disp16
@itemx if rd == imm32 goto disp16
Jump if equal, unsigned.

@item jgt32 rd, rs, disp16
@itemx jgt32 rd, imm32, disp16
@itemx if rd > rs goto disp16
@itemx if rd > imm32 goto disp16
Jump if greater, unsigned.

@item jge32 rd, rs, disp16
@itemx jge32 rd, imm32, disp16
@itemx if rd >= rs goto disp16
@itemx if rd >= imm32 goto disp16
Jump if greater or equal.

@item jlt32 rd, rs, disp16
@itemx jlt32 rd, imm32, disp16
@itemx if rd < rs goto disp16
@itemx if rd < imm32 goto disp16
Jump if lesser.

@item jle32 rd , rs, disp16
@itemx jle32 rd, imm32, disp16
@itemx if rd <= rs goto disp16
@itemx if rd <= imm32 goto disp16
Jump if lesser or equal.

@item jset32 rd, rs, disp16
@itemx jset32 rd, imm32, disp16
@itemx if rd & rs goto disp16
@itemx if rd & imm32 goto disp16
Jump if signed equal.

@item jne32 rd, rs, disp16
@itemx jne32 rd, imm32, disp16
@itemx if rd != rs goto disp16
@itemx if rd != imm32 goto disp16
Jump if not equal.

@item jsgt32 rd, rs, disp16
@itemx jsgt32 rd, imm32, disp16
@itemx if rd s> rs goto disp16
@itemx if rd s> imm32 goto disp16
Jump if signed greater.

@item jsge32 rd, rs, disp16
@itemx jsge32 rd, imm32, disp16
@itemx if rd s>= rd goto disp16
@itemx if rd s>= imm32 goto disp16
Jump if signed greater or equal.

@item jslt32 rd, rs, disp16
@itemx jslt32 rd, imm32, disp16
@itemx if rd s< rs goto disp16
@itemx if rd s< imm32 goto disp16
Jump if signed lesser.

@item jsle32 rd, rs, disp16
@itemx jsle32 rd, imm32, disp16
@itemx if rd s<= rs goto disp16
@itemx if rd s<= imm32 goto disp16
Jump if signed lesser or equal.
@end table

@subsection Atomic instructions

Atomic exchange instructions are provided in two flavors: one for
compare-and-swap, one for unconditional exchange.

@table @code
@item acmp [rd + offset16], rs
@itemx r0 = cmpxchg_64 (rd + offset16, r0, rs)
Atomic compare-and-swap.  Compares value in @code{r0} to value
addressed by @code{rd + offset16}.  On match, the value addressed by
@code{rd + offset16} is replaced with the value in @code{rs}.
Regardless, the value that was at @code{rd + offset16} is
zero-extended and loaded into @code{r0}.

@item axchg [rd + offset16], rs
@itemx rs = xchg_64 (rd + offset16, rs)
Atomic exchange.  Atomically exchanges the value in @code{rs} with
the value addressed by @code{rd + offset16}.
@end table

@noindent
The following instructions provide atomic arithmetic operations.

@table @code
@item aadd [rd + offset16], rs
@itemx lock *(u64 *)(rd + offset16) = rs
Atomic add instruction.

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

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

@item axor [rd + offset16], rs
@itemx lock *(u64 *) (rd + offset16) ^= rs
Atomic xor instruction.
@end table

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

@table @code
@item afadd [rd + offset16], rs
@itemx rs = atomic_fetch_add ((u64 *)(rd + offset16), rs)
Atomic fetch-and-add instruction.

@item afor [rd + offset16], rs
@itemx rs = atomic_fetch_or ((u64 *)(rd + offset16), rs)
Atomic fetch-and-or instruction.

@item afand [rd + offset16], rs
@itemx rs = atomic_fetch_and ((u64 *)(rd + offset16), rs)
Atomic fetch-and-and instruction.

@item afxor [rd + offset16], rs
@itemx rs = atomic_fetch_xor ((u64 *)(rd + offset16), rs)
Atomic fetch-and-or instruction.
@end table

The above instructions were introduced in the V3 of the BPF
instruction set.  The following instruction is supported for backwards
compatibility:

@table @code
@item xadddw [rd + offset16], rs
Alias to @code{aadd}.
@end table

@subsection 32-bit atomic instructions

32-bit atomic exchange instructions are provided in two flavors: one
for compare-and-swap, one for unconditional exchange.

@table @code
@item acmp32 [rd + offset16], rs
@itemx w0 = cmpxchg32_32 (rd + offset16, w0, ws)
Atomic compare-and-swap.  Compares value in @code{w0} to value
addressed by @code{rd + offset16}.  On match, the value addressed by
@code{rd + offset16} is replaced with the value in @code{ws}.
Regardless, the value that was at @code{rd + offset16} is
zero-extended and loaded into @code{w0}.

@item axchg [rd + offset16], rs
@itemx ws = xchg32_32 (rd + offset16, ws)
Atomic exchange.  Atomically exchanges the value in @code{ws} with
the value addressed by @code{rd + offset16}.
@end table

@noindent
The following instructions provide 32-bit atomic arithmetic operations.

@table @code
@item aadd32 [rd + offset16], rs
@itemx lock *(u32 *)(rd + offset16) = rs
Atomic add instruction.

@item aor32 [rd + offset16], rs
@itemx lock *(u32 *) (rd + offset16) |= rs
Atomic or instruction.

@item aand32 [rd + offset16], rs
@itemx lock *(u32 *) (rd + offset16) &= rs
Atomic and instruction.

@item axor32 [rd + offset16], rs
@itemx lock *(u32 *) (rd + offset16) ^= rs
Atomic xor instruction
@end table

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

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

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

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

@item afxor32 [dr + offset16], rs
@itemx ws = atomic_fetch_xor ((u32 *)(rd + offset16), ws)
Atomic fetch-and-or instruction
@end table

The above instructions were introduced in the V3 of the BPF
instruction set.  The following instruction is supported for backwards
compatibility:

@table @code
@item xaddw [rd + offset16], rs
Alias to @code{aadd32}.
@end table