Skip to content

Implement the frexp HLSL Function #99119

@farzonl

Description

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

DirectX

There were no DXIL opcodes found for frexp.

SPIR-V

FrexpStruct:

Description:

FrexpStruct

Same semantics as in Frexp, except that the entire result is in the
instruction’s result; there is not a pointer operand to write through.

Result Type must be an OpTypeStruct with two members. Member 0
must have the same type as the type of x. Member 0 holds the
significand. Member 1 must be a scalar or vector with integer
component type, with 32-bit component width. Member 1 holds exponent.
These two members must have the same number of components. This
structure type must be explicitly declared by the module.

Number Operand 1 Operand 2 Operand 3 Operand 4

52

<id>
x

Test Case(s)

Example 1

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

export float4 fn(float4 p1, float4 p2) {
    return frexp(p1, p2);
}

HLSL:

Returns the mantissa and exponent of the specified floating-point value.

ret frexp(x, exp)

The return value is the mantissa, and the value returned by exp parameter is the exponent.

Parameters

Item Description
x
[in] The specified floating-point value. If the x parameter is 0, this function returns 0 for both the mantissa and the exponent.
exp
[out] The returned exponent of the x parameter.

Return Value

The mantissa of the x parameter.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float any
exp same as input x float same dimension(s) as input x
ret same as input x float same dimension(s) as input x

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 3 (DirectX HLSL) and higher shader models yes
Shader Model 2 (DirectX HLSL) yes (ps_2_x only)
Shader Model 1 (DirectX HLSL) no

Remarks

Requirements

Requirement Value
Header
Corecrt_math.h

See also

Intrinsic Functions (DirectX HLSL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    HLSLHLSL Language Supportbackend:SPIR-Vbot:HLSLmetaissueIssue to collect references to a group of similar or related issues.

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions