[Mlir-commits] [mlir] 9eb57b6 - [MLIR][NVVM] Add `NVVM_F32UnaryApproxOp` Base Class (NFC) (#194378)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun May 3 02:06:12 PDT 2026
Author: Guray Ozen
Date: 2026-05-03T11:06:07+02:00
New Revision: 9eb57b6cdb51ae0aea7c76608195eccebe62733d
URL: https://github.com/llvm/llvm-project/commit/9eb57b6cdb51ae0aea7c76608195eccebe62733d
DIFF: https://github.com/llvm/llvm-project/commit/9eb57b6cdb51ae0aea7c76608195eccebe62733d.diff
LOG: [MLIR][NVVM] Add `NVVM_F32UnaryApproxOp` Base Class (NFC) (#194378)
Add `NVVM_F32UnaryApproxOp` tablegen class to unify implementation
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index 73afdb29b6149..51ff22dfdc65c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -302,6 +302,16 @@ class NVVM_SingleResultIntrinsicOp<string mnemonic, list<Trait> traits = [], str
}];
}
+class NVVM_F32UnaryApproxOp<string mnemonic, list<Trait> traits = []> :
+ NVVM_SingleResultIntrinsicOp<mnemonic,
+ traits # [Pure, SameOperandsAndResultType]> {
+ let arguments = (ins F32:$src,
+ DefaultValuedAttr<BoolAttr, "false">:$ftz);
+ let results = (outs F32:$res);
+ let assemblyFormat = "$src attr-dict `:` type($src)";
+}
+
+
//===----------------------------------------------------------------------===//
// NVVM special register op definitions
//===----------------------------------------------------------------------===//
@@ -529,64 +539,43 @@ def NVVM_RcpApproxFtzF32Op : NVVM_IntrOp<"rcp.approx.ftz.f", [Pure], 1> {
// keeps the NVVM dialect self-contained -- users don't need to reach for
// `math.*` ops for something that already has a PTX instruction.
-def NVVM_SinOp : NVVM_SingleResultIntrinsicOp<"sin",
- [Pure, SameOperandsAndResultType]> {
+def NVVM_SinOp : NVVM_F32UnaryApproxOp<"sin"> {
let summary = "Sine (fast approximation)";
let description = [{
Computes a fast approximation of the sine of the input value (in radians).
- The `ftz` attribute, when set, flushes subnormal inputs and results to
+ The `ftz` attribute, when set, flushes subnormal inputs and results to
sign-preserving zero.
For more information, see PTX ISA:
[sin](https://docs.nvidia.com/cuda/parallel-thread-execution/#floating-point-instructions-sin)
}];
- let arguments = (ins F32:$src,
- DefaultValuedAttr<BoolAttr, "false">:$ftz);
- let results = (outs F32:$res);
- let assemblyFormat = "$src attr-dict `:` type($src)";
}
-
-def NVVM_CosOp : NVVM_SingleResultIntrinsicOp<"cos",
- [Pure, SameOperandsAndResultType]> {
+def NVVM_CosOp : NVVM_F32UnaryApproxOp<"cos"> {
let summary = "Cosine (fast approximation)";
let description = [{
Computes a fast approximation of the cosine of the input value (in
radians). The `ftz` attribute, when set, flushes subnormal inputs
and results to sign-preserving zero.
}];
- let arguments = (ins F32:$src,
- DefaultValuedAttr<BoolAttr, "false">:$ftz);
- let results = (outs F32:$res);
- let assemblyFormat = "$src attr-dict `:` type($src)";
}
-def NVVM_Log2Op : NVVM_SingleResultIntrinsicOp<"log2",
- [Pure, SameOperandsAndResultType]> {
+def NVVM_Log2Op : NVVM_F32UnaryApproxOp<"log2"> {
let summary = "Base-2 logarithm (fast approximation)";
let description = [{
Computes a fast approximation of the base-2 logarithm of the input
value. The `ftz` attribute, when set, flushes subnormal inputs and
results to sign-preserving zero.
}];
- let arguments = (ins F32:$src,
- DefaultValuedAttr<BoolAttr, "false">:$ftz);
- let results = (outs F32:$res);
- let assemblyFormat = "$src attr-dict `:` type($src)";
}
-def NVVM_Ex2Op : NVVM_SingleResultIntrinsicOp<"ex2",
- [Pure, SameOperandsAndResultType]> {
+def NVVM_Ex2Op : NVVM_F32UnaryApproxOp<"ex2"> {
let summary = "Base-2 exponential (fast approximation)";
let description = [{
Computes a fast approximation of 2 raised to the power of the input
value. The `ftz` attribute, when set, flushes subnormal inputs and
results to sign-preserving zero.
}];
- let arguments = (ins F32:$src,
- DefaultValuedAttr<BoolAttr, "false">:$ftz);
- let results = (outs F32:$res);
- let assemblyFormat = "$src attr-dict `:` type($src)";
}
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list