Skip to content

Commit 98424e1

Browse files
IgWod-IMGtomtor
authored andcommitted
[mlir][spirv] Add definition for GL Exp2 (llvm#143678)
1 parent d422ba3 commit 98424e1

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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

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

839839
// -----
840840

841+
def SPIRV_GLExp2Op : SPIRV_GLUnaryArithmeticOp<"Exp2", 29, SPIRV_Float16or32> {
842+
let summary = "Result is 2 raised to the x power";
843+
844+
let description = [{
845+
Result is 2 raised to the x power; 2**x.
846+
847+
```
848+
exp2(Inf) = Inf.
849+
exp2(-Inf) = +0.
850+
```
851+
852+
The operand x must be a scalar or vector whose component type is 16-bit or
853+
32-bit floating-point.
854+
855+
Result Type and the type of x must be the same type. Results are computed
856+
per component.
857+
858+
#### Example:
859+
860+
```mlir
861+
%2 = spirv.GL.Exp2 %0 : f32
862+
%3 = spirv.GL.Exp2 %1 : vector<3xf16>
863+
```
864+
}];
865+
}
866+
867+
// -----
868+
841869
def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> {
842870
let summary = "Result is the base-2 logarithm of x";
843871

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,29 @@ func.func @tanh_invalid_type(%arg0 : i32) -> () {
789789
%0 = spirv.GL.Tanh %arg0 : i32
790790
return
791791
}
792+
793+
// -----
794+
795+
//===----------------------------------------------------------------------===//
796+
// spirv.GL.Exp2
797+
//===----------------------------------------------------------------------===//
798+
799+
func.func @exp2(%arg0 : f32) -> () {
800+
// CHECK: spirv.GL.Exp2 {{%.*}} : f32
801+
%0 = spirv.GL.Exp2 %arg0 : f32
802+
return
803+
}
804+
805+
func.func @exp2vec(%arg0 : vector<3xf16>) -> () {
806+
// CHECK: spirv.GL.Exp2 {{%.*}} : vector<3xf16>
807+
%0 = spirv.GL.Exp2 %arg0 : vector<3xf16>
808+
return
809+
}
810+
811+
// -----
812+
813+
func.func @exp2_invalid_type(%arg0 : i32) -> () {
814+
// expected-error @+1 {{op operand #0 must be 16/32-bit float or vector of 16/32-bit float values}}
815+
%0 = spirv.GL.Exp2 %arg0 : i32
816+
return
817+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
4444
%20 = spirv.GL.Log2 %arg0 : f32
4545
// CHECK: {{%.*}} = spirv.GL.Tanh {{%.*}} : f32
4646
%21 = spirv.GL.Tanh %arg0 : f32
47+
// CHECK: {{%.*}} = spirv.GL.Exp2 {{%.*}} : f32
48+
%22 = spirv.GL.Exp2 %arg0 : f32
4749
spirv.Return
4850
}
4951

0 commit comments

Comments
 (0)