authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-19 02:07:14-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-25 19:14:03-04:00
loge13aa915b20db3f5521f5f280ba0bd9b1a79f1c0
tree19082aab1d785855ffebbc4b43b7567f0c48cc91
parent5b742785100bb2662f6fc0ee11ac84b2fed9be9e

x86_64: add error for saturating arithmetic


1 files changed, 15 insertions(+), 2 deletions(-)

src/arch/x86_64/CodeGen.zig+15-2
......@@ -2935,6 +2935,10 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
29352935 const mod = self.bin_file.options.module.?;
29362936 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
29372937 const ty = self.typeOf(bin_op.lhs);
2938 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
2939 "TODO implement addMulSat for {}",
2940 .{ty.fmt(mod)},
2941 );
29382942
29392943 const lhs_mcv = try self.resolveInst(bin_op.lhs);
29402944 const dst_mcv = if (lhs_mcv.isRegister() and self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv))
......@@ -3014,6 +3018,10 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
30143018 const mod = self.bin_file.options.module.?;
30153019 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
30163020 const ty = self.typeOf(bin_op.lhs);
3021 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
3022 "TODO implement addMulSat for {}",
3023 .{ty.fmt(mod)},
3024 );
30173025
30183026 const lhs_mcv = try self.resolveInst(bin_op.lhs);
30193027 const dst_mcv = if (lhs_mcv.isRegister() and self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv))
......@@ -3086,6 +3094,10 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
30863094 const mod = self.bin_file.options.module.?;
30873095 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
30883096 const ty = self.typeOf(bin_op.lhs);
3097 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail(
3098 "TODO implement addMulSat for {}",
3099 .{ty.fmt(mod)},
3100 );
30893101
30903102 try self.spillRegisters(&.{ .rax, .rdx });
30913103 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });
......@@ -6346,8 +6358,9 @@ fn genBinOp(
63466358 const lhs_ty = self.typeOf(lhs_air);
63476359 const rhs_ty = self.typeOf(rhs_air);
63486360 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));
6349 if (lhs_ty.scalarType(mod).isRuntimeFloat() and
6350 lhs_ty.scalarType(mod).floatBits(self.target.*) == 80)
6361 if ((lhs_ty.scalarType(mod).isRuntimeFloat() and
6362 lhs_ty.scalarType(mod).floatBits(self.target.*) == 80) or
6363 lhs_ty.abiSize(mod) > @as(u6, if (self.hasFeature(.avx)) 32 else 16))
63516364 return self.fail("TODO implement genBinOp for {s} {}", .{
63526365 @tagName(air_tag), lhs_ty.fmt(mod),
63536366 });