authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-07-27 08:14:09-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-07-27 08:14:09-07:00
logb20007daf74f44cfc86c5f2d2d7e2acde079e127
tree2e668e489364df07df79ce949a0801a72c2012b9
parent8f84212855115799def2106e8b3a807c766058ed
signaturelock-open Commit is signed but in an unrecognized format.

riscv: correct airAsm to generate correct jalr call


1 files changed, 30 insertions(+), 14 deletions(-)

src/arch/riscv64/CodeGen.zig+30-14
......@@ -1841,7 +1841,7 @@ fn finishAir(
18411841}
18421842
18431843const FrameLayout = struct {
1844 stack_adjust: u32,
1844 stack_adjust: i12,
18451845 save_reg_list: Mir.RegisterList,
18461846};
18471847
......@@ -1855,10 +1855,7 @@ fn setFrameLoc(
18551855 const frame_i = @intFromEnum(frame_index);
18561856 if (aligned) {
18571857 const alignment: InternPool.Alignment = func.frame_allocs.items(.abi_align)[frame_i];
1858 offset.* = if (math.sign(offset.*) < 0)
1859 -1 * @as(i32, @intCast(alignment.backward(@intCast(@abs(offset.*)))))
1860 else
1861 @intCast(alignment.forward(@intCast(@abs(offset.*))));
1858 offset.* = math.sign(offset.*) * @as(i32, @intCast(alignment.backward(@intCast(@abs(offset.*)))));
18621859 }
18631860 func.frame_locs.set(frame_i, .{ .base = base, .disp = offset.* });
18641861 offset.* += func.frame_allocs.items(.abi_size)[frame_i];
......@@ -6216,7 +6213,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {
62166213 .jalr => try func.addInst(.{
62176214 .tag = mnem,
62186215 .data = .{ .i_type = .{
6219 .rd = .zero,
6216 .rd = .ra,
62206217 .rs1 = reg1,
62216218 .imm12 = Immediate.s(0),
62226219 } },
......@@ -7337,15 +7334,34 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
73377334 else => return func.fail("TODO: airCmpxchg Int size {}", .{val_abi_size}),
73387335 }
73397336
7340 const succ_order: struct { aq: Mir.Barrier, rl: Mir.Barrier } = switch (extra.successOrder()) {
7337 const lr_order: struct { aq: Mir.Barrier, rl: Mir.Barrier } = switch (extra.successOrder()) {
7338 .unordered,
7339 => unreachable,
7340
7341 .monotonic,
7342 .release,
7343 => .{ .aq = .none, .rl = .none },
7344 .acquire,
7345 .acq_rel,
7346 => .{ .aq = .aq, .rl = .none },
7347 .seq_cst => .{ .aq = .aq, .rl = .rl },
7348 };
7349
7350 const sc_order: struct { aq: Mir.Barrier, rl: Mir.Barrier } = switch (extra.failureOrder()) {
73417351 .unordered,
73427352 .release,
73437353 .acq_rel,
73447354 => unreachable,
73457355
7346 .monotonic => .{ .aq = .none, .rl = .none },
7347 .acquire => .{ .aq = .aq, .rl = .none },
7348 .seq_cst => .{ .aq = .aq, .rl = .rl },
7356 .monotonic,
7357 .acquire,
7358 .seq_cst,
7359 => switch (extra.successOrder()) {
7360 .release,
7361 .seq_cst,
7362 => .{ .aq = .none, .rl = .rl },
7363 else => .{ .aq = .none, .rl = .none },
7364 },
73497365 };
73507366
73517367 const ptr_mcv = try func.resolveInst(extra.ptr);
......@@ -7371,8 +7387,8 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
73717387 const jump_back = try func.addInst(.{
73727388 .tag = if (val_ty.bitSize(pt) <= 32) .lrw else .lrd,
73737389 .data = .{ .amo = .{
7374 .aq = succ_order.aq,
7375 .rl = succ_order.rl,
7390 .aq = lr_order.aq,
7391 .rl = lr_order.rl,
73767392 .rd = branch_reg,
73777393 .rs1 = ptr_reg,
73787394 .rs2 = .zero,
......@@ -7392,8 +7408,8 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
73927408 _ = try func.addInst(.{
73937409 .tag = if (val_ty.bitSize(pt) <= 32) .scw else .scd,
73947410 .data = .{ .amo = .{
7395 .aq = .none,
7396 .rl = succ_order.rl,
7411 .aq = sc_order.aq,
7412 .rl = sc_order.rl,
73977413 .rd = fallthrough_reg,
73987414 .rs1 = ptr_reg,
73997415 .rs2 = new_reg,