| ... | ... | @@ -460,27 +460,32 @@ pub const Insn = packed struct { |
| 460 | 460 | }; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | | fn ld_imm_impl(dst: Reg, src: Reg, imm: u64) [2]Insn { |
| 464 | | return [2]Insn{ |
| 465 | | Insn{ |
| 466 | | .code = LD | DW | IMM, |
| 467 | | .dst = @enumToInt(dst), |
| 468 | | .src = @enumToInt(src), |
| 469 | | .off = 0, |
| 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 | | }, |
| 463 | fn ld_imm_impl1(dst: Reg, src: Reg, imm: u64) Insn { |
| 464 | return Insn{ |
| 465 | .code = LD | DW | IMM, |
| 466 | .dst = @enumToInt(dst), |
| 467 | .src = @enumToInt(src), |
| 468 | .off = 0, |
| 469 | .imm = @intCast(i32, @truncate(u32, imm)), |
| 479 | 470 | }; |
| 480 | 471 | } |
| 481 | 472 | |
| 482 | | pub fn ld_map_fd(dst: Reg, map_fd: fd_t) [2]Insn { |
| 483 | | return ld_imm_impl(dst, @intToEnum(Reg, PSEUDO_MAP_FD), @intCast(u64, map_fd)); |
| 473 | fn ld_imm_impl2(imm: u64) Insn { |
| 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 | } |
| 485 | 490 | |
| 486 | 491 | pub fn call(helper: Helper) Insn { |
| ... | ... | @@ -533,9 +538,8 @@ test "ld_abs" { |
| 533 | 538 | } |
| 534 | 539 | |
| 535 | 540 | test "ld_map_fd" { |
| 536 | | const insns = Insn.ld_map_fd(.r1, 42); |
| 537 | | expect_insn(insns[0], 0x0000002a00001118); |
| 538 | | expect_insn(insns[1], 0x0000000000000000); |
| 541 | expect_insn(Insn.ld_map_fd1(.r1, 42), 0x0000002a00001118); |
| 542 | expect_insn(Insn.ld_map_fd2(42), 0x0000000000000000); |
| 539 | 543 | } |
| 540 | 544 | |
| 541 | 545 | // st instructions |