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

[HLSL] implement exp intrinsic #70072

Closed
Tracked by #30
llvm-beanz opened this issue Oct 24, 2023 · 0 comments · Fixed by #83832
Closed
Tracked by #30

[HLSL] implement exp intrinsic #70072

llvm-beanz opened this issue Oct 24, 2023 · 0 comments · Fixed by #83832
Assignees
Labels
backend:DirectX HLSL HLSL Language Support

Comments

@llvm-beanz
Copy link
Collaborator

Implement and expose the HLSL exp intrinsic:

https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-exp

@llvm-beanz llvm-beanz converted this from a draft issue Oct 24, 2023
@llvm-beanz llvm-beanz added HLSL HLSL Language Support and removed new issue labels Oct 24, 2023
@farzonl farzonl self-assigned this Mar 4, 2024
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 4, 2024
 This change implements: llvm#70072

hlsl_intrinsics.h - add the exp api
DXIL.td add the llvm intrinsic to DXIL opcode lowering mapping
This change reuses llvm's existing intrinsic __builtin_elementwise_exp\ int_exp
@farzonl farzonl moved this to In Progress in HLSL Support Mar 4, 2024
@farzonl farzonl moved this from In Progress to Needs Review in HLSL Support Mar 4, 2024
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 4, 2024
 This change implements: llvm#70072

hlsl_intrinsics.h - add the exp api
DXIL.td add the llvm intrinsic to DXIL opcode lowering mapping
This change reuses llvm's existing intrinsic __builtin_elementwise_exp\ int_exp
farzonl added a commit that referenced this issue Mar 5, 2024
This change implements: #70072

- `hlsl_intrinsics.h` - add the `exp` api
- `DXIL.td` - add the llvm intrinsic to DXIL opcode lowering mapping.
- This change reuses llvm's existing intrinsic
`__builtin_elementwise_exp` \ `int_exp` & `__builtin_elementwise_exp2` \
`int_exp2`
- This PR is part 1 of 2.
- Part 2 requires an intrinsic to instructions lowering.
Part2 will expand `int_exp` to 
```
A = Builder.CreateFMul(log2eConst, val);
int_exp2(A)
```
just like we do in
[TranslateExp](https://github.com/microsoft/DirectXShaderCompiler/blob/main/lib/HLSL/HLOperationLower.cpp#L2220C1-L2236C2)
@farzonl farzonl moved this from Needs Review to Done in HLSL Support Mar 5, 2024
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 8, 2024
This change implements lowering for llvm#70076, llvm#70100, llvm#70072, & llvm#70102
CGBuiltin.cpp - - simplify lerp intrinsic
IntrinsicsDirectX.td - simplify lerp intrinsic
SemaChecking.cpp - remove unnecessary check
DXILIntrinsicExpansion.* - add intrinsic to instruction expansion cases
DXILOpLowering.cpp -  make sure DXILIntrinsicExpansion happens first
DirectX.h - changes to support new pass
DirectXTargetMachine.cpp - changes to support new pass
@farzonl farzonl linked a pull request Mar 12, 2024 that will close this issue
@farzonl farzonl closed this as completed Mar 12, 2024
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 12, 2024
This change implements lowering for llvm#70076, llvm#70100, llvm#70072, & llvm#70102
CGBuiltin.cpp - - simplify lerp intrinsic
IntrinsicsDirectX.td - simplify lerp intrinsic
SemaChecking.cpp - remove unnecessary check
DXILIntrinsicExpansion.* - add intrinsic to instruction expansion cases
DXILOpLowering.cpp -  make sure DXILIntrinsicExpansion happens first
DirectX.h - changes to support new pass
DirectXTargetMachine.cpp - changes to support new pass
farzonl added a commit to farzonl/llvm-project that referenced this issue Mar 14, 2024
This change implements lowering for llvm#70076, llvm#70100, llvm#70072, & llvm#70102
`CGBuiltin.cpp` - - simplify `lerp` intrinsic
`IntrinsicsDirectX.td` - simplify `lerp` intrinsic
`SemaChecking.cpp` - remove unnecessary check
`DXILIntrinsicExpansion.*` - add intrinsic to instruction expansion cases
`DXILOpLowering.cpp` -  make sure `DXILIntrinsicExpansion` happens first
`DirectX.h` - changes to support new pass
`DirectXTargetMachine.cpp` - changes to support new pass

Why `any`, and `lerp` as instruction expansion just for DXIL?
-  SPIR-V there is an [OpAny](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpAny)
- SPIR-V has a GLSL lerp extension via [Fmix](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#FMix)

Why `exp` instruction expansion?
- We have an `exp2` opcode and `exp` reuses that opcode. So instruction expansion is a convenient way to do preprocessing.
- Further SPIR-V has a GLSL exp extension via  [Exp](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#Exp) and [Exp2](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#Exp2)

Why `rcp` as instruction expansion?
This one is a bit of the odd man out and might have to move to `cgbuiltins` when we better understand SPIRV requirements. However I included it because it seems like [fast math mode has an AllowRecip flag](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_fp_fast_math_mode) which lets you compute the reciprocal without performing the division.  We don't have that in DXIL so thought to include it.
farzonl added a commit that referenced this issue Mar 15, 2024
This change implements lowering for #70076, #70100, #70072, & #70102 
`CGBuiltin.cpp` - - simplify `lerp` intrinsic
`IntrinsicsDirectX.td` - simplify `lerp` intrinsic
`SemaChecking.cpp` - remove unnecessary check
`DXILIntrinsicExpansion.*` - add intrinsic to instruction expansion
cases
`DXILOpLowering.cpp` - make sure `DXILIntrinsicExpansion` happens first
`DirectX.h` - changes to support new pass
`DirectXTargetMachine.cpp` - changes to support new pass

Why `any`, and `lerp` as instruction expansion just for DXIL?
- SPIR-V there is an
[OpAny](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpAny)
- SPIR-V has a GLSL lerp extension via
[Fmix](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#FMix)

Why `exp` instruction expansion?
- We have an `exp2` opcode and `exp` reuses that opcode. So instruction
expansion is a convenient way to do preprocessing.
- Further SPIR-V has a GLSL exp extension via
[Exp](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#Exp)
and
[Exp2](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#Exp2)

Why `rcp` as instruction expansion?
This one is a bit of the odd man out and might have to move to
`cgbuiltins` when we better understand SPIRV requirements. However I
included it because it seems like [fast math mode has an AllowRecip
flag](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_fp_fast_math_mode)
which lets you compute the reciprocal without performing the division.
We don't have that in DXIL so thought to include it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX HLSL HLSL Language Support
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants