[flang-commits] [flang] [flang] Implement `sinpi` (PR #149525)
Connector Switch via flang-commits
flang-commits at lists.llvm.org
Mon Jul 21 08:51:44 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);
----------------
c8ef wrote:
```
LogicalResult FloatAttr::verify(function_ref<InFlightDiagnostic()> emitError,
Type type, APFloat value) {
// Verify that the type is correct.
if (!llvm::isa<FloatType>(type))
return emitError() << "expected floating point type";
// Verify that the type semantics match that of the value.
if (&llvm::cast<FloatType>(type).getFloatSemantics() !=
&value.getSemantics()) {
return emitError()
<< "FloatAttr type doesn't match the type implied by its value";
}
return success();
}
```
It appears these two floating-point types have different semantics. To ensure pi uses the same semantics as the argument type, we'd still need to convert it from APFloat. Either way, a conversion seems necessary.
https://github.com/llvm/llvm-project/pull/149525
More information about the flang-commits
mailing list