Don't use _BitScanForward64/_BitScanReverse64 on 32-bit MSVC builds
authorDavid Rowley <[email protected]>
Wed, 7 Jun 2023 22:10:34 +0000 (10:10 +1200)
committerDavid Rowley <[email protected]>
Wed, 7 Jun 2023 22:10:34 +0000 (10:10 +1200)
677319746 added support for making use of MSVC's bit scanning functions.
However, that commit failed to consider 32-bit MSVC builds where the
64-bit versions of these functions are unavailable.  This resulted in
compilation failures on 32-bit MSVC.

Here we adjust the code so we fall back on the manual way of finding the
bit positions for 64-bit integers when building on 32-bit MSVC.

Bug: #17967
Reported-by: Youmiu Mo
Discussion: https://postgr.es/m/17967-cd21e34a314141b2@postgresql.org

src/include/port/pg_bitutils.h

index 158ef73a2b2635c389f0c870495502ebe3a66fc4..21a4fa0341059c722be99a61665edeb5f23c7a8f 100644 (file)
@@ -81,7 +81,7 @@ pg_leftmost_one_pos64(uint64 word)
 #error must have a working 64-bit integer datatype
 #endif                         /* HAVE_LONG_INT_64 */
 
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_ARM64))
    unsigned long result;
    bool        non_zero;
 
@@ -152,7 +152,7 @@ pg_rightmost_one_pos64(uint64 word)
 #error must have a working 64-bit integer datatype
 #endif                         /* HAVE_LONG_INT_64 */
 
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_ARM64))
    unsigned long result;
    bool        non_zero;