From 255ef951f61d9cd172a35efdc55980b13f4edf54 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 17 Sep 2018 19:54:36 -0700 Subject: Fixed 32-bit windows build --- Platforms/Win32/include/Win32PlatformMisc.h | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Platforms/Win32/include/Win32PlatformMisc.h b/Platforms/Win32/include/Win32PlatformMisc.h index 05b1bc52..384b36e4 100644 --- a/Platforms/Win32/include/Win32PlatformMisc.h +++ b/Platforms/Win32/include/Win32PlatformMisc.h @@ -46,7 +46,21 @@ struct WindowsMisc : public BasicPlatformMisc if( Val == 0 )return 64; unsigned long MSB = 64; +#if _WIN64 _BitScanReverse64(&MSB, Val); +#else + Diligent::Uint32 high = static_cast((Val>>32) & 0xFFFFFFFF); + if (high!=0) + { + MSB = 32 + GetMSB(high); + } + else + { + Diligent::Uint32 low = static_cast(Val & 0xFFFFFFFF); + VERIFY_EXPR(low != 0); + MSB = GetMSB(low); + } +#endif VERIFY_EXPR(MSB == BasicPlatformMisc::GetMSB(Val)); return MSB; @@ -68,9 +82,23 @@ struct WindowsMisc : public BasicPlatformMisc if( Val == 0 )return 64; unsigned long LSB = 64; +#if _WIN64 _BitScanForward64(&LSB, Val); - VERIFY_EXPR(LSB == BasicPlatformMisc::GetLSB(Val)); +#else + Diligent::Uint32 low = static_cast(Val & 0xFFFFFFFF); + if (low != 0) + { + LSB = GetLSB(low); + } + else + { + Diligent::Uint32 high = static_cast((Val>>32) & 0xFFFFFFFF); + VERIFY_EXPR(high != 0); + LSB = 32 + GetLSB(high); + } +#endif + VERIFY_EXPR(LSB == BasicPlatformMisc::GetLSB(Val)); return LSB; } @@ -83,7 +111,12 @@ struct WindowsMisc : public BasicPlatformMisc inline static Diligent::Uint32 CountOneBits(Diligent::Uint64 Val) { +#if _WIN64 auto Bits = __popcnt64(Val); +#else + auto Bits = CountOneBits( static_cast((Val >> 0) & 0xFFFFFFFF) ) + + CountOneBits( static_cast((Val >> 32) & 0xFFFFFFFF) ); +#endif VERIFY_EXPR(Bits == BasicPlatformMisc::CountOneBits(Val)); return static_cast(Bits); } -- cgit v1.2.3