From 98009a2f66de32d1ea4df41cc03d5ad3d723b3ed Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 28 Oct 2021 17:41:45 -0700 Subject: C backend: implement trunc instruction Note that there is not any test coverage yet for integer truncation involving non-power-of-two integers. --- src/codegen/c.zig | 12 +----------- src/codegen/llvm.zig | 3 +-- 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index ffc9bb0fe0..444adf0aa1 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1089,7 +1089,6 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .call => try airCall(f, inst), .dbg_stmt => try airDbgStmt(f, inst), .intcast => try airIntCast(f, inst), - .trunc => try airTrunc(f, inst), .bool_to_int => try airBoolToInt(f, inst), .load => try airLoad(f, inst), .ret => try airRet(f, inst), @@ -1117,6 +1116,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .float_to_int, .fptrunc, .fpext, + .trunc, => try airSimpleCast(f, inst), .ptrtoint => try airPtrToInt(f, inst), @@ -1366,16 +1366,6 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue { return local; } -fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { - if (f.liveness.isUnused(inst)) - return CValue.none; - - const ty_op = f.air.instructions.items(.data)[inst].ty_op; - const operand = try f.resolveInst(ty_op.operand); - _ = operand; - return f.fail("TODO: C backend: airTrunc", .{}); -} - fn airBoolToInt(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 9c2fd22df0..572e23ff28 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -3153,8 +3153,7 @@ pub const FuncGen = struct { } fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { - if (self.liveness.isUnused(inst)) - return null; + if (self.liveness.isUnused(inst)) return null; const ty_op = self.air.instructions.items(.data)[inst].ty_op; const operand = try self.resolveInst(ty_op.operand); -- cgit v1.2.3