x86_64: fix typo and lower optimized insts

This commit is contained in:
Jacob Young 2025-01-23 06:58:40 -05:00
parent b1fa89439a
commit ba82d6e83e
5 changed files with 34 additions and 32 deletions

View File

@ -2440,10 +2440,15 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
.shr, .shr_exact => try cg.airShlShrBinOp(inst), .shr, .shr_exact => try cg.airShlShrBinOp(inst),
.shl, .shl_exact => try cg.airShlShrBinOp(inst), .shl, .shl_exact => try cg.airShlShrBinOp(inst),
.mul => try cg.airMulDivBinOp(inst), .mul,
.mul_wrap => try cg.airMulDivBinOp(inst), .mul_wrap,
.rem => try cg.airMulDivBinOp(inst), .rem,
.mod => try cg.airMulDivBinOp(inst), .mod,
.div_float,
.div_trunc,
.div_floor,
.div_exact,
=> |air_tag| try cg.airMulDivBinOp(inst, air_tag),
.add_sat => try cg.airAddSat(inst), .add_sat => try cg.airAddSat(inst),
.sub_sat => try cg.airSubSat(inst), .sub_sat => try cg.airSubSat(inst),
@ -2465,15 +2470,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
.ceil => try cg.airRound(inst, .{ .mode = .up, .precision = .inexact }), .ceil => try cg.airRound(inst, .{ .mode = .up, .precision = .inexact }),
.trunc_float => try cg.airRound(inst, .{ .mode = .zero, .precision = .inexact }), .trunc_float => try cg.airRound(inst, .{ .mode = .zero, .precision = .inexact }),
.sqrt => try cg.airSqrt(inst), .sqrt => try cg.airSqrt(inst),
.neg => try cg.airFloatSign(inst), .neg => |air_tag| try cg.airFloatSign(inst, air_tag),
.add_with_overflow => try cg.airAddSubWithOverflow(inst), .add_with_overflow => try cg.airAddSubWithOverflow(inst),
.sub_with_overflow => try cg.airAddSubWithOverflow(inst), .sub_with_overflow => try cg.airAddSubWithOverflow(inst),
.mul_with_overflow => try cg.airMulWithOverflow(inst), .mul_with_overflow => try cg.airMulWithOverflow(inst),
.shl_with_overflow => try cg.airShlWithOverflow(inst), .shl_with_overflow => try cg.airShlWithOverflow(inst),
.div_float, .div_trunc, .div_floor, .div_exact => try cg.airMulDivBinOp(inst),
.cmp_lt_errors_len => try cg.airCmpLtErrorsLen(inst), .cmp_lt_errors_len => try cg.airCmpLtErrorsLen(inst),
.bitcast => try cg.airBitCast(inst), .bitcast => try cg.airBitCast(inst),
@ -2528,19 +2531,19 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
.sub_safe, .sub_safe,
.mul_safe, .mul_safe,
=> return cg.fail("TODO implement safety_checked_instructions", .{}), => return cg.fail("TODO implement safety_checked_instructions", .{}),
.add_optimized,
.sub_optimized, .add_optimized => try cg.airBinOp(inst, .add),
.mul_optimized, .sub_optimized => try cg.airBinOp(inst, .sub),
.div_float_optimized, .mul_optimized => try cg.airBinOp(inst, .mul),
.div_trunc_optimized, .div_float_optimized => try cg.airMulDivBinOp(inst, .div_float),
.div_floor_optimized, .div_trunc_optimized => try cg.airMulDivBinOp(inst, .div_trunc),
.div_exact_optimized, .div_floor_optimized => try cg.airMulDivBinOp(inst, .div_floor),
.rem_optimized, .div_exact_optimized => try cg.airMulDivBinOp(inst, .div_exact),
.mod_optimized, .rem_optimized => try cg.airMulDivBinOp(inst, .rem),
.neg_optimized, .mod_optimized => try cg.airMulDivBinOp(inst, .mod),
.reduce_optimized, .neg_optimized => try cg.airFloatSign(inst, .neg),
.int_from_float_optimized, .reduce_optimized => try cg.airReduce(inst),
=> return cg.fail("TODO implement optimized float mode", .{}), .int_from_float_optimized => try cg.airIntFromFloat(inst),
.arg => try cg.airDbgArg(inst), .arg => try cg.airDbgArg(inst),
.ptr_add => |air_tag| if (use_old) try cg.airPtrArithmetic(inst, air_tag) else { .ptr_add => |air_tag| if (use_old) try cg.airPtrArithmetic(inst, air_tag) else {
@ -16257,12 +16260,11 @@ fn activeIntBits(self: *CodeGen, dst_air: Air.Inst.Ref) u16 {
return dst_info.bits; return dst_info.bits;
} }
fn airMulDivBinOp(self: *CodeGen, inst: Air.Inst.Index) !void { fn airMulDivBinOp(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
const pt = self.pt; const pt = self.pt;
const zcu = pt.zcu; const zcu = pt.zcu;
const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
const result = result: { const result = result: {
const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
const dst_ty = self.typeOfIndex(inst); const dst_ty = self.typeOfIndex(inst);
switch (dst_ty.zigTypeTag(zcu)) { switch (dst_ty.zigTypeTag(zcu)) {
.float, .vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs), .float, .vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),
@ -19600,10 +19602,9 @@ fn airBitReverse(self: *CodeGen, inst: Air.Inst.Index) !void {
return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none }); return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
} }
fn floatSign(self: *CodeGen, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void { fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: Air.Inst.Ref, ty: Type) !void {
const pt = self.pt; const pt = self.pt;
const zcu = pt.zcu; const zcu = pt.zcu;
const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
const result = result: { const result = result: {
const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*); const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*);
@ -19728,10 +19729,10 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Ty
return self.finishAir(inst, result, .{ operand, .none, .none }); return self.finishAir(inst, result, .{ operand, .none, .none });
} }
fn airFloatSign(self: *CodeGen, inst: Air.Inst.Index) !void { fn airFloatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op; const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
const ty = self.typeOf(un_op); const ty = self.typeOf(un_op);
return self.floatSign(inst, un_op, ty); return self.floatSign(inst, tag, un_op, ty);
} }
const RoundMode = packed struct(u5) { const RoundMode = packed struct(u5) {
@ -20014,7 +20015,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
break :result dst_mcv; break :result dst_mcv;
}, },
}, },
.float => return self.floatSign(inst, ty_op.operand, ty), .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
.vector => switch (ty.childType(zcu).zigTypeTag(zcu)) { .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
else => null, else => null,
.int => switch (ty.childType(zcu).intInfo(zcu).bits) { .int => switch (ty.childType(zcu).intInfo(zcu).bits) {
@ -20050,7 +20051,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
5...8 => if (self.hasFeature(.avx2)) .{ .vp_d, .abs } else null, 5...8 => if (self.hasFeature(.avx2)) .{ .vp_d, .abs } else null,
}, },
}, },
.float => return self.floatSign(inst, ty_op.operand, ty), .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
}, },
}) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)}); }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
@ -22911,7 +22912,7 @@ fn genBinOp(
.mul => .{ .v_ss, .mul }, .mul => .{ .v_ss, .mul },
.div_float, .div_trunc, .div_floor, .div_exact => .{ .v_ss, .div }, .div_float, .div_trunc, .div_floor, .div_exact => .{ .v_ss, .div },
.max => .{ .v_ss, .max }, .max => .{ .v_ss, .max },
.min => .{ .v_ss, .max }, .min => .{ .v_ss, .min },
else => unreachable, else => unreachable,
}, },
dst_reg, dst_reg,

