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) {...@@ -155,6 +155,8 @@ pub const MCValue = union(enum) {
155 .memory,155 .memory,
156 .stack_offset,156 .stack_offset,
157 .ptr_stack_offset,157 .ptr_stack_offset,
158 .direct_load,
159 .got_load,
158 => true,160 => true,
159 else => false,161 else => false,
160 };162 };
...@@ -3131,20 +3133,19 @@ fn genBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_rhs:...@@ -3131,20 +3133,19 @@ fn genBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_rhs:
3131}3133}
31323134
3133fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {3135fn 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.*));
3135 switch (dst_mcv) {3137 switch (dst_mcv) {
3136 .none => unreachable,3138 .none => unreachable,
3137 .undef => unreachable,3139 .undef => unreachable,
3138 .dead, .unreach, .immediate => unreachable,3140 .dead, .unreach, .immediate => unreachable,
3139 .compare_flags_unsigned => unreachable,3141 .compare_flags_unsigned => unreachable,
3140 .compare_flags_signed => unreachable,3142 .compare_flags_signed => unreachable,
3141 .ptr_stack_offset => unreachable,
3142 .register_overflow_unsigned => unreachable,3143 .register_overflow_unsigned => unreachable,
3143 .register_overflow_signed => unreachable,3144 .register_overflow_signed => unreachable,
3144 .register => |dst_reg| {3145 .register => |dst_reg| {
3145 switch (src_mcv) {3146 switch (src_mcv) {
3146 .none => unreachable,3147 .none => unreachable,
3147 .undef => try self.genSetReg(dst_ty, dst_reg, .undef),3148 .undef => unreachable,
3148 .dead, .unreach => unreachable,3149 .dead, .unreach => unreachable,
3149 .register_overflow_unsigned => unreachable,3150 .register_overflow_unsigned => unreachable,
3150 .register_overflow_signed => unreachable,3151 .register_overflow_signed => unreachable,
...@@ -3168,7 +3169,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3168,7 +3169,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3168 _ = try self.addInst(.{3169 _ = try self.addInst(.{
3169 .tag = mir_tag,3170 .tag = mir_tag,
3170 .ops = (Mir.Ops{3171 .ops = (Mir.Ops{
3171 .reg1 = registerAlias(dst_reg, @intCast(u32, abi_size)),3172 .reg1 = registerAlias(dst_reg, abi_size),
3172 }).encode(),3173 }).encode(),
3173 .data = .{ .imm = @truncate(u32, imm) },3174 .data = .{ .imm = @truncate(u32, imm) },
3174 });3175 });
...@@ -3192,7 +3193,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3192,7 +3193,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3192 _ = try self.addInst(.{3193 _ = try self.addInst(.{
3193 .tag = mir_tag,3194 .tag = mir_tag,
3194 .ops = (Mir.Ops{3195 .ops = (Mir.Ops{
3195 .reg1 = registerAlias(dst_reg, @intCast(u32, abi_size)),3196 .reg1 = registerAlias(dst_reg, abi_size),
3196 .reg2 = .rbp,3197 .reg2 = .rbp,
3197 .flags = 0b01,3198 .flags = 0b01,
3198 }).encode(),3199 }).encode(),
...@@ -3201,19 +3202,18 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3201,19 +3202,18 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3201 },3202 },
3202 }3203 }
3203 },3204 },
3204 .stack_offset => |off| {3205 .ptr_stack_offset, .stack_offset => |off| {
3205 if (off > math.maxInt(i32)) {3206 if (off > math.maxInt(i32)) {
3206 return self.fail("stack offset too large", .{});3207 return self.fail("stack offset too large", .{});
3207 }3208 }
3208 if (abi_size > 8) {3209 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});
3210 }3211 }
32113212
3212 switch (src_mcv) {3213 switch (src_mcv) {
3213 .none => unreachable,3214 .none => unreachable,
3214 .undef => return self.genSetStack(dst_ty, off, .undef, .{}),3215 .undef => unreachable,
3215 .dead, .unreach => unreachable,3216 .dead, .unreach => unreachable,
3216 .ptr_stack_offset => unreachable,
3217 .register_overflow_unsigned => unreachable,3217 .register_overflow_unsigned => unreachable,
3218 .register_overflow_signed => unreachable,3218 .register_overflow_signed => unreachable,
3219 .register => |src_reg| {3219 .register => |src_reg| {
...@@ -3221,7 +3221,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3221,7 +3221,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3221 .tag = mir_tag,3221 .tag = mir_tag,
3222 .ops = (Mir.Ops{3222 .ops = (Mir.Ops{
3223 .reg1 = .rbp,3223 .reg1 = .rbp,
3224 .reg2 = registerAlias(src_reg, @intCast(u32, abi_size)),3224 .reg2 = registerAlias(src_reg, abi_size),
3225 .flags = 0b10,3225 .flags = 0b10,
3226 }).encode(),3226 }).encode(),
3227 .data = .{ .imm = @bitCast(u32, -off) },3227 .data = .{ .imm = @bitCast(u32, -off) },
...@@ -3257,7 +3257,10 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC...@@ -3257,7 +3257,10 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
3257 .data = .{ .payload = payload },3257 .data = .{ .payload = payload },
3258 });3258 });
3259 },3259 },
3260 .memory, .stack_offset => {3260 .memory,
3261 .stack_offset,
3262 .ptr_stack_offset,
3263 => {
3261 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});3264 return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{});
3262 },3265 },
3263 .got_load, .direct_load => {3266 .got_load, .direct_load => {
src/codegen.zig+8-10
...@@ -426,22 +426,20 @@ pub fn generateSymbol(...@@ -426,22 +426,20 @@ pub fn generateSymbol(
426 },426 },
427 },427 },
428 .Int => {428 .Int => {
429 // TODO populate .debug_info for the integer429 const info = typed_value.ty.intInfo(target);
430 const info = typed_value.ty.intInfo(bin_file.options.target);
431 if (info.bits <= 8) {430 if (info.bits <= 8) {
432 const x = @intCast(u8, typed_value.val.toUnsignedInt(target));431 const x = @intCast(u8, typed_value.val.toUnsignedInt(target));
433 try code.append(x);432 try code.append(x);
434 return Result{ .appended = {} };433 return Result{ .appended = {} };
435 }434 }
436 if (info.bits > 64) {435 if (info.bits > 64) {
437 return Result{436 var bigint_buffer: Value.BigIntSpace = undefined;
438 .fail = try ErrorMsg.create(437 const bigint = typed_value.val.toBigInt(&bigint_buffer, target);
439 bin_file.allocator,438 const abi_size = try math.cast(usize, typed_value.ty.abiSize(target));
440 src_loc,439 const start = code.items.len;
441 "TODO implement generateSymbol for big ints ('{}')",440 try code.resize(start + abi_size);
442 .{typed_value.ty.fmtDebug()},441 bigint.writeTwosComplement(code.items[start..][0..abi_size], info.bits, abi_size, endian);
443 ),442 return Result{ .appended = {} };
444 };
445 }443 }
446 switch (info.signedness) {444 switch (info.signedness) {
447 .unsigned => {445 .unsigned => {