Skip to content

Commit 89c75f1

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd61a06e25533' from llvm.org/main into next
2 parents 0cde632 + d61a06e commit 89c75f1

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,36 @@ def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32>
838838

839839
// -----
840840

841+
def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> {
842+
let summary = "Result is the base-2 logarithm of x";
843+
844+
let description = [{
845+
Result is the base-2 logarithm of x, i.e., the value y which satisfies the
846+
equation x = 2**y. The resulting value is NaN if x < 0. Moreover:
847+
848+
```
849+
log(Inf) = Inf
850+
log(1.0) = +0
851+
log(±0) = -Inf
852+
```
853+
854+
The operand x must be a scalar or vector whose component type is 16-bit or
855+
32-bit floating-point.
856+
857+
Result Type and the type of x must be the same type. Results are computed
858+
per component.
859+
860+
#### Example:
861+
862+
```mlir
863+
%2 = spirv.GL.Log2 %0 : f32
864+
%3 = spirv.GL.Log2 %1 : vector<3xf16>
865+
```
866+
}];
867+
}
868+
869+
// -----
870+
841871
def SPIRV_GLFClampOp : SPIRV_GLTernaryArithmeticOp<"FClamp", 43, SPIRV_Float> {
842872
let summary = "Clamp x between min and max values.";
843873

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,29 @@ func.func @fract_invalid_type(%arg0 : i32) {
737737
%0 = spirv.GL.Fract %arg0 : i32
738738
return
739739
}
740+
741+
// -----
742+
743+
//===----------------------------------------------------------------------===//
744+
// spirv.GL.Log2
745+
//===----------------------------------------------------------------------===//
746+
747+
func.func @log2(%arg0 : f32) -> () {
748+
// CHECK: spirv.GL.Log2 {{%.*}} : f32
749+
%0 = spirv.GL.Log2 %arg0 : f32
750+
return
751+
}
752+
753+
func.func @log2vec(%arg0 : vector<3xf16>) -> () {
754+
// CHECK: spirv.GL.Log2 {{%.*}} : vector<3xf16>
755+
%0 = spirv.GL.Log2 %arg0 : vector<3xf16>
756+
return
757+
}
758+
759+
// -----
760+
761+
func.func @log2_invalid_type(%arg0 : i32) -> () {
762+
// expected-error @+1 {{op operand #0 must be 16/32-bit float or vector of 16/32-bit float values}}
763+
%0 = spirv.GL.Log2 %arg0 : i32
764+
return
765+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
4040
%18 = spirv.GL.Acosh %arg0 : f32
4141
// CHECK: {{%.*}} = spirv.GL.Atanh {{%.*}} : f32
4242
%19 = spirv.GL.Atanh %arg0 : f32
43+
// CHECK: {{%.*}} = spirv.GL.Log2 {{%.*}} : f32
44+
%20 = spirv.GL.Log2 %arg0 : f32
4345
spirv.Return
4446
}
4547

0 commit comments

Comments
 (0)