[flang-commits] [flang] [flang] Implement `sinpi` (PR #149525)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Mon Jul 21 10:08:50 PDT 2025
================
@@ -8060,6 +8061,21 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType,
return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg});
}
+// SINPI
+mlir::Value IntrinsicLibrary::genSinpi(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), pi);
+ mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
----------------
tblah wrote:
Ahh okay what I think is happening here is that APFloat is forcing its size to f64 because `llvm::numbers::pi` is defined as a double. I'm concerned that this could produce inaccurate results for real(16) (aka floating point types with more precision than `f64`: f128 on aarch64 systems, I think f80 on x86).
https://github.com/llvm/llvm-project/pull/149525
More information about the flang-commits
mailing list