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 {...@@ -2935,6 +2935,10 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
2935 const mod = self.bin_file.options.module.?;2935 const mod = self.bin_file.options.module.?;
2936 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2936 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2937 const ty = self.typeOf(bin_op.lhs);2937 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
2939 const lhs_mcv = try self.resolveInst(bin_op.lhs);2943 const lhs_mcv = try self.resolveInst(bin_op.lhs);
2940 const dst_mcv = if (lhs_mcv.isRegister() and self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv))2944 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 {...@@ -3014,6 +3018,10 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
3014 const mod = self.bin_file.options.module.?;3018 const mod = self.bin_file.options.module.?;
3015 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3019 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3016 const ty = self.typeOf(bin_op.lhs);3020 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
3018 const lhs_mcv = try self.resolveInst(bin_op.lhs);3026 const lhs_mcv = try self.resolveInst(bin_op.lhs);
3019 const dst_mcv = if (lhs_mcv.isRegister() and self.reuseOperand(inst, bin_op.lhs, 0, lhs_mcv))3027 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 {...@@ -3086,6 +3094,10 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
3086 const mod = self.bin_file.options.module.?;3094 const mod = self.bin_file.options.module.?;
3087 const bin_op = self.air.instructions.items(.data)[inst].bin_op;3095 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
3088 const ty = self.typeOf(bin_op.lhs);3096 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
3090 try self.spillRegisters(&.{ .rax, .rdx });3102 try self.spillRegisters(&.{ .rax, .rdx });
3091 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });3103 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });
...@@ -6346,8 +6358,9 @@ fn genBinOp(...@@ -6346,8 +6358,9 @@ fn genBinOp(
6346 const lhs_ty = self.typeOf(lhs_air);6358 const lhs_ty = self.typeOf(lhs_air);
6347 const rhs_ty = self.typeOf(rhs_air);6359 const rhs_ty = self.typeOf(rhs_air);
6348 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));6360 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));
6349 if (lhs_ty.scalarType(mod).isRuntimeFloat() and6361 if ((lhs_ty.scalarType(mod).isRuntimeFloat() and
6350 lhs_ty.scalarType(mod).floatBits(self.target.*) == 80)6362 lhs_ty.scalarType(mod).floatBits(self.target.*) == 80) or
6363 lhs_ty.abiSize(mod) > @as(u6, if (self.hasFeature(.avx)) 32 else 16))
6351 return self.fail("TODO implement genBinOp for {s} {}", .{6364 return self.fail("TODO implement genBinOp for {s} {}", .{
6352 @tagName(air_tag), lhs_ty.fmt(mod),6365 @tagName(air_tag), lhs_ty.fmt(mod),
6353 });6366 });