Skip to content

Implement the isnan HLSL Function #99132

Open
@farzonl

Description

@farzonl
  • Implement isnan clang builtin,
  • Link isnan clang builtin with hlsl_intrinsics.h
  • Add sema checks for isnan to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for isnan to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/isnan.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/isnan-errors.hlsl
  • Create the int_dx_isnan intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_isnan to 8 in DXIL.td
  • Create the isnan.ll and isnan_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_isnan intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the isnan lowering and map it to int_spv_isnan in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/isnan.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
8 IsNaN 6.0 ()

SPIR-V

OpIsNan:

Description:

Result is true if x is a NaN for the floating-point encoding used
by the type of x, otherwise result is false.

Result Type must be a scalar or vector of Boolean
type
.

x must be a scalar or vector of floating-point type. It
must have the same number of components as Result Type.

Results are computed per component.

Word Count Opcode Results Operands

4

156

<id>
Result Type

Result <id>

<id>
x

Test Case(s)

Example 1

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

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

HLSL:

Determines if the specified value is NAN or QNAN.

ret isnan(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 NAN or QNAN. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions