From e13aa915b20db3f5521f5f280ba0bd9b1a79f1c0 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 19 May 2023 02:07:14 -0400 Subject: [PATCH] x86_64: add error for saturating arithmetic --- src/arch/x86_64/CodeGen.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index abb1c08d54..7b5f47a777 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -2935,6 +2935,10 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void { const mod = self.bin_file.options.module.?; const bin_op = self.air.instructions.items(.data)[inst].bin_op; const ty = self.typeOf(bin_op.lhs); + if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail( + "TODO implement addMulSat for {}", + .{ty.fmt(mod)}, + ); const lhs_mcv = try self.resolveInst(bin_op.lhs); 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 { const mod = self.bin_file.options.module.?; const bin_op = self.air.instructions.items(.data)[inst].bin_op; const ty = self.typeOf(bin_op.lhs); + if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail( + "TODO implement addMulSat for {}", + .{ty.fmt(mod)}, + ); const lhs_mcv = try self.resolveInst(bin_op.lhs); 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 { const mod = self.bin_file.options.module.?; const bin_op = self.air.instructions.items(.data)[inst].bin_op; const ty = self.typeOf(bin_op.lhs); + if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(mod) > 8) return self.fail( + "TODO implement addMulSat for {}", + .{ty.fmt(mod)}, + ); try self.spillRegisters(&.{ .rax, .rdx }); const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx }); @@ -6346,8 +6358,9 @@ fn genBinOp( const lhs_ty = self.typeOf(lhs_air); const rhs_ty = self.typeOf(rhs_air); const abi_size: u32 = @intCast(lhs_ty.abiSize(mod)); - if (lhs_ty.scalarType(mod).isRuntimeFloat() and - lhs_ty.scalarType(mod).floatBits(self.target.*) == 80) + if ((lhs_ty.scalarType(mod).isRuntimeFloat() and + lhs_ty.scalarType(mod).floatBits(self.target.*) == 80) or + lhs_ty.abiSize(mod) > @as(u6, if (self.hasFeature(.avx)) 32 else 16)) return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(mod), });