[Mlir-commits] [mlir] d61a06e - [mlir][spirv] Add definition for GL Log2 (#143409)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jun 10 02:40:53 PDT 2025


Author: Igor Wodiany
Date: 2025-06-10T10:40:50+01:00
New Revision: d61a06e25533efd940296ab9dbd122f3797714de

URL: https://github.com/llvm/llvm-project/commit/d61a06e25533efd940296ab9dbd122f3797714de
DIFF: https://github.com/llvm/llvm-project/commit/d61a06e25533efd940296ab9dbd122f3797714de.diff

LOG: [mlir][spirv] Add definition for GL Log2 (#143409)

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
    mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
    mlir/test/Target/SPIRV/gl-ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index feae817c9b4ef..4c7186077fae0 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -838,6 +838,36 @@ def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32>
 
 // -----
 
+def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> {
+  let summary = "Result is the base-2 logarithm of x";
+
+  let description = [{
+    Result is the base-2 logarithm of x, i.e., the value y which satisfies the
+    equation x = 2**y. The resulting value is NaN if x < 0. Moreover:
+
+    ```
+    log(Inf) = Inf
+    log(1.0) = +0
+    log(±0) = -Inf
+    ```
+    
+    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.Log2 %0 : f32
+    %3 = spirv.GL.Log2 %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPIRV_GLFClampOp : SPIRV_GLTernaryArithmeticOp<"FClamp", 43, SPIRV_Float> {
   let summary = "Clamp x between min and max values.";
 

diff  --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index 680a7e12b1082..f238336f14a4d 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -737,3 +737,29 @@ func.func @fract_invalid_type(%arg0 : i32) {
   %0 = spirv.GL.Fract %arg0 : i32
   return
 }
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Log2
+//===----------------------------------------------------------------------===//
+
+func.func @log2(%arg0 : f32) -> () {
+  // CHECK: spirv.GL.Log2 {{%.*}} : f32
+  %0 = spirv.GL.Log2 %arg0 : f32
+  return
+}
+
+func.func @log2vec(%arg0 : vector<3xf16>) -> () {
+  // CHECK: spirv.GL.Log2 {{%.*}} : vector<3xf16>
+  %0 = spirv.GL.Log2 %arg0 : vector<3xf16>
+  return
+}
+
+// -----
+
+func.func @log2_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.Log2 %arg0 : i32
+  return
+}

diff  --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index 28e5a1fd72ec5..64592a4d5079b 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -40,6 +40,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
     %18 = spirv.GL.Acosh %arg0 : f32
     // CHECK: {{%.*}} = spirv.GL.Atanh {{%.*}} : f32
     %19 = spirv.GL.Atanh %arg0 : f32
+    // CHECK: {{%.*}} = spirv.GL.Log2 {{%.*}} : f32
+    %20 = spirv.GL.Log2 %arg0 : f32
     spirv.Return
   }
 


        


More information about the Mlir-commits mailing list