Skip to content

Commit 18c5d63

Browse files
committed
[mlir][spirv] Add definition for GL Fract
1 parent f737df7 commit 18c5d63

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,4 +1161,29 @@ 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 x - floor x.
1171+
1172+
fract(±0) = +0.
1173+
1174+
fract(±Inf) = NaN.
1175+
1176+
The operand x must be a scalar or vector whose component type is floating-point.
1177+
1178+
Result Type and the type of x must be the same type. Results are computed per component.
1179+
1180+
#### Example:
1181+
1182+
```mlir
1183+
%result = spirv.GL.Sqrt %x : f32
1184+
%result = spirv.GL.Sqrt %x : vector<3xf16>
1185+
```
1186+
}];
1187+
}
1188+
11641189
#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)