authorgravatar for mattnite@protonmail.comMatt Knight <mattnite@protonmail.com> 2020-08-18 22:18:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-21 11:40:35-07:00
logbc1536f4bf01e45af80a930b31b9271551de1dc0
tree5e4c86125923fee074416a2f50d16b9fe1d26abb
parent7f1378909b54dec1636920389e60d8dfacb4e614

decided to split up loading of 64-bit immediates


1 files changed, 25 insertions(+), 21 deletions(-)

lib/std/os/bits/linux/bpf.zig+25-21
...@@ -460,27 +460,32 @@ pub const Insn = packed struct {...@@ -460,27 +460,32 @@ pub const Insn = packed struct {
460 };460 };
461 }461 }
462462
463 fn ld_imm_impl(dst: Reg, src: Reg, imm: u64) [2]Insn {463 fn ld_imm_impl1(dst: Reg, src: Reg, imm: u64) Insn {
464 return [2]Insn{464 return Insn{
465 Insn{465 .code = LD | DW | IMM,
466 .code = LD | DW | IMM,466 .dst = @enumToInt(dst),
467 .dst = @enumToInt(dst),467 .src = @enumToInt(src),
468 .src = @enumToInt(src),468 .off = 0,
469 .off = 0,469 .imm = @intCast(i32, @truncate(u32, imm)),
470 .imm = @intCast(i32, @truncate(u32, imm)),
471 },
472 Insn{
473 .code = 0,
474 .dst = 0,
475 .src = 0,
476 .off = 0,
477 .imm = @intCast(i32, @truncate(u32, imm >> 32)),
478 },
479 };470 };
480 }471 }
481472
482 pub fn ld_map_fd(dst: Reg, map_fd: fd_t) [2]Insn {473 fn ld_imm_impl2(imm: u64) Insn {
483 return ld_imm_impl(dst, @intToEnum(Reg, PSEUDO_MAP_FD), @intCast(u64, map_fd));474 return Insn{
475 .code = 0,
476 .dst = 0,
477 .src = 0,
478 .off = 0,
479 .imm = @intCast(i32, @truncate(u32, imm >> 32)),
480 };
481 }
482
483 pub fn ld_map_fd1(dst: Reg, map_fd: fd_t) Insn {
484 return ld_imm_impl1(dst, @intToEnum(Reg, PSEUDO_MAP_FD), @intCast(u64, map_fd));
485 }
486
487 pub fn ld_map_fd2(map_fd: fd_t) Insn {
488 return ld_imm_impl2(@intCast(u64, map_fd));
484 }489 }
485490
486 pub fn call(helper: Helper) Insn {491 pub fn call(helper: Helper) Insn {
...@@ -533,9 +538,8 @@ test "ld_abs" {...@@ -533,9 +538,8 @@ test "ld_abs" {
533}538}
534539
535test "ld_map_fd" {540test "ld_map_fd" {
536 const insns = Insn.ld_map_fd(.r1, 42);541 expect_insn(Insn.ld_map_fd1(.r1, 42), 0x0000002a00001118);
537 expect_insn(insns[0], 0x0000002a00001118);542 expect_insn(Insn.ld_map_fd2(42), 0x0000000000000000);
538 expect_insn(insns[1], 0x0000000000000000);
539}543}
540544
541// st instructions545// st instructions