summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-28 22:35:14 -0700
committerGitHub <noreply@github.com>2025-07-29 05:35:14 +0000
commite8797496bf7caeb08b5334d13d0d5aa039106210 (patch)
treefdfd68a6d9122c43523c37b5b20893d11aad1c06 /tests
parenta2d93ae0122aff62866e9266e5e51d4615a00783 (diff)
Fix CUDA backend missing U32_firstbitlow implementation (#7921)
* Initial plan * Add U32_firstbitlow implementation for CUDA and CPP backends Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com> * Add I32_firstbitlow and comprehensive testing for signed/unsigned firstbitlow Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com> * Convert firstbitlow test to use inline filecheck syntax Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Add U32_firstbithigh and I32_firstbithigh implementations for CUDA and CPP backends Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Update prelude/slang-cpp-scalar-intrinsics.h * Update prelude/slang-cpp-scalar-intrinsics.h * Update prelude/slang-cpp-scalar-intrinsics.h * Refactor Metal bit intrinsics to handle zero case correctly Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Update slang-cuda-prelude.h remove fake links * Update hlsl.meta.slang * if -1, return -1 due to implicit hlsl rule * -1 or 0 is ~0u as per hlsl implictly * 0 or -1 as per hlsl * fix the math to map to hlsl * fix compile error * forgot `31 - clz` * format code (#7943) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Update source/slang/hlsl.meta.slang * Update source/slang/hlsl.meta.slang * Update source/slang/hlsl.meta.slang * Update source/slang/hlsl.meta.slang --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com> Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: ArielG-NV <aglasroth@nvidia.com> Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/hlsl-intrinsic/firstbithigh.slang37
-rw-r--r--tests/hlsl-intrinsic/firstbitlow.slang39
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/hlsl-intrinsic/firstbithigh.slang b/tests/hlsl-intrinsic/firstbithigh.slang
new file mode 100644
index 000000000..f5b0bc038
--- /dev/null
+++ b/tests/hlsl-intrinsic/firstbithigh.slang
@@ -0,0 +1,37 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -dx12 -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -compute -shaderobj
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ bool result = true;
+ result = result && firstbithigh(0) == -1;
+ result = result && firstbithigh(1) == 0;
+ result = result && firstbithigh(2) == 1;
+ result = result && firstbithigh(3) == 1;
+ result = result && firstbithigh(4) == 2;
+ result = result && firstbithigh(5) == 2;
+ result = result && firstbithigh(6) == 2;
+ result = result && firstbithigh(7) == 2;
+ result = result && firstbithigh(8) == 3;
+
+ result = result && firstbithigh(-1) == -1;
+ result = result && firstbithigh(-2) == 0;
+ result = result && firstbithigh(-3) == 1;
+ result = result && firstbithigh(-4) == 1;
+ result = result && firstbithigh(-5) == 2;
+ result = result && firstbithigh(-6) == 2;
+ result = result && firstbithigh(-7) == 2;
+ result = result && firstbithigh(-8) == 2;
+ result = result && firstbithigh(-9) == 3;
+
+ outputBuffer[0] = (result == true) ? 1 : 0;
+}
+
+// CHECK: 1
diff --git a/tests/hlsl-intrinsic/firstbitlow.slang b/tests/hlsl-intrinsic/firstbitlow.slang
new file mode 100644
index 000000000..418b8aa6f
--- /dev/null
+++ b/tests/hlsl-intrinsic/firstbitlow.slang
@@ -0,0 +1,39 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -dx12 -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -compute -shaderobj
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+[numthreads(10, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint idx = dispatchThreadID.x;
+
+ if (idx < 5) {
+ // Test unsigned values
+ uint testValues[5] = {0, 1, 2, 4, 8};
+ uint value = testValues[idx];
+ uint result = firstbitlow(value);
+ outputBuffer[idx] = result;
+ } else {
+ // Test signed values
+ int testValues[5] = {-1, -2, -4, -8, 0}; // 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFC, 0xFFFFFFF8, 0
+ int value = testValues[idx - 5];
+ uint result = firstbitlow(value);
+ outputBuffer[idx] = result;
+ }
+}
+
+// CHECK: FFFFFFFF
+// CHECK: 0
+// CHECK: 1
+// CHECK: 2
+// CHECK: 3
+// CHECK: 0
+// CHECK: 1
+// CHECK: 2
+// CHECK: 3
+// CHECK: FFFFFFFF \ No newline at end of file