-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][spirv] Add definition for GL Fract #132921
Conversation
@llvm/pr-subscribers-mlir-spirv @llvm/pr-subscribers-mlir Author: Igor Wodiany (IgWod-IMG) ChangesFull diff: https://github.com/llvm/llvm-project/pull/132921.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index 1cdfa02f81787..d6dc0e0d7d000 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -1161,4 +1161,29 @@ def SPIRV_GLFindUMsbOp : SPIRV_GLUnaryArithmeticOp<"FindUMsb", 75, SPIRV_Int32>
}];
}
+// ----
+
+def SPIRV_GLFractOp : SPIRV_GLUnaryArithmeticOp<"Fract", 10, SPIRV_Float> {
+ let summary = "Returns the x - floor(x) of the operand";
+
+ let description = [{
+ Result is x - floor x.
+
+ fract(±0) = +0.
+
+ fract(±Inf) = NaN.
+
+ The operand x must be a scalar or vector whose component type is floating-point.
+
+ Result Type and the type of x must be the same type. Results are computed per component.
+
+ #### Example:
+
+ ```mlir
+ %result = spirv.GL.Sqrt %x : f32
+ %result = spirv.GL.Sqrt %x : vector<3xf16>
+ ```
+ }];
+}
+
#endif // MLIR_DIALECT_SPIRV_IR_GL_OPS
diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index beda3872bc8d2..0be047932c1f3 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -663,3 +663,29 @@ func.func @reflect_invalid_type(%arg0 : i32, %arg1 : i32) {
%0 = spirv.GL.Reflect %arg0, %arg1 : i32
return
}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Fract
+//===----------------------------------------------------------------------===//
+
+func.func @fract(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Fract {{%.*}} : f32
+ %0 = spirv.GL.Fract %arg0 : f32
+ return
+}
+
+func.func @fractvec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Fract {{%.*}} : vector<3xf16>
+ %0 = spirv.GL.Fract %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+func.func @fract_invalid_type(%arg0 : i32) {
+ // expected-error @+1 {{'spirv.GL.Fract' op operand #0 must be 16/32/64-bit float or vector of 16/32/64-bit float values}}
+ %0 = spirv.GL.Fract %arg0 : i32
+ return
+}
diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index 119304cea7d4a..7f9771220b75d 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -32,6 +32,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
%14 = spirv.GL.Ldexp %arg0 : f32, %arg2 : i32 -> f32
// CHECK: {{%.*}} = spirv.GL.FMix {{%.*}} : f32, {{%.*}} : f32, {{%.*}} : f32 -> f32
%15 = spirv.GL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32
+ // CHECK: {{%.*}} = spirv.GL.Fract {{%.*}} : f32
+ %16 = spirv.GL.Fract %arg0 : f32
spirv.Return
}
|
Result is x - floor x. | ||
|
||
fract(±0) = +0. | ||
|
||
fract(±Inf) = NaN. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could wrap this in a code block maybe to make the formatting nicer to read on the website -- it doesn't have to be 1:1 import from the spirv spec
I have updated the description and pushed an update. Let me know if you had something else in mind. |
No description provided.