Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement the ldexp HLSL Function #99133

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

Closed
3 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 1 comment · Fixed by #138182
Closed
3 tasks
Tracked by #99235

Implement the ldexp HLSL Function #99133

farzonl opened this issue Jul 16, 2024 · 1 comment · Fixed by #138182
Assignees
Labels
backend:DirectX 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 ldexp entirely in hlsl_intrinsics.h and other hlsl headers.
  • Implement ldexp codgen tests in clang/test/CodeGenHLSL/builtins/ldexp.hlsl
  • Implement ldexp sema tests in clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl

https://hlsl.godbolt.org/z/97c4GxGrP

Implementation should look something like this:

template <typename T, int N>
constexpr T ldexp(T p0, T p1) {
  return  exp2(p1) * p0;
}

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
21 Exp2 6.0 ()

SPIR-V

Exp2:

Description:

Exp2

Result is 2 raised to the x power; 2x.

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.

Number Operand 1 Operand 2 Operand 3 Operand 4

29

<id>
x

Test Case(s)

Example 1

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

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

HLSL:

Returns the result of multiplying the specified value by two, raised to the power of the specified exponent.

ret ldexp(x, exp)

This function uses the following formula: x * 2exp

Parameters

Item Description
x
[in] The specified value.
exp
[in] The specified exponent.

Return Value

The result of multiplying the x parameter by two, raised to the power of the exp 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 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 farzonl added backend:DirectX 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 another with a global intrinsic

@pow2clk pow2clk moved this from Planning to Ready in HLSL Support Nov 19, 2024
@farzonl farzonl moved this from Ready to Designing in HLSL Support Mar 19, 2025
@farzonl farzonl self-assigned this Mar 19, 2025
@damyanp damyanp removed the status in HLSL Support Apr 25, 2025
@farzonl farzonl removed their assignment Apr 30, 2025
@farzonl farzonl moved this to Ready in HLSL Support Apr 30, 2025
@kmpeng kmpeng moved this from Ready to Active in HLSL Support Apr 30, 2025
@kmpeng kmpeng closed this as completed in d11df05 May 3, 2025
@github-project-automation github-project-automation bot moved this from Active to Closed in HLSL Support May 3, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this issue May 6, 2025
Closes llvm#99133.

Implemented `ldexp` entirely in `hlsl_intrinsics.h` and
`hlsl_intrinsic_helpers.h`, added coresponding tests in
`clang/test/CodeGenHLSL/builtins/ldexp.hlsl` and
`clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl`.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this issue May 6, 2025
Closes llvm#99133.

Implemented `ldexp` entirely in `hlsl_intrinsics.h` and
`hlsl_intrinsic_helpers.h`, added coresponding tests in
`clang/test/CodeGenHLSL/builtins/ldexp.hlsl` and
`clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl`.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this issue May 6, 2025
Closes llvm#99133.

Implemented `ldexp` entirely in `hlsl_intrinsics.h` and
`hlsl_intrinsic_helpers.h`, added coresponding tests in
`clang/test/CodeGenHLSL/builtins/ldexp.hlsl` and
`clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl`.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this issue May 7, 2025
Closes llvm#99133.

Implemented `ldexp` entirely in `hlsl_intrinsics.h` and
`hlsl_intrinsic_helpers.h`, added coresponding tests in
`clang/test/CodeGenHLSL/builtins/ldexp.hlsl` and
`clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

3 participants