summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
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