From 722d4a11bbba4052558f6f69b7e710d1206f3355 Mon Sep 17 00:00:00 2001 From: John Schmidt Date: Fri, 4 Feb 2022 20:21:15 +0100 Subject: stage2: implement @sqrt for f{16,32,64} Support for f128, comptime_float, and c_longdouble require improvements to compiler_rt and will implemented in a later PR. Some of the code in this commit could be made more generic, for instance `llvm.airSqrt` could probably be `llvm.airUnaryMath`, but let's cross that bridge when we get to it. --- src/codegen/llvm.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/codegen/llvm.zig') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index abf371c85b..5a2c21eece 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2050,6 +2050,8 @@ pub const FuncGen = struct { .shr => try self.airShr(inst, false), .shr_exact => try self.airShr(inst, true), + .sqrt => try self.airSqrt(inst), + .cmp_eq => try self.airCmp(inst, .eq), .cmp_gt => try self.airCmp(inst, .gt), .cmp_gte => try self.airCmp(inst, .gte), @@ -4211,6 +4213,20 @@ pub const FuncGen = struct { } } + fn airSqrt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { + if (self.liveness.isUnused(inst)) return null; + + const un_op = self.air.instructions.items(.data)[inst].un_op; + const operand = try self.resolveInst(un_op); + const operand_ty = self.air.typeOf(un_op); + + const operand_llvm_ty = try self.dg.llvmType(operand_ty); + const fn_val = self.getIntrinsic("llvm.sqrt", &.{operand_llvm_ty}); + const params = [_]*const llvm.Value{operand}; + + return self.builder.buildCall(fn_val, ¶ms, params.len, .C, .Auto, ""); + } + fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, prefix: [*:0]const u8) !?*const llvm.Value { if (self.liveness.isUnused(inst)) return null; -- cgit v1.2.3