authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2023-01-04 12:53:11+07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 16:46:04-07:00
log486ab3852e22f8d5ba474691a5b068f1f1729f2e
treed236d70245f80793cc19b6000286a47123320bf9
parentcc2a5185d631b8b33eb5d466cc52ceb092435fd4

stage2: sparc64: Factor machine offset calculation


1 files changed, 16 insertions(+), 3 deletions(-)

src/arch/sparc64/CodeGen.zig+16-3
......@@ -141,6 +141,8 @@ const MCValue = union(enum) {
141141 /// The value is one of the stack variables.
142142 /// If the type is a pointer, it means the pointer address is in the stack at this offset.
143143 /// Note that this stores the plain value (i.e without the effects of the stack bias).
144 /// Always convert this value into machine offsets with realStackOffset() before
145 /// lowering into asm!
144146 stack_offset: u32,
145147 /// The value is a pointer to one of the stack variables (payload is stack offset).
146148 ptr_stack_offset: u32,
......@@ -3651,7 +3653,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
36513653 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });
36523654 },
36533655 .ptr_stack_offset => |off| {
3654 const real_offset = off + abi.stack_bias + abi.stack_reserved_area;
3656 const real_offset = realStackOffset(off);
36553657 const simm13 = math.cast(i13, real_offset) orelse
36563658 return self.fail("TODO larger stack offsets: {}", .{real_offset});
36573659
......@@ -3783,7 +3785,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
37833785 try self.genLoad(reg, reg, i13, 0, ty.abiSize(self.target.*));
37843786 },
37853787 .stack_offset => |off| {
3786 const real_offset = off + abi.stack_bias + abi.stack_reserved_area;
3788 const real_offset = realStackOffset(off);
37873789 const simm13 = math.cast(i13, real_offset) orelse
37883790 return self.fail("TODO larger stack offsets: {}", .{real_offset});
37893791 try self.genLoad(reg, .sp, i13, simm13, ty.abiSize(self.target.*));
......@@ -3817,7 +3819,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
38173819 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
38183820 },
38193821 .register => |reg| {
3820 const real_offset = stack_offset + abi.stack_bias + abi.stack_reserved_area;
3822 const real_offset = realStackOffset(stack_offset);
38213823 const simm13 = math.cast(i13, real_offset) orelse
38223824 return self.fail("TODO larger stack offsets: {}", .{real_offset});
38233825 return self.genStore(reg, .sp, i13, simm13, abi_size);
......@@ -4252,6 +4254,17 @@ fn processDeath(self: *Self, inst: Air.Inst.Index) void {
42524254 }
42534255}
42544256
4257/// Turns stack_offset MCV into a real SPARCv9 stack offset usable for asm.
4258fn realStackOffset(off: u32) u32 {
4259 return off
4260 // SPARCv9 %sp points away from the stack by some amount.
4261 + abi.stack_bias
4262 // The first couple bytes of each stack frame is reserved
4263 // for ABI and hardware purposes.
4264 + abi.stack_reserved_area;
4265 // Only after that we have the usable stack frame portion.
4266}
4267
42554268/// Caller must call `CallMCValues.deinit`.
42564269fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) !CallMCValues {
42574270 const cc = fn_ty.fnCallingConvention();