Skip to content

Commit 7b3885d

Browse files
authored
[mlir][spirv] Add definition for GL Fract (#132921)
1 parent 8704635 commit 7b3885d

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,4 +1161,31 @@ def SPIRV_GLFindUMsbOp : SPIRV_GLUnaryArithmeticOp<"FindUMsb", 75, SPIRV_Int32>
11611161
}];
11621162
}
11631163

1164+
// ----
1165+
1166+
def SPIRV_GLFractOp : SPIRV_GLUnaryArithmeticOp<"Fract", 10, SPIRV_Float> {
1167+
let summary = "Returns the `x - floor(x)` of the operand";
1168+
1169+
let description = [{
1170+
Result is:
1171+
1172+
```
1173+
fract(x) = x - floor(x)
1174+
fract(±0) = +0
1175+
fract(±Inf) = NaN
1176+
```
1177+
1178+
The operand x must be a scalar or vector whose component type is floating-point.
1179+
1180+
Result Type and the type of x must be the same type. Results are computed per component.
1181+
1182+
#### Example:
1183+
1184+
```mlir
1185+
%result = spirv.GL.Sqrt %x : f32
1186+
%result = spirv.GL.Sqrt %x : vector<3xf16>
1187+
```
1188+
}];
1189+
}
1190+
11641191
#endif // MLIR_DIALECT_SPIRV_IR_GL_OPS

mlir/test/Dialect/SPIRV/IR/gl-ops.mlir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,3 +663,29 @@ func.func @reflect_invalid_type(%arg0 : i32, %arg1 : i32) {
663663
%0 = spirv.GL.Reflect %arg0, %arg1 : i32
664664
return
665665
}
666+
667+
// -----
668+
669+
//===----------------------------------------------------------------------===//
670+
// spirv.GL.Fract
671+
//===----------------------------------------------------------------------===//
672+
673+
func.func @fract(%arg0 : f32) -> () {
674+
// CHECK: spirv.GL.Fract {{%.*}} : f32
675+
%0 = spirv.GL.Fract %arg0 : f32
676+
return
677+
}
678+
679+
func.func @fractvec(%arg0 : vector<3xf16>) -> () {
680+
// CHECK: spirv.GL.Fract {{%.*}} : vector<3xf16>
681+
%0 = spirv.GL.Fract %arg0 : vector<3xf16>
682+
return
683+
}
684+
685+
// -----
686+
687+
func.func @fract_invalid_type(%arg0 : i32) {
688+
// 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}}
689+
%0 = spirv.GL.Fract %arg0 : i32
690+
return
691+
}

mlir/test/Target/SPIRV/gl-ops.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
3232
%14 = spirv.GL.Ldexp %arg0 : f32, %arg2 : i32 -> f32
3333
// CHECK: {{%.*}} = spirv.GL.FMix {{%.*}} : f32, {{%.*}} : f32, {{%.*}} : f32 -> f32
3434
%15 = spirv.GL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32
35+
// CHECK: {{%.*}} = spirv.GL.Fract {{%.*}} : f32
36+
%16 = spirv.GL.Fract %arg0 : f32
3537
spirv.Return
3638
}
3739

0 commit comments

Comments
 (0)