llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.39k stars 12.15k forks source link

Implement the `ldexp` HLSL Function #99133

Open farzonl opened 4 months ago

farzonl commented 4 months ago

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
21 Exp 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)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
pow2clk commented 1 week ago

@farzonl another with a global intrinsic