Skip to content
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

Implement the frexp HLSL Function #99119

Open
9 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 1 comment
Open
9 tasks
Tracked by #99235

Implement the frexp HLSL Function #99119

farzonl opened this issue Jul 16, 2024 · 1 comment
Labels
backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • 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)

@farzonl farzonl added backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@pow2clk
Copy link
Contributor

pow2clk commented Nov 19, 2024

@farzonl could you update the description to mention the global intrinsic?

@pow2clk pow2clk moved this from Planning to Ready in HLSL Support Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Ready
Development

No branches or pull requests

2 participants