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 {
25682568 80, 128 => true,
25692569 else => unreachable,
25702570 },
2571 80 => switch (dst_bits) {
2571 80 => switch (src_bits) {
25722572 128 => true,
25732573 else => unreachable,
25742574 },
......@@ -10278,6 +10278,8 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
1027810278}
1027910279
1028010280fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
10281 const mod = self.bin_file.options.module.?;
10282
1028110283 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
1028210284 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
1031510317 .off = -dst_reg_off.off,
1031610318 } },
1031710319 }),
10318 .register_pair => |dst_regs| for (dst_regs, 0..) |dst_reg, dst_reg_i| switch (src_mcv) {
10319 .register_pair => |src_regs| try self.genSetReg(
10320 dst_reg,
10321 Type.usize,
10322 .{ .register = src_regs[dst_reg_i] },
10323 ),
10324 else => try self.genSetReg(
10325 dst_reg,
10326 Type.usize,
10327 src_mcv.address().offset(@intCast(dst_reg_i * 8)).deref(),
10328 ),
10329 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref)),
10320 .register_pair => |dst_regs| {
10321 switch (src_mcv) {
10322 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref)),
10323 else => {},
10324 }
10325 const classes = mem.sliceTo(&abi.classifySystemV(ty, mod, .other), .none);
10326 for (dst_regs, classes, 0..) |dst_reg, class, dst_reg_i| {
10327 const class_ty = switch (class) {
10328 .integer => Type.usize,
10329 .sse => Type.f64,
10330 else => unreachable,
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 }
1033010345 },
1033110346 .indirect => |reg_off| try self.genSetMem(.{ .reg = reg_off.reg }, reg_off.off, ty, src_mcv),
1033210347 .memory, .load_direct, .load_got, .load_tlv => {
......@@ -12566,7 +12581,7 @@ fn resolveCallingConventionValues(
1256612581
1256712582 const classes = switch (resolved_cc) {
1256812583 .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)},
1257012585 else => unreachable,
1257112586 };
1257212587 for (classes) |class| switch (class) {
......@@ -12639,9 +12654,10 @@ fn resolveCallingConventionValues(
1263912654 var arg_mcv: [2]MCValue = undefined;
1264012655 var arg_mcv_i: usize = 0;
1264112656
12642 const classes = switch (self.target.os.tag) {
12643 .windows => &[1]abi.Class{abi.classifyWindows(ty, mod)},
12644 else => mem.sliceTo(&abi.classifySystemV(ty, mod, .arg), .none),
12657 const classes = switch (resolved_cc) {
12658 .SysV => mem.sliceTo(&abi.classifySystemV(ty, mod, .arg), .none),
12659 .Win64 => &.{abi.classifyWindows(ty, mod)},
12660 else => unreachable,
1264512661 };
1264612662 for (classes) |class| switch (class) {
1264712663 .integer => {
src/arch/x86_64/abi.zig+5-5
......@@ -64,7 +64,7 @@ pub fn classifyWindows(ty: Type, mod: *Module) Class {
6464 }
6565}
6666
67pub const Context = enum { ret, arg, other };
67pub const Context = enum { ret, arg, field, other };
6868
6969/// There are a maximum of 8 possible return slots. Returned values are in
7070/// 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 {
120120 },
121121 .Float => switch (ty.floatBits(target)) {
122122 16 => {
123 if (ctx == .other) {
123 if (ctx == .field) {
124124 result[0] = .memory;
125125 } else {
126126 // 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 {
140140 // "Arguments of types __float128, _Decimal128 and __m128 are
141141 // split into two halves. The least significant ones belong
142142 // to class SSE, the most significant one to class SSEUP."
143 if (ctx == .other) {
143 if (ctx == .field) {
144144 result[0] = .memory;
145145 return result;
146146 }
......@@ -229,7 +229,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
229229 if (field_align != .none and field_align.compare(.lt, field_ty.abiAlignment(mod)))
230230 return memory_class;
231231 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);
233233 const field_class = std.mem.sliceTo(&field_class_array, .none);
234234 if (byte_i + field_size <= 8) {
235235 // Combine this field with the previous one.
......@@ -347,7 +347,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
347347 return memory_class;
348348 }
349349 // 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);
351351 for (&result, 0..) |*result_item, i| {
352352 const field_item = field_class[i];
353353 // "If both classes are equal, this is the resulting class."