Description
Note atan2 has been identified as a potential generic llvm intrinsic:
Investigation: #87367
RFC: https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294
- Implement
atan2
clang builtin, - Link
atan2
clang builtin withhlsl_intrinsics.h
- Add sema checks for
atan2
toCheckHLSLBuiltinFunctionCall
inSemaChecking.cpp
- Add codegen for
atan2
toEmitHLSLBuiltinExpr
inCGBuiltin.cpp
- Add codegen tests to
clang/test/CodeGenHLSL/builtins/atan2.hlsl
- Add sema tests to
clang/test/SemaHLSL/BuiltIns/atan2-errors.hlsl
-
Create theint_atan2
intrinsic inIntrinsics.td
-
Create theint_dx_atan2
intrinsic inIntrinsicsDirectX.td
- Create the
DXILOpMapping
ofint_atan2
to17
inDXIL.td
- Create the
atan2.ll
andatan2_errors.ll
tests inllvm/test/CodeGen/DirectX/
-
Create theint_spv_atan2
intrinsic inIntrinsicsSPIRV.td
-
In SPIRVInstructionSelector.cpp create theatan2
lowering and map it toint_spv_atan2
inSPIRVInstructionSelector::selectIntrinsic
. - In SPIRVInstructionSelector.cpp:
SPIRVInstructionSelector::spvSelect
Add
case TargetOpcode::G_FATAN2:
return selectExtInst(ResVReg, ResType, I, CL::atan2, GL::Atan2);
- Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/atan2.ll
DirectX
DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
---|---|---|---|
17 | Atan | 6.0 | () |
SPIR-V
Atan2:
Description:
Atan2
Arc tangent. Result is an angle, in radians, whose tangent is y / x.
The signs of x and y are used to determine what quadrant the angle
is in. The range of result values is [-π, π] . Result is undefined if
x and y are both 0.
The operand x and y must be a scalar or vector whose component type
is 16-bit or 32-bit floating-point.
Result Type and the type of all operands must be the same type.
Results are computed per component.
Number | Operand 1 | Operand 2 | Operand 3 | Operand 4 |
---|---|---|---|---|
25 |
<id> |
<id> |
Test Case(s)
Example 1
//dxc atan2_test.hlsl -T lib_6_8 -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0
export float4 fn(float4 p1, float4 p2) {
return atan2(p1, p2);
}
HLSL:
Returns the arctangent of two values (x,y).
ret atan2(y, x) |
---|
Parameters
Item | Description |
---|---|
y |
[in] The y value. |
x |
[in] The x value. |
Return Value
The arctangent of (y,x).
Remarks
The signs of the x and y parameters are used to determine the quadrant of the return values within the range of -π to π. The atan2 HLSL intrinsic function is well-defined for every point other than the origin, even if y equals 0 and x does not equal 0.
Type Description
Name | Template Type | Component Type | Size |
---|---|---|---|
y | same as input x | float | same dimension(s) as input x |
x | scalar, vector, or matrix | float | any |
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) | vs_1_1 |
Requirements
Requirement | Value |
---|---|
Header |
|
See also
Metadata
Metadata
Assignees
Labels
Type
Projects
Status