Skip to content

[mlir][spirv] Add definitions for GL inverse hyperbolic functions #141720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,77 @@ def SPIRV_GLTanhOp : SPIRV_GLUnaryArithmeticOp<"Tanh", 21, SPIRV_Float16or32> {

// -----

def SPIRV_GLAsinhOp : SPIRV_GLUnaryArithmeticOp<"Asinh", 22, SPIRV_Float16or32> {
let summary = "Arc hyperbolic sine of operand in radians.";

let description = [{
Arc hyperbolic sine; result is the inverse of sinh.

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.Asinh %0 : f32
%3 = spirv.GL.Asinh %1 : vector<3xf16>
```
}];
}

// -----

def SPIRV_GLAcoshOp : SPIRV_GLUnaryArithmeticOp<"Acosh", 23, SPIRV_Float16or32> {
let summary = "Arc hyperbolic cosine of operand in radians.";

let description = [{
Arc hyperbolic cosine; result is the non-negative inverse of cosh. The resulting
value is NaN if x < 1.

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.Acosh %0 : f32
%3 = spirv.GL.Acosh %1 : vector<3xf16>
```
}];
}

// -----

def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32> {
let summary = "Arc hyperbolic tangent of operand in radians.";

let description = [{
Arc hyperbolic tangent; result is the inverse of tanh. The resulting value
is NaN if abs x ≥ 1.

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.Atanh %0 : f32
%3 = spirv.GL.Atanh %1 : vector<3xf16>
```
}];
}

// -----

def SPIRV_GLFClampOp : SPIRV_GLTernaryArithmeticOp<"FClamp", 43, SPIRV_Float> {
let summary = "Clamp x between min and max values.";

Expand Down
48 changes: 48 additions & 0 deletions mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,54 @@ func.func @coshvec(%arg0 : vector<3xf16>) -> () {
return
}

//===----------------------------------------------------------------------===//
// spirv.GL.Asinh
//===----------------------------------------------------------------------===//

func.func @asinh(%arg0 : f32) -> () {
// CHECK: spirv.GL.Asinh {{%.*}} : f32
%2 = spirv.GL.Asinh %arg0 : f32
return
}

func.func @asinhvec(%arg0 : vector<3xf16>) -> () {
// CHECK: spirv.GL.Asinh {{%.*}} : vector<3xf16>
%2 = spirv.GL.Asinh %arg0 : vector<3xf16>
return
}

//===----------------------------------------------------------------------===//
// spirv.GL.Acosh
//===----------------------------------------------------------------------===//

func.func @acosh(%arg0 : f32) -> () {
// CHECK: spirv.GL.Acosh {{%.*}} : f32
%2 = spirv.GL.Acosh %arg0 : f32
return
}

func.func @acoshvec(%arg0 : vector<3xf16>) -> () {
// CHECK: spirv.GL.Acosh {{%.*}} : vector<3xf16>
%2 = spirv.GL.Acosh %arg0 : vector<3xf16>
return
}

//===----------------------------------------------------------------------===//
// spirv.GL.Atanh
//===----------------------------------------------------------------------===//

func.func @atanh(%arg0 : f32) -> () {
// CHECK: spirv.GL.Atanh {{%.*}} : f32
%2 = spirv.GL.Atanh %arg0 : f32
return
}

func.func @atanhvec(%arg0 : vector<3xf16>) -> () {
// CHECK: spirv.GL.Atanh {{%.*}} : vector<3xf16>
%2 = spirv.GL.Atanh %arg0 : vector<3xf16>
return
}

//===----------------------------------------------------------------------===//
// spirv.GL.Pow
//===----------------------------------------------------------------------===//
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Target/SPIRV/gl-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
%15 = spirv.GL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32
// CHECK: {{%.*}} = spirv.GL.Fract {{%.*}} : f32
%16 = spirv.GL.Fract %arg0 : f32
// CHECK: {{%.*}} = spirv.GL.Asinh {{%.*}} : f32
%17 = spirv.GL.Asinh %arg0 : f32
// CHECK: {{%.*}} = spirv.GL.Acosh {{%.*}} : f32
%18 = spirv.GL.Acosh %arg0 : f32
// CHECK: {{%.*}} = spirv.GL.Atanh {{%.*}} : f32
%19 = spirv.GL.Atanh %arg0 : f32
spirv.Return
}

Expand Down
Loading