blob: b17af4d88e783abdf645b281d1824a3f8934ddfe [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Test int bit math.</title>
<script src="js/whlsl-test-harness.js"></script>
<script src="js/webgpu-functions.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
const whlslTests = {};
whlslTests.intBitAnd = async () =>
{
let program = `
int foo(int a, int b)
{
return a & b;
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(1), makeInt(7)]), 1);
assert_equals(await callIntFunction(program, "foo", [makeInt(65535), makeInt(42)]), 42);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1), makeInt(-7)]), -7);
assert_equals(await callIntFunction(program, "foo", [makeInt(0), makeInt(85732)]), 0);
}
whlslTests.intBitOr = async () =>
{
let program = `
int foo(int a, int b)
{
return a | b;
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(1), makeInt(7)]), 7);
assert_equals(await callIntFunction(program, "foo", [makeInt(65535), makeInt(42)]), 65535);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1), makeInt(-7)]), -1);
assert_equals(await callIntFunction(program, "foo", [makeInt(0), makeInt(85732)]), 85732);
}
whlslTests.intBitXor = async () =>
{
let program = `
int foo(int a, int b)
{
return a ^ b;
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(1), makeInt(7)]), 6);
assert_equals(await callIntFunction(program, "foo", [makeInt(65535), makeInt(42)]), 65493);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1), makeInt(-7)]), 6);
assert_equals(await callIntFunction(program, "foo", [makeInt(0), makeInt(85732)]), 85732);
}
whlslTests.intBitNot = async () =>
{
let program = `
int foo(int a)
{
return ~a;
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(1)]), -2);
assert_equals(await callIntFunction(program, "foo", [makeInt(65535)]), -65536);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(0)]), -1);
}
whlslTests.intLShift = async () =>
{
let program = `
int foo(int a, uint b)
{
return a << b;
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(1), makeUint(7)]), 128);
assert_equals(await callIntFunction(program, "foo", [makeInt(65535), makeUint(2)]), 262140);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1), makeUint(5)]), -32);
assert_equals(await callIntFunction(program, "foo", [makeInt(0), makeUint(3)]), 0);
}
whlslTests.intRShift = async () =>
{
let program = `
int foo(int a, uint b)
{
return a >> b;
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(1), makeUint(7)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(65535), makeUint(2)]), 16383);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1), makeUint(5)]), -1);
assert_equals(await callIntFunction(program, "foo", [makeInt(0), makeUint(3)]), 0);
}
whlslTests.intSimpleMath = async () => {
let program = "int foo(int x, int y) { return x + y; }";
assert_equals(await callIntFunction(program, "foo", [makeInt(7), makeInt(5)]), 12);
program = "int foo(int x, int y) { return x - y; }";
assert_equals(await callIntFunction(program, "foo", [makeInt(7), makeInt(5)]), 2);
assert_equals(await callIntFunction(program, "foo", [makeInt(5), makeInt(7)]), -2);
program = "int foo(int x, int y) { return x * y; }";
assert_equals(await callIntFunction(program, "foo", [makeInt(7), makeInt(5)]), 35);
assert_equals(await callIntFunction(program, "foo", [makeInt(7), makeInt(-5)]), -35);
}
runTests(whlslTests);
</script>
</html>