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 {...@@ -2440,10 +2440,15 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2440 .shr, .shr_exact => try cg.airShlShrBinOp(inst),2440 .shr, .shr_exact => try cg.airShlShrBinOp(inst),
2441 .shl, .shl_exact => try cg.airShlShrBinOp(inst),2441 .shl, .shl_exact => try cg.airShlShrBinOp(inst),
24422442
2443 .mul => try cg.airMulDivBinOp(inst),2443 .mul,
2444 .mul_wrap => try cg.airMulDivBinOp(inst),2444 .mul_wrap,
2445 .rem => try cg.airMulDivBinOp(inst),2445 .rem,
2446 .mod => try cg.airMulDivBinOp(inst),2446 .mod,
2447 .div_float,
2448 .div_trunc,
2449 .div_floor,
2450 .div_exact,
2451 => |air_tag| try cg.airMulDivBinOp(inst, air_tag),
24472452
2448 .add_sat => try cg.airAddSat(inst),2453 .add_sat => try cg.airAddSat(inst),
2449 .sub_sat => try cg.airSubSat(inst),2454 .sub_sat => try cg.airSubSat(inst),
...@@ -2465,15 +2470,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -2465,15 +2470,13 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2465 .ceil => try cg.airRound(inst, .{ .mode = .up, .precision = .inexact }),2470 .ceil => try cg.airRound(inst, .{ .mode = .up, .precision = .inexact }),
2466 .trunc_float => try cg.airRound(inst, .{ .mode = .zero, .precision = .inexact }),2471 .trunc_float => try cg.airRound(inst, .{ .mode = .zero, .precision = .inexact }),
2467 .sqrt => try cg.airSqrt(inst),2472 .sqrt => try cg.airSqrt(inst),
2468 .neg => try cg.airFloatSign(inst),2473 .neg => |air_tag| try cg.airFloatSign(inst, air_tag),
24692474
2470 .add_with_overflow => try cg.airAddSubWithOverflow(inst),2475 .add_with_overflow => try cg.airAddSubWithOverflow(inst),
2471 .sub_with_overflow => try cg.airAddSubWithOverflow(inst),2476 .sub_with_overflow => try cg.airAddSubWithOverflow(inst),
2472 .mul_with_overflow => try cg.airMulWithOverflow(inst),2477 .mul_with_overflow => try cg.airMulWithOverflow(inst),
2473 .shl_with_overflow => try cg.airShlWithOverflow(inst),2478 .shl_with_overflow => try cg.airShlWithOverflow(inst),
24742479
2475 .div_float, .div_trunc, .div_floor, .div_exact => try cg.airMulDivBinOp(inst),
2476
2477 .cmp_lt_errors_len => try cg.airCmpLtErrorsLen(inst),2480 .cmp_lt_errors_len => try cg.airCmpLtErrorsLen(inst),
24782481
2479 .bitcast => try cg.airBitCast(inst),2482 .bitcast => try cg.airBitCast(inst),
...@@ -2528,19 +2531,19 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -2528,19 +2531,19 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2528 .sub_safe,2531 .sub_safe,
2529 .mul_safe,2532 .mul_safe,
2530 => return cg.fail("TODO implement safety_checked_instructions", .{}),2533 => return cg.fail("TODO implement safety_checked_instructions", .{}),
2531 .add_optimized,2534
2532 .sub_optimized,2535 .add_optimized => try cg.airBinOp(inst, .add),
2533 .mul_optimized,2536 .sub_optimized => try cg.airBinOp(inst, .sub),
2534 .div_float_optimized,2537 .mul_optimized => try cg.airBinOp(inst, .mul),
2535 .div_trunc_optimized,2538 .div_float_optimized => try cg.airMulDivBinOp(inst, .div_float),
2536 .div_floor_optimized,2539 .div_trunc_optimized => try cg.airMulDivBinOp(inst, .div_trunc),
2537 .div_exact_optimized,2540 .div_floor_optimized => try cg.airMulDivBinOp(inst, .div_floor),
2538 .rem_optimized,2541 .div_exact_optimized => try cg.airMulDivBinOp(inst, .div_exact),
2539 .mod_optimized,2542 .rem_optimized => try cg.airMulDivBinOp(inst, .rem),
2540 .neg_optimized,2543 .mod_optimized => try cg.airMulDivBinOp(inst, .mod),
2541 .reduce_optimized,2544 .neg_optimized => try cg.airFloatSign(inst, .neg),
2542 .int_from_float_optimized,2545 .reduce_optimized => try cg.airReduce(inst),
2543 => return cg.fail("TODO implement optimized float mode", .{}),2546 .int_from_float_optimized => try cg.airIntFromFloat(inst),
25442547
2545 .arg => try cg.airDbgArg(inst),2548 .arg => try cg.airDbgArg(inst),
2546 .ptr_add => |air_tag| if (use_old) try cg.airPtrArithmetic(inst, air_tag) else {2549 .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 {...@@ -16257,12 +16260,11 @@ fn activeIntBits(self: *CodeGen, dst_air: Air.Inst.Ref) u16 {
16257 return dst_info.bits;16260 return dst_info.bits;
16258}16261}
1625916262
16260fn airMulDivBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {16263fn airMulDivBinOp(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
16261 const pt = self.pt;16264 const pt = self.pt;
16262 const zcu = pt.zcu;16265 const zcu = pt.zcu;
16263 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;16266 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
16264 const result = result: {16267 const result = result: {
16265 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
16266 const dst_ty = self.typeOfIndex(inst);16268 const dst_ty = self.typeOfIndex(inst);
16267 switch (dst_ty.zigTypeTag(zcu)) {16269 switch (dst_ty.zigTypeTag(zcu)) {
16268 .float, .vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),16270 .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 {...@@ -19600,10 +19602,9 @@ fn airBitReverse(self: *CodeGen, inst: Air.Inst.Index) !void {
19600 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });19602 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
19601}19603}
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 {
19604 const pt = self.pt;19606 const pt = self.pt;
19605 const zcu = pt.zcu;19607 const zcu = pt.zcu;
19606 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
1960719608
19608 const result = result: {19609 const result = result: {
19609 const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*);19610 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...@@ -19728,10 +19729,10 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Ty
19728 return self.finishAir(inst, result, .{ operand, .none, .none });19729 return self.finishAir(inst, result, .{ operand, .none, .none });
19729}19730}
1973019731
19731fn airFloatSign(self: *CodeGen, inst: Air.Inst.Index) !void {19732fn airFloatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
19732 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;19733 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
19733 const ty = self.typeOf(un_op);19734 const ty = self.typeOf(un_op);
19734 return self.floatSign(inst, un_op, ty);19735 return self.floatSign(inst, tag, un_op, ty);
19735}19736}
1973619737
19737const RoundMode = packed struct(u5) {19738const RoundMode = packed struct(u5) {
...@@ -20014,7 +20015,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -20014,7 +20015,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
20014 break :result dst_mcv;20015 break :result dst_mcv;
20015 },20016 },
20016 },20017 },
20017 .float => return self.floatSign(inst, ty_op.operand, ty),20018 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
20018 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {20019 .vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
20019 else => null,20020 else => null,
20020 .int => switch (ty.childType(zcu).intInfo(zcu).bits) {20021 .int => switch (ty.childType(zcu).intInfo(zcu).bits) {
...@@ -20050,7 +20051,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -20050,7 +20051,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
20050 5...8 => if (self.hasFeature(.avx2)) .{ .vp_d, .abs } else null,20051 5...8 => if (self.hasFeature(.avx2)) .{ .vp_d, .abs } else null,
20051 },20052 },
20052 },20053 },
20053 .float => return self.floatSign(inst, ty_op.operand, ty),20054 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
20054 },20055 },
20055 }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});20056 }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
2005620057
...@@ -22911,7 +22912,7 @@ fn genBinOp(...@@ -22911,7 +22912,7 @@ fn genBinOp(
22911 .mul => .{ .v_ss, .mul },22912 .mul => .{ .v_ss, .mul },
22912 .div_float, .div_trunc, .div_floor, .div_exact => .{ .v_ss, .div },22913 .div_float, .div_trunc, .div_floor, .div_exact => .{ .v_ss, .div },
22913 .max => .{ .v_ss, .max },22914 .max => .{ .v_ss, .max },
22914 .min => .{ .v_ss, .max },22915 .min => .{ .v_ss, .min },
22915 else => unreachable,22916 else => unreachable,
22916 },22917 },
22917 dst_reg,22918 dst_reg,
test/behavior/floatop.zig+1
...@@ -1654,6 +1654,7 @@ test "runtime isNan(inf * 0)" {...@@ -1654,6 +1654,7 @@ test "runtime isNan(inf * 0)" {
1654}1654}
16551655
1656test "optimized float mode" {1656test "optimized float mode" {
1657 if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest;
1657 if (builtin.mode == .Debug) return error.SkipZigTest;1658 if (builtin.mode == .Debug) return error.SkipZigTest;
16581659
1659 const big = 0x1p40;1660 const big = 0x1p40;
test/cases/compile_errors/anytype_param_requires_comptime.zig+1-1
...@@ -15,6 +15,6 @@ pub export fn entry() void {...@@ -15,6 +15,6 @@ pub export fn entry() void {
15// error15// error
16//16//
17// :7:25: error: unable to resolve comptime value17// :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-known18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_447.C' must be comptime-known
19// :4:16: note: struct requires comptime because of this field19// :4:16: note: struct requires comptime because of this field
20// :4:16: note: types are not available at runtime20// :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 {...@@ -16,5 +16,5 @@ pub export fn entry2() void {
16//16//
17// :3:6: error: no field or member function named 'copy' in '[]const u8'17// :3:6: error: no field or member function named 'copy' in '[]const u8'
18// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'18// :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'
20// :12:6: note: struct declared here20// :12:6: note: struct declared here
test/cases/compile_errors/coerce_anon_struct.zig+1-1
...@@ -6,6 +6,6 @@ export fn foo() void {...@@ -6,6 +6,6 @@ export fn foo() void {
66
7// error7// error
8//8//
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'
10// :3:16: note: struct declared here10// :3:16: note: struct declared here
11// :1:11: note: struct declared here11// :1:11: note: struct declared here