aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig7
-rw-r--r--src/codegen/llvm.zig15
2 files changed, 16 insertions, 6 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 070aa0a238..f6a3105760 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1157,6 +1157,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
.shl_sat => try airSatOp(f, inst, "shls_"),
.add_with_overflow => try airAddWithOverflow(f, inst),
+ .mul_with_overflow => try airMulWithOverflow(f, inst),
.min => try airMinMax(f, inst, "<"),
.max => try airMinMax(f, inst, ">"),
@@ -1873,6 +1874,12 @@ fn airAddWithOverflow(f: *Function, inst: Air.Inst.Index) !CValue {
return f.fail("TODO add with overflow", .{});
}
+fn airMulWithOverflow(f: *Function, inst: Air.Inst.Index) !CValue {
+ _ = f;
+ _ = inst;
+ return f.fail("TODO mul with overflow", .{});
+}
+
fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {
if (f.liveness.isUnused(inst))
return CValue.none;
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 0a2b12dd1e..209e3fb4de 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1714,7 +1714,8 @@ pub const FuncGen = struct {
.max => try self.airMax(inst),
.slice => try self.airSlice(inst),
- .add_with_overflow => try self.airAddWithOverflow(inst),
+ .add_with_overflow => try self.airOverflow(inst, "llvm.sadd.with.overflow", "llvm.uadd.with.overflow"),
+ .mul_with_overflow => try self.airOverflow(inst, "llvm.smul.with.overflow", "llvm.umul.with.overflow"),
.bit_and, .bool_and => try self.airAnd(inst),
.bit_or, .bool_or => try self.airOr(inst),
@@ -3136,7 +3137,12 @@ pub const FuncGen = struct {
}
}
- fn airAddWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ fn airOverflow(
+ self: *FuncGen,
+ inst: Air.Inst.Index,
+ signed_intrinsic: []const u8,
+ unsigned_intrinsic: []const u8,
+ ) !?*const llvm.Value {
if (self.liveness.isUnused(inst))
return null;
@@ -3150,10 +3156,7 @@ pub const FuncGen = struct {
const ptr_ty = self.air.typeOf(pl_op.operand);
const lhs_ty = self.air.typeOf(extra.lhs);
- const intrinsic_name: []const u8 = if (lhs_ty.isSignedInt())
- "llvm.sadd.with.overflow"
- else
- "llvm.uadd.with.overflow";
+ const intrinsic_name = if (lhs_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic;
const llvm_lhs_ty = try self.dg.llvmType(lhs_ty);