-
Notifications
You must be signed in to change notification settings - Fork 15k
[HLSL] Implement the degrees intrinsic
#111209
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
Merged
+311
−0
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // RUN: %clang_cc1 -finclude-default-header -triple \ | ||
| // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ | ||
| // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ | ||
| // RUN: --check-prefixes=CHECK,NATIVE_HALF \ | ||
| // RUN: -DFNATTRS=noundef -DTARGET=dx | ||
| // RUN: %clang_cc1 -finclude-default-header -triple \ | ||
| // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ | ||
| // RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \ | ||
| // RUN: -DFNATTRS=noundef -DTARGET=dx | ||
| // RUN: %clang_cc1 -finclude-default-header -triple \ | ||
| // RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \ | ||
| // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ | ||
| // RUN: --check-prefixes=CHECK,NATIVE_HALF \ | ||
| // RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv | ||
| // RUN: %clang_cc1 -finclude-default-header -triple \ | ||
| // RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \ | ||
| // RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \ | ||
| // RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv | ||
|
|
||
| // NATIVE_HALF: define [[FNATTRS]] half @ | ||
| // NATIVE_HALF: %hlsl.degrees = call half @llvm.[[TARGET]].degrees.f16( | ||
| // NATIVE_HALF: ret half %hlsl.degrees | ||
| // NO_HALF: define [[FNATTRS]] float @ | ||
| // NO_HALF: %hlsl.degrees = call float @llvm.[[TARGET]].degrees.f32( | ||
| // NO_HALF: ret float %hlsl.degrees | ||
| half test_degrees_half(half p0) { return degrees(p0); } | ||
| // NATIVE_HALF: define [[FNATTRS]] <2 x half> @ | ||
| // NATIVE_HALF: %hlsl.degrees = call <2 x half> @llvm.[[TARGET]].degrees.v2f16 | ||
| // NATIVE_HALF: ret <2 x half> %hlsl.degrees | ||
| // NO_HALF: define [[FNATTRS]] <2 x float> @ | ||
| // NO_HALF: %hlsl.degrees = call <2 x float> @llvm.[[TARGET]].degrees.v2f32( | ||
| // NO_HALF: ret <2 x float> %hlsl.degrees | ||
| half2 test_degrees_half2(half2 p0) { return degrees(p0); } | ||
| // NATIVE_HALF: define [[FNATTRS]] <3 x half> @ | ||
| // NATIVE_HALF: %hlsl.degrees = call <3 x half> @llvm.[[TARGET]].degrees.v3f16 | ||
| // NATIVE_HALF: ret <3 x half> %hlsl.degrees | ||
| // NO_HALF: define [[FNATTRS]] <3 x float> @ | ||
| // NO_HALF: %hlsl.degrees = call <3 x float> @llvm.[[TARGET]].degrees.v3f32( | ||
| // NO_HALF: ret <3 x float> %hlsl.degrees | ||
| half3 test_degrees_half3(half3 p0) { return degrees(p0); } | ||
| // NATIVE_HALF: define [[FNATTRS]] <4 x half> @ | ||
| // NATIVE_HALF: %hlsl.degrees = call <4 x half> @llvm.[[TARGET]].degrees.v4f16 | ||
| // NATIVE_HALF: ret <4 x half> %hlsl.degrees | ||
| // NO_HALF: define [[FNATTRS]] <4 x float> @ | ||
| // NO_HALF: %hlsl.degrees = call <4 x float> @llvm.[[TARGET]].degrees.v4f32( | ||
| // NO_HALF: ret <4 x float> %hlsl.degrees | ||
| half4 test_degrees_half4(half4 p0) { return degrees(p0); } | ||
|
|
||
| // CHECK: define [[FNATTRS]] float @ | ||
| // CHECK: %hlsl.degrees = call float @llvm.[[TARGET]].degrees.f32( | ||
| // CHECK: ret float %hlsl.degrees | ||
| float test_degrees_float(float p0) { return degrees(p0); } | ||
| // CHECK: define [[FNATTRS]] <2 x float> @ | ||
| // CHECK: %hlsl.degrees = call <2 x float> @llvm.[[TARGET]].degrees.v2f32 | ||
| // CHECK: ret <2 x float> %hlsl.degrees | ||
| float2 test_degrees_float2(float2 p0) { return degrees(p0); } | ||
| // CHECK: define [[FNATTRS]] <3 x float> @ | ||
| // CHECK: %hlsl.degrees = call <3 x float> @llvm.[[TARGET]].degrees.v3f32 | ||
| // CHECK: ret <3 x float> %hlsl.degrees | ||
| float3 test_degrees_float3(float3 p0) { return degrees(p0); } | ||
| // CHECK: define [[FNATTRS]] <4 x float> @ | ||
| // CHECK: %hlsl.degrees = call <4 x float> @llvm.[[TARGET]].degrees.v4f32 | ||
| // CHECK: ret <4 x float> %hlsl.degrees | ||
| float4 test_degrees_float4(float4 p0) { return degrees(p0); } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify | ||
|
|
||
| float test_too_few_arg() { | ||
| return __builtin_hlsl_elementwise_degrees(); | ||
| // expected-error@-1 {{too few arguments to function call, expected 1, have 0}} | ||
| } | ||
|
|
||
| float2 test_too_many_arg(float2 p0) { | ||
| return __builtin_hlsl_elementwise_degrees(p0, p0); | ||
| // expected-error@-1 {{too many arguments to function call, expected 1, have 2}} | ||
| } | ||
|
|
||
| float builtin_bool_to_float_type_promotion(bool p1) { | ||
| return __builtin_hlsl_elementwise_degrees(p1); | ||
| // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} | ||
| } | ||
|
|
||
| float builtin_degrees_int_to_float_promotion(int p1) { | ||
| return __builtin_hlsl_elementwise_degrees(p1); | ||
| // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} | ||
| } | ||
|
|
||
| float2 builtin_degrees_int2_to_float2_promotion(int2 p1) { | ||
| return __builtin_hlsl_elementwise_degrees(p1); | ||
| // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| ; RUN: opt -S -dxil-intrinsic-expansion -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s | ||
|
|
||
| ; Make sure dxil op function calls for degrees are expanded and lowered as fmul for float and half. | ||
|
|
||
| define noundef half @degrees_half(half noundef %a) { | ||
| ; CHECK-LABEL: define noundef half @degrees_half( | ||
| ; CHECK-SAME: half noundef [[A:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ; CHECK-NEXT: [[DX_DEGREES1:%.*]] = fmul half [[A]], 0xH5329 | ||
| ; CHECK-NEXT: ret half [[DX_DEGREES1]] | ||
| ; | ||
| entry: | ||
| %dx.degrees = call half @llvm.dx.degrees.f16(half %a) | ||
| ret half %dx.degrees | ||
| } | ||
|
|
||
| define noundef float @degrees_float(float noundef %a) #0 { | ||
| ; CHECK-LABEL: define noundef float @degrees_float( | ||
| ; CHECK-SAME: float noundef [[A:%.*]]) { | ||
| ; CHECK-NEXT: entry: | ||
| ; CHECK-NEXT: [[DEGREES:%.*]] = fmul float [[A]], 0x404CA5DC20000000 | ||
| ; CHECK-NEXT: ret float [[DEGREES]] | ||
| ; | ||
| entry: | ||
| %dx.degrees = call float @llvm.dx.degrees.f32(float %a) | ||
| ret float %dx.degrees | ||
| } | ||
|
|
||
| define noundef <4 x float> @degrees_float4(<4 x float> noundef %a) #0 { | ||
| ; CHECK-LABEL: define noundef <4 x float> @degrees_float4( | ||
| ; CHECK-SAME: <4 x float> noundef [[A:%.*]]) { | ||
| ; CHECK-NEXT: entry: | ||
| ; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A]], i64 0 | ||
| ; CHECK-NEXT: [[DEGREES_A0:%.*]] = fmul float [[A0]], 0x404CA5DC20000000 | ||
| ; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i64 1 | ||
| ; CHECK-NEXT: [[DEGREES_A1:%.*]] = fmul float [[A1]], 0x404CA5DC20000000 | ||
| ; CHECK-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i64 2 | ||
| ; CHECK-NEXT: [[DEGREES_A2:%.*]] = fmul float [[A2]], 0x404CA5DC20000000 | ||
| ; CHECK-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i64 3 | ||
| ; CHECK-NEXT: [[DEGREES_A3:%.*]] = fmul float [[A3]], 0x404CA5DC20000000 | ||
| ; CHECK-NEXT: [[INSERT_0:%.*]] = insertelement <4 x float> poison, float [[DEGREES_A0]], i64 0 | ||
| ; CHECK-NEXT: [[INSERT_1:%.*]] = insertelement <4 x float> [[INSERT_0]], float [[DEGREES_A1]], i64 1 | ||
| ; CHECK-NEXT: [[INSERT_2:%.*]] = insertelement <4 x float> [[INSERT_1]], float [[DEGREES_A2]], i64 2 | ||
| ; CHECK-NEXT: [[RES:%.*]] = insertelement <4 x float> [[INSERT_2]], float [[DEGREES_A3]], i64 3 | ||
| ; CHECK-NEXT: ret <4 x float> [[RES]] | ||
| ; | ||
| entry: | ||
| %2 = call <4 x float> @llvm.dx.degrees.v4f32(<4 x float> %a) | ||
| ret <4 x float> %2 | ||
| } | ||
|
|
||
| declare half @llvm.dx.degrees.f16(half) | ||
| declare float @llvm.dx.degrees.f32(float) | ||
| declare <4 x float> @llvm.dx.degrees.v4f32(<4 x float>) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s | ||
| ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %} | ||
|
|
||
| ; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "GLSL.std.450" | ||
|
|
||
| ; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32 | ||
| ; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16 | ||
| ; CHECK-DAG: %[[#float_64:]] = OpTypeFloat 64 | ||
|
|
||
| ; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4 | ||
| ; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4 | ||
| ; CHECK-DAG: %[[#vec4_float_64:]] = OpTypeVector %[[#float_64]] 4 | ||
|
|
||
| ; CHECK-LABEL: Begin function degrees_float | ||
| define noundef float @degrees_float(float noundef %a) { | ||
| entry: | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ; CHECK: %[[#float_32_arg:]] = OpFunctionParameter %[[#float_32]] | ||
| ; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Degrees %[[#float_32_arg]] | ||
| %elt.degrees = call float @llvm.spv.degrees.f32(float %a) | ||
| ret float %elt.degrees | ||
| } | ||
|
|
||
| ; CHECK-LABEL: Begin function degrees_half | ||
| define noundef half @degrees_half(half noundef %a) { | ||
| entry: | ||
| ; CHECK: %[[#float_16_arg:]] = OpFunctionParameter %[[#float_16]] | ||
| ; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Degrees %[[#float_16_arg]] | ||
| %elt.degrees = call half @llvm.spv.degrees.f16(half %a) | ||
| ret half %elt.degrees | ||
| } | ||
|
|
||
| ; CHECK-LABEL: Begin function degrees_double | ||
| define noundef double @degrees_double(double noundef %a) { | ||
| entry: | ||
| ; CHECK: %[[#float_64_arg:]] = OpFunctionParameter %[[#float_64]] | ||
| ; CHECK: %[[#]] = OpExtInst %[[#float_64]] %[[#op_ext_glsl]] Degrees %[[#float_64_arg]] | ||
| %elt.degrees = call double @llvm.spv.degrees.f64(double %a) | ||
| ret double %elt.degrees | ||
| } | ||
|
|
||
| ; CHECK-LABEL: Begin function degrees_float_vector | ||
| define noundef <4 x float> @degrees_float_vector(<4 x float> noundef %a) { | ||
| entry: | ||
| ; CHECK: %[[#vec4_float_32_arg:]] = OpFunctionParameter %[[#vec4_float_32]] | ||
| ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] Degrees %[[#vec4_float_32_arg]] | ||
| %elt.degrees = call <4 x float> @llvm.spv.degrees.v4f32(<4 x float> %a) | ||
| ret <4 x float> %elt.degrees | ||
| } | ||
|
|
||
| ; CHECK-LABEL: Begin function degrees_half_vector | ||
| define noundef <4 x half> @degrees_half_vector(<4 x half> noundef %a) { | ||
| entry: | ||
| ; CHECK: %[[#vec4_float_16_arg:]] = OpFunctionParameter %[[#vec4_float_16]] | ||
| ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] Degrees %[[#vec4_float_16_arg]] | ||
| %elt.degrees = call <4 x half> @llvm.spv.degrees.v4f16(<4 x half> %a) | ||
| ret <4 x half> %elt.degrees | ||
| } | ||
|
|
||
| ; CHECK-LABEL: Begin function degrees_double_vector | ||
| define noundef <4 x double> @degrees_double_vector(<4 x double> noundef %a) { | ||
| entry: | ||
| ; CHECK: %[[#vec4_float_64_arg:]] = OpFunctionParameter %[[#vec4_float_64]] | ||
| ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_64]] %[[#op_ext_glsl]] Degrees %[[#vec4_float_64_arg]] | ||
| %elt.degrees = call <4 x double> @llvm.spv.degrees.v4f64(<4 x double> %a) | ||
| ret <4 x double> %elt.degrees | ||
| } | ||
|
|
||
| declare half @llvm.spv.degrees.f16(half) | ||
| declare float @llvm.spv.degrees.f32(float) | ||
| declare double @llvm.spv.degrees.f64(double) | ||
|
|
||
| declare <4 x float> @llvm.spv.degrees.v4f32(<4 x float>) | ||
| declare <4 x half> @llvm.spv.degrees.v4f16(<4 x half>) | ||
| declare <4 x double> @llvm.spv.degrees.v4f64(<4 x double>) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.