View File

@ -1654,6 +1654,7 @@ test "runtime isNan(inf * 0)" {
} }
test "optimized float mode" { test "optimized float mode" {
if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest;
if (builtin.mode == .Debug) return error.SkipZigTest; if (builtin.mode == .Debug) return error.SkipZigTest;
const big = 0x1p40; const big = 0x1p40;

View File

@ -15,6 +15,6 @@ pub export fn entry() void {
// error // error
// //
// :7:25: error: unable to resolve comptime value // :7:25: error: unable to resolve comptime value
// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_441.C' must be comptime-known // :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_447.C' must be comptime-known
// :4:16: note: struct requires comptime because of this field // :4:16: note: struct requires comptime because of this field
// :4:16: note: types are not available at runtime // :4:16: note: types are not available at runtime

View File

@ -16,5 +16,5 @@ pub export fn entry2() void {
// //
// :3:6: error: no field or member function named 'copy' in '[]const u8' // :3:6: error: no field or member function named 'copy' in '[]const u8'
// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})' // :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_445' // :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_451'
// :12:6: note: struct declared here // :12:6: note: struct declared here

View File

@ -6,6 +6,6 @@ export fn foo() void {
// error // error
// //
// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_434' // :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_440'
// :3:16: note: struct declared here // :3:16: note: struct declared here
// :1:11: note: struct declared here // :1:11: note: struct declared here