authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-15 13:46:51+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-15 11:50:08-04:00
log52c8ac1a847f893bc54cab5621738c0aa16f7c9d
tree90d06edbf485730a58c0d8a34b9ade9f1fec3648
parent3723eb7f3164c40c9cb204cb81efeb6ae3f43847

stage2: lower u128, and refactor some bits in x64


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

src/arch/x86_64/CodeGen.zig+14-11
......@@ -155,6 +155,8 @@ pub const MCValue = union(enum) {
155155 .memory,
156156 .stack_offset,
157157 .ptr_stack_offset,
158 .direct_load,
159 .got_load,
158160 => true,
159161 else => false,
160162 };
......@@ -3131,20 +3133,19 @@ fn genBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_rhs:
31313133}
31323134
31333135fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {
3134 const abi_size = dst_ty.abiSize(self.target.*);
3136 const abi_size = @intCast(u32, dst_ty.abiSize(self.target.*));
31353137 switch (dst_mcv) {
31363138 .none => unreachable,
31373139 .undef => unreachable,
31383140 .dead, .unreach, .immediate => unreachable,
31393141 .compare_flags_unsigned => unreachable,
31403142 .compare_flags_signed => unreachable,
3141 .ptr_stack_offset => unreachable,
31423143 .register_overflow_unsigned => unreachable,
31433144 .register_overflow_signed => unreachable,
31443145 .register => |dst_reg| {
31453146 switch (src_mcv) {
31463147 .none => unreachable,
3147 .undef => try self.genSetReg(dst_ty, dst_reg, .undef),
3148 .undef => unreachable,
31483149 .dead, .unreach => unreachable,
31493150 .register_overflow_unsigned => unreachable,
31503151 .register_overflow_signed => unreachable,
......@@ -3168,7 +3169,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
31683169 _ = try self.addInst(.{
31693170 .tag = mir_tag,
31703171 .ops = (Mir.Ops{
3171 .reg1 = registerAlias(dst_reg, @intCast(u32, abi_size)),
3172 .reg1 = registerAlias(dst_reg, abi_size),
31723173 }).encode(),
31733174 .data = .{ .imm = @truncate(u32, imm) },
31743175 });
......@@ -3192,7 +3193,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
31923193 _ = try self.addInst(.{
31933194 .tag = mir_tag,
31943195 .ops = (Mir.Ops{
3195 .reg1 = registerAlias(dst_reg, @intCast(u32, abi_size)),
3196 .reg1 = registerAlias(dst_reg, abi_size),
31963197 .reg2 = .rbp,
31973198 .flags = 0b01,
31983199 }).encode(),
......@@ -3201,19 +3202,18 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
32013202 },
32023203 }
32033204 },
3204 .stack_offset => |off| {
3205 .ptr_stack_offset, .stack_offset => |off| {
32053206 if (off > math.maxInt(i32)) {
32063207 return self.fail("stack offset too large", .{});
32073208 }
32083209 if (abi_size > 8) {
3209 return self.fail("TODO implement ADD/SUB/CMP for stack dst with large ABI", .{});
3210 return self.fail("TODO implement {} for stack dst with large ABI", .{mir_tag});
32103211 }
32113212
32123213 switch (src_mcv) {
32133214 .none => unreachable,
3214 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),
3215 .undef => unreachable,
32153216 .dead, .unreach => unreachable,
3216 .ptr_stack_offset => unreachable,
32173217 .register_overflow_unsigned => unreachable,
32183218 .register_overflow_signed => unreachable,
32193219 .register => |src_reg| {
......@@ -3221,7 +3221,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
32213221 .tag = mir_tag,
32223222 .ops = (Mir.Ops{
32233223 .reg1 = .rbp,
3224 .reg2 = registerAlias(src_reg, @intCast(u32, abi_size)),
3224 .reg2 = registerAlias(src_reg, abi_size),
32253225 .flags = 0b10,
32263226 }).encode(),
32273227 .data = .{ .imm = @bitCast(u32, -off) },
......@@ -3257,7 +3257,10 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
32573257 .data = .{ .payload = payload },
32583258 });
32593259 },
3260 .memory, .stack_offset => {
3260 .memory,
3261 .stack_offset,
3262 .ptr_stack_offset,
3263 => {
32613264 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});
32623265 },
32633266 .got_load, .direct_load => {
src/codegen.zig+8-10
......@@ -426,22 +426,20 @@ pub fn generateSymbol(
426426 },
427427 },
428428 .Int => {
429 // TODO populate .debug_info for the integer
430 const info = typed_value.ty.intInfo(bin_file.options.target);
429 const info = typed_value.ty.intInfo(target);
431430 if (info.bits <= 8) {
432431 const x = @intCast(u8, typed_value.val.toUnsignedInt(target));
433432 try code.append(x);
434433 return Result{ .appended = {} };
435434 }
436435 if (info.bits > 64) {
437 return Result{
438 .fail = try ErrorMsg.create(
439 bin_file.allocator,
440 src_loc,
441 "TODO implement generateSymbol for big ints ('{}')",
442 .{typed_value.ty.fmtDebug()},
443 ),
444 };
436 var bigint_buffer: Value.BigIntSpace = undefined;
437 const bigint = typed_value.val.toBigInt(&bigint_buffer, target);
438 const abi_size = try math.cast(usize, typed_value.ty.abiSize(target));
439 const start = code.items.len;
440 try code.resize(start + abi_size);
441 bigint.writeTwosComplement(code.items[start..][0..abi_size], info.bits, abi_size, endian);
442 return Result{ .appended = {} };
445443 }
446444 switch (info.signedness) {
447445 .unsigned => {