authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-01-23 06:58:40-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-01-24 20:56:11-05:00
logba82d6e83e3e0dc00ad235fae52c21f9014ebd78
tree92265713d7818b35dc1aab81037d36282be90e4c
parentb1fa89439ae56001779061c42a08cf9db7906432

x86_64: fix typo and lower optimized insts


5 files changed, 34 insertions(+), 32 deletions(-)

src/arch/x86_64/CodeGen.zig+30-29
......@@ -2440,10 +2440,15 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
24402440 .shr, .shr_exact => try cg.airShlShrBinOp(inst),
24412441 .shl, .shl_exact => try cg.airShlShrBinOp(inst),
24422442
2443 .mul => try cg.airMulDivBinOp(inst),
2444 .mul_wrap => try cg.airMulDivBinOp(inst),
2445 .rem => try cg.airMulDivBinOp(inst),
2446 .mod => try cg.airMulDivBinOp(inst),
2443 .mul,
2444 .mul_wrap,
2445 .rem,
2446 .mod,
2447 .div_float,
2448 .div_trunc,
2449 .div_floor,
2450 .div_exact,
2451 => |air_tag| try cg.airMulDivBinOp(inst, air_tag),
24472452
24482453 .add_sat => try cg.airAddSat(inst),
24492454 .sub_sat => try cg.airSubSat(inst),
......@@ -2465,15 +2470,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
24652470 .ceil => try cg.airRound(inst, .{ .mode = .up, .precision = .inexact }),
24662471 .trunc_float => try cg.airRound(inst, .{ .mode = .zero, .precision = .inexact }),
24672472 .sqrt => try cg.airSqrt(inst),
2468 .neg => try cg.airFloatSign(inst),
2473 .neg => |air_tag| try cg.airFloatSign(inst, air_tag),
24692474
24702475 .add_with_overflow => try cg.airAddSubWithOverflow(inst),
24712476 .sub_with_overflow => try cg.airAddSubWithOverflow(inst),
24722477 .mul_with_overflow => try cg.airMulWithOverflow(inst),
24732478 .shl_with_overflow => try cg.airShlWithOverflow(inst),
24742479
2475 .div_float, .div_trunc, .div_floor, .div_exact => try cg.airMulDivBinOp(inst),
2476
24772480 .cmp_lt_errors_len => try cg.airCmpLtErrorsLen(inst),
24782481
24792482 .bitcast => try cg.airBitCast(inst),
......@@ -2528,19 +2531,19 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
25282531 .sub_safe,
25292532 .mul_safe,
25302533 => return cg.fail("TODO implement safety_checked_instructions", .{}),
2531 .add_optimized,
2532 .sub_optimized,
2533 .mul_optimized,
2534 .div_float_optimized,
2535 .div_trunc_optimized,
2536 .div_floor_optimized,
2537 .div_exact_optimized,
2538 .rem_optimized,
2539 .mod_optimized,
2540 .neg_optimized,
2541 .reduce_optimized,
2542 .int_from_float_optimized,
2543 => return cg.fail("TODO implement optimized float mode", .{}),
2534
2535 .add_optimized => try cg.airBinOp(inst, .add),
2536 .sub_optimized => try cg.airBinOp(inst, .sub),
2537 .mul_optimized => try cg.airBinOp(inst, .mul),
2538 .div_float_optimized => try cg.airMulDivBinOp(inst, .div_float),
2539 .div_trunc_optimized => try cg.airMulDivBinOp(inst, .div_trunc),
2540 .div_floor_optimized => try cg.airMulDivBinOp(inst, .div_floor),
2541 .div_exact_optimized => try cg.airMulDivBinOp(inst, .div_exact),
2542 .rem_optimized => try cg.airMulDivBinOp(inst, .rem),
2543 .mod_optimized => try cg.airMulDivBinOp(inst, .mod),
2544 .neg_optimized => try cg.airFloatSign(inst, .neg),
2545 .reduce_optimized => try cg.airReduce(inst),
2546 .int_from_float_optimized => try cg.airIntFromFloat(inst),
25442547
25452548 .arg => try cg.airDbgArg(inst),
25462549 .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 {
1625716260 return dst_info.bits;
1625816261}
1625916262
16260fn airMulDivBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {
16263fn airMulDivBinOp(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1626116264 const pt = self.pt;
1626216265 const zcu = pt.zcu;
1626316266 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1626416267 const result = result: {
16265 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1626616268 const dst_ty = self.typeOfIndex(inst);
1626716269 switch (dst_ty.zigTypeTag(zcu)) {
1626816270 .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 {
1960019602 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
1960119603}
1960219604
19603fn floatSign(self: *CodeGen, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {
19605fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: Air.Inst.Ref, ty: Type) !void {
1960419606 const pt = self.pt;
1960519607 const zcu = pt.zcu;
19606 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1960719608
1960819609 const result = result: {
1960919610 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
1972819729 return self.finishAir(inst, result, .{ operand, .none, .none });
1972919730}
1973019731
19731fn airFloatSign(self: *CodeGen, inst: Air.Inst.Index) !void {
19732fn airFloatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
1973219733 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1973319734 const ty = self.typeOf(un_op);
19734 return self.floatSign(inst, un_op, ty);
19735 return self.floatSign(inst, tag, un_op, ty);
1973519736}
1973619737
1973719738const RoundMode = packed struct(u5) {
......@@ -20014,7 +20015,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
2001420015 break :result dst_mcv;
2001520016 },
2001620017 },
20017 .float => return self.floatSign(inst, ty_op.operand, ty),
20018 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
2001820019 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2001920020 else => null,
2002020021 .int => switch (ty.childType(zcu).intInfo(zcu).bits) {
......@@ -20050,7 +20051,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
2005020051 5...8 => if (self.hasFeature(.avx2)) .{ .vp_d, .abs } else null,
2005120052 },
2005220053 },
20053 .float => return self.floatSign(inst, ty_op.operand, ty),
20054 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
2005420055 },
2005520056 }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
2005620057
......@@ -22911,7 +22912,7 @@ fn genBinOp(
2291122912 .mul => .{ .v_ss, .mul },
2291222913 .div_float, .div_trunc, .div_floor, .div_exact => .{ .v_ss, .div },
2291322914 .max => .{ .v_ss, .max },
22914 .min => .{ .v_ss, .max },
22915 .min => .{ .v_ss, .min },
2291522916 else => unreachable,
2291622917 },
2291722918 dst_reg,
test/behavior/floatop.zig+1
......@@ -1654,6 +1654,7 @@ test "runtime isNan(inf * 0)" {
16541654}
16551655
16561656test "optimized float mode" {
1657 if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest;
16571658 if (builtin.mode == .Debug) return error.SkipZigTest;
16581659
16591660 const big = 0x1p40;
test/cases/compile_errors/anytype_param_requires_comptime.zig+1-1
......@@ -15,6 +15,6 @@ pub export fn entry() void {
1515// error
1616//
1717// :7:25: error: unable to resolve comptime value
18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_441.C' must be comptime-known
18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_447.C' must be comptime-known
1919// :4:16: note: struct requires comptime because of this field
2020// :4:16: note: types are not available at runtime
test/cases/compile_errors/bogus_method_call_on_slice.zig+1-1
......@@ -16,5 +16,5 @@ pub export fn entry2() void {
1616//
1717// :3:6: error: no field or member function named 'copy' in '[]const u8'
1818// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
19// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_445'
19// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_451'
2020// :12:6: note: struct declared here
test/cases/compile_errors/coerce_anon_struct.zig+1-1
......@@ -6,6 +6,6 @@ export fn foo() void {
66
77// error
88//
9// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_434'
9// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_440'
1010// :3:16: note: struct declared here
1111// :1:11: note: struct declared here