authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-03-25 03:28:11-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-05-11 02:17:11-07:00
log06089fc89a47e6ae84d09e6e21db23b7a57f885e
tree343cb80d558948d9ecc4e2940920c950cb10828b
parentc96989aa4b283c5d386c5f19e2b12a6b13dd521a

riscv: fix how we calculate stack offsets. allows for pass by reference arguments.


1 files changed, 11 insertions(+), 4 deletions(-)

src/arch/riscv64/Emit.zig+11-4
......@@ -536,11 +536,18 @@ fn lowerMir(emit: *Emit) !void {
536536 const data = mir_datas[inst].i_type;
537537 // TODO: probably create a psuedo instruction for s0 loads/stores instead of this.
538538 if (data.rs1 == .s0) {
539 const casted_size = math.cast(i12, emit.stack_size) orelse {
540 return emit.fail("TODO: support bigger stack sizes lowerMir", .{});
541 };
542539 const offset = mir_datas[inst].i_type.imm12;
543 mir_datas[inst].i_type.imm12 = -(casted_size - 12 - offset);
540
541 // sp + 32 (aka s0)
542 // ra -- previous ra spilled
543 // s0 -- previous s0 spilled
544 // --- this is -16(s0)
545
546 // TODO: this "+ 8" is completely arbiratary as the largest possible store
547 // we don't want to actually use it. instead we need to calculate the difference
548 // between the first and second stack store and use it instead.
549
550 mir_datas[inst].i_type.imm12 = -(16 + offset + 8);
544551 }
545552 }
546553