This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] add cos library function
ClosedPublic

Authored by bob80905 on Sep 29 2022, 4:20 PM.

Details

Summary

This change exposes the cos library function for HLSL,
excluding long, int, and long long doubles.
Cos is supported for all scalar, vector, and matrix types.

Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the cos function only works on floating type arguments.

The full documentation of the HLSL cos function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-cos

Diff Detail

Event Timeline

bob80905 created this revision.Sep 29 2022, 4:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2022, 4:20 PM
Herald added a subscriber: Anastasia. · View Herald Transcript
bob80905 requested review of this revision.Sep 29 2022, 4:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2022, 4:20 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
python3kgae added inline comments.Sep 29 2022, 4:27 PM
clang/lib/Headers/hlsl/hlsl_intrinsics.h
111

why there're integer overloads?

bob80905 updated this revision to Diff 464091.Sep 29 2022, 4:33 PM
  • remove int overloads
python3kgae added inline comments.Sep 29 2022, 4:52 PM
clang/test/CodeGenHLSL/builtins/cos.hlsl
12

We want to lower it into llvm::Intrinsic::cos.

You can add it in CodeGenFunction::EmitBuiltinExpr like how elementwise_ceil is lowered.
And add people who did the elementwise_ceil work to review. Better create another PR.

bob80905 updated this revision to Diff 464407.Sep 30 2022, 2:40 PM
  • remove double
bob80905 updated this revision to Diff 464428.Sep 30 2022, 4:12 PM
  • lower cos to llvm
  • lower cos to llvm

This will affect things outside HLSL.
Please create a new PR without HLSL related part. Sorry I didn't make things clear before :(.

You can copy what https://github.com/llvm/llvm-project/commit/8680f951c21e675a110e79c9b8dc59bb94290b01 did when adding __builtin_elementwise_ceil
Also need to modify docs like https://github.com/llvm/llvm-project/commit/025988ded6b2a57022dbf9775f35a1a933584bfa

bob80905 updated this revision to Diff 464447.Sep 30 2022, 5:40 PM

revert revision, remove int overloads

python3kgae accepted this revision.Nov 12 2022, 5:08 PM
This revision is now accepted and ready to land.Nov 12 2022, 5:08 PM
bob80905 updated this revision to Diff 475633.Nov 15 2022, 4:53 PM
  • remove int overloads
  • remove double
  • update tests after new builtin landed
bob80905 updated this revision to Diff 475861.Nov 16 2022, 10:08 AM
  • clang format
This revision was automatically updated to reflect the committed changes.