authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-05 17:45:02-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-07 00:29:17-04:00
log9f8b2ff9e223315682fbe9237239714b7d8883f6
tree562887294a349bf7213756059147e3726d6ad99d
parentd68f39b5412e0aeb59d71c9f676221212261dc8c

x86_64: fix C abi typos


2 files changed, 38 insertions(+), 22 deletions(-)

src/arch/x86_64/CodeGen.zig+33-17
...@@ -2568,7 +2568,7 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -2568,7 +2568,7 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
2568 80, 128 => true,2568 80, 128 => true,
2569 else => unreachable,2569 else => unreachable,
2570 },2570 },
2571 80 => switch (dst_bits) {2571 80 => switch (src_bits) {
2572 128 => true,2572 128 => true,
2573 else => unreachable,2573 else => unreachable,
2574 },2574 },
...@@ -10278,6 +10278,8 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {...@@ -10278,6 +10278,8 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
10278}10278}
1027910279
10280fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {10280fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
10281 const mod = self.bin_file.options.module.?;
10282
10281 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;10283 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
10282 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);10284 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
1028310285
...@@ -10315,18 +10317,31 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError...@@ -10315,18 +10317,31 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError
10315 .off = -dst_reg_off.off,10317 .off = -dst_reg_off.off,
10316 } },10318 } },
10317 }),10319 }),
10318 .register_pair => |dst_regs| for (dst_regs, 0..) |dst_reg, dst_reg_i| switch (src_mcv) {10320 .register_pair => |dst_regs| {
10319 .register_pair => |src_regs| try self.genSetReg(10321 switch (src_mcv) {
10320 dst_reg,10322 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref)),
10321 Type.usize,10323 else => {},
10322 .{ .register = src_regs[dst_reg_i] },10324 }
10323 ),10325 const classes = mem.sliceTo(&abi.classifySystemV(ty, mod, .other), .none);
10324 else => try self.genSetReg(10326 for (dst_regs, classes, 0..) |dst_reg, class, dst_reg_i| {
10325 dst_reg,10327 const class_ty = switch (class) {
10326 Type.usize,10328 .integer => Type.usize,
10327 src_mcv.address().offset(@intCast(dst_reg_i * 8)).deref(),10329 .sse => Type.f64,
10328 ),10330 else => unreachable,
10329 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref)),10331 };
10332 switch (src_mcv) {
10333 .register_pair => |src_regs| try self.genSetReg(
10334 dst_reg,
10335 class_ty,
10336 .{ .register = src_regs[dst_reg_i] },
10337 ),
10338 else => try self.genSetReg(
10339 dst_reg,
10340 class_ty,
10341 src_mcv.address().offset(@intCast(dst_reg_i * 8)).deref(),
10342 ),
10343 }
10344 }
10330 },10345 },
10331 .indirect => |reg_off| try self.genSetMem(.{ .reg = reg_off.reg }, reg_off.off, ty, src_mcv),10346 .indirect => |reg_off| try self.genSetMem(.{ .reg = reg_off.reg }, reg_off.off, ty, src_mcv),
10332 .memory, .load_direct, .load_got, .load_tlv => {10347 .memory, .load_direct, .load_got, .load_tlv => {
...@@ -12566,7 +12581,7 @@ fn resolveCallingConventionValues(...@@ -12566,7 +12581,7 @@ fn resolveCallingConventionValues(
1256612581
12567 const classes = switch (resolved_cc) {12582 const classes = switch (resolved_cc) {
12568 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, mod, .ret), .none),12583 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, mod, .ret), .none),
12569 .Win64 => &[1]abi.Class{abi.classifyWindows(ret_ty, mod)},12584 .Win64 => &.{abi.classifyWindows(ret_ty, mod)},
12570 else => unreachable,12585 else => unreachable,
12571 };12586 };
12572 for (classes) |class| switch (class) {12587 for (classes) |class| switch (class) {
...@@ -12639,9 +12654,10 @@ fn resolveCallingConventionValues(...@@ -12639,9 +12654,10 @@ fn resolveCallingConventionValues(
12639 var arg_mcv: [2]MCValue = undefined;12654 var arg_mcv: [2]MCValue = undefined;
12640 var arg_mcv_i: usize = 0;12655 var arg_mcv_i: usize = 0;
1264112656
12642 const classes = switch (self.target.os.tag) {12657 const classes = switch (resolved_cc) {
12643 .windows => &[1]abi.Class{abi.classifyWindows(ty, mod)},12658 .SysV => mem.sliceTo(&abi.classifySystemV(ty, mod, .arg), .none),
12644 else => mem.sliceTo(&abi.classifySystemV(ty, mod, .arg), .none),12659 .Win64 => &.{abi.classifyWindows(ty, mod)},
12660 else => unreachable,
12645 };12661 };
12646 for (classes) |class| switch (class) {12662 for (classes) |class| switch (class) {
12647 .integer => {12663 .integer => {
src/arch/x86_64/abi.zig+5-5
...@@ -64,7 +64,7 @@ pub fn classifyWindows(ty: Type, mod: *Module) Class {...@@ -64,7 +64,7 @@ pub fn classifyWindows(ty: Type, mod: *Module) Class {
64 }64 }
65}65}
6666
67pub const Context = enum { ret, arg, other };67pub const Context = enum { ret, arg, field, other };
6868
69/// There are a maximum of 8 possible return slots. Returned values are in69/// There are a maximum of 8 possible return slots. Returned values are in
70/// the beginning of the array; unused slots are filled with .none.70/// the beginning of the array; unused slots are filled with .none.
...@@ -120,7 +120,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -120,7 +120,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
120 },120 },
121 .Float => switch (ty.floatBits(target)) {121 .Float => switch (ty.floatBits(target)) {
122 16 => {122 16 => {
123 if (ctx == .other) {123 if (ctx == .field) {
124 result[0] = .memory;124 result[0] = .memory;
125 } else {125 } else {
126 // TODO clang doesn't allow __fp16 as .ret or .arg126 // TODO clang doesn't allow __fp16 as .ret or .arg
...@@ -140,7 +140,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -140,7 +140,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
140 // "Arguments of types __float128, _Decimal128 and __m128 are140 // "Arguments of types __float128, _Decimal128 and __m128 are
141 // split into two halves. The least significant ones belong141 // split into two halves. The least significant ones belong
142 // to class SSE, the most significant one to class SSEUP."142 // to class SSE, the most significant one to class SSEUP."
143 if (ctx == .other) {143 if (ctx == .field) {
144 result[0] = .memory;144 result[0] = .memory;
145 return result;145 return result;
146 }146 }
...@@ -229,7 +229,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -229,7 +229,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
229 if (field_align != .none and field_align.compare(.lt, field_ty.abiAlignment(mod)))229 if (field_align != .none and field_align.compare(.lt, field_ty.abiAlignment(mod)))
230 return memory_class;230 return memory_class;
231 const field_size = field_ty.abiSize(mod);231 const field_size = field_ty.abiSize(mod);
232 const field_class_array = classifySystemV(field_ty, mod, .other);232 const field_class_array = classifySystemV(field_ty, mod, .field);
233 const field_class = std.mem.sliceTo(&field_class_array, .none);233 const field_class = std.mem.sliceTo(&field_class_array, .none);
234 if (byte_i + field_size <= 8) {234 if (byte_i + field_size <= 8) {
235 // Combine this field with the previous one.235 // Combine this field with the previous one.
...@@ -347,7 +347,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -347,7 +347,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
347 return memory_class;347 return memory_class;
348 }348 }
349 // Combine this field with the previous one.349 // Combine this field with the previous one.
350 const field_class = classifySystemV(field_ty.toType(), mod, .other);350 const field_class = classifySystemV(field_ty.toType(), mod, .field);
351 for (&result, 0..) |*result_item, i| {351 for (&result, 0..) |*result_item, i| {
352 const field_item = field_class[i];352 const field_item = field_class[i];
353 // "If both classes are equal, this is the resulting class."353 // "If both classes are equal, this is the resulting class."