-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] Implement elementwise popcount #108121
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
Merged
Changes from all commits
Commits
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
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,80 @@ | ||
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ | ||
// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s | ||
|
||
#ifdef __HLSL_ENABLE_16_BIT | ||
// CHECK-LABEL: test_countbits_ushort | ||
// CHECK: call i16 @llvm.ctpop.i16 | ||
uint16_t test_countbits_ushort(uint16_t p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_ushort2 | ||
// CHECK: call <2 x i16> @llvm.ctpop.v2i16 | ||
uint16_t2 test_countbits_ushort2(uint16_t2 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_ushort3 | ||
// CHECK: call <3 x i16> @llvm.ctpop.v3i16 | ||
uint16_t3 test_countbits_ushort3(uint16_t3 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_ushort4 | ||
// CHECK: call <4 x i16> @llvm.ctpop.v4i16 | ||
uint16_t4 test_countbits_ushort4(uint16_t4 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
#endif | ||
|
||
// CHECK-LABEL: test_countbits_uint | ||
// CHECK: call i32 @llvm.ctpop.i32 | ||
int test_countbits_uint(uint p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_uint2 | ||
// CHECK: call <2 x i32> @llvm.ctpop.v2i32 | ||
uint2 test_countbits_uint2(uint2 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_uint3 | ||
// CHECK: call <3 x i32> @llvm.ctpop.v3i32 | ||
uint3 test_countbits_uint3(uint3 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_uint4 | ||
// CHECK: call <4 x i32> @llvm.ctpop.v4i32 | ||
uint4 test_countbits_uint4(uint4 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_countbits_long | ||
// CHECK: call i64 @llvm.ctpop.i64 | ||
uint64_t test_countbits_long(uint64_t p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_long2 | ||
// CHECK: call <2 x i64> @llvm.ctpop.v2i64 | ||
uint64_t2 test_countbits_long2(uint64_t2 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_long3 | ||
// CHECK: call <3 x i64> @llvm.ctpop.v3i64 | ||
uint64_t3 test_countbits_long3(uint64_t3 p0) | ||
{ | ||
return countbits(p0); | ||
} | ||
// CHECK-LABEL: test_countbits_long4 | ||
// CHECK: call <4 x i64> @llvm.ctpop.v4i64 | ||
uint64_t4 test_countbits_long4(uint64_t4 p0) | ||
{ | ||
return countbits(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
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,28 @@ | ||
// RUN: %clang_cc1 -finclude-default-header | ||
// -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only | ||
// -disable-llvm-passes -verify | ||
|
||
double2 test_int_builtin(double2 p0) { | ||
return __builtin_hlsl_elementwise_countbits(p0); | ||
// expected-error@-1 {{passing 'double2' (aka 'vector<double, 2>') to | ||
// parameter of incompatible type | ||
// '__attribute__((__vector_size__(2 * sizeof(int)))) int' | ||
// (vector of 2 'int' values)}} | ||
} | ||
|
||
float test_ambiguous(float p0) { | ||
return countbits(p0); | ||
// expected-error@-1 {{call to 'countbits' is ambiguous}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}} | ||
} | ||
|
||
float test_float_builtin(float p0) { | ||
return __builtin_hlsl_elementwise_countbits(p0); | ||
// expected-error@-1 {{passing 'double' to parameter of incompatible type | ||
// 'int'}} | ||
} |
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,21 @@ | ||
// RUN: %clang_cc1 -finclude-default-header | ||
// -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only | ||
// -disable-llvm-passes -verify -verify-ignore-unexpected | ||
|
||
|
||
double test_int_builtin(double p0) { | ||
return countbits(p0); | ||
// expected-error@-1 {{call to 'countbits' is ambiguous}} | ||
} | ||
|
||
double2 test_int_builtin_2(double2 p0) { | ||
return __builtin_elementwise_popcount(p0); | ||
// expected-error@-1 {{1st argument must be a vector of integers | ||
// (was 'double2' (aka 'vector<double, 2>'))}} | ||
} | ||
|
||
double test_int_builtin_3(float p0) { | ||
return __builtin_elementwise_popcount(p0); | ||
// expected-error@-1 {{1st argument must be a vector of integers | ||
// (was '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
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.