Commit 2a7d0faa authored by Xiao Shi's avatar Xiao Shi Committed by Facebook Github Bot

make conversion explicit in `findLastSet` for longer integral types

Summary:
When the param type is larger than `unsigned int`, the wider type `size{}` was
implicitly converted to the return type `unsigned int` in `findLastSet`. This
diff makes the conversion explicit.

Reviewed By: yfeldblum

Differential Revision: D8971589

fbshipit-source-id: 8828504c462e9296b84a746bcb7f701bc4a7d20e
parent 83a22fdd
...@@ -122,7 +122,7 @@ inline FOLLY_INTRINSIC_CONSTEXPR unsigned int findLastSet(T const v) { ...@@ -122,7 +122,7 @@ inline FOLLY_INTRINSIC_CONSTEXPR unsigned int findLastSet(T const v) {
// allows GCC to remove its own xor that it adds to implement clz using bsr. // allows GCC to remove its own xor that it adds to implement clz using bsr.
// clang-format off // clang-format off
using size = index_constant<constexpr_max(sizeof(T), sizeof(U0))>; using size = index_constant<constexpr_max(sizeof(T), sizeof(U0))>;
return v ? 1u + ((8u * size{} - 1u) ^ static_cast<unsigned int>( return v ? 1u + static_cast<unsigned int>((8u * size{} - 1u) ^ (
sizeof(T) <= sizeof(U0) ? __builtin_clz(bits_to_unsigned<U0>(v)) : sizeof(T) <= sizeof(U0) ? __builtin_clz(bits_to_unsigned<U0>(v)) :
sizeof(T) <= sizeof(U1) ? __builtin_clzl(bits_to_unsigned<U1>(v)) : sizeof(T) <= sizeof(U1) ? __builtin_clzl(bits_to_unsigned<U1>(v)) :
sizeof(T) <= sizeof(U2) ? __builtin_clzll(bits_to_unsigned<U2>(v)) : sizeof(T) <= sizeof(U2) ? __builtin_clzll(bits_to_unsigned<U2>(v)) :
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment