llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Implement the `isfinite` HLSL Function

Open farzonl opened this issue 2 years ago • 6 comments

  • [ ] Implement isfinite clang builtin,
  • [ ] Link isfinite clang builtin with hlsl_intrinsics.h
  • [ ] Add sema checks for isfinite to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • [ ] Add codegen for isfinite to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • [ ] Add codegen tests to clang/test/CodeGenHLSL/builtins/isfinite.hlsl
  • [ ] Add sema tests to clang/test/SemaHLSL/BuiltIns/isfinite-errors.hlsl
  • [ ] Create the int_dx_isfinite intrinsic in IntrinsicsDirectX.td
  • [ ] Create the DXILOpMapping of int_dx_isfinite to 10 in DXIL.td
  • [ ] Create the isfinite.ll and isfinite_errors.ll tests in llvm/test/CodeGen/DirectX/

Matrix implementation is also needed:

  • [ ] https://github.com/llvm/wg-hlsl/issues/387

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
10 IsFinite 6.0 ()

In SM6.8 and earlier the 16 bit overload of isfinite must be emulated, because the 16 bit overload isn't supported until sm6.9.

SPIR-V

There is a OpIsFinite spirv OP but it cannot be used because it requires the Kernel capability. This op can be emulated using OpIsInf and OpIsNan.

Test Case(s)

Example 1

//dxc isfinite_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool4 fn(float4 p1) {
    return isfinite(p1);
}

HLSL:

Determines if the specified floating-point value is finite.

ret isfinite(x)

Parameters

Item Description
x
[in] The specified value.

Return Value

Returns a value of the same size as the input, with a value set to True if the x parameter is finite; otherwise False.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float any
ret scalar, vector, or matrix bool as input

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 2 (DirectX HLSL) and higher shader models yes
Shader Model 1 (DirectX HLSL) yes (vs_1_1 only)

Requirements

Requirement Value
Header
Corecrt_math.h

See also

Intrinsic Functions (DirectX HLSL)

farzonl avatar Jul 16 '24 19:07 farzonl

For SM6.8 and earlier in DXIL the 16 bit overload of this operation should be emulated.

spall avatar Aug 29 '25 17:08 spall

In SPIRV isfinite can be emulated using OpIsInf and OpIsNaN

spall avatar Aug 29 '25 17:08 spall

@danbrown-amd Could you assign yourself to this issue or comment so I can assign you to it?

kmpeng avatar Sep 25 '26 22:09 kmpeng

I can't assign myself so please assign me.

danbrown-amd avatar Sep 25 '26 22:09 danbrown-amd

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

- [ ] Implement `isfinite` clang builtin, - [ ] Link `isfinite` clang builtin with `hlsl_intrinsics.h` - [ ] Add sema checks for `isfinite` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [ ] Add codegen for `isfinite` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/isfinite.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/isfinite-errors.hlsl` - [ ] Create the `int_dx_isfinite` intrinsic in `IntrinsicsDirectX.td` - [ ] Create the `DXILOpMapping` of `int_dx_isfinite` to `10` in `DXIL.td` - [ ] Create the `isfinite.ll` and `isfinite_errors.ll` tests in `llvm/test/CodeGen/DirectX/`

Matrix implementation is also needed:

  • [ ] https://github.com/llvm/wg-hlsl/issues/387

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
10 IsFinite 6.0 ()

In SM6.8 and earlier the 16 bit overload of isfinite must be emulated, because the 16 bit overload isn't supported until sm6.9.

SPIR-V

There is a OpIsFinite spirv OP but it cannot be used because it requires the Kernel capability. This op can be emulated using OpIsInf and OpIsNan.

Test Case(s)

Example 1

//dxc isfinite_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool4 fn(float4 p1) {
    return isfinite(p1);
}

HLSL:

Determines if the specified floating-point value is finite.

ret isfinite(x)

Parameters

Item Description
<span id="x"></span><span id="X"></span>x<br/> [in] The specified value.<br/>

Return Value

Returns a value of the same size as the input, with a value set to True if the x parameter is finite; otherwise False.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float any
ret scalar, vector, or matrix bool as input

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 2 (DirectX HLSL) and higher shader models yes
Shader Model 1 (DirectX HLSL) yes (vs_1_1 only)

Requirements

Requirement Value
Header<br/> <dl> <dt>Corecrt_math.h</dt> </dl>

See also

<dl> <dt>

Intrinsic Functions (DirectX HLSL) </dt> </dl>

@llvm/issue-subscribers-clang-frontend

Author: Farzon Lotfi (farzonl)

- [ ] Implement `isfinite` clang builtin, - [ ] Link `isfinite` clang builtin with `hlsl_intrinsics.h` - [ ] Add sema checks for `isfinite` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [ ] Add codegen for `isfinite` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/isfinite.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/isfinite-errors.hlsl` - [ ] Create the `int_dx_isfinite` intrinsic in `IntrinsicsDirectX.td` - [ ] Create the `DXILOpMapping` of `int_dx_isfinite` to `10` in `DXIL.td` - [ ] Create the `isfinite.ll` and `isfinite_errors.ll` tests in `llvm/test/CodeGen/DirectX/`

Matrix implementation is also needed:

  • [ ] https://github.com/llvm/wg-hlsl/issues/387

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
10 IsFinite 6.0 ()

In SM6.8 and earlier the 16 bit overload of isfinite must be emulated, because the 16 bit overload isn't supported until sm6.9.

SPIR-V

There is a OpIsFinite spirv OP but it cannot be used because it requires the Kernel capability. This op can be emulated using OpIsInf and OpIsNan.

Test Case(s)

Example 1

//dxc isfinite_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool4 fn(float4 p1) {
    return isfinite(p1);
}

HLSL:

Determines if the specified floating-point value is finite.

ret isfinite(x)

Parameters

Item Description
<span id="x"></span><span id="X"></span>x<br/> [in] The specified value.<br/>

Return Value

Returns a value of the same size as the input, with a value set to True if the x parameter is finite; otherwise False.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float any
ret scalar, vector, or matrix bool as input

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 2 (DirectX HLSL) and higher shader models yes
Shader Model 1 (DirectX HLSL) yes (vs_1_1 only)

Requirements

Requirement Value
Header<br/> <dl> <dt>Corecrt_math.h</dt> </dl>

See also

<dl> <dt>

Intrinsic Functions (DirectX HLSL) </dt> </dl>