Fix MSVC warnings (#5926)
* Fix warning C4146: unary minus operator applied to unsigned type, result still unsigned
* Fix warning C4068: unknown pragma 'nounroll'
* Fix warning C4068: unknown pragma 'unroll'
* Fix warning C4068: unknown pragma 'clang'
* Fix warning C4305: 'initializing': truncation from 'double' to 'float'
* Fix warning C4267: 'argument': conversion from 'size_t' to 'utils::FixedCapacityVector<filament::uberz::WritableArchive::Material,std::allocator<T>,true>::size_type', possible loss of data
* Fix warning C4267: 'argument': conversion from 'size_t' to 'uint32_t', possible loss of data
* Fix warning C4244: 'initializing': conversion from 'A' to 'T', possible loss of data
* Fix warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
* Fix warning C4293: '>>': shift count negative or too big, undefined behavior
* Fix diagnostic warning C4189: 'channels': local variable is initialized but not referenced
* Use [[maybe_unused]] where possible and revert aa79bd6fa8.
* Revert unary minus for non-MSVC compilers
* Add macro for enabling warnings temporarily
* Get rid of UTILS_HAS_CXX17
* Revisit warning related macros
Co-authored-by: Levente Koncz <levente.koncz@shapr3d.com>
This commit is contained in:
@@ -46,10 +46,10 @@ constexpr inline T clz(T x) noexcept {
|
||||
x |= (x >> 4u);
|
||||
x |= (x >> 8u);
|
||||
x |= (x >> 16u);
|
||||
if (sizeof(T) * CHAR_BIT >= 64) { // just to silence compiler warning
|
||||
if constexpr (sizeof(T) * CHAR_BIT >= 64) { // just to silence compiler warning
|
||||
x |= (x >> 32u);
|
||||
}
|
||||
if (sizeof(T) * CHAR_BIT >= 128) { // just to silence compiler warning
|
||||
if constexpr (sizeof(T) * CHAR_BIT >= 128) { // just to silence compiler warning
|
||||
x |= (x >> 64u);
|
||||
}
|
||||
return T(sizeof(T) * CHAR_BIT) - details::popcount(x);
|
||||
@@ -59,7 +59,13 @@ template<typename T, typename = std::enable_if_t<std::is_unsigned<T>::value>>
|
||||
constexpr inline T ctz(T x) noexcept {
|
||||
static_assert(sizeof(T) * CHAR_BIT <= 64, "details::ctz() only support up to 64 bits");
|
||||
T c = sizeof(T) * CHAR_BIT;
|
||||
x &= -x; // equivalent to x & (~x + 1)
|
||||
#if defined(_MSC_VER)
|
||||
// equivalent to x & -x, but MSVC yield a warning for using unary minus operator on unsigned types
|
||||
x &= (~x + 1);
|
||||
#else
|
||||
// equivalent to x & (~x + 1), but some compilers generate a better sequence on ARM
|
||||
x &= -x;
|
||||
#endif
|
||||
if (x) c--;
|
||||
if (sizeof(T) * CHAR_BIT >= 64) {
|
||||
if (x & T(0x00000000FFFFFFFF)) c -= 32;
|
||||
|
||||
Reference in New Issue
Block a user