mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Add MSVC support for pg_leftmost_one_pos32() and friends
To allow testing for general support for fast bitscan intrinsics, add symbols HAVE_BITSCAN_REVERSE and HAVE_BITSCAN_FORWARD. Also do related cleanup in AllocSetFreeIndex(): Previously, we tested for HAVE__BUILTIN_CLZ and copied the relevant internals of pg_leftmost_one_pos32(), with a special fallback that does less work than the general fallback for that function. Now that we have a more general test, we just call pg_leftmost_one_pos32() directly for platforms with intrinsic support. On gcc at least, there is no difference in the binary for non-assert builds. Discussion: https://www.postgresql.org/message-id/CAFBsxsEPc%2BFnX_0vmmQ5DHv60sk4rL_RZJ%2BMD6ei%3D76L0kFMvA%40mail.gmail.com
This commit is contained in:
@@ -289,7 +289,7 @@ AllocSetFreeIndex(Size size)
|
||||
* or equivalently
|
||||
* pg_leftmost_one_pos32(size - 1) - ALLOC_MINBITS + 1
|
||||
*
|
||||
* However, rather than just calling that function, we duplicate the
|
||||
* However, for platforms without intrinsic support, we duplicate the
|
||||
* logic here, allowing an additional optimization. It's reasonable
|
||||
* to assume that ALLOC_CHUNK_LIMIT fits in 16 bits, so we can unroll
|
||||
* the byte-at-a-time loop in pg_leftmost_one_pos32 and just handle
|
||||
@@ -299,8 +299,8 @@ AllocSetFreeIndex(Size size)
|
||||
* much trouble.
|
||||
*----------
|
||||
*/
|
||||
#ifdef HAVE__BUILTIN_CLZ
|
||||
idx = 31 - __builtin_clz((uint32) size - 1) - ALLOC_MINBITS + 1;
|
||||
#ifdef HAVE_BITSCAN_REVERSE
|
||||
idx = pg_leftmost_one_pos32((uint32) size - 1) - ALLOC_MINBITS + 1;
|
||||
#else
|
||||
uint32 t,
|
||||
tsize;
|
||||
|
||||
Reference in New Issue
Block a user