From 4b9be0ef4b38b2ee8a1cc1914881155218bee491 Mon Sep 17 00:00:00 2001 From: Igor Wodiany Date: Tue, 10 Jun 2025 16:44:52 +0100 Subject: [PATCH] [mlir][spirv] Add definition for GL Exp2 --- .../mlir/Dialect/SPIRV/IR/SPIRVGLOps.td | 28 +++++++++++++++++++ mlir/test/Dialect/SPIRV/IR/gl-ops.mlir | 26 +++++++++++++++++ mlir/test/Target/SPIRV/gl-ops.mlir | 2 ++ 3 files changed, 56 insertions(+) diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td index 4c7186077fae0..f3f75240e5214 100644 --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td @@ -838,6 +838,34 @@ def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32> // ----- +def SPIRV_GLExp2Op : SPIRV_GLUnaryArithmeticOp<"Exp2", 29, SPIRV_Float16or32> { + let summary = "Result is 2 raised to the x power"; + + let description = [{ + Result is 2 raised to the x power; 2**x. + + ``` + exp2(Inf) = Inf. + exp2(-Inf) = +0. + ``` + + The operand x must be a scalar or vector whose component type is 16-bit or + 32-bit floating-point. + + Result Type and the type of x must be the same type. Results are computed + per component. + + #### Example: + + ```mlir + %2 = spirv.GL.Exp2 %0 : f32 + %3 = spirv.GL.Exp2 %1 : vector<3xf16> + ``` + }]; +} + +// ----- + def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> { let summary = "Result is the base-2 logarithm of x"; diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir index 50cf1b26d42ab..29beee5aea93c 100644 --- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir @@ -789,3 +789,29 @@ func.func @tanh_invalid_type(%arg0 : i32) -> () { %0 = spirv.GL.Tanh %arg0 : i32 return } + +// ----- + +//===----------------------------------------------------------------------===// +// spirv.GL.Exp2 +//===----------------------------------------------------------------------===// + +func.func @exp2(%arg0 : f32) -> () { + // CHECK: spirv.GL.Exp2 {{%.*}} : f32 + %0 = spirv.GL.Exp2 %arg0 : f32 + return +} + +func.func @exp2vec(%arg0 : vector<3xf16>) -> () { + // CHECK: spirv.GL.Exp2 {{%.*}} : vector<3xf16> + %0 = spirv.GL.Exp2 %arg0 : vector<3xf16> + return +} + +// ----- + +func.func @exp2_invalid_type(%arg0 : i32) -> () { + // expected-error @+1 {{op operand #0 must be 16/32-bit float or vector of 16/32-bit float values}} + %0 = spirv.GL.Exp2 %arg0 : i32 + return +} diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir index 368f60e102dc1..3dee03345e9a1 100644 --- a/mlir/test/Target/SPIRV/gl-ops.mlir +++ b/mlir/test/Target/SPIRV/gl-ops.mlir @@ -44,6 +44,8 @@ spirv.module Logical GLSL450 requires #spirv.vce { %20 = spirv.GL.Log2 %arg0 : f32 // CHECK: {{%.*}} = spirv.GL.Tanh {{%.*}} : f32 %21 = spirv.GL.Tanh %arg0 : f32 + // CHECK: {{%.*}} = spirv.GL.Exp2 {{%.*}} : f32 + %22 = spirv.GL.Exp2 %arg0 : f32 spirv.Return }