diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td b/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td @@ -328,6 +328,36 @@ // ----- +def SPV_GLSLRoundOp: SPV_GLSLUnaryArithmeticOp<"Round", 1, SPV_Float> { + let summary = "Rounds to the whole number"; + + let description = [{ + Result is the value equal to the nearest whole number. + + 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. + + + ``` + float-scalar-vector-type ::= float-type | + `vector<` integer-literal `x` float-type `>` + floor-op ::= ssa-id `=` `spv.GLSL.Round` ssa-use `:` + float-scalar-vector-type + ``` + #### Example: + + ```mlir + %2 = spv.GLSL.Round %0 : f32 + %3 = spv.GLSL.Round %1 : vector<3xf16> + ``` + }]; +} + +// ----- + def SPV_GLSLInverseSqrtOp : SPV_GLSLUnaryArithmeticOp<"InverseSqrt", 32, SPV_Float> { let summary = "Reciprocal of sqrt(operand)"; diff --git a/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir b/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir --- a/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir @@ -14,6 +14,8 @@ %4 = spv.GLSL.Sin %arg0 : f32 // CHECK: {{%.*}} = spv.GLSL.Tan {{%.*}} : f32 %5 = spv.GLSL.Tan %arg0 : f32 + // CHECK: {{%.*}} = spv.GLSL.Round {{%.*}} : f32 + %6 = spv.GLSL.Round %arg0 : f32 spv.Return } } diff --git a/mlir/test/Dialect/SPIRV/glslops.mlir b/mlir/test/Dialect/SPIRV/glslops.mlir --- a/mlir/test/Dialect/SPIRV/glslops.mlir +++ b/mlir/test/Dialect/SPIRV/glslops.mlir @@ -155,3 +155,19 @@ %2 = spv.GLSL.Tan %arg0 : vector<3xf16> return } + +//===----------------------------------------------------------------------===// +// spv.GLSL.Round +//===----------------------------------------------------------------------===// + +func @round(%arg0 : f32) -> () { + // CHECK: spv.GLSL.Round {{%.*}} : f32 + %2 = spv.GLSL.Round %arg0 : f32 + return +} + +func @roundvec(%arg0 : vector<3xf16>) -> () { + // CHECK: spv.GLSL.Round {{%.*}} : vector<3xf16> + %2 = spv.GLSL.Round %arg0 : vector<3xf16> + return +}