This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] add sqrt library function
ClosedPublic

Authored by bob80905 on Aug 25 2022, 5:21 PM.

Details

Summary

This change exposes the sqrt library function for HLSL scalar types,
excluding long and long long doubles. Sqrt is supported for all scalar, vector,
and matrix types. This patch only adds a subset of scalar type support.

Long and long long double support is missing in this patch because that type
doesn't exist in HLSL.

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

Diff Detail

Event Timeline

bob80905 created this revision.Aug 25 2022, 5:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 5:21 PM
Herald added a subscriber: Anastasia. · View Herald Transcript
bob80905 requested review of this revision.Aug 25 2022, 5:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 5:21 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

A very minor suggestion. This looks pretty straightforward.

clang/test/CodeGenHLSL/builtins/sqrt.hlsl
6

The -fnative-half-type suggests that you're readying this for when 16-bit types are available. That's fine, but in the spirit of starting as early as possible as we tend to do with these, you might want to target shadermodel6.2 instead since that's where they were introduced and sqrt is as old as HLSL 1.0 AFAIK.

bob80905 updated this revision to Diff 458513.Sep 7 2022, 10:45 AM

Shader Model target update
Change the shader model target to 6.2, because that is when fnative-half-type was introduced.

bob80905 updated this revision to Diff 461405.Sep 19 2022, 4:18 PM

rebase
rebasing review to latest origin/main.

bob80905 updated this revision to Diff 461636.Sep 20 2022, 11:24 AM

include both commits

bob80905 updated this revision to Diff 461638.Sep 20 2022, 11:30 AM

add hlslintr.h file

bob80905 updated this revision to Diff 461656.Sep 20 2022, 12:16 PM

Include previous commit

beanz accepted this revision.Sep 20 2022, 12:41 PM

LGTM

This revision is now accepted and ready to land.Sep 20 2022, 12:41 PM
bob80905 updated this revision to Diff 461674.Sep 20 2022, 1:17 PM
  • add empty line to end of file sqrt.hlsl
This revision was landed with ongoing or failed builds.Sep 20 2022, 1:42 PM
Closed by commit rGb95c57444a8a: [HLSL] add sqrt library function (authored by bob80905, committed by beanz). · Explain Why
This revision was automatically updated to reflect the committed changes.
python3kgae added inline comments.
clang/lib/Headers/hlsl/hlsl_intrinsics.h
17

This should be removed.
We're using __builtin_elementwise_abs now.