forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HLSL] Implement elementwise firstbitlow builtin (llvm#116858)
Closes llvm#99116 Implements `firstbitlow` by extracting common functionality from `firstbithigh` into a shared function while also fixing a bug for an edge case where `u64x3` and larger vectors will attempt to create vectors larger than the SPRIV max of 4. --------- Co-authored-by: Steven Perron <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,021 additions
and
134 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,153 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s -DTARGET=dx | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \ | ||
// RUN: -emit-llvm -disable-llvm-passes \ | ||
// RUN: -o - | FileCheck %s -DTARGET=spv | ||
|
||
#ifdef __HLSL_ENABLE_16_BIT | ||
// CHECK-LABEL: test_firstbitlow_ushort | ||
// CHECK: call i32 @llvm.[[TARGET]].firstbitlow.i16 | ||
uint test_firstbitlow_ushort(uint16_t p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ushort2 | ||
// CHECK: call <2 x i32> @llvm.[[TARGET]].firstbitlow.v2i16 | ||
uint2 test_firstbitlow_ushort2(uint16_t2 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ushort3 | ||
// CHECK: call <3 x i32> @llvm.[[TARGET]].firstbitlow.v3i16 | ||
uint3 test_firstbitlow_ushort3(uint16_t3 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ushort4 | ||
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i16 | ||
uint4 test_firstbitlow_ushort4(uint16_t4 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_short | ||
// CHECK: call i32 @llvm.[[TARGET]].firstbitlow.i16 | ||
uint test_firstbitlow_short(int16_t p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_short2 | ||
// CHECK: call <2 x i32> @llvm.[[TARGET]].firstbitlow.v2i16 | ||
uint2 test_firstbitlow_short2(int16_t2 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_short3 | ||
// CHECK: call <3 x i32> @llvm.[[TARGET]].firstbitlow.v3i16 | ||
uint3 test_firstbitlow_short3(int16_t3 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_short4 | ||
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i16 | ||
uint4 test_firstbitlow_short4(int16_t4 p0) { | ||
return firstbitlow(p0); | ||
} | ||
#endif // __HLSL_ENABLE_16_BIT | ||
|
||
// CHECK-LABEL: test_firstbitlow_uint | ||
// CHECK: call i32 @llvm.[[TARGET]].firstbitlow.i32 | ||
uint test_firstbitlow_uint(uint p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_uint2 | ||
// CHECK: call <2 x i32> @llvm.[[TARGET]].firstbitlow.v2i32 | ||
uint2 test_firstbitlow_uint2(uint2 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_uint3 | ||
// CHECK: call <3 x i32> @llvm.[[TARGET]].firstbitlow.v3i32 | ||
uint3 test_firstbitlow_uint3(uint3 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_uint4 | ||
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i32 | ||
uint4 test_firstbitlow_uint4(uint4 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ulong | ||
// CHECK: call i32 @llvm.[[TARGET]].firstbitlow.i64 | ||
uint test_firstbitlow_ulong(uint64_t p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ulong2 | ||
// CHECK: call <2 x i32> @llvm.[[TARGET]].firstbitlow.v2i64 | ||
uint2 test_firstbitlow_ulong2(uint64_t2 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ulong3 | ||
// CHECK: call <3 x i32> @llvm.[[TARGET]].firstbitlow.v3i64 | ||
uint3 test_firstbitlow_ulong3(uint64_t3 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_ulong4 | ||
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i64 | ||
uint4 test_firstbitlow_ulong4(uint64_t4 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_int | ||
// CHECK: call i32 @llvm.[[TARGET]].firstbitlow.i32 | ||
uint test_firstbitlow_int(int p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_int2 | ||
// CHECK: call <2 x i32> @llvm.[[TARGET]].firstbitlow.v2i32 | ||
uint2 test_firstbitlow_int2(int2 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_int3 | ||
// CHECK: call <3 x i32> @llvm.[[TARGET]].firstbitlow.v3i32 | ||
uint3 test_firstbitlow_int3(int3 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_int4 | ||
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i32 | ||
uint4 test_firstbitlow_int4(int4 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_long | ||
// CHECK: call i32 @llvm.[[TARGET]].firstbitlow.i64 | ||
uint test_firstbitlow_long(int64_t p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_long2 | ||
// CHECK: call <2 x i32> @llvm.[[TARGET]].firstbitlow.v2i64 | ||
uint2 test_firstbitlow_long2(int64_t2 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_long3 | ||
// CHECK: call <3 x i32> @llvm.[[TARGET]].firstbitlow.v3i64 | ||
uint3 test_firstbitlow_long3(int64_t3 p0) { | ||
return firstbitlow(p0); | ||
} | ||
|
||
// CHECK-LABEL: test_firstbitlow_long4 | ||
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i64 | ||
uint4 test_firstbitlow_long4(int64_t4 p0) { | ||
return firstbitlow(p0); | ||
} |
This file contains 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 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 -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected | ||
|
||
int test_too_few_arg() { | ||
return firstbitlow(); | ||
// expected-error@-1 {{no matching function for call to 'firstbitlow'}} | ||
} | ||
|
||
int test_too_many_arg(int p0) { | ||
return firstbitlow(p0, p0); | ||
// expected-error@-1 {{no matching function for call to 'firstbitlow'}} | ||
} | ||
|
||
double test_int_builtin(double p0) { | ||
return firstbitlow(p0); | ||
// expected-error@-1 {{call to 'firstbitlow' is ambiguous}} | ||
} | ||
|
||
double2 test_int_builtin_2(double2 p0) { | ||
return __builtin_hlsl_elementwise_firstbitlow(p0); | ||
// expected-error@-1 {{1st argument must be a vector of integers (was 'double2' (aka 'vector<double, 2>'))}} | ||
} | ||
|
||
float test_int_builtin_3(float p0) { | ||
return __builtin_hlsl_elementwise_firstbitlow(p0); | ||
// expected-error@-1 {{1st argument must be a vector of integers (was 'double')}} | ||
} |
This file contains 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 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 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 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.