Debian Codegraph @

gcc/config/bpf/bpf.md

raw
1 ;; Machine description for eBPF.
2 ;; Copyright (C) 2019-2025 Free Software Foundation, Inc.
3
4 ;; This file is part of GCC.
5
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
10
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
15
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 (include "predicates.md")
21 (include "constraints.md")
22
23 ;;;; Instruction Scheduler FSM
24
25 ;; This is just to get INSN_SCHEDULING defined, so that combine does
26 ;; not make paradoxical subregs of memory. These subregs seems to
27 ;; confuse LRA that ends generating wrong instructions.
28
29 (define_automaton "frob")
30 (define_cpu_unit "frob_unit" "frob")
31 (define_insn_reservation "frobnicator" 814
32 (const_int 0) "frob_unit")
33
34 ;;;; Unspecs
35
36 (define_c_enum "unspec" [
37 UNSPEC_LDINDABS
38 UNSPEC_AADD
39 UNSPEC_AAND
40 UNSPEC_AOR
41 UNSPEC_AXOR
42 UNSPEC_AFADD
43 UNSPEC_AFAND
44 UNSPEC_AFOR
45 UNSPEC_AFXOR
46 UNSPEC_AXCHG
47 UNSPEC_ACMP
48 UNSPEC_CORE_RELOC
49 ])
50
51 ;;;; Constants
52
53 (define_constants
54 [(R0_REGNUM 0)
55 (R1_REGNUM 1)
56 (R2_REGNUM 2)
57 (R3_REGNUM 3)
58 (R4_REGNUM 4)
59 (R5_REGNUM 5)
60 (R6_REGNUM 6)
61 (R7_REGNUM 7)
62 (R8_REGNUM 8)
63 (R9_REGNUM 9)
64 (R10_REGNUM 10)
65 (R11_REGNUM 11)
66 ])
67
68 ;;;; Attributes
69
70 ;; Instruction classes.
71 ;; alu 64-bit arithmetic.
72 ;; alu32 32-bit arithmetic.
73 ;; end endianness conversion or byte swap instructions.
74 ;; ld load instructions.
75 ;; lddx load 64-bit immediate instruction.
76 ;; ldx generic load instructions.
77 ;; st generic store instructions for immediates.
78 ;; stx generic store instructions.
79 ;; jmp jump instructions.
80 ;; multi multiword sequence (or user asm statements).
81
82 (define_attr "type"
83 "unknown,alu,alu32,end,ld,lddw,ldx,st,stx,jmp,multi,atomic"
84 (const_string "unknown"))
85
86 ;; Length of instruction in bytes.
87 (define_attr "length" ""
88 (cond [
89 (eq_attr "type" "lddw") (const_int 16)
90 ] (const_int 8)))
91
92 ;; Describe a user's asm statement.
93 (define_asm_attributes
94 [(set_attr "type" "multi")])
95
96 ;;;; Mode attributes and iterators
97
98 (define_mode_attr mop [(QI "b") (HI "h") (SI "w") (DI "dw")
99 (SF "w") (DF "dw")])
100 (define_mode_attr smop [(QI "u8") (HI "u16") (SI "u32") (DI "u64")
101 (SF "u32") (DF "u64")])
102 (define_mode_attr mtype [(SI "alu32") (DI "alu")])
103 (define_mode_attr msuffix [(SI "32") (DI "")])
104
105 ;;;; NOPs
106
107 ;; The Linux kernel verifier performs some optimizations that rely on
108 ;; nop instructions to be encoded as `ja 0', i.e. a jump to offset 0,
109 ;; which actually means to jump to the next instruction, since in BPF
110 ;; offsets are expressed in 64-bit words _minus one_.
111
112 (define_insn "nop"
113 [(const_int 0)]
114 ""
115 "{ja\t0|goto 0}"
116 [(set_attr "type" "alu")])
117
118 ;;;; Stack usage
119
120 (define_expand "allocate_stack"
121 [(match_operand:DI 0 "general_operand" "")
122 (match_operand:DI 1 "general_operand" "")]
123 ""
124 {
125 sorry ("dynamic stack allocation not supported");
126 emit_insn (gen_nop ());
127 DONE;
128 })
129
130 ;;;; Arithmetic/Logical
131
132 ;; The arithmetic and logic operations below are defined for SI and DI
133 ;; modes. The mode iterator AM is used in order to expand to two
134 ;; insns, with the proper modes.
135 ;;
136 ;; 32-bit arithmetic (for SI modes) is implemented using the alu32
137 ;; instructions, if available.
138
139 (define_mode_iterator AM [(SI "bpf_has_alu32") DI])
140
141 ;;; Addition
142 (define_insn "add<AM:mode>3"
143 [(set (match_operand:AM 0 "register_operand" "=r,r")
144 (plus:AM (match_operand:AM 1 "register_operand" " 0,0")
145 (match_operand:AM 2 "reg_or_imm_operand" " r,I")))]
146 "1"
147 "{add<msuffix>\t%0,%2|%w0 += %w2}"
148 [(set_attr "type" "<mtype>")])
149
150 ;;; Subtraction
151
152 ;; Note that subtractions of constants become additions, so there is
153 ;; no need to handle immediate operands in the subMODE3 insns.
154
155 (define_insn "sub<AM:mode>3"
156 [(set (match_operand:AM 0 "register_operand" "=r")
157 (minus:AM (match_operand:AM 1 "register_operand" " 0")
158 (match_operand:AM 2 "register_operand" " r")))]
159 ""
160 "{sub<msuffix>\t%0,%2|%w0 -= %w2}"
161 [(set_attr "type" "<mtype>")])
162
163 ;;; Negation
164 (define_insn "neg<AM:mode>2"
165 [(set (match_operand:AM 0 "register_operand" "=r")
166 (neg:AM (match_operand:AM 1 "register_operand" " 0")))]
167 ""
168 "{neg<msuffix>\t%0|%w0 = -%w1}"
169 [(set_attr "type" "<mtype>")])
170
171 ;;; Multiplication
172 (define_insn "mul<AM:mode>3"
173 [(set (match_operand:AM 0 "register_operand" "=r,r")
174 (mult:AM (match_operand:AM 1 "register_operand" " 0,0")
175 (match_operand:AM 2 "reg_or_imm_operand" " r,I")))]
176 ""
177 "{mul<msuffix>\t%0,%2|%w0 *= %w2}"
178 [(set_attr "type" "<mtype>")])
179
180 (define_insn "*mulsidi3_zeroextend"
181 [(set (match_operand:DI 0 "register_operand" "=r,r")
182 (zero_extend:DI
183 (mult:SI (match_operand:SI 1 "register_operand" "0,0")
184 (match_operand:SI 2 "reg_or_imm_operand" "r,I"))))]
185 ""
186 "{mul32\t%0,%2|%W0 *= %W2}"
187 [(set_attr "type" "alu32")])
188
189 ;;; Division
190
191 ;; Note that eBPF <= V3 doesn't provide instructions for signed
192 ;; integer division.
193
194 (define_insn "udiv<AM:mode>3"
195 [(set (match_operand:AM 0 "register_operand" "=r,r")
196 (udiv:AM (match_operand:AM 1 "register_operand" " 0,0")
197 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
198 ""
199 "{div<msuffix>\t%0,%2|%w0 /= %w2}"
200 [(set_attr "type" "<mtype>")])
201
202 ;; However, BPF V4 does provide a signed division operator, sdiv.
203
204 (define_insn "div<AM:mode>3"
205 [(set (match_operand:AM 0 "register_operand" "=r,r")
206 (div:AM (match_operand:AM 1 "register_operand" " 0,0")
207 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
208 "bpf_has_sdiv"
209 "{sdiv<msuffix>\t%0,%2|%w0 s/= %w2}"
210 [(set_attr "type" "<mtype>")])
211
212 ;;; Modulus
213
214 ;; Note that eBPF <= V3 doesn't provide instructions for signed
215 ;; integer remainder.
216
217 (define_insn "umod<AM:mode>3"
218 [(set (match_operand:AM 0 "register_operand" "=r,r")
219 (umod:AM (match_operand:AM 1 "register_operand" " 0,0")
220 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
221 ""
222 "{mod<msuffix>\t%0,%2|%w0 %%= %w2}"
223 [(set_attr "type" "<mtype>")])
224
225 ;; However, BPF V4 does provide a signed modulus operator, smod.
226
227 (define_insn "mod<AM:mode>3"
228 [(set (match_operand:AM 0 "register_operand" "=r,r")
229 (mod:AM (match_operand:AM 1 "register_operand" " 0,0")
230 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
231 "bpf_has_sdiv"
232 "{smod<msuffix>\t%0,%2|%w0 s%%= %w2}"
233 [(set_attr "type" "<mtype>")])
234
235 ;;; Logical AND
236 (define_insn "and<AM:mode>3"
237 [(set (match_operand:AM 0 "register_operand" "=r,r")
238 (and:AM (match_operand:AM 1 "register_operand" " 0,0")
239 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
240 ""
241 "{and<msuffix>\t%0,%2|%w0 &= %w2}"
242 [(set_attr "type" "<mtype>")])
243
244 ;;; Logical inclusive-OR
245 (define_insn "ior<AM:mode>3"
246 [(set (match_operand:AM 0 "register_operand" "=r,r")
247 (ior:AM (match_operand:AM 1 "register_operand" " 0,0")
248 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
249 ""
250 "{or<msuffix>\t%0,%2|%w0 %|= %w2}"
251 [(set_attr "type" "<mtype>")])
252
253 ;;; Logical exclusive-OR
254 (define_insn "xor<AM:mode>3"
255 [(set (match_operand:AM 0 "register_operand" "=r,r")
256 (xor:AM (match_operand:AM 1 "register_operand" " 0,0")
257 (match_operand:AM 2 "reg_or_imm_operand" "r,I")))]
258 ""
259 "{xor<msuffix>\t%0,%2|%w0 ^= %w2}"
260 [(set_attr "type" "<mtype>")])
261
262 ;;;; Conversions
263
264 ;;; Zero-extensions
265
266 ;; For register operands smaller than 32-bit zero-extending is
267 ;; achieved ANDing the value in the source register to a suitable
268 ;; mask.
269 ;;
270 ;; For register operands bigger or equal than 32-bit, we generate a
271 ;; mov32 instruction to zero the high 32-bits of the destination
272 ;; register.
273 ;;
274 ;; For memory operands, of any width, zero-extending is achieved using
275 ;; the ldx{bhwdw} instructions to load the values in registers.
276
277 (define_insn "zero_extendhidi2"
278 [(set (match_operand:DI 0 "register_operand" "=r,r,r")
279 (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "0,r,q")))]
280 ""
281 "@
282 {and\t%0,0xffff|%0 &= 0xffff}
283 *return bpf_output_move (operands, \"{mov\t%0,%1\;and\t%0,0xffff|%0 = %1;%0 &= 0xffff}\");
284 *return bpf_output_move (operands, \"{ldxh\t%0,%1|%0 = *(u16 *) %1}\");"
285 [(set_attr "type" "alu,alu,ldx")])
286
287 (define_insn "zero_extendqidi2"
288 [(set (match_operand:DI 0 "register_operand" "=r,r,r")
289 (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "0,r,q")))]
290 ""
291 "@
292 {and\t%0,0xff|%0 &= 0xff}
293 *return bpf_output_move (operands, \"{mov\t%0,%1\;and\t%0,0xff|%0 = %1;%0 &= 0xff}\");
294 *return bpf_output_move (operands, \"{ldxb\t%0,%1|%0 = *(u8 *) %1}\");"
295 [(set_attr "type" "alu,alu,ldx")])
296
297 (define_insn "zero_extendsidi2"
298 [(set (match_operand:DI 0 "register_operand" "=r,r")
299 (zero_extend:DI
300 (match_operand:SI 1 "nonimmediate_operand" "r,q")))]
301 ""
302 "@
303 *return bpf_output_move (operands, bpf_has_alu32 ? \"{mov32\t%0,%1|%W0 = %W1}\" : \"{mov\t%0,%1\;and\t%0,0xffffffff|%0 = %1;%0 &= 0xffffffff}\");
304 *return bpf_output_move (operands, \"{ldxw\t%0,%1|%0 = *(u32 *) %1}\");"
305 [(set_attr "type" "alu,ldx")])
306
307 ;;; Sign-extension
308
309 ;; Sign-extending a 32-bit value into a 64-bit value is achieved using
310 ;; shifting, with instructions generated by the expand below.
311
312 (define_expand "extendsidi2"
313 [(set (match_operand:DI 0 "register_operand")
314 (sign_extend:DI (match_operand:SI 1 "register_operand")))]
315 ""
316 {
317 operands[1] = gen_lowpart (DImode, operands[1]);
318 emit_insn (gen_ashldi3 (operands[0], operands[1], GEN_INT (32)));
319 emit_insn (gen_ashrdi3 (operands[0], operands[0], GEN_INT (32)));
320 DONE;
321 })
322
323 ;; ISA V4 introduces sign-extending move and load operations.
324
325 (define_insn "*extendsidi2"
326 [(set (match_operand:DI 0 "register_operand" "=r,r")
327 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,q")))]
328 "bpf_has_smov"
329 "@
330 *return bpf_output_move (operands, \"{movs\t%0,%1,32|%0 = (s32) %1}\");
331 *return bpf_output_move (operands, \"{ldxsw\t%0,%1|%0 = *(s32 *) %1}\");"
332 [(set_attr "type" "alu,ldx")])
333
334 (define_insn "extendhidi2"
335 [(set (match_operand:DI 0 "register_operand" "=r,r")
336 (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,q")))]
337 "bpf_has_smov"
338 "@
339 *return bpf_output_move (operands, \"{movs\t%0,%1,16|%0 = (s16) %1}\");
340 *return bpf_output_move (operands, \"{ldxsh\t%0,%1|%0 = *(s16 *) %1}\");"
341 [(set_attr "type" "alu,ldx")])
342
343 (define_insn "extendqidi2"
344 [(set (match_operand:DI 0 "register_operand" "=r,r")
345 (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "r,q")))]
346 "bpf_has_smov"
347 "@
348 *return bpf_output_move (operands, \"{movs\t%0,%1,8|%0 = (s8) %1}\");
349 *return bpf_output_move (operands, \"{ldxsb\t%0,%1|%0 = *(s8 *) %1}\");"
350 [(set_attr "type" "alu,ldx")])
351
352 (define_insn "extendhisi2"
353 [(set (match_operand:SI 0 "register_operand" "=r")
354 (sign_extend:SI (match_operand:HI 1 "register_operand" "r")))]
355 "bpf_has_smov"
356 "*return bpf_output_move (operands, \"{movs32\t%0,%1,16|%w0 = (s16) %w1}\");"
357 [(set_attr "type" "alu")])
358
359 (define_insn "extendqisi2"
360 [(set (match_operand:SI 0 "register_operand" "=r")
361 (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
362 "bpf_has_smov"
363 "*return bpf_output_move (operands, \"{movs32\t%0,%1,8|%w0 = (s8) %w1}\");"
364 [(set_attr "type" "alu")])
365
366 ;;;; Data movement
367
368 (define_mode_iterator MM [QI HI SI DI SF DF])
369
370 (define_expand "mov<MM:mode>"
371 [(set (match_operand:MM 0 "general_operand")
372 (match_operand:MM 1 "general_operand"))]
373 ""
374 "
375 {
376 if (!register_operand(operands[0], <MM:MODE>mode)
377 && !register_operand(operands[1], <MM:MODE>mode))
378 operands[1] = force_reg (<MM:MODE>mode, operands[1]);
379 }")
380
381 (define_insn "*mov<MM:mode>"
382 [(set (match_operand:MM 0 "nonimmediate_operand" "=r, r, r,q,q")
383 (match_operand:MM 1 "mov_src_operand" " q,rIc,BC,r,I"))]
384 ""
385 "@
386 *return bpf_output_move (operands, \"{ldx<mop>\t%0,%1|%0 = *(<smop> *) %1}\");
387 *return bpf_output_move (operands, \"{mov\t%0,%1|%0 = %1}\");
388 *return bpf_output_move (operands, \"{lddw\t%0,%1|%0 = %1 ll}\");
389 *return bpf_output_move (operands, \"{stx<mop>\t%0,%1|*(<smop> *) %0 = %1}\");
390 *return bpf_output_move (operands, \"{st<mop>\t%0,%1|*(<smop> *) %0 = %1}\");"
391 [(set_attr "type" "ldx,alu,alu,stx,st")])
392
393 ;;;; Shifts
394
395 (define_mode_iterator SIM [(SI "bpf_has_alu32") DI])
396
397 (define_insn "ashr<SIM:mode>3"
398 [(set (match_operand:SIM 0 "register_operand" "=r,r")
399 (ashiftrt:SIM (match_operand:SIM 1 "register_operand" " 0,0")
400 (match_operand:SIM 2 "reg_or_imm_operand" " r,I")))]
401 ""
402 "{arsh<msuffix>\t%0,%2|%w0 s>>= %w2}"
403 [(set_attr "type" "<mtype>")])
404
405 (define_insn "ashl<SIM:mode>3"
406 [(set (match_operand:SIM 0 "register_operand" "=r,r")
407 (ashift:SIM (match_operand:SIM 1 "register_operand" " 0,0")
408 (match_operand:SIM 2 "reg_or_imm_operand" " r,I")))]
409 ""
410 "{lsh<msuffix>\t%0,%2|%w0 <<= %w2}"
411 [(set_attr "type" "<mtype>")])
412
413 (define_insn "lshr<SIM:mode>3"
414 [(set (match_operand:SIM 0 "register_operand" "=r,r")
415 (lshiftrt:SIM (match_operand:SIM 1 "register_operand" " 0,0")
416 (match_operand:SIM 2 "reg_or_imm_operand" " r,I")))]
417 ""
418 "{rsh<msuffix>\t%0,%2|%w0 >>= %w2}"
419 [(set_attr "type" "<mtype>")])
420
421 ;;;; Byte swapping
422
423 (define_mode_iterator BSM [HI SI DI])
424 (define_mode_attr endmode [(HI "16") (SI "32") (DI "64")])
425
426 (define_insn "bswap<BSM:mode>2"
427 [(set (match_operand:BSM 0 "register_operand" "=r")
428 (bswap:BSM (match_operand:BSM 1 "register_operand" " 0")))]
429 ""
430 {
431 if (bpf_has_bswap)
432 return "{bswap\t%0, <endmode>|%0 = bswap<endmode> %1}";
433 else
434 {
435 if (TARGET_BIG_ENDIAN)
436 return "{endle\t%0, <endmode>|%0 = le<endmode> %1}";
437 else
438 return "{endbe\t%0, <endmode>|%0 = be<endmode> %1}";
439 }
440 }
441 [(set_attr "type" "end")])
442
443 ;;;; Conditional branches
444
445 ;; The eBPF jump instructions use 64-bit arithmetic when evaluating
446 ;; the jump conditions. Therefore we use DI modes below.
447
448 (define_mode_iterator JM [(SI "bpf_has_jmp32") DI])
449
450 (define_expand "cbranch<JM:mode>4"
451 [(set (pc)
452 (if_then_else (match_operator 0 "comparison_operator"
453 [(match_operand:JM 1 "register_operand")
454 (match_operand:JM 2 "reg_or_imm_operand")])
455 (label_ref (match_operand 3 "" ""))
456 (pc)))]
457 ""
458 {
459 if (!ordered_comparison_operator (operands[0], VOIDmode))
460 FAIL;
461
462 bpf_expand_cbranch (<JM:MODE>mode, operands);
463 })
464
465 (define_insn "*branch_on_<JM:mode>"
466 [(set (pc)
467 (if_then_else (match_operator 3 "ordered_comparison_operator"
468 [(match_operand:JM 0 "register_operand" "r")
469 (match_operand:JM 1 "reg_or_imm_operand" "rI")])
470 (label_ref (match_operand 2 "" ""))
471 (pc)))]
472 ""
473 {
474 int code = GET_CODE (operands[3]);
475
476 switch (code)
477 {
478 case EQ: return "{jeq<msuffix>\t%0,%1,%2|if %w0 == %w1 goto %2}"; break;
479 case NE: return "{jne<msuffix>\t%0,%1,%2|if %w0 != %w1 goto %2}"; break;
480 case LT: return "{jslt<msuffix>\t%0,%1,%2|if %w0 s< %w1 goto %2}"; break;
481 case LE: return "{jsle<msuffix>\t%0,%1,%2|if %w0 s<= %w1 goto %2}"; break;
482 case GT: return "{jsgt<msuffix>\t%0,%1,%2|if %w0 s> %w1 goto %2}"; break;
483 case GE: return "{jsge<msuffix>\t%0,%1,%2|if %w0 s>= %w1 goto %2}"; break;
484 case LTU: return "{jlt<msuffix>\t%0,%1,%2|if %w0 < %w1 goto %2}"; break;
485 case LEU: return "{jle<msuffix>\t%0,%1,%2|if %w0 <= %w1 goto %2}"; break;
486 case GTU: return "{jgt<msuffix>\t%0,%1,%2|if %w0 > %w1 goto %2}"; break;
487 case GEU: return "{jge<msuffix>\t%0,%1,%2|if %w0 >= %w1 goto %2}"; break;
488 default:
489 gcc_unreachable ();
490 return "";
491 }
492 }
493 [(set_attr "type" "jmp")])
494
495 ;;;; Unconditional branches
496
497 (define_insn "jump"
498 [(set (pc)
499 (label_ref (match_operand 0 "" "")))]
500 ""
501 "{ja\t%0|goto %0}"
502 [(set_attr "type" "jmp")])
503
504 ;;;; Function prologue/epilogue
505
506 (define_insn "exit"
507 [(simple_return)]
508 ""
509 "exit"
510 [(set_attr "type" "jmp")])
511
512 (define_expand "prologue"
513 [(const_int 0)]
514 ""
515 {
516 bpf_expand_prologue ();
517 DONE;
518 })
519
520 (define_expand "epilogue"
521 [(const_int 0)]
522 ""
523 {
524 bpf_expand_epilogue ();
525 DONE;
526 })
527
528 ;;;; Function calls
529
530 (define_expand "call"
531 [(parallel [(call (match_operand 0 "")
532 (match_operand 1 ""))
533 (use (match_operand 2 "")) ;; next_arg_reg
534 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
535 ""
536 {
537 rtx target = XEXP (operands[0], 0);
538 emit_call_insn (gen_call_internal (target, operands[1]));
539 DONE;
540 })
541
542 (define_insn "call_internal"
543 [(call (mem:DI (match_operand:DI 0 "call_operand" "Sr"))
544 (match_operand:SI 1 "general_operand" ""))]
545 ;; operands[2] is next_arg_register
546 ;; operands[3] is struct_value_size_rtx.
547 ""
548 { return bpf_output_call (operands[0]); }
549 [(set_attr "type" "jmp")])
550
551 (define_expand "call_value"
552 [(parallel [(set (match_operand 0 "")
553 (call (match_operand 1 "")
554 (match_operand 2 "")))
555 (use (match_operand 3 ""))])] ;; next_arg_reg
556 ""
557 {
558 rtx target = XEXP (operands[1], 0);
559 emit_call_insn (gen_call_value_internal (operands[0], target,
560 operands[2]));
561 DONE;
562 })
563
564 (define_insn "call_value_internal"
565 [(set (match_operand 0 "register_operand" "")
566 (call (mem:DI (match_operand:DI 1 "call_operand" "Sr"))
567 (match_operand:SI 2 "general_operand" "")))]
568 ;; operands[3] is next_arg_register
569 ;; operands[4] is struct_value_size_rtx.
570 ""
571 { return bpf_output_call (operands[1]); }
572 [(set_attr "type" "jmp")])
573
574 (define_insn "sibcall"
575 [(call (label_ref (match_operand 0 "" ""))
576 (match_operand:SI 1 "general_operand" ""))]
577 ;; operands[2] is next_arg_register
578 ;; operands[3] is struct_value_size_rtx.
579 ""
580 "{ja\t%0|goto %0}"
581 [(set_attr "type" "jmp")])
582
583 ;;;; Non-generic load instructions
584
585 (define_mode_iterator LDM [QI HI SI DI])
586 (define_mode_attr ldop [(QI "b") (HI "h") (SI "w") (DI "dw")])
587 (define_mode_attr pldop [(QI "u8") (HI "u16") (SI "u32") (DI "u64")])
588
589 (define_insn "ldind<ldop>"
590 [(set (reg:LDM R0_REGNUM)
591 (unspec:LDM [(match_operand:DI 0 "register_operand" "r")
592 (match_operand:SI 1 "imm32_operand" "I")]
593 UNSPEC_LDINDABS))
594 (clobber (reg:DI R1_REGNUM))
595 (clobber (reg:DI R2_REGNUM))
596 (clobber (reg:DI R3_REGNUM))
597 (clobber (reg:DI R4_REGNUM))]
598 ""
599 "{ldind<ldop>\t%0,%1|r0 = *(<pldop> *) skb[%0 + %1]}"
600 [(set_attr "type" "ld")])
601
602 (define_insn "ldabs<ldop>"
603 [(set (reg:LDM R0_REGNUM)
604 (unspec:LDM [(match_operand:SI 0 "imm32_operand" "I")
605 (match_operand:SI 1 "imm32_operand" "I")]
606 UNSPEC_LDINDABS))
607 (clobber (reg:DI R1_REGNUM))
608 (clobber (reg:DI R2_REGNUM))
609 (clobber (reg:DI R3_REGNUM))
610 (clobber (reg:DI R4_REGNUM))]
611 ""
612 "{ldabs<ldop>\t%0|r0 = *(<pldop> *) skb[%0]}"
613 [(set_attr "type" "ld")])
614
615 ;;; memmove and memcopy
616
617 ;; 0 is dst
618 ;; 1 is src
619 ;; 2 is size of copy in bytes
620 ;; 3 is alignment
621
622 (define_expand "cpymemdi"
623 [(match_operand:BLK 0 "memory_operand")
624 (match_operand:BLK 1 "memory_operand")
625 (match_operand:DI 2 "general_operand")
626 (match_operand:DI 3 "immediate_operand")]
627 ""
628 {
629 if (bpf_expand_cpymem (operands, false))
630 DONE;
631 FAIL;
632 })
633
634 ;; 0 is dst
635 ;; 1 is src
636 ;; 2 is size of copy in bytes
637 ;; 3 is alignment
638
639 (define_expand "movmemdi"
640 [(match_operand:BLK 0 "memory_operand")
641 (match_operand:BLK 1 "memory_operand")
642 (match_operand:DI 2 "general_operand")
643 (match_operand:DI 3 "immediate_operand")]
644 ""
645 {
646 if (bpf_expand_cpymem (operands, true))
647 DONE;
648 FAIL;
649 })
650
651 ;; memset
652 ;; 0 is dst
653 ;; 1 is length
654 ;; 2 is value
655 ;; 3 is alignment
656 (define_expand "setmemdi"
657 [(set (match_operand:BLK 0 "memory_operand")
658 (match_operand:QI 2 "nonmemory_operand"))
659 (use (match_operand:DI 1 "general_operand"))
660 (match_operand 3 "immediate_operand")]
661 ""
662 {
663 if (bpf_expand_setmem (operands))
664 DONE;
665 FAIL;
666 })
667
668 (include "atomic.md")