Skip to content

Commit 4e68962

Browse files
authored
[mlir][spirv] Add definitions for GL inverse hyperbolic functions (#141720)
Adds definitions for `Asinh`, `Acosh` and `Atanh` based on [SPIR-V extended instructions for GLSL](https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html). Their instruction numbers are 22, 23 and 24.
1 parent a8c2b43 commit 4e68962

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,77 @@ def SPIRV_GLTanhOp : SPIRV_GLUnaryArithmeticOp<"Tanh", 21, SPIRV_Float16or32> {
767767

768768
// -----
769769

770+
def SPIRV_GLAsinhOp : SPIRV_GLUnaryArithmeticOp<"Asinh", 22, SPIRV_Float16or32> {
771+
let summary = "Arc hyperbolic sine of operand in radians.";
772+
773+
let description = [{
774+
Arc hyperbolic sine; result is the inverse of sinh.
775+
776+
The operand x must be a scalar or vector whose component type is 16-bit or
777+
32-bit floating-point.
778+
779+
Result Type and the type of x must be the same type. Results are computed
780+
per component.
781+
782+
#### Example:
783+
784+
```mlir
785+
%2 = spirv.GL.Asinh %0 : f32
786+
%3 = spirv.GL.Asinh %1 : vector<3xf16>
787+
```
788+
}];
789+
}
790+
791+
// -----
792+
793+
def SPIRV_GLAcoshOp : SPIRV_GLUnaryArithmeticOp<"Acosh", 23, SPIRV_Float16or32> {
794+
let summary = "Arc hyperbolic cosine of operand in radians.";
795+
796+
let description = [{
797+
Arc hyperbolic cosine; result is the non-negative inverse of cosh. The resulting
798+
value is NaN if x < 1.
799+
800+
The operand x must be a scalar or vector whose component type is 16-bit or
801+
32-bit floating-point.
802+
803+
Result Type and the type of x must be the same type. Results are computed
804+
per component.
805+
806+
#### Example:
807+
808+
```mlir
809+
%2 = spirv.GL.Acosh %0 : f32
810+
%3 = spirv.GL.Acosh %1 : vector<3xf16>
811+
```
812+
}];
813+
}
814+
815+
// -----
816+
817+
def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32> {
818+
let summary = "Arc hyperbolic tangent of operand in radians.";
819+
820+
let description = [{
821+
Arc hyperbolic tangent; result is the inverse of tanh. The resulting value
822+
is NaN if abs x ≥ 1.
823+
824+
The operand x must be a scalar or vector whose component type is 16-bit or
825+
32-bit floating-point.
826+
827+
Result Type and the type of x must be the same type. Results are computed
828+
per component.
829+
830+
#### Example:
831+
832+
```mlir
833+
%2 = spirv.GL.Atanh %0 : f32
834+
%3 = spirv.GL.Atanh %1 : vector<3xf16>
835+
```
836+
}];
837+
}
838+
839+
// -----
840+
770841
def SPIRV_GLFClampOp : SPIRV_GLTernaryArithmeticOp<"FClamp", 43, SPIRV_Float> {
771842
let summary = "Clamp x between min and max values.";
772843

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,54 @@ func.func @coshvec(%arg0 : vector<3xf16>) -> () {
254254
return
255255
}
256256

257+
//===----------------------------------------------------------------------===//
258+
// spirv.GL.Asinh
259+
//===----------------------------------------------------------------------===//
260+
261+
func.func @asinh(%arg0 : f32) -> () {
262+
// CHECK: spirv.GL.Asinh {{%.*}} : f32
263+
%2 = spirv.GL.Asinh %arg0 : f32
264+
return
265+
}
266+
267+
func.func @asinhvec(%arg0 : vector<3xf16>) -> () {
268+
// CHECK: spirv.GL.Asinh {{%.*}} : vector<3xf16>
269+
%2 = spirv.GL.Asinh %arg0 : vector<3xf16>
270+
return
271+
}
272+
273+
//===----------------------------------------------------------------------===//
274+
// spirv.GL.Acosh
275+
//===----------------------------------------------------------------------===//
276+
277+
func.func @acosh(%arg0 : f32) -> () {
278+
// CHECK: spirv.GL.Acosh {{%.*}} : f32
279+
%2 = spirv.GL.Acosh %arg0 : f32
280+
return
281+
}
282+
283+
func.func @acoshvec(%arg0 : vector<3xf16>) -> () {
284+
// CHECK: spirv.GL.Acosh {{%.*}} : vector<3xf16>
285+
%2 = spirv.GL.Acosh %arg0 : vector<3xf16>
286+
return
287+
}
288+
289+
//===----------------------------------------------------------------------===//
290+
// spirv.GL.Atanh
291+
//===----------------------------------------------------------------------===//
292+
293+
func.func @atanh(%arg0 : f32) -> () {
294+
// CHECK: spirv.GL.Atanh {{%.*}} : f32
295+
%2 = spirv.GL.Atanh %arg0 : f32
296+
return
297+
}
298+
299+
func.func @atanhvec(%arg0 : vector<3xf16>) -> () {
300+
// CHECK: spirv.GL.Atanh {{%.*}} : vector<3xf16>
301+
%2 = spirv.GL.Atanh %arg0 : vector<3xf16>
302+
return
303+
}
304+
257305
//===----------------------------------------------------------------------===//
258306
// spirv.GL.Pow
259307
//===----------------------------------------------------------------------===//

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
3434
%15 = spirv.GL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32
3535
// CHECK: {{%.*}} = spirv.GL.Fract {{%.*}} : f32
3636
%16 = spirv.GL.Fract %arg0 : f32
37+
// CHECK: {{%.*}} = spirv.GL.Asinh {{%.*}} : f32
38+
%17 = spirv.GL.Asinh %arg0 : f32
39+
// CHECK: {{%.*}} = spirv.GL.Acosh {{%.*}} : f32
40+
%18 = spirv.GL.Acosh %arg0 : f32
41+
// CHECK: {{%.*}} = spirv.GL.Atanh {{%.*}} : f32
42+
%19 = spirv.GL.Atanh %arg0 : f32
3743
spirv.Return
3844
}
3945

0 commit comments

Comments
 (0)