From a3175f28f6d80e826eebe399b6b53430df6de6f2 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Mon, 31 Oct 2022 22:57:14 +0000 Subject: [PATCH] tint: const eval of firstTrailingBit Bug: tint:1581 Change-Id: I4a9cb113780439849aec10cd0fc8e2f6d2ab55cc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107881 Commit-Queue: Antonio Maiorano Kokoro: Kokoro Reviewed-by: Ben Clayton --- src/tint/intrinsics.def | 4 +- src/tint/resolver/const_eval.cc | 55 ++++++-- src/tint/resolver/const_eval.h | 9 ++ src/tint/resolver/const_eval_builtin_test.cc | 33 +++++ src/tint/resolver/intrinsic_table.inl | 4 +- .../110f2c.wgsl.expected.dxc.hlsl | 17 +-- .../110f2c.wgsl.expected.fxc.hlsl | 17 +-- .../110f2c.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/110f2c.wgsl.expected.msl | 17 +-- .../110f2c.wgsl.expected.spvasm | 118 +++------------- .../3a2acc.wgsl.expected.dxc.hlsl | 17 +-- .../3a2acc.wgsl.expected.fxc.hlsl | 17 +-- .../3a2acc.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/3a2acc.wgsl.expected.msl | 17 +-- .../3a2acc.wgsl.expected.spvasm | 113 +++------------- .../45eb10.wgsl.expected.dxc.hlsl | 17 +-- .../45eb10.wgsl.expected.fxc.hlsl | 17 +-- .../45eb10.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/45eb10.wgsl.expected.msl | 17 +-- .../45eb10.wgsl.expected.spvasm | 118 +++------------- .../47d475.wgsl.expected.dxc.hlsl | 17 +-- .../47d475.wgsl.expected.fxc.hlsl | 17 +-- .../47d475.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/47d475.wgsl.expected.msl | 17 +-- .../47d475.wgsl.expected.spvasm | 109 ++++----------- .../50c072.wgsl.expected.dxc.hlsl | 17 +-- .../50c072.wgsl.expected.fxc.hlsl | 17 +-- .../50c072.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/50c072.wgsl.expected.msl | 17 +-- .../50c072.wgsl.expected.spvasm | 126 +++--------------- .../7496d6.wgsl.expected.dxc.hlsl | 17 +-- .../7496d6.wgsl.expected.fxc.hlsl | 17 +-- .../7496d6.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/7496d6.wgsl.expected.msl | 17 +-- .../7496d6.wgsl.expected.spvasm | 126 +++--------------- .../86551b.wgsl.expected.dxc.hlsl | 17 +-- .../86551b.wgsl.expected.fxc.hlsl | 17 +-- .../86551b.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/86551b.wgsl.expected.msl | 17 +-- .../86551b.wgsl.expected.spvasm | 126 +++--------------- .../cb51ce.wgsl.expected.dxc.hlsl | 17 +-- .../cb51ce.wgsl.expected.fxc.hlsl | 17 +-- .../cb51ce.wgsl.expected.glsl | 51 +------ .../firstTrailingBit/cb51ce.wgsl.expected.msl | 17 +-- .../cb51ce.wgsl.expected.spvasm | 118 +++------------- webgpu-cts/expectations.txt | 8 -- 46 files changed, 315 insertions(+), 1568 deletions(-) diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def index 4bed6b91af..9a6bae20d6 100644 --- a/src/tint/intrinsics.def +++ b/src/tint/intrinsics.def @@ -469,8 +469,8 @@ fn extractBits(vec, u32, u32) -> vec fn faceForward(vec, vec, vec) -> vec @const fn firstLeadingBit(T) -> T @const fn firstLeadingBit(vec) -> vec -fn firstTrailingBit(T) -> T -fn firstTrailingBit(vec) -> vec +@const fn firstTrailingBit(T) -> T +@const fn firstTrailingBit(vec) -> vec fn floor(T) -> T fn floor(vec) -> vec fn fma(T, T, T) -> T diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index efe7b8b75b..b61151d62b 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -209,6 +209,23 @@ auto CountLeadingBits(T e, T bit_value_to_count) -> std::make_unsigned_t { return count; } +/// @returns the number of consecutive trailing bits set to `@p bit_value_to_count` in `@p e` +template +auto CountTrailingBits(T e, T bit_value_to_count) -> std::make_unsigned_t { + using UT = std::make_unsigned_t; + constexpr UT kNumBits = sizeof(UT) * 8; + constexpr UT kRightMost = UT{1}; + const UT b = static_cast(bit_value_to_count); + + auto v = static_cast(e); + auto count = UT{0}; + while ((count < kNumBits) && ((v & kRightMost) == b)) { + ++count; + v >>= 1; + } + return count; +} + /// ImplConstant inherits from sem::Constant to add an private implementation method for conversion. struct ImplConstant : public sem::Constant { /// Convert attempts to convert the constant value to the given type. On error, Convert() @@ -1695,17 +1712,7 @@ ConstEval::Result ConstEval::countTrailingZeros(const sem::Type* ty, auto create = [&](auto e) { using NumberT = decltype(e); using T = UnwrapNumber; - using UT = std::make_unsigned_t; - constexpr UT kNumBits = sizeof(UT) * 8; - constexpr UT kRightMost = UT{1}; - - auto v = static_cast(e); - auto count = UT{0}; - while ((count < kNumBits) && ((v & kRightMost) == 0)) { - ++count; - v >>= 1; - } - + auto count = CountTrailingBits(T{e}, T{0}); return CreateElement(builder, c0->Type(), NumberT(count)); }; return Dispatch_iu32(create, c0); @@ -1757,6 +1764,32 @@ ConstEval::Result ConstEval::firstLeadingBit(const sem::Type* ty, return TransformElements(builder, ty, transform, args[0]); } +ConstEval::Result ConstEval::firstTrailingBit(const sem::Type* ty, + utils::VectorRef args, + const Source&) { + auto transform = [&](const sem::Constant* c0) { + auto create = [&](auto e) { + using NumberT = decltype(e); + using T = UnwrapNumber; + using UT = std::make_unsigned_t; + + NumberT result; + if (e == T{0}) { + // T(-1) if e is zero. + result = NumberT(static_cast(-1)); + } else { + // Otherwise the position of the least significant 1 bit in e. + UT pos = CountTrailingBits(T{e}, T{0}); + result = NumberT(pos); + } + + return CreateElement(builder, c0->Type(), result); + }; + return Dispatch_iu32(create, c0); + }; + return TransformElements(builder, ty, transform, args[0]); +} + ConstEval::Result ConstEval::saturate(const sem::Type* ty, utils::VectorRef args, const Source&) { diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h index 3474bcc9c6..91189fab25 100644 --- a/src/tint/resolver/const_eval.h +++ b/src/tint/resolver/const_eval.h @@ -476,6 +476,15 @@ class ConstEval { utils::VectorRef args, const Source& source); + /// firstTrailingBit builtin + /// @param ty the expression type + /// @param args the input arguments + /// @param source the source location of the conversion + /// @return the result value, or null if the value cannot be calculated + Result firstTrailingBit(const sem::Type* ty, + utils::VectorRef args, + const Source& source); + /// saturate builtin /// @param ty the expression type /// @param args the input arguments diff --git a/src/tint/resolver/const_eval_builtin_test.cc b/src/tint/resolver/const_eval_builtin_test.cc index f831dccde6..3c275cb5fe 100644 --- a/src/tint/resolver/const_eval_builtin_test.cc +++ b/src/tint/resolver/const_eval_builtin_test.cc @@ -680,6 +680,39 @@ INSTANTIATE_TEST_SUITE_P( // testing::ValuesIn(Concat(FirstLeadingBitCases(), // FirstLeadingBitCases())))); +template +std::vector FirstTrailingBitCases() { + using B = BitValues; + auto r = std::vector{ + C({T(0)}, T(-1)), + + C({B::Lsh(1, 31)}, T(31)), // + C({B::Lsh(1, 30)}, T(30)), // + C({B::Lsh(1, 29)}, T(29)), // + C({B::Lsh(1, 28)}, T(28)), + //... + C({B::Lsh(1, 3)}, T(3)), // + C({B::Lsh(1, 2)}, T(2)), // + C({B::Lsh(1, 1)}, T(1)), // + C({B::Lsh(1, 0)}, T(0)), + + C({T(0b0000'0000'0100'1000'1000'1000'0000'0000)}, T(11)), + C({T(0b0000'0100'1000'1000'1000'0000'0000'0000)}, T(15)), + + // Vector tests + C({Vec(B::Lsh(1, 31), B::Lsh(1, 30), B::Lsh(1, 29))}, Vec(T(31), T(30), T(29))), + C({Vec(B::Lsh(1, 2), B::Lsh(1, 1), B::Lsh(1, 0))}, Vec(T(2), T(1), T(0))), + }; + + return r; +} +INSTANTIATE_TEST_SUITE_P( // + FirstTrailingBit, + ResolverConstEvalBuiltinTest, + testing::Combine(testing::Values(sem::BuiltinType::kFirstTrailingBit), + testing::ValuesIn(Concat(FirstTrailingBitCases(), // + FirstTrailingBitCases())))); + template std::vector SaturateCases() { return { diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl index 265bf04fef..c6d3ad46d2 100644 --- a/src/tint/resolver/intrinsic_table.inl +++ b/src/tint/resolver/intrinsic_table.inl @@ -13516,7 +13516,7 @@ constexpr OverloadInfo kOverloads[] = { /* parameters */ &kParameters[908], /* return matcher indices */ &kMatcherIndices[1], /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline), - /* const eval */ nullptr, + /* const eval */ &ConstEval::firstTrailingBit, }, { /* [433] */ @@ -13528,7 +13528,7 @@ constexpr OverloadInfo kOverloads[] = { /* parameters */ &kParameters[907], /* return matcher indices */ &kMatcherIndices[30], /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline), - /* const eval */ nullptr, + /* const eval */ &ConstEval::firstTrailingBit, }, { /* [434] */ diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.dxc.hlsl index 4b15e1f6f7..9be7e495db 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -uint4 tint_first_trailing_bit(uint4 v) { - uint4 x = uint4(v); - const uint4 b16 = (bool4((x & (65535u).xxxx)) ? (0u).xxxx : (16u).xxxx); - x = (x >> b16); - const uint4 b8 = (bool4((x & (255u).xxxx)) ? (0u).xxxx : (8u).xxxx); - x = (x >> b8); - const uint4 b4 = (bool4((x & (15u).xxxx)) ? (0u).xxxx : (4u).xxxx); - x = (x >> b4); - const uint4 b2 = (bool4((x & (3u).xxxx)) ? (0u).xxxx : (2u).xxxx); - x = (x >> b2); - const uint4 b1 = (bool4((x & (1u).xxxx)) ? (0u).xxxx : (1u).xxxx); - const uint4 is_zero = ((x == (0u).xxxx) ? (4294967295u).xxxx : (0u).xxxx); - return uint4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_110f2c() { - uint4 res = tint_first_trailing_bit((1u).xxxx); + uint4 res = (0u).xxxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.fxc.hlsl index 4b15e1f6f7..9be7e495db 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -uint4 tint_first_trailing_bit(uint4 v) { - uint4 x = uint4(v); - const uint4 b16 = (bool4((x & (65535u).xxxx)) ? (0u).xxxx : (16u).xxxx); - x = (x >> b16); - const uint4 b8 = (bool4((x & (255u).xxxx)) ? (0u).xxxx : (8u).xxxx); - x = (x >> b8); - const uint4 b4 = (bool4((x & (15u).xxxx)) ? (0u).xxxx : (4u).xxxx); - x = (x >> b4); - const uint4 b2 = (bool4((x & (3u).xxxx)) ? (0u).xxxx : (2u).xxxx); - x = (x >> b2); - const uint4 b1 = (bool4((x & (1u).xxxx)) ? (0u).xxxx : (1u).xxxx); - const uint4 is_zero = ((x == (0u).xxxx) ? (4294967295u).xxxx : (0u).xxxx); - return uint4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_110f2c() { - uint4 res = tint_first_trailing_bit((1u).xxxx); + uint4 res = (0u).xxxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.glsl index b9d3ec1a27..94c175d5b5 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -uvec4 tint_first_trailing_bit(uvec4 v) { - uvec4 x = uvec4(v); - uvec4 b16 = mix(uvec4(16u), uvec4(0u), bvec4((x & uvec4(65535u)))); - x = (x >> b16); - uvec4 b8 = mix(uvec4(8u), uvec4(0u), bvec4((x & uvec4(255u)))); - x = (x >> b8); - uvec4 b4 = mix(uvec4(4u), uvec4(0u), bvec4((x & uvec4(15u)))); - x = (x >> b4); - uvec4 b2 = mix(uvec4(2u), uvec4(0u), bvec4((x & uvec4(3u)))); - x = (x >> b2); - uvec4 b1 = mix(uvec4(1u), uvec4(0u), bvec4((x & uvec4(1u)))); - uvec4 is_zero = mix(uvec4(0u), uvec4(4294967295u), equal(x, uvec4(0u))); - return uvec4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_110f2c() { - uvec4 res = tint_first_trailing_bit(uvec4(1u)); + uvec4 res = uvec4(0u); } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -uvec4 tint_first_trailing_bit(uvec4 v) { - uvec4 x = uvec4(v); - uvec4 b16 = mix(uvec4(16u), uvec4(0u), bvec4((x & uvec4(65535u)))); - x = (x >> b16); - uvec4 b8 = mix(uvec4(8u), uvec4(0u), bvec4((x & uvec4(255u)))); - x = (x >> b8); - uvec4 b4 = mix(uvec4(4u), uvec4(0u), bvec4((x & uvec4(15u)))); - x = (x >> b4); - uvec4 b2 = mix(uvec4(2u), uvec4(0u), bvec4((x & uvec4(3u)))); - x = (x >> b2); - uvec4 b1 = mix(uvec4(1u), uvec4(0u), bvec4((x & uvec4(1u)))); - uvec4 is_zero = mix(uvec4(0u), uvec4(4294967295u), equal(x, uvec4(0u))); - return uvec4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_110f2c() { - uvec4 res = tint_first_trailing_bit(uvec4(1u)); + uvec4 res = uvec4(0u); } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -uvec4 tint_first_trailing_bit(uvec4 v) { - uvec4 x = uvec4(v); - uvec4 b16 = mix(uvec4(16u), uvec4(0u), bvec4((x & uvec4(65535u)))); - x = (x >> b16); - uvec4 b8 = mix(uvec4(8u), uvec4(0u), bvec4((x & uvec4(255u)))); - x = (x >> b8); - uvec4 b4 = mix(uvec4(4u), uvec4(0u), bvec4((x & uvec4(15u)))); - x = (x >> b4); - uvec4 b2 = mix(uvec4(2u), uvec4(0u), bvec4((x & uvec4(3u)))); - x = (x >> b2); - uvec4 b1 = mix(uvec4(1u), uvec4(0u), bvec4((x & uvec4(1u)))); - uvec4 is_zero = mix(uvec4(0u), uvec4(4294967295u), equal(x, uvec4(0u))); - return uvec4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_110f2c() { - uvec4 res = tint_first_trailing_bit(uvec4(1u)); + uvec4 res = uvec4(0u); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.msl index df5194c488..a8b4502d1e 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -uint4 tint_first_trailing_bit(uint4 v) { - uint4 x = uint4(v); - uint4 const b16 = select(uint4(16u), uint4(0u), bool4((x & uint4(65535u)))); - x = (x >> b16); - uint4 const b8 = select(uint4(8u), uint4(0u), bool4((x & uint4(255u)))); - x = (x >> b8); - uint4 const b4 = select(uint4(4u), uint4(0u), bool4((x & uint4(15u)))); - x = (x >> b4); - uint4 const b2 = select(uint4(2u), uint4(0u), bool4((x & uint4(3u)))); - x = (x >> b2); - uint4 const b1 = select(uint4(1u), uint4(0u), bool4((x & uint4(1u)))); - uint4 const is_zero = select(uint4(0u), uint4(4294967295u), (x == uint4(0u))); - return uint4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_110f2c() { - uint4 res = tint_first_trailing_bit(uint4(1u)); + uint4 res = uint4(0u); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.spvasm index 36c66d9aa3..bf6cca8576 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/110f2c.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 98 +; Bound: 32 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_110f2c "firstTrailingBit_110f2c" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,110 +28,39 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 + %void = OpTypeVoid + %9 = OpTypeFunction %void %uint = OpTypeInt 32 0 %v4uint = OpTypeVector %uint 4 - %9 = OpTypeFunction %v4uint %v4uint + %15 = OpConstantNull %v4uint %_ptr_Function_v4uint = OpTypePointer Function %v4uint - %18 = OpConstantNull %v4uint - %bool = OpTypeBool - %v4bool = OpTypeVector %bool 4 - %uint_65535 = OpConstant %uint 65535 - %25 = OpConstantComposite %v4uint %uint_65535 %uint_65535 %uint_65535 %uint_65535 - %uint_16 = OpConstant %uint 16 - %28 = OpConstantComposite %v4uint %uint_16 %uint_16 %uint_16 %uint_16 - %uint_255 = OpConstant %uint 255 - %35 = OpConstantComposite %v4uint %uint_255 %uint_255 %uint_255 %uint_255 - %uint_8 = OpConstant %uint 8 - %38 = OpConstantComposite %v4uint %uint_8 %uint_8 %uint_8 %uint_8 - %uint_15 = OpConstant %uint 15 - %45 = OpConstantComposite %v4uint %uint_15 %uint_15 %uint_15 %uint_15 - %uint_4 = OpConstant %uint 4 - %48 = OpConstantComposite %v4uint %uint_4 %uint_4 %uint_4 %uint_4 - %uint_3 = OpConstant %uint 3 - %55 = OpConstantComposite %v4uint %uint_3 %uint_3 %uint_3 %uint_3 - %uint_2 = OpConstant %uint 2 - %58 = OpConstantComposite %v4uint %uint_2 %uint_2 %uint_2 %uint_2 - %uint_1 = OpConstant %uint 1 - %65 = OpConstantComposite %v4uint %uint_1 %uint_1 %uint_1 %uint_1 -%uint_4294967295 = OpConstant %uint 4294967295 - %71 = OpConstantComposite %v4uint %uint_4294967295 %uint_4294967295 %uint_4294967295 %uint_4294967295 - %void = OpTypeVoid - %78 = OpTypeFunction %void - %84 = OpTypeFunction %v4float + %18 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %v4uint None %9 - %v = OpFunctionParameter %v4uint - %14 = OpLabel - %x = OpVariable %_ptr_Function_v4uint Function %18 - OpStore %x %v - %23 = OpLoad %v4uint %x - %26 = OpBitwiseAnd %v4uint %23 %25 - %20 = OpINotEqual %v4bool %26 %18 - %19 = OpSelect %v4uint %20 %18 %28 - %29 = OpLoad %v4uint %x - %30 = OpShiftRightLogical %v4uint %29 %19 - OpStore %x %30 - %33 = OpLoad %v4uint %x - %36 = OpBitwiseAnd %v4uint %33 %35 - %32 = OpINotEqual %v4bool %36 %18 - %31 = OpSelect %v4uint %32 %18 %38 - %39 = OpLoad %v4uint %x - %40 = OpShiftRightLogical %v4uint %39 %31 - OpStore %x %40 - %43 = OpLoad %v4uint %x - %46 = OpBitwiseAnd %v4uint %43 %45 - %42 = OpINotEqual %v4bool %46 %18 - %41 = OpSelect %v4uint %42 %18 %48 - %49 = OpLoad %v4uint %x - %50 = OpShiftRightLogical %v4uint %49 %41 - OpStore %x %50 - %53 = OpLoad %v4uint %x - %56 = OpBitwiseAnd %v4uint %53 %55 - %52 = OpINotEqual %v4bool %56 %18 - %51 = OpSelect %v4uint %52 %18 %58 - %59 = OpLoad %v4uint %x - %60 = OpShiftRightLogical %v4uint %59 %51 - OpStore %x %60 - %63 = OpLoad %v4uint %x - %66 = OpBitwiseAnd %v4uint %63 %65 - %62 = OpINotEqual %v4bool %66 %18 - %61 = OpSelect %v4uint %62 %18 %65 - %68 = OpLoad %v4uint %x - %69 = OpIEqual %v4bool %68 %18 - %67 = OpSelect %v4uint %69 %71 %18 - %73 = OpBitwiseOr %v4uint %19 %31 - %74 = OpBitwiseOr %v4uint %73 %41 - %75 = OpBitwiseOr %v4uint %74 %51 - %76 = OpBitwiseOr %v4uint %75 %61 - %77 = OpBitwiseOr %v4uint %76 %67 - OpReturnValue %77 - OpFunctionEnd -%firstTrailingBit_110f2c = OpFunction %void None %78 - %81 = OpLabel - %res = OpVariable %_ptr_Function_v4uint Function %18 - %82 = OpFunctionCall %v4uint %tint_first_trailing_bit %65 - OpStore %res %82 +%firstTrailingBit_110f2c = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_v4uint Function %15 + OpStore %res %15 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %84 - %86 = OpLabel - %87 = OpFunctionCall %void %firstTrailingBit_110f2c +%vertex_main_inner = OpFunction %v4float None %18 + %20 = OpLabel + %21 = OpFunctionCall %void %firstTrailingBit_110f2c OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %78 - %89 = OpLabel - %90 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %90 +%vertex_main = OpFunction %void None %9 + %23 = OpLabel + %24 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %24 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %78 - %93 = OpLabel - %94 = OpFunctionCall %void %firstTrailingBit_110f2c +%fragment_main = OpFunction %void None %9 + %27 = OpLabel + %28 = OpFunctionCall %void %firstTrailingBit_110f2c OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %78 - %96 = OpLabel - %97 = OpFunctionCall %void %firstTrailingBit_110f2c +%compute_main = OpFunction %void None %9 + %30 = OpLabel + %31 = OpFunctionCall %void %firstTrailingBit_110f2c OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.dxc.hlsl index 1e0c06eb4d..e84a941d40 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -int tint_first_trailing_bit(int v) { - uint x = uint(v); - const uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - const uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - const uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - const uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - const uint b1 = (bool((x & 1u)) ? 0u : 1u); - const uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return int((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_3a2acc() { - int res = tint_first_trailing_bit(1); + int res = 0; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.fxc.hlsl index 1e0c06eb4d..e84a941d40 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -int tint_first_trailing_bit(int v) { - uint x = uint(v); - const uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - const uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - const uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - const uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - const uint b1 = (bool((x & 1u)) ? 0u : 1u); - const uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return int((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_3a2acc() { - int res = tint_first_trailing_bit(1); + int res = 0; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.glsl index 61aa479684..c807448b3a 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -int tint_first_trailing_bit(int v) { - uint x = uint(v); - uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - uint b1 = (bool((x & 1u)) ? 0u : 1u); - uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return int((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_3a2acc() { - int res = tint_first_trailing_bit(1); + int res = 0; } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -int tint_first_trailing_bit(int v) { - uint x = uint(v); - uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - uint b1 = (bool((x & 1u)) ? 0u : 1u); - uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return int((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_3a2acc() { - int res = tint_first_trailing_bit(1); + int res = 0; } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -int tint_first_trailing_bit(int v) { - uint x = uint(v); - uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - uint b1 = (bool((x & 1u)) ? 0u : 1u); - uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return int((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_3a2acc() { - int res = tint_first_trailing_bit(1); + int res = 0; } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.msl index fcef721243..9c972c714a 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -int tint_first_trailing_bit(int v) { - uint x = uint(v); - uint const b16 = select(16u, 0u, bool((x & 65535u))); - x = (x >> b16); - uint const b8 = select(8u, 0u, bool((x & 255u))); - x = (x >> b8); - uint const b4 = select(4u, 0u, bool((x & 15u))); - x = (x >> b4); - uint const b2 = select(2u, 0u, bool((x & 3u))); - x = (x >> b2); - uint const b1 = select(1u, 0u, bool((x & 1u))); - uint const is_zero = select(0u, 4294967295u, (x == 0u)); - return int((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_3a2acc() { - int res = tint_first_trailing_bit(1); + int res = 0; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.spvasm index 353d5ddc11..49910237ec 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/3a2acc.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 90 +; Bound: 31 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_3a2acc "firstTrailingBit_3a2acc" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,104 +28,38 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 - %int = OpTypeInt 32 1 - %9 = OpTypeFunction %int %int - %uint = OpTypeInt 32 0 -%_ptr_Function_uint = OpTypePointer Function %uint - %18 = OpConstantNull %uint - %bool = OpTypeBool - %uint_65535 = OpConstant %uint 65535 - %uint_16 = OpConstant %uint 16 - %uint_255 = OpConstant %uint 255 - %uint_8 = OpConstant %uint 8 - %uint_15 = OpConstant %uint 15 - %uint_4 = OpConstant %uint 4 - %uint_3 = OpConstant %uint 3 - %uint_2 = OpConstant %uint 2 - %uint_1 = OpConstant %uint 1 -%uint_4294967295 = OpConstant %uint 4294967295 %void = OpTypeVoid - %67 = OpTypeFunction %void - %int_1 = OpConstant %int 1 + %9 = OpTypeFunction %void + %int = OpTypeInt 32 1 + %14 = OpConstantNull %int %_ptr_Function_int = OpTypePointer Function %int - %75 = OpConstantNull %int - %76 = OpTypeFunction %v4float + %17 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %int None %9 - %v = OpFunctionParameter %int - %13 = OpLabel - %x = OpVariable %_ptr_Function_uint Function %18 - %14 = OpBitcast %uint %v - OpStore %x %14 - %22 = OpLoad %uint %x - %24 = OpBitwiseAnd %uint %22 %uint_65535 - %20 = OpINotEqual %bool %24 %18 - %19 = OpSelect %uint %20 %18 %uint_16 - %26 = OpLoad %uint %x - %27 = OpShiftRightLogical %uint %26 %19 - OpStore %x %27 - %30 = OpLoad %uint %x - %32 = OpBitwiseAnd %uint %30 %uint_255 - %29 = OpINotEqual %bool %32 %18 - %28 = OpSelect %uint %29 %18 %uint_8 - %34 = OpLoad %uint %x - %35 = OpShiftRightLogical %uint %34 %28 - OpStore %x %35 - %38 = OpLoad %uint %x - %40 = OpBitwiseAnd %uint %38 %uint_15 - %37 = OpINotEqual %bool %40 %18 - %36 = OpSelect %uint %37 %18 %uint_4 - %42 = OpLoad %uint %x - %43 = OpShiftRightLogical %uint %42 %36 - OpStore %x %43 - %46 = OpLoad %uint %x - %48 = OpBitwiseAnd %uint %46 %uint_3 - %45 = OpINotEqual %bool %48 %18 - %44 = OpSelect %uint %45 %18 %uint_2 - %50 = OpLoad %uint %x - %51 = OpShiftRightLogical %uint %50 %44 - OpStore %x %51 - %54 = OpLoad %uint %x - %56 = OpBitwiseAnd %uint %54 %uint_1 - %53 = OpINotEqual %bool %56 %18 - %52 = OpSelect %uint %53 %18 %uint_1 - %58 = OpLoad %uint %x - %59 = OpIEqual %bool %58 %18 - %57 = OpSelect %uint %59 %uint_4294967295 %18 - %62 = OpBitwiseOr %uint %19 %28 - %63 = OpBitwiseOr %uint %62 %36 - %64 = OpBitwiseOr %uint %63 %44 - %65 = OpBitwiseOr %uint %64 %52 - %66 = OpBitwiseOr %uint %65 %57 - %61 = OpBitcast %int %66 - OpReturnValue %61 - OpFunctionEnd -%firstTrailingBit_3a2acc = OpFunction %void None %67 - %70 = OpLabel - %res = OpVariable %_ptr_Function_int Function %75 - %71 = OpFunctionCall %int %tint_first_trailing_bit %int_1 - OpStore %res %71 +%firstTrailingBit_3a2acc = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_int Function %14 + OpStore %res %14 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %76 - %78 = OpLabel - %79 = OpFunctionCall %void %firstTrailingBit_3a2acc +%vertex_main_inner = OpFunction %v4float None %17 + %19 = OpLabel + %20 = OpFunctionCall %void %firstTrailingBit_3a2acc OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %67 - %81 = OpLabel - %82 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %82 +%vertex_main = OpFunction %void None %9 + %22 = OpLabel + %23 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %23 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %67 - %85 = OpLabel - %86 = OpFunctionCall %void %firstTrailingBit_3a2acc +%fragment_main = OpFunction %void None %9 + %26 = OpLabel + %27 = OpFunctionCall %void %firstTrailingBit_3a2acc OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %67 - %88 = OpLabel - %89 = OpFunctionCall %void %firstTrailingBit_3a2acc +%compute_main = OpFunction %void None %9 + %29 = OpLabel + %30 = OpFunctionCall %void %firstTrailingBit_3a2acc OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.dxc.hlsl index 93af66bfe2..6d20831da2 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -uint2 tint_first_trailing_bit(uint2 v) { - uint2 x = uint2(v); - const uint2 b16 = (bool2((x & (65535u).xx)) ? (0u).xx : (16u).xx); - x = (x >> b16); - const uint2 b8 = (bool2((x & (255u).xx)) ? (0u).xx : (8u).xx); - x = (x >> b8); - const uint2 b4 = (bool2((x & (15u).xx)) ? (0u).xx : (4u).xx); - x = (x >> b4); - const uint2 b2 = (bool2((x & (3u).xx)) ? (0u).xx : (2u).xx); - x = (x >> b2); - const uint2 b1 = (bool2((x & (1u).xx)) ? (0u).xx : (1u).xx); - const uint2 is_zero = ((x == (0u).xx) ? (4294967295u).xx : (0u).xx); - return uint2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_45eb10() { - uint2 res = tint_first_trailing_bit((1u).xx); + uint2 res = (0u).xx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.fxc.hlsl index 93af66bfe2..6d20831da2 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -uint2 tint_first_trailing_bit(uint2 v) { - uint2 x = uint2(v); - const uint2 b16 = (bool2((x & (65535u).xx)) ? (0u).xx : (16u).xx); - x = (x >> b16); - const uint2 b8 = (bool2((x & (255u).xx)) ? (0u).xx : (8u).xx); - x = (x >> b8); - const uint2 b4 = (bool2((x & (15u).xx)) ? (0u).xx : (4u).xx); - x = (x >> b4); - const uint2 b2 = (bool2((x & (3u).xx)) ? (0u).xx : (2u).xx); - x = (x >> b2); - const uint2 b1 = (bool2((x & (1u).xx)) ? (0u).xx : (1u).xx); - const uint2 is_zero = ((x == (0u).xx) ? (4294967295u).xx : (0u).xx); - return uint2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_45eb10() { - uint2 res = tint_first_trailing_bit((1u).xx); + uint2 res = (0u).xx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.glsl index d9b84b2bc8..e7ca9b2ea7 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -uvec2 tint_first_trailing_bit(uvec2 v) { - uvec2 x = uvec2(v); - uvec2 b16 = mix(uvec2(16u), uvec2(0u), bvec2((x & uvec2(65535u)))); - x = (x >> b16); - uvec2 b8 = mix(uvec2(8u), uvec2(0u), bvec2((x & uvec2(255u)))); - x = (x >> b8); - uvec2 b4 = mix(uvec2(4u), uvec2(0u), bvec2((x & uvec2(15u)))); - x = (x >> b4); - uvec2 b2 = mix(uvec2(2u), uvec2(0u), bvec2((x & uvec2(3u)))); - x = (x >> b2); - uvec2 b1 = mix(uvec2(1u), uvec2(0u), bvec2((x & uvec2(1u)))); - uvec2 is_zero = mix(uvec2(0u), uvec2(4294967295u), equal(x, uvec2(0u))); - return uvec2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_45eb10() { - uvec2 res = tint_first_trailing_bit(uvec2(1u)); + uvec2 res = uvec2(0u); } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -uvec2 tint_first_trailing_bit(uvec2 v) { - uvec2 x = uvec2(v); - uvec2 b16 = mix(uvec2(16u), uvec2(0u), bvec2((x & uvec2(65535u)))); - x = (x >> b16); - uvec2 b8 = mix(uvec2(8u), uvec2(0u), bvec2((x & uvec2(255u)))); - x = (x >> b8); - uvec2 b4 = mix(uvec2(4u), uvec2(0u), bvec2((x & uvec2(15u)))); - x = (x >> b4); - uvec2 b2 = mix(uvec2(2u), uvec2(0u), bvec2((x & uvec2(3u)))); - x = (x >> b2); - uvec2 b1 = mix(uvec2(1u), uvec2(0u), bvec2((x & uvec2(1u)))); - uvec2 is_zero = mix(uvec2(0u), uvec2(4294967295u), equal(x, uvec2(0u))); - return uvec2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_45eb10() { - uvec2 res = tint_first_trailing_bit(uvec2(1u)); + uvec2 res = uvec2(0u); } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -uvec2 tint_first_trailing_bit(uvec2 v) { - uvec2 x = uvec2(v); - uvec2 b16 = mix(uvec2(16u), uvec2(0u), bvec2((x & uvec2(65535u)))); - x = (x >> b16); - uvec2 b8 = mix(uvec2(8u), uvec2(0u), bvec2((x & uvec2(255u)))); - x = (x >> b8); - uvec2 b4 = mix(uvec2(4u), uvec2(0u), bvec2((x & uvec2(15u)))); - x = (x >> b4); - uvec2 b2 = mix(uvec2(2u), uvec2(0u), bvec2((x & uvec2(3u)))); - x = (x >> b2); - uvec2 b1 = mix(uvec2(1u), uvec2(0u), bvec2((x & uvec2(1u)))); - uvec2 is_zero = mix(uvec2(0u), uvec2(4294967295u), equal(x, uvec2(0u))); - return uvec2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_45eb10() { - uvec2 res = tint_first_trailing_bit(uvec2(1u)); + uvec2 res = uvec2(0u); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.msl index 744afadfa6..90c1afd99f 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -uint2 tint_first_trailing_bit(uint2 v) { - uint2 x = uint2(v); - uint2 const b16 = select(uint2(16u), uint2(0u), bool2((x & uint2(65535u)))); - x = (x >> b16); - uint2 const b8 = select(uint2(8u), uint2(0u), bool2((x & uint2(255u)))); - x = (x >> b8); - uint2 const b4 = select(uint2(4u), uint2(0u), bool2((x & uint2(15u)))); - x = (x >> b4); - uint2 const b2 = select(uint2(2u), uint2(0u), bool2((x & uint2(3u)))); - x = (x >> b2); - uint2 const b1 = select(uint2(1u), uint2(0u), bool2((x & uint2(1u)))); - uint2 const is_zero = select(uint2(0u), uint2(4294967295u), (x == uint2(0u))); - return uint2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_45eb10() { - uint2 res = tint_first_trailing_bit(uint2(1u)); + uint2 res = uint2(0u); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.spvasm index 5aac2e5421..99a65b33eb 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/45eb10.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 98 +; Bound: 32 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_45eb10 "firstTrailingBit_45eb10" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,110 +28,39 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 + %void = OpTypeVoid + %9 = OpTypeFunction %void %uint = OpTypeInt 32 0 %v2uint = OpTypeVector %uint 2 - %9 = OpTypeFunction %v2uint %v2uint + %15 = OpConstantNull %v2uint %_ptr_Function_v2uint = OpTypePointer Function %v2uint - %18 = OpConstantNull %v2uint - %bool = OpTypeBool - %v2bool = OpTypeVector %bool 2 - %uint_65535 = OpConstant %uint 65535 - %25 = OpConstantComposite %v2uint %uint_65535 %uint_65535 - %uint_16 = OpConstant %uint 16 - %28 = OpConstantComposite %v2uint %uint_16 %uint_16 - %uint_255 = OpConstant %uint 255 - %35 = OpConstantComposite %v2uint %uint_255 %uint_255 - %uint_8 = OpConstant %uint 8 - %38 = OpConstantComposite %v2uint %uint_8 %uint_8 - %uint_15 = OpConstant %uint 15 - %45 = OpConstantComposite %v2uint %uint_15 %uint_15 - %uint_4 = OpConstant %uint 4 - %48 = OpConstantComposite %v2uint %uint_4 %uint_4 - %uint_3 = OpConstant %uint 3 - %55 = OpConstantComposite %v2uint %uint_3 %uint_3 - %uint_2 = OpConstant %uint 2 - %58 = OpConstantComposite %v2uint %uint_2 %uint_2 - %uint_1 = OpConstant %uint 1 - %65 = OpConstantComposite %v2uint %uint_1 %uint_1 -%uint_4294967295 = OpConstant %uint 4294967295 - %71 = OpConstantComposite %v2uint %uint_4294967295 %uint_4294967295 - %void = OpTypeVoid - %78 = OpTypeFunction %void - %84 = OpTypeFunction %v4float + %18 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %v2uint None %9 - %v = OpFunctionParameter %v2uint - %14 = OpLabel - %x = OpVariable %_ptr_Function_v2uint Function %18 - OpStore %x %v - %23 = OpLoad %v2uint %x - %26 = OpBitwiseAnd %v2uint %23 %25 - %20 = OpINotEqual %v2bool %26 %18 - %19 = OpSelect %v2uint %20 %18 %28 - %29 = OpLoad %v2uint %x - %30 = OpShiftRightLogical %v2uint %29 %19 - OpStore %x %30 - %33 = OpLoad %v2uint %x - %36 = OpBitwiseAnd %v2uint %33 %35 - %32 = OpINotEqual %v2bool %36 %18 - %31 = OpSelect %v2uint %32 %18 %38 - %39 = OpLoad %v2uint %x - %40 = OpShiftRightLogical %v2uint %39 %31 - OpStore %x %40 - %43 = OpLoad %v2uint %x - %46 = OpBitwiseAnd %v2uint %43 %45 - %42 = OpINotEqual %v2bool %46 %18 - %41 = OpSelect %v2uint %42 %18 %48 - %49 = OpLoad %v2uint %x - %50 = OpShiftRightLogical %v2uint %49 %41 - OpStore %x %50 - %53 = OpLoad %v2uint %x - %56 = OpBitwiseAnd %v2uint %53 %55 - %52 = OpINotEqual %v2bool %56 %18 - %51 = OpSelect %v2uint %52 %18 %58 - %59 = OpLoad %v2uint %x - %60 = OpShiftRightLogical %v2uint %59 %51 - OpStore %x %60 - %63 = OpLoad %v2uint %x - %66 = OpBitwiseAnd %v2uint %63 %65 - %62 = OpINotEqual %v2bool %66 %18 - %61 = OpSelect %v2uint %62 %18 %65 - %68 = OpLoad %v2uint %x - %69 = OpIEqual %v2bool %68 %18 - %67 = OpSelect %v2uint %69 %71 %18 - %73 = OpBitwiseOr %v2uint %19 %31 - %74 = OpBitwiseOr %v2uint %73 %41 - %75 = OpBitwiseOr %v2uint %74 %51 - %76 = OpBitwiseOr %v2uint %75 %61 - %77 = OpBitwiseOr %v2uint %76 %67 - OpReturnValue %77 - OpFunctionEnd -%firstTrailingBit_45eb10 = OpFunction %void None %78 - %81 = OpLabel - %res = OpVariable %_ptr_Function_v2uint Function %18 - %82 = OpFunctionCall %v2uint %tint_first_trailing_bit %65 - OpStore %res %82 +%firstTrailingBit_45eb10 = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_v2uint Function %15 + OpStore %res %15 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %84 - %86 = OpLabel - %87 = OpFunctionCall %void %firstTrailingBit_45eb10 +%vertex_main_inner = OpFunction %v4float None %18 + %20 = OpLabel + %21 = OpFunctionCall %void %firstTrailingBit_45eb10 OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %78 - %89 = OpLabel - %90 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %90 +%vertex_main = OpFunction %void None %9 + %23 = OpLabel + %24 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %24 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %78 - %93 = OpLabel - %94 = OpFunctionCall %void %firstTrailingBit_45eb10 +%fragment_main = OpFunction %void None %9 + %27 = OpLabel + %28 = OpFunctionCall %void %firstTrailingBit_45eb10 OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %78 - %96 = OpLabel - %97 = OpFunctionCall %void %firstTrailingBit_45eb10 +%compute_main = OpFunction %void None %9 + %30 = OpLabel + %31 = OpFunctionCall %void %firstTrailingBit_45eb10 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.dxc.hlsl index 3b50087bc9..0aece4efd7 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -uint tint_first_trailing_bit(uint v) { - uint x = uint(v); - const uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - const uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - const uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - const uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - const uint b1 = (bool((x & 1u)) ? 0u : 1u); - const uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_47d475() { - uint res = tint_first_trailing_bit(1u); + uint res = 0u; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.fxc.hlsl index 3b50087bc9..0aece4efd7 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -uint tint_first_trailing_bit(uint v) { - uint x = uint(v); - const uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - const uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - const uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - const uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - const uint b1 = (bool((x & 1u)) ? 0u : 1u); - const uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_47d475() { - uint res = tint_first_trailing_bit(1u); + uint res = 0u; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.glsl index 5fdedcd855..7ae6bba199 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -uint tint_first_trailing_bit(uint v) { - uint x = uint(v); - uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - uint b1 = (bool((x & 1u)) ? 0u : 1u); - uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_47d475() { - uint res = tint_first_trailing_bit(1u); + uint res = 0u; } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -uint tint_first_trailing_bit(uint v) { - uint x = uint(v); - uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - uint b1 = (bool((x & 1u)) ? 0u : 1u); - uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_47d475() { - uint res = tint_first_trailing_bit(1u); + uint res = 0u; } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -uint tint_first_trailing_bit(uint v) { - uint x = uint(v); - uint b16 = (bool((x & 65535u)) ? 0u : 16u); - x = (x >> b16); - uint b8 = (bool((x & 255u)) ? 0u : 8u); - x = (x >> b8); - uint b4 = (bool((x & 15u)) ? 0u : 4u); - x = (x >> b4); - uint b2 = (bool((x & 3u)) ? 0u : 2u); - x = (x >> b2); - uint b1 = (bool((x & 1u)) ? 0u : 1u); - uint is_zero = ((x == 0u) ? 4294967295u : 0u); - return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_47d475() { - uint res = tint_first_trailing_bit(1u); + uint res = 0u; } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.msl index fba301cc40..7009d683e4 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -uint tint_first_trailing_bit(uint v) { - uint x = uint(v); - uint const b16 = select(16u, 0u, bool((x & 65535u))); - x = (x >> b16); - uint const b8 = select(8u, 0u, bool((x & 255u))); - x = (x >> b8); - uint const b4 = select(4u, 0u, bool((x & 15u))); - x = (x >> b4); - uint const b2 = select(2u, 0u, bool((x & 3u))); - x = (x >> b2); - uint const b1 = select(1u, 0u, bool((x & 1u))); - uint const is_zero = select(0u, 4294967295u, (x == 0u)); - return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_47d475() { - uint res = tint_first_trailing_bit(1u); + uint res = 0u; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.spvasm index 7f60ef1b61..3e70c04326 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/47d475.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 86 +; Bound: 31 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_47d475 "firstTrailingBit_47d475" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,98 +28,38 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 - %uint = OpTypeInt 32 0 - %9 = OpTypeFunction %uint %uint -%_ptr_Function_uint = OpTypePointer Function %uint - %17 = OpConstantNull %uint - %bool = OpTypeBool - %uint_65535 = OpConstant %uint 65535 - %uint_16 = OpConstant %uint 16 - %uint_255 = OpConstant %uint 255 - %uint_8 = OpConstant %uint 8 - %uint_15 = OpConstant %uint 15 - %uint_4 = OpConstant %uint 4 - %uint_3 = OpConstant %uint 3 - %uint_2 = OpConstant %uint 2 - %uint_1 = OpConstant %uint 1 -%uint_4294967295 = OpConstant %uint 4294967295 %void = OpTypeVoid - %66 = OpTypeFunction %void - %72 = OpTypeFunction %v4float + %9 = OpTypeFunction %void + %uint = OpTypeInt 32 0 + %14 = OpConstantNull %uint +%_ptr_Function_uint = OpTypePointer Function %uint + %17 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %uint None %9 - %v = OpFunctionParameter %uint - %13 = OpLabel - %x = OpVariable %_ptr_Function_uint Function %17 - OpStore %x %v - %21 = OpLoad %uint %x - %23 = OpBitwiseAnd %uint %21 %uint_65535 - %19 = OpINotEqual %bool %23 %17 - %18 = OpSelect %uint %19 %17 %uint_16 - %25 = OpLoad %uint %x - %26 = OpShiftRightLogical %uint %25 %18 - OpStore %x %26 - %29 = OpLoad %uint %x - %31 = OpBitwiseAnd %uint %29 %uint_255 - %28 = OpINotEqual %bool %31 %17 - %27 = OpSelect %uint %28 %17 %uint_8 - %33 = OpLoad %uint %x - %34 = OpShiftRightLogical %uint %33 %27 - OpStore %x %34 - %37 = OpLoad %uint %x - %39 = OpBitwiseAnd %uint %37 %uint_15 - %36 = OpINotEqual %bool %39 %17 - %35 = OpSelect %uint %36 %17 %uint_4 - %41 = OpLoad %uint %x - %42 = OpShiftRightLogical %uint %41 %35 - OpStore %x %42 - %45 = OpLoad %uint %x - %47 = OpBitwiseAnd %uint %45 %uint_3 - %44 = OpINotEqual %bool %47 %17 - %43 = OpSelect %uint %44 %17 %uint_2 - %49 = OpLoad %uint %x - %50 = OpShiftRightLogical %uint %49 %43 - OpStore %x %50 - %53 = OpLoad %uint %x - %55 = OpBitwiseAnd %uint %53 %uint_1 - %52 = OpINotEqual %bool %55 %17 - %51 = OpSelect %uint %52 %17 %uint_1 - %57 = OpLoad %uint %x - %58 = OpIEqual %bool %57 %17 - %56 = OpSelect %uint %58 %uint_4294967295 %17 - %61 = OpBitwiseOr %uint %18 %27 - %62 = OpBitwiseOr %uint %61 %35 - %63 = OpBitwiseOr %uint %62 %43 - %64 = OpBitwiseOr %uint %63 %51 - %65 = OpBitwiseOr %uint %64 %56 - OpReturnValue %65 - OpFunctionEnd -%firstTrailingBit_47d475 = OpFunction %void None %66 - %69 = OpLabel - %res = OpVariable %_ptr_Function_uint Function %17 - %70 = OpFunctionCall %uint %tint_first_trailing_bit %uint_1 - OpStore %res %70 +%firstTrailingBit_47d475 = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_uint Function %14 + OpStore %res %14 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %72 - %74 = OpLabel - %75 = OpFunctionCall %void %firstTrailingBit_47d475 +%vertex_main_inner = OpFunction %v4float None %17 + %19 = OpLabel + %20 = OpFunctionCall %void %firstTrailingBit_47d475 OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %66 - %77 = OpLabel - %78 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %78 +%vertex_main = OpFunction %void None %9 + %22 = OpLabel + %23 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %23 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %66 - %81 = OpLabel - %82 = OpFunctionCall %void %firstTrailingBit_47d475 +%fragment_main = OpFunction %void None %9 + %26 = OpLabel + %27 = OpFunctionCall %void %firstTrailingBit_47d475 OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %66 - %84 = OpLabel - %85 = OpFunctionCall %void %firstTrailingBit_47d475 +%compute_main = OpFunction %void None %9 + %29 = OpLabel + %30 = OpFunctionCall %void %firstTrailingBit_47d475 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.dxc.hlsl index 6831c5b781..7182ae5724 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -int2 tint_first_trailing_bit(int2 v) { - uint2 x = uint2(v); - const uint2 b16 = (bool2((x & (65535u).xx)) ? (0u).xx : (16u).xx); - x = (x >> b16); - const uint2 b8 = (bool2((x & (255u).xx)) ? (0u).xx : (8u).xx); - x = (x >> b8); - const uint2 b4 = (bool2((x & (15u).xx)) ? (0u).xx : (4u).xx); - x = (x >> b4); - const uint2 b2 = (bool2((x & (3u).xx)) ? (0u).xx : (2u).xx); - x = (x >> b2); - const uint2 b1 = (bool2((x & (1u).xx)) ? (0u).xx : (1u).xx); - const uint2 is_zero = ((x == (0u).xx) ? (4294967295u).xx : (0u).xx); - return int2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_50c072() { - int2 res = tint_first_trailing_bit((1).xx); + int2 res = (0).xx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.fxc.hlsl index 6831c5b781..7182ae5724 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -int2 tint_first_trailing_bit(int2 v) { - uint2 x = uint2(v); - const uint2 b16 = (bool2((x & (65535u).xx)) ? (0u).xx : (16u).xx); - x = (x >> b16); - const uint2 b8 = (bool2((x & (255u).xx)) ? (0u).xx : (8u).xx); - x = (x >> b8); - const uint2 b4 = (bool2((x & (15u).xx)) ? (0u).xx : (4u).xx); - x = (x >> b4); - const uint2 b2 = (bool2((x & (3u).xx)) ? (0u).xx : (2u).xx); - x = (x >> b2); - const uint2 b1 = (bool2((x & (1u).xx)) ? (0u).xx : (1u).xx); - const uint2 is_zero = ((x == (0u).xx) ? (4294967295u).xx : (0u).xx); - return int2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_50c072() { - int2 res = tint_first_trailing_bit((1).xx); + int2 res = (0).xx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.glsl index f59914622d..207e75909e 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -ivec2 tint_first_trailing_bit(ivec2 v) { - uvec2 x = uvec2(v); - uvec2 b16 = mix(uvec2(16u), uvec2(0u), bvec2((x & uvec2(65535u)))); - x = (x >> b16); - uvec2 b8 = mix(uvec2(8u), uvec2(0u), bvec2((x & uvec2(255u)))); - x = (x >> b8); - uvec2 b4 = mix(uvec2(4u), uvec2(0u), bvec2((x & uvec2(15u)))); - x = (x >> b4); - uvec2 b2 = mix(uvec2(2u), uvec2(0u), bvec2((x & uvec2(3u)))); - x = (x >> b2); - uvec2 b1 = mix(uvec2(1u), uvec2(0u), bvec2((x & uvec2(1u)))); - uvec2 is_zero = mix(uvec2(0u), uvec2(4294967295u), equal(x, uvec2(0u))); - return ivec2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_50c072() { - ivec2 res = tint_first_trailing_bit(ivec2(1)); + ivec2 res = ivec2(0); } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -ivec2 tint_first_trailing_bit(ivec2 v) { - uvec2 x = uvec2(v); - uvec2 b16 = mix(uvec2(16u), uvec2(0u), bvec2((x & uvec2(65535u)))); - x = (x >> b16); - uvec2 b8 = mix(uvec2(8u), uvec2(0u), bvec2((x & uvec2(255u)))); - x = (x >> b8); - uvec2 b4 = mix(uvec2(4u), uvec2(0u), bvec2((x & uvec2(15u)))); - x = (x >> b4); - uvec2 b2 = mix(uvec2(2u), uvec2(0u), bvec2((x & uvec2(3u)))); - x = (x >> b2); - uvec2 b1 = mix(uvec2(1u), uvec2(0u), bvec2((x & uvec2(1u)))); - uvec2 is_zero = mix(uvec2(0u), uvec2(4294967295u), equal(x, uvec2(0u))); - return ivec2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_50c072() { - ivec2 res = tint_first_trailing_bit(ivec2(1)); + ivec2 res = ivec2(0); } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -ivec2 tint_first_trailing_bit(ivec2 v) { - uvec2 x = uvec2(v); - uvec2 b16 = mix(uvec2(16u), uvec2(0u), bvec2((x & uvec2(65535u)))); - x = (x >> b16); - uvec2 b8 = mix(uvec2(8u), uvec2(0u), bvec2((x & uvec2(255u)))); - x = (x >> b8); - uvec2 b4 = mix(uvec2(4u), uvec2(0u), bvec2((x & uvec2(15u)))); - x = (x >> b4); - uvec2 b2 = mix(uvec2(2u), uvec2(0u), bvec2((x & uvec2(3u)))); - x = (x >> b2); - uvec2 b1 = mix(uvec2(1u), uvec2(0u), bvec2((x & uvec2(1u)))); - uvec2 is_zero = mix(uvec2(0u), uvec2(4294967295u), equal(x, uvec2(0u))); - return ivec2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_50c072() { - ivec2 res = tint_first_trailing_bit(ivec2(1)); + ivec2 res = ivec2(0); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.msl index 77d08a2f77..723c4fc1c7 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -int2 tint_first_trailing_bit(int2 v) { - uint2 x = uint2(v); - uint2 const b16 = select(uint2(16u), uint2(0u), bool2((x & uint2(65535u)))); - x = (x >> b16); - uint2 const b8 = select(uint2(8u), uint2(0u), bool2((x & uint2(255u)))); - x = (x >> b8); - uint2 const b4 = select(uint2(4u), uint2(0u), bool2((x & uint2(15u)))); - x = (x >> b4); - uint2 const b2 = select(uint2(2u), uint2(0u), bool2((x & uint2(3u)))); - x = (x >> b2); - uint2 const b1 = select(uint2(1u), uint2(0u), bool2((x & uint2(1u)))); - uint2 const is_zero = select(uint2(0u), uint2(4294967295u), (x == uint2(0u))); - return int2((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_50c072() { - int2 res = tint_first_trailing_bit(int2(1)); + int2 res = int2(0); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.spvasm index 3b8a036a99..3437073539 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/50c072.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 104 +; Bound: 32 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_50c072 "firstTrailingBit_50c072" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,118 +28,39 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 + %void = OpTypeVoid + %9 = OpTypeFunction %void %int = OpTypeInt 32 1 %v2int = OpTypeVector %int 2 - %9 = OpTypeFunction %v2int %v2int - %uint = OpTypeInt 32 0 - %v2uint = OpTypeVector %uint 2 -%_ptr_Function_v2uint = OpTypePointer Function %v2uint - %20 = OpConstantNull %v2uint - %bool = OpTypeBool - %v2bool = OpTypeVector %bool 2 - %uint_65535 = OpConstant %uint 65535 - %27 = OpConstantComposite %v2uint %uint_65535 %uint_65535 - %uint_16 = OpConstant %uint 16 - %30 = OpConstantComposite %v2uint %uint_16 %uint_16 - %uint_255 = OpConstant %uint 255 - %37 = OpConstantComposite %v2uint %uint_255 %uint_255 - %uint_8 = OpConstant %uint 8 - %40 = OpConstantComposite %v2uint %uint_8 %uint_8 - %uint_15 = OpConstant %uint 15 - %47 = OpConstantComposite %v2uint %uint_15 %uint_15 - %uint_4 = OpConstant %uint 4 - %50 = OpConstantComposite %v2uint %uint_4 %uint_4 - %uint_3 = OpConstant %uint 3 - %57 = OpConstantComposite %v2uint %uint_3 %uint_3 - %uint_2 = OpConstant %uint 2 - %60 = OpConstantComposite %v2uint %uint_2 %uint_2 - %uint_1 = OpConstant %uint 1 - %67 = OpConstantComposite %v2uint %uint_1 %uint_1 -%uint_4294967295 = OpConstant %uint 4294967295 - %73 = OpConstantComposite %v2uint %uint_4294967295 %uint_4294967295 - %void = OpTypeVoid - %80 = OpTypeFunction %void - %int_1 = OpConstant %int 1 - %86 = OpConstantComposite %v2int %int_1 %int_1 + %15 = OpConstantNull %v2int %_ptr_Function_v2int = OpTypePointer Function %v2int - %89 = OpConstantNull %v2int - %90 = OpTypeFunction %v4float + %18 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %v2int None %9 - %v = OpFunctionParameter %v2int - %14 = OpLabel - %x = OpVariable %_ptr_Function_v2uint Function %20 - %15 = OpBitcast %v2uint %v - OpStore %x %15 - %25 = OpLoad %v2uint %x - %28 = OpBitwiseAnd %v2uint %25 %27 - %22 = OpINotEqual %v2bool %28 %20 - %21 = OpSelect %v2uint %22 %20 %30 - %31 = OpLoad %v2uint %x - %32 = OpShiftRightLogical %v2uint %31 %21 - OpStore %x %32 - %35 = OpLoad %v2uint %x - %38 = OpBitwiseAnd %v2uint %35 %37 - %34 = OpINotEqual %v2bool %38 %20 - %33 = OpSelect %v2uint %34 %20 %40 - %41 = OpLoad %v2uint %x - %42 = OpShiftRightLogical %v2uint %41 %33 - OpStore %x %42 - %45 = OpLoad %v2uint %x - %48 = OpBitwiseAnd %v2uint %45 %47 - %44 = OpINotEqual %v2bool %48 %20 - %43 = OpSelect %v2uint %44 %20 %50 - %51 = OpLoad %v2uint %x - %52 = OpShiftRightLogical %v2uint %51 %43 - OpStore %x %52 - %55 = OpLoad %v2uint %x - %58 = OpBitwiseAnd %v2uint %55 %57 - %54 = OpINotEqual %v2bool %58 %20 - %53 = OpSelect %v2uint %54 %20 %60 - %61 = OpLoad %v2uint %x - %62 = OpShiftRightLogical %v2uint %61 %53 - OpStore %x %62 - %65 = OpLoad %v2uint %x - %68 = OpBitwiseAnd %v2uint %65 %67 - %64 = OpINotEqual %v2bool %68 %20 - %63 = OpSelect %v2uint %64 %20 %67 - %70 = OpLoad %v2uint %x - %71 = OpIEqual %v2bool %70 %20 - %69 = OpSelect %v2uint %71 %73 %20 - %75 = OpBitwiseOr %v2uint %21 %33 - %76 = OpBitwiseOr %v2uint %75 %43 - %77 = OpBitwiseOr %v2uint %76 %53 - %78 = OpBitwiseOr %v2uint %77 %63 - %79 = OpBitwiseOr %v2uint %78 %69 - %74 = OpBitcast %v2int %79 - OpReturnValue %74 - OpFunctionEnd -%firstTrailingBit_50c072 = OpFunction %void None %80 - %83 = OpLabel - %res = OpVariable %_ptr_Function_v2int Function %89 - %84 = OpFunctionCall %v2int %tint_first_trailing_bit %86 - OpStore %res %84 +%firstTrailingBit_50c072 = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_v2int Function %15 + OpStore %res %15 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %90 - %92 = OpLabel - %93 = OpFunctionCall %void %firstTrailingBit_50c072 +%vertex_main_inner = OpFunction %v4float None %18 + %20 = OpLabel + %21 = OpFunctionCall %void %firstTrailingBit_50c072 OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %80 - %95 = OpLabel - %96 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %96 +%vertex_main = OpFunction %void None %9 + %23 = OpLabel + %24 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %24 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %80 - %99 = OpLabel - %100 = OpFunctionCall %void %firstTrailingBit_50c072 +%fragment_main = OpFunction %void None %9 + %27 = OpLabel + %28 = OpFunctionCall %void %firstTrailingBit_50c072 OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %80 - %102 = OpLabel - %103 = OpFunctionCall %void %firstTrailingBit_50c072 +%compute_main = OpFunction %void None %9 + %30 = OpLabel + %31 = OpFunctionCall %void %firstTrailingBit_50c072 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.dxc.hlsl index b6a770e919..b2a4bd1792 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -int3 tint_first_trailing_bit(int3 v) { - uint3 x = uint3(v); - const uint3 b16 = (bool3((x & (65535u).xxx)) ? (0u).xxx : (16u).xxx); - x = (x >> b16); - const uint3 b8 = (bool3((x & (255u).xxx)) ? (0u).xxx : (8u).xxx); - x = (x >> b8); - const uint3 b4 = (bool3((x & (15u).xxx)) ? (0u).xxx : (4u).xxx); - x = (x >> b4); - const uint3 b2 = (bool3((x & (3u).xxx)) ? (0u).xxx : (2u).xxx); - x = (x >> b2); - const uint3 b1 = (bool3((x & (1u).xxx)) ? (0u).xxx : (1u).xxx); - const uint3 is_zero = ((x == (0u).xxx) ? (4294967295u).xxx : (0u).xxx); - return int3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_7496d6() { - int3 res = tint_first_trailing_bit((1).xxx); + int3 res = (0).xxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.fxc.hlsl index b6a770e919..b2a4bd1792 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -int3 tint_first_trailing_bit(int3 v) { - uint3 x = uint3(v); - const uint3 b16 = (bool3((x & (65535u).xxx)) ? (0u).xxx : (16u).xxx); - x = (x >> b16); - const uint3 b8 = (bool3((x & (255u).xxx)) ? (0u).xxx : (8u).xxx); - x = (x >> b8); - const uint3 b4 = (bool3((x & (15u).xxx)) ? (0u).xxx : (4u).xxx); - x = (x >> b4); - const uint3 b2 = (bool3((x & (3u).xxx)) ? (0u).xxx : (2u).xxx); - x = (x >> b2); - const uint3 b1 = (bool3((x & (1u).xxx)) ? (0u).xxx : (1u).xxx); - const uint3 is_zero = ((x == (0u).xxx) ? (4294967295u).xxx : (0u).xxx); - return int3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_7496d6() { - int3 res = tint_first_trailing_bit((1).xxx); + int3 res = (0).xxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.glsl index f32c11889d..1aafc02fc5 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -ivec3 tint_first_trailing_bit(ivec3 v) { - uvec3 x = uvec3(v); - uvec3 b16 = mix(uvec3(16u), uvec3(0u), bvec3((x & uvec3(65535u)))); - x = (x >> b16); - uvec3 b8 = mix(uvec3(8u), uvec3(0u), bvec3((x & uvec3(255u)))); - x = (x >> b8); - uvec3 b4 = mix(uvec3(4u), uvec3(0u), bvec3((x & uvec3(15u)))); - x = (x >> b4); - uvec3 b2 = mix(uvec3(2u), uvec3(0u), bvec3((x & uvec3(3u)))); - x = (x >> b2); - uvec3 b1 = mix(uvec3(1u), uvec3(0u), bvec3((x & uvec3(1u)))); - uvec3 is_zero = mix(uvec3(0u), uvec3(4294967295u), equal(x, uvec3(0u))); - return ivec3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_7496d6() { - ivec3 res = tint_first_trailing_bit(ivec3(1)); + ivec3 res = ivec3(0); } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -ivec3 tint_first_trailing_bit(ivec3 v) { - uvec3 x = uvec3(v); - uvec3 b16 = mix(uvec3(16u), uvec3(0u), bvec3((x & uvec3(65535u)))); - x = (x >> b16); - uvec3 b8 = mix(uvec3(8u), uvec3(0u), bvec3((x & uvec3(255u)))); - x = (x >> b8); - uvec3 b4 = mix(uvec3(4u), uvec3(0u), bvec3((x & uvec3(15u)))); - x = (x >> b4); - uvec3 b2 = mix(uvec3(2u), uvec3(0u), bvec3((x & uvec3(3u)))); - x = (x >> b2); - uvec3 b1 = mix(uvec3(1u), uvec3(0u), bvec3((x & uvec3(1u)))); - uvec3 is_zero = mix(uvec3(0u), uvec3(4294967295u), equal(x, uvec3(0u))); - return ivec3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_7496d6() { - ivec3 res = tint_first_trailing_bit(ivec3(1)); + ivec3 res = ivec3(0); } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -ivec3 tint_first_trailing_bit(ivec3 v) { - uvec3 x = uvec3(v); - uvec3 b16 = mix(uvec3(16u), uvec3(0u), bvec3((x & uvec3(65535u)))); - x = (x >> b16); - uvec3 b8 = mix(uvec3(8u), uvec3(0u), bvec3((x & uvec3(255u)))); - x = (x >> b8); - uvec3 b4 = mix(uvec3(4u), uvec3(0u), bvec3((x & uvec3(15u)))); - x = (x >> b4); - uvec3 b2 = mix(uvec3(2u), uvec3(0u), bvec3((x & uvec3(3u)))); - x = (x >> b2); - uvec3 b1 = mix(uvec3(1u), uvec3(0u), bvec3((x & uvec3(1u)))); - uvec3 is_zero = mix(uvec3(0u), uvec3(4294967295u), equal(x, uvec3(0u))); - return ivec3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_7496d6() { - ivec3 res = tint_first_trailing_bit(ivec3(1)); + ivec3 res = ivec3(0); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.msl index ebbd9e5d47..f304f8c714 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -int3 tint_first_trailing_bit(int3 v) { - uint3 x = uint3(v); - uint3 const b16 = select(uint3(16u), uint3(0u), bool3((x & uint3(65535u)))); - x = (x >> b16); - uint3 const b8 = select(uint3(8u), uint3(0u), bool3((x & uint3(255u)))); - x = (x >> b8); - uint3 const b4 = select(uint3(4u), uint3(0u), bool3((x & uint3(15u)))); - x = (x >> b4); - uint3 const b2 = select(uint3(2u), uint3(0u), bool3((x & uint3(3u)))); - x = (x >> b2); - uint3 const b1 = select(uint3(1u), uint3(0u), bool3((x & uint3(1u)))); - uint3 const is_zero = select(uint3(0u), uint3(4294967295u), (x == uint3(0u))); - return int3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_7496d6() { - int3 res = tint_first_trailing_bit(int3(1)); + int3 res = int3(0); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.spvasm index 19085fc050..bd16ed2b1c 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/7496d6.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 104 +; Bound: 32 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_7496d6 "firstTrailingBit_7496d6" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,118 +28,39 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 + %void = OpTypeVoid + %9 = OpTypeFunction %void %int = OpTypeInt 32 1 %v3int = OpTypeVector %int 3 - %9 = OpTypeFunction %v3int %v3int - %uint = OpTypeInt 32 0 - %v3uint = OpTypeVector %uint 3 -%_ptr_Function_v3uint = OpTypePointer Function %v3uint - %20 = OpConstantNull %v3uint - %bool = OpTypeBool - %v3bool = OpTypeVector %bool 3 - %uint_65535 = OpConstant %uint 65535 - %27 = OpConstantComposite %v3uint %uint_65535 %uint_65535 %uint_65535 - %uint_16 = OpConstant %uint 16 - %30 = OpConstantComposite %v3uint %uint_16 %uint_16 %uint_16 - %uint_255 = OpConstant %uint 255 - %37 = OpConstantComposite %v3uint %uint_255 %uint_255 %uint_255 - %uint_8 = OpConstant %uint 8 - %40 = OpConstantComposite %v3uint %uint_8 %uint_8 %uint_8 - %uint_15 = OpConstant %uint 15 - %47 = OpConstantComposite %v3uint %uint_15 %uint_15 %uint_15 - %uint_4 = OpConstant %uint 4 - %50 = OpConstantComposite %v3uint %uint_4 %uint_4 %uint_4 - %uint_3 = OpConstant %uint 3 - %57 = OpConstantComposite %v3uint %uint_3 %uint_3 %uint_3 - %uint_2 = OpConstant %uint 2 - %60 = OpConstantComposite %v3uint %uint_2 %uint_2 %uint_2 - %uint_1 = OpConstant %uint 1 - %67 = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1 -%uint_4294967295 = OpConstant %uint 4294967295 - %73 = OpConstantComposite %v3uint %uint_4294967295 %uint_4294967295 %uint_4294967295 - %void = OpTypeVoid - %80 = OpTypeFunction %void - %int_1 = OpConstant %int 1 - %86 = OpConstantComposite %v3int %int_1 %int_1 %int_1 + %15 = OpConstantNull %v3int %_ptr_Function_v3int = OpTypePointer Function %v3int - %89 = OpConstantNull %v3int - %90 = OpTypeFunction %v4float + %18 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %v3int None %9 - %v = OpFunctionParameter %v3int - %14 = OpLabel - %x = OpVariable %_ptr_Function_v3uint Function %20 - %15 = OpBitcast %v3uint %v - OpStore %x %15 - %25 = OpLoad %v3uint %x - %28 = OpBitwiseAnd %v3uint %25 %27 - %22 = OpINotEqual %v3bool %28 %20 - %21 = OpSelect %v3uint %22 %20 %30 - %31 = OpLoad %v3uint %x - %32 = OpShiftRightLogical %v3uint %31 %21 - OpStore %x %32 - %35 = OpLoad %v3uint %x - %38 = OpBitwiseAnd %v3uint %35 %37 - %34 = OpINotEqual %v3bool %38 %20 - %33 = OpSelect %v3uint %34 %20 %40 - %41 = OpLoad %v3uint %x - %42 = OpShiftRightLogical %v3uint %41 %33 - OpStore %x %42 - %45 = OpLoad %v3uint %x - %48 = OpBitwiseAnd %v3uint %45 %47 - %44 = OpINotEqual %v3bool %48 %20 - %43 = OpSelect %v3uint %44 %20 %50 - %51 = OpLoad %v3uint %x - %52 = OpShiftRightLogical %v3uint %51 %43 - OpStore %x %52 - %55 = OpLoad %v3uint %x - %58 = OpBitwiseAnd %v3uint %55 %57 - %54 = OpINotEqual %v3bool %58 %20 - %53 = OpSelect %v3uint %54 %20 %60 - %61 = OpLoad %v3uint %x - %62 = OpShiftRightLogical %v3uint %61 %53 - OpStore %x %62 - %65 = OpLoad %v3uint %x - %68 = OpBitwiseAnd %v3uint %65 %67 - %64 = OpINotEqual %v3bool %68 %20 - %63 = OpSelect %v3uint %64 %20 %67 - %70 = OpLoad %v3uint %x - %71 = OpIEqual %v3bool %70 %20 - %69 = OpSelect %v3uint %71 %73 %20 - %75 = OpBitwiseOr %v3uint %21 %33 - %76 = OpBitwiseOr %v3uint %75 %43 - %77 = OpBitwiseOr %v3uint %76 %53 - %78 = OpBitwiseOr %v3uint %77 %63 - %79 = OpBitwiseOr %v3uint %78 %69 - %74 = OpBitcast %v3int %79 - OpReturnValue %74 - OpFunctionEnd -%firstTrailingBit_7496d6 = OpFunction %void None %80 - %83 = OpLabel - %res = OpVariable %_ptr_Function_v3int Function %89 - %84 = OpFunctionCall %v3int %tint_first_trailing_bit %86 - OpStore %res %84 +%firstTrailingBit_7496d6 = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_v3int Function %15 + OpStore %res %15 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %90 - %92 = OpLabel - %93 = OpFunctionCall %void %firstTrailingBit_7496d6 +%vertex_main_inner = OpFunction %v4float None %18 + %20 = OpLabel + %21 = OpFunctionCall %void %firstTrailingBit_7496d6 OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %80 - %95 = OpLabel - %96 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %96 +%vertex_main = OpFunction %void None %9 + %23 = OpLabel + %24 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %24 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %80 - %99 = OpLabel - %100 = OpFunctionCall %void %firstTrailingBit_7496d6 +%fragment_main = OpFunction %void None %9 + %27 = OpLabel + %28 = OpFunctionCall %void %firstTrailingBit_7496d6 OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %80 - %102 = OpLabel - %103 = OpFunctionCall %void %firstTrailingBit_7496d6 +%compute_main = OpFunction %void None %9 + %30 = OpLabel + %31 = OpFunctionCall %void %firstTrailingBit_7496d6 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.dxc.hlsl index 83b0e6c5c8..cfd124dca7 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -int4 tint_first_trailing_bit(int4 v) { - uint4 x = uint4(v); - const uint4 b16 = (bool4((x & (65535u).xxxx)) ? (0u).xxxx : (16u).xxxx); - x = (x >> b16); - const uint4 b8 = (bool4((x & (255u).xxxx)) ? (0u).xxxx : (8u).xxxx); - x = (x >> b8); - const uint4 b4 = (bool4((x & (15u).xxxx)) ? (0u).xxxx : (4u).xxxx); - x = (x >> b4); - const uint4 b2 = (bool4((x & (3u).xxxx)) ? (0u).xxxx : (2u).xxxx); - x = (x >> b2); - const uint4 b1 = (bool4((x & (1u).xxxx)) ? (0u).xxxx : (1u).xxxx); - const uint4 is_zero = ((x == (0u).xxxx) ? (4294967295u).xxxx : (0u).xxxx); - return int4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_86551b() { - int4 res = tint_first_trailing_bit((1).xxxx); + int4 res = (0).xxxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.fxc.hlsl index 83b0e6c5c8..cfd124dca7 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -int4 tint_first_trailing_bit(int4 v) { - uint4 x = uint4(v); - const uint4 b16 = (bool4((x & (65535u).xxxx)) ? (0u).xxxx : (16u).xxxx); - x = (x >> b16); - const uint4 b8 = (bool4((x & (255u).xxxx)) ? (0u).xxxx : (8u).xxxx); - x = (x >> b8); - const uint4 b4 = (bool4((x & (15u).xxxx)) ? (0u).xxxx : (4u).xxxx); - x = (x >> b4); - const uint4 b2 = (bool4((x & (3u).xxxx)) ? (0u).xxxx : (2u).xxxx); - x = (x >> b2); - const uint4 b1 = (bool4((x & (1u).xxxx)) ? (0u).xxxx : (1u).xxxx); - const uint4 is_zero = ((x == (0u).xxxx) ? (4294967295u).xxxx : (0u).xxxx); - return int4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_86551b() { - int4 res = tint_first_trailing_bit((1).xxxx); + int4 res = (0).xxxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.glsl index 5965aea01d..99a9d7a75e 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -ivec4 tint_first_trailing_bit(ivec4 v) { - uvec4 x = uvec4(v); - uvec4 b16 = mix(uvec4(16u), uvec4(0u), bvec4((x & uvec4(65535u)))); - x = (x >> b16); - uvec4 b8 = mix(uvec4(8u), uvec4(0u), bvec4((x & uvec4(255u)))); - x = (x >> b8); - uvec4 b4 = mix(uvec4(4u), uvec4(0u), bvec4((x & uvec4(15u)))); - x = (x >> b4); - uvec4 b2 = mix(uvec4(2u), uvec4(0u), bvec4((x & uvec4(3u)))); - x = (x >> b2); - uvec4 b1 = mix(uvec4(1u), uvec4(0u), bvec4((x & uvec4(1u)))); - uvec4 is_zero = mix(uvec4(0u), uvec4(4294967295u), equal(x, uvec4(0u))); - return ivec4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_86551b() { - ivec4 res = tint_first_trailing_bit(ivec4(1)); + ivec4 res = ivec4(0); } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -ivec4 tint_first_trailing_bit(ivec4 v) { - uvec4 x = uvec4(v); - uvec4 b16 = mix(uvec4(16u), uvec4(0u), bvec4((x & uvec4(65535u)))); - x = (x >> b16); - uvec4 b8 = mix(uvec4(8u), uvec4(0u), bvec4((x & uvec4(255u)))); - x = (x >> b8); - uvec4 b4 = mix(uvec4(4u), uvec4(0u), bvec4((x & uvec4(15u)))); - x = (x >> b4); - uvec4 b2 = mix(uvec4(2u), uvec4(0u), bvec4((x & uvec4(3u)))); - x = (x >> b2); - uvec4 b1 = mix(uvec4(1u), uvec4(0u), bvec4((x & uvec4(1u)))); - uvec4 is_zero = mix(uvec4(0u), uvec4(4294967295u), equal(x, uvec4(0u))); - return ivec4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_86551b() { - ivec4 res = tint_first_trailing_bit(ivec4(1)); + ivec4 res = ivec4(0); } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -ivec4 tint_first_trailing_bit(ivec4 v) { - uvec4 x = uvec4(v); - uvec4 b16 = mix(uvec4(16u), uvec4(0u), bvec4((x & uvec4(65535u)))); - x = (x >> b16); - uvec4 b8 = mix(uvec4(8u), uvec4(0u), bvec4((x & uvec4(255u)))); - x = (x >> b8); - uvec4 b4 = mix(uvec4(4u), uvec4(0u), bvec4((x & uvec4(15u)))); - x = (x >> b4); - uvec4 b2 = mix(uvec4(2u), uvec4(0u), bvec4((x & uvec4(3u)))); - x = (x >> b2); - uvec4 b1 = mix(uvec4(1u), uvec4(0u), bvec4((x & uvec4(1u)))); - uvec4 is_zero = mix(uvec4(0u), uvec4(4294967295u), equal(x, uvec4(0u))); - return ivec4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_86551b() { - ivec4 res = tint_first_trailing_bit(ivec4(1)); + ivec4 res = ivec4(0); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.msl index 1f2e6b2eb5..c6cbfc7602 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -int4 tint_first_trailing_bit(int4 v) { - uint4 x = uint4(v); - uint4 const b16 = select(uint4(16u), uint4(0u), bool4((x & uint4(65535u)))); - x = (x >> b16); - uint4 const b8 = select(uint4(8u), uint4(0u), bool4((x & uint4(255u)))); - x = (x >> b8); - uint4 const b4 = select(uint4(4u), uint4(0u), bool4((x & uint4(15u)))); - x = (x >> b4); - uint4 const b2 = select(uint4(2u), uint4(0u), bool4((x & uint4(3u)))); - x = (x >> b2); - uint4 const b1 = select(uint4(1u), uint4(0u), bool4((x & uint4(1u)))); - uint4 const is_zero = select(uint4(0u), uint4(4294967295u), (x == uint4(0u))); - return int4((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_86551b() { - int4 res = tint_first_trailing_bit(int4(1)); + int4 res = int4(0); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.spvasm index fb88fcd4ab..2baed71a21 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/86551b.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 104 +; Bound: 32 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_86551b "firstTrailingBit_86551b" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,118 +28,39 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 + %void = OpTypeVoid + %9 = OpTypeFunction %void %int = OpTypeInt 32 1 %v4int = OpTypeVector %int 4 - %9 = OpTypeFunction %v4int %v4int - %uint = OpTypeInt 32 0 - %v4uint = OpTypeVector %uint 4 -%_ptr_Function_v4uint = OpTypePointer Function %v4uint - %20 = OpConstantNull %v4uint - %bool = OpTypeBool - %v4bool = OpTypeVector %bool 4 - %uint_65535 = OpConstant %uint 65535 - %27 = OpConstantComposite %v4uint %uint_65535 %uint_65535 %uint_65535 %uint_65535 - %uint_16 = OpConstant %uint 16 - %30 = OpConstantComposite %v4uint %uint_16 %uint_16 %uint_16 %uint_16 - %uint_255 = OpConstant %uint 255 - %37 = OpConstantComposite %v4uint %uint_255 %uint_255 %uint_255 %uint_255 - %uint_8 = OpConstant %uint 8 - %40 = OpConstantComposite %v4uint %uint_8 %uint_8 %uint_8 %uint_8 - %uint_15 = OpConstant %uint 15 - %47 = OpConstantComposite %v4uint %uint_15 %uint_15 %uint_15 %uint_15 - %uint_4 = OpConstant %uint 4 - %50 = OpConstantComposite %v4uint %uint_4 %uint_4 %uint_4 %uint_4 - %uint_3 = OpConstant %uint 3 - %57 = OpConstantComposite %v4uint %uint_3 %uint_3 %uint_3 %uint_3 - %uint_2 = OpConstant %uint 2 - %60 = OpConstantComposite %v4uint %uint_2 %uint_2 %uint_2 %uint_2 - %uint_1 = OpConstant %uint 1 - %67 = OpConstantComposite %v4uint %uint_1 %uint_1 %uint_1 %uint_1 -%uint_4294967295 = OpConstant %uint 4294967295 - %73 = OpConstantComposite %v4uint %uint_4294967295 %uint_4294967295 %uint_4294967295 %uint_4294967295 - %void = OpTypeVoid - %80 = OpTypeFunction %void - %int_1 = OpConstant %int 1 - %86 = OpConstantComposite %v4int %int_1 %int_1 %int_1 %int_1 + %15 = OpConstantNull %v4int %_ptr_Function_v4int = OpTypePointer Function %v4int - %89 = OpConstantNull %v4int - %90 = OpTypeFunction %v4float + %18 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %v4int None %9 - %v = OpFunctionParameter %v4int - %14 = OpLabel - %x = OpVariable %_ptr_Function_v4uint Function %20 - %15 = OpBitcast %v4uint %v - OpStore %x %15 - %25 = OpLoad %v4uint %x - %28 = OpBitwiseAnd %v4uint %25 %27 - %22 = OpINotEqual %v4bool %28 %20 - %21 = OpSelect %v4uint %22 %20 %30 - %31 = OpLoad %v4uint %x - %32 = OpShiftRightLogical %v4uint %31 %21 - OpStore %x %32 - %35 = OpLoad %v4uint %x - %38 = OpBitwiseAnd %v4uint %35 %37 - %34 = OpINotEqual %v4bool %38 %20 - %33 = OpSelect %v4uint %34 %20 %40 - %41 = OpLoad %v4uint %x - %42 = OpShiftRightLogical %v4uint %41 %33 - OpStore %x %42 - %45 = OpLoad %v4uint %x - %48 = OpBitwiseAnd %v4uint %45 %47 - %44 = OpINotEqual %v4bool %48 %20 - %43 = OpSelect %v4uint %44 %20 %50 - %51 = OpLoad %v4uint %x - %52 = OpShiftRightLogical %v4uint %51 %43 - OpStore %x %52 - %55 = OpLoad %v4uint %x - %58 = OpBitwiseAnd %v4uint %55 %57 - %54 = OpINotEqual %v4bool %58 %20 - %53 = OpSelect %v4uint %54 %20 %60 - %61 = OpLoad %v4uint %x - %62 = OpShiftRightLogical %v4uint %61 %53 - OpStore %x %62 - %65 = OpLoad %v4uint %x - %68 = OpBitwiseAnd %v4uint %65 %67 - %64 = OpINotEqual %v4bool %68 %20 - %63 = OpSelect %v4uint %64 %20 %67 - %70 = OpLoad %v4uint %x - %71 = OpIEqual %v4bool %70 %20 - %69 = OpSelect %v4uint %71 %73 %20 - %75 = OpBitwiseOr %v4uint %21 %33 - %76 = OpBitwiseOr %v4uint %75 %43 - %77 = OpBitwiseOr %v4uint %76 %53 - %78 = OpBitwiseOr %v4uint %77 %63 - %79 = OpBitwiseOr %v4uint %78 %69 - %74 = OpBitcast %v4int %79 - OpReturnValue %74 - OpFunctionEnd -%firstTrailingBit_86551b = OpFunction %void None %80 - %83 = OpLabel - %res = OpVariable %_ptr_Function_v4int Function %89 - %84 = OpFunctionCall %v4int %tint_first_trailing_bit %86 - OpStore %res %84 +%firstTrailingBit_86551b = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_v4int Function %15 + OpStore %res %15 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %90 - %92 = OpLabel - %93 = OpFunctionCall %void %firstTrailingBit_86551b +%vertex_main_inner = OpFunction %v4float None %18 + %20 = OpLabel + %21 = OpFunctionCall %void %firstTrailingBit_86551b OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %80 - %95 = OpLabel - %96 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %96 +%vertex_main = OpFunction %void None %9 + %23 = OpLabel + %24 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %24 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %80 - %99 = OpLabel - %100 = OpFunctionCall %void %firstTrailingBit_86551b +%fragment_main = OpFunction %void None %9 + %27 = OpLabel + %28 = OpFunctionCall %void %firstTrailingBit_86551b OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %80 - %102 = OpLabel - %103 = OpFunctionCall %void %firstTrailingBit_86551b +%compute_main = OpFunction %void None %9 + %30 = OpLabel + %31 = OpFunctionCall %void %firstTrailingBit_86551b OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.dxc.hlsl index 18d192c25b..b70b3f0b74 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.dxc.hlsl @@ -1,20 +1,5 @@ -uint3 tint_first_trailing_bit(uint3 v) { - uint3 x = uint3(v); - const uint3 b16 = (bool3((x & (65535u).xxx)) ? (0u).xxx : (16u).xxx); - x = (x >> b16); - const uint3 b8 = (bool3((x & (255u).xxx)) ? (0u).xxx : (8u).xxx); - x = (x >> b8); - const uint3 b4 = (bool3((x & (15u).xxx)) ? (0u).xxx : (4u).xxx); - x = (x >> b4); - const uint3 b2 = (bool3((x & (3u).xxx)) ? (0u).xxx : (2u).xxx); - x = (x >> b2); - const uint3 b1 = (bool3((x & (1u).xxx)) ? (0u).xxx : (1u).xxx); - const uint3 is_zero = ((x == (0u).xxx) ? (4294967295u).xxx : (0u).xxx); - return uint3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_cb51ce() { - uint3 res = tint_first_trailing_bit((1u).xxx); + uint3 res = (0u).xxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.fxc.hlsl index 18d192c25b..b70b3f0b74 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.fxc.hlsl @@ -1,20 +1,5 @@ -uint3 tint_first_trailing_bit(uint3 v) { - uint3 x = uint3(v); - const uint3 b16 = (bool3((x & (65535u).xxx)) ? (0u).xxx : (16u).xxx); - x = (x >> b16); - const uint3 b8 = (bool3((x & (255u).xxx)) ? (0u).xxx : (8u).xxx); - x = (x >> b8); - const uint3 b4 = (bool3((x & (15u).xxx)) ? (0u).xxx : (4u).xxx); - x = (x >> b4); - const uint3 b2 = (bool3((x & (3u).xxx)) ? (0u).xxx : (2u).xxx); - x = (x >> b2); - const uint3 b1 = (bool3((x & (1u).xxx)) ? (0u).xxx : (1u).xxx); - const uint3 is_zero = ((x == (0u).xxx) ? (4294967295u).xxx : (0u).xxx); - return uint3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_cb51ce() { - uint3 res = tint_first_trailing_bit((1u).xxx); + uint3 res = (0u).xxx; } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.glsl b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.glsl index c7568164df..53f19343b6 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.glsl @@ -1,22 +1,7 @@ #version 310 es -uvec3 tint_first_trailing_bit(uvec3 v) { - uvec3 x = uvec3(v); - uvec3 b16 = mix(uvec3(16u), uvec3(0u), bvec3((x & uvec3(65535u)))); - x = (x >> b16); - uvec3 b8 = mix(uvec3(8u), uvec3(0u), bvec3((x & uvec3(255u)))); - x = (x >> b8); - uvec3 b4 = mix(uvec3(4u), uvec3(0u), bvec3((x & uvec3(15u)))); - x = (x >> b4); - uvec3 b2 = mix(uvec3(2u), uvec3(0u), bvec3((x & uvec3(3u)))); - x = (x >> b2); - uvec3 b1 = mix(uvec3(1u), uvec3(0u), bvec3((x & uvec3(1u)))); - uvec3 is_zero = mix(uvec3(0u), uvec3(4294967295u), equal(x, uvec3(0u))); - return uvec3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_cb51ce() { - uvec3 res = tint_first_trailing_bit(uvec3(1u)); + uvec3 res = uvec3(0u); } vec4 vertex_main() { @@ -35,23 +20,8 @@ void main() { #version 310 es precision mediump float; -uvec3 tint_first_trailing_bit(uvec3 v) { - uvec3 x = uvec3(v); - uvec3 b16 = mix(uvec3(16u), uvec3(0u), bvec3((x & uvec3(65535u)))); - x = (x >> b16); - uvec3 b8 = mix(uvec3(8u), uvec3(0u), bvec3((x & uvec3(255u)))); - x = (x >> b8); - uvec3 b4 = mix(uvec3(4u), uvec3(0u), bvec3((x & uvec3(15u)))); - x = (x >> b4); - uvec3 b2 = mix(uvec3(2u), uvec3(0u), bvec3((x & uvec3(3u)))); - x = (x >> b2); - uvec3 b1 = mix(uvec3(1u), uvec3(0u), bvec3((x & uvec3(1u)))); - uvec3 is_zero = mix(uvec3(0u), uvec3(4294967295u), equal(x, uvec3(0u))); - return uvec3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_cb51ce() { - uvec3 res = tint_first_trailing_bit(uvec3(1u)); + uvec3 res = uvec3(0u); } void fragment_main() { @@ -64,23 +34,8 @@ void main() { } #version 310 es -uvec3 tint_first_trailing_bit(uvec3 v) { - uvec3 x = uvec3(v); - uvec3 b16 = mix(uvec3(16u), uvec3(0u), bvec3((x & uvec3(65535u)))); - x = (x >> b16); - uvec3 b8 = mix(uvec3(8u), uvec3(0u), bvec3((x & uvec3(255u)))); - x = (x >> b8); - uvec3 b4 = mix(uvec3(4u), uvec3(0u), bvec3((x & uvec3(15u)))); - x = (x >> b4); - uvec3 b2 = mix(uvec3(2u), uvec3(0u), bvec3((x & uvec3(3u)))); - x = (x >> b2); - uvec3 b1 = mix(uvec3(1u), uvec3(0u), bvec3((x & uvec3(1u)))); - uvec3 is_zero = mix(uvec3(0u), uvec3(4294967295u), equal(x, uvec3(0u))); - return uvec3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_cb51ce() { - uvec3 res = tint_first_trailing_bit(uvec3(1u)); + uvec3 res = uvec3(0u); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.msl b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.msl index 9acc871fce..fa8aac62b2 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.msl @@ -1,23 +1,8 @@ #include using namespace metal; -uint3 tint_first_trailing_bit(uint3 v) { - uint3 x = uint3(v); - uint3 const b16 = select(uint3(16u), uint3(0u), bool3((x & uint3(65535u)))); - x = (x >> b16); - uint3 const b8 = select(uint3(8u), uint3(0u), bool3((x & uint3(255u)))); - x = (x >> b8); - uint3 const b4 = select(uint3(4u), uint3(0u), bool3((x & uint3(15u)))); - x = (x >> b4); - uint3 const b2 = select(uint3(2u), uint3(0u), bool3((x & uint3(3u)))); - x = (x >> b2); - uint3 const b1 = select(uint3(1u), uint3(0u), bool3((x & uint3(1u)))); - uint3 const is_zero = select(uint3(0u), uint3(4294967295u), (x == uint3(0u))); - return uint3((((((b16 | b8) | b4) | b2) | b1) | is_zero)); -} - void firstTrailingBit_cb51ce() { - uint3 res = tint_first_trailing_bit(uint3(1u)); + uint3 res = uint3(0u); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.spvasm index 06c2e92d04..c79ad8e9b6 100644 --- a/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/firstTrailingBit/cb51ce.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 98 +; Bound: 32 ; Schema: 0 OpCapability Shader OpMemoryModel Logical GLSL450 @@ -12,9 +12,6 @@ OpExecutionMode %compute_main LocalSize 1 1 1 OpName %value "value" OpName %vertex_point_size "vertex_point_size" - OpName %tint_first_trailing_bit "tint_first_trailing_bit" - OpName %v "v" - OpName %x "x" OpName %firstTrailingBit_cb51ce "firstTrailingBit_cb51ce" OpName %res "res" OpName %vertex_main_inner "vertex_main_inner" @@ -31,110 +28,39 @@ %_ptr_Output_float = OpTypePointer Output %float %8 = OpConstantNull %float %vertex_point_size = OpVariable %_ptr_Output_float Output %8 + %void = OpTypeVoid + %9 = OpTypeFunction %void %uint = OpTypeInt 32 0 %v3uint = OpTypeVector %uint 3 - %9 = OpTypeFunction %v3uint %v3uint + %15 = OpConstantNull %v3uint %_ptr_Function_v3uint = OpTypePointer Function %v3uint - %18 = OpConstantNull %v3uint - %bool = OpTypeBool - %v3bool = OpTypeVector %bool 3 - %uint_65535 = OpConstant %uint 65535 - %25 = OpConstantComposite %v3uint %uint_65535 %uint_65535 %uint_65535 - %uint_16 = OpConstant %uint 16 - %28 = OpConstantComposite %v3uint %uint_16 %uint_16 %uint_16 - %uint_255 = OpConstant %uint 255 - %35 = OpConstantComposite %v3uint %uint_255 %uint_255 %uint_255 - %uint_8 = OpConstant %uint 8 - %38 = OpConstantComposite %v3uint %uint_8 %uint_8 %uint_8 - %uint_15 = OpConstant %uint 15 - %45 = OpConstantComposite %v3uint %uint_15 %uint_15 %uint_15 - %uint_4 = OpConstant %uint 4 - %48 = OpConstantComposite %v3uint %uint_4 %uint_4 %uint_4 - %uint_3 = OpConstant %uint 3 - %55 = OpConstantComposite %v3uint %uint_3 %uint_3 %uint_3 - %uint_2 = OpConstant %uint 2 - %58 = OpConstantComposite %v3uint %uint_2 %uint_2 %uint_2 - %uint_1 = OpConstant %uint 1 - %65 = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1 -%uint_4294967295 = OpConstant %uint 4294967295 - %71 = OpConstantComposite %v3uint %uint_4294967295 %uint_4294967295 %uint_4294967295 - %void = OpTypeVoid - %78 = OpTypeFunction %void - %84 = OpTypeFunction %v4float + %18 = OpTypeFunction %v4float %float_1 = OpConstant %float 1 -%tint_first_trailing_bit = OpFunction %v3uint None %9 - %v = OpFunctionParameter %v3uint - %14 = OpLabel - %x = OpVariable %_ptr_Function_v3uint Function %18 - OpStore %x %v - %23 = OpLoad %v3uint %x - %26 = OpBitwiseAnd %v3uint %23 %25 - %20 = OpINotEqual %v3bool %26 %18 - %19 = OpSelect %v3uint %20 %18 %28 - %29 = OpLoad %v3uint %x - %30 = OpShiftRightLogical %v3uint %29 %19 - OpStore %x %30 - %33 = OpLoad %v3uint %x - %36 = OpBitwiseAnd %v3uint %33 %35 - %32 = OpINotEqual %v3bool %36 %18 - %31 = OpSelect %v3uint %32 %18 %38 - %39 = OpLoad %v3uint %x - %40 = OpShiftRightLogical %v3uint %39 %31 - OpStore %x %40 - %43 = OpLoad %v3uint %x - %46 = OpBitwiseAnd %v3uint %43 %45 - %42 = OpINotEqual %v3bool %46 %18 - %41 = OpSelect %v3uint %42 %18 %48 - %49 = OpLoad %v3uint %x - %50 = OpShiftRightLogical %v3uint %49 %41 - OpStore %x %50 - %53 = OpLoad %v3uint %x - %56 = OpBitwiseAnd %v3uint %53 %55 - %52 = OpINotEqual %v3bool %56 %18 - %51 = OpSelect %v3uint %52 %18 %58 - %59 = OpLoad %v3uint %x - %60 = OpShiftRightLogical %v3uint %59 %51 - OpStore %x %60 - %63 = OpLoad %v3uint %x - %66 = OpBitwiseAnd %v3uint %63 %65 - %62 = OpINotEqual %v3bool %66 %18 - %61 = OpSelect %v3uint %62 %18 %65 - %68 = OpLoad %v3uint %x - %69 = OpIEqual %v3bool %68 %18 - %67 = OpSelect %v3uint %69 %71 %18 - %73 = OpBitwiseOr %v3uint %19 %31 - %74 = OpBitwiseOr %v3uint %73 %41 - %75 = OpBitwiseOr %v3uint %74 %51 - %76 = OpBitwiseOr %v3uint %75 %61 - %77 = OpBitwiseOr %v3uint %76 %67 - OpReturnValue %77 - OpFunctionEnd -%firstTrailingBit_cb51ce = OpFunction %void None %78 - %81 = OpLabel - %res = OpVariable %_ptr_Function_v3uint Function %18 - %82 = OpFunctionCall %v3uint %tint_first_trailing_bit %65 - OpStore %res %82 +%firstTrailingBit_cb51ce = OpFunction %void None %9 + %12 = OpLabel + %res = OpVariable %_ptr_Function_v3uint Function %15 + OpStore %res %15 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %84 - %86 = OpLabel - %87 = OpFunctionCall %void %firstTrailingBit_cb51ce +%vertex_main_inner = OpFunction %v4float None %18 + %20 = OpLabel + %21 = OpFunctionCall %void %firstTrailingBit_cb51ce OpReturnValue %5 OpFunctionEnd -%vertex_main = OpFunction %void None %78 - %89 = OpLabel - %90 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %90 +%vertex_main = OpFunction %void None %9 + %23 = OpLabel + %24 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %24 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd -%fragment_main = OpFunction %void None %78 - %93 = OpLabel - %94 = OpFunctionCall %void %firstTrailingBit_cb51ce +%fragment_main = OpFunction %void None %9 + %27 = OpLabel + %28 = OpFunctionCall %void %firstTrailingBit_cb51ce OpReturn OpFunctionEnd -%compute_main = OpFunction %void None %78 - %96 = OpLabel - %97 = OpFunctionCall %void %firstTrailingBit_cb51ce +%compute_main = OpFunction %void None %9 + %30 = OpLabel + %31 = OpFunctionCall %void %firstTrailingBit_cb51ce OpReturn OpFunctionEnd diff --git a/webgpu-cts/expectations.txt b/webgpu-cts/expectations.txt index f7170a6c37..8525aa43fb 100644 --- a/webgpu-cts/expectations.txt +++ b/webgpu-cts/expectations.txt @@ -494,14 +494,6 @@ crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,extractBits: crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="const";width=2 [ Failure ] crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="const";width=3 [ Failure ] crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="const";width=4 [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="const";vectorize="_undef_" [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="const";vectorize=2 [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="const";vectorize=3 [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="const";vectorize=4 [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:u32:inputSource="const";vectorize="_undef_" [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:u32:inputSource="const";vectorize=2 [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:u32:inputSource="const";vectorize=3 [ Failure ] -crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,firstTrailingBit:u32:inputSource="const";vectorize=4 [ Failure ] crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,floor:f32:inputSource="const";vectorize="_undef_" [ Failure ] crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,floor:f32:inputSource="const";vectorize=2 [ Failure ] crbug.com/tint/1613 webgpu:shader,execution,expression,call,builtin,floor:f32:inputSource="const";vectorize=3 [ Failure ]