src/backend/utils/mmgr/aset.c
static inline int
AllocSetFreeIndex(Size size)
{
	int			idx;

	if (size > (1 << ALLOC_MINBITS))
	{
		/*----------
		 * At this point we must compute ceil(log2(size >> ALLOC_MINBITS)).
		 * This is the same as
		 *		pg_leftmost_one_pos32((size - 1) >> ALLOC_MINBITS) + 1
		 * or equivalently
		 *		pg_leftmost_one_pos32(size - 1) - ALLOC_MINBITS + 1
		 *
		 * However, rather than just calling that function, 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
		 * the last two bytes.
		 *
		 * Yes, this function is enough of a hot-spot to make it worth this
		 * much trouble.
		 *----------
		 */
#ifdef HAVE__BUILTIN_CLZ
		idx = 31 - __builtin_clz((uint32) size - 1) - ALLOC_MINBITS + 1;
#else
		uint32		t,
					tsize;

		/* Statically assert that we only have a 16-bit input value. */
		StaticAssertStmt(ALLOC_CHUNK_LIMIT < (1 << 16),
						 "ALLOC_CHUNK_LIMIT must be less than 64kB");

		tsize = size - 1;
		t = tsize >> 8;
		idx = t ? pg_leftmost_one_pos[t] + 8 : pg_leftmost_one_pos[tsize];
		idx -= ALLOC_MINBITS - 1;
#endif

		Assert(idx < ALLOCSET_NUM_FREELISTS);
	}
	else
		idx = 0;

	return idx;
}
/* ----------
 * AllocSetFreeIndex -
 *
 *		Depending on the size of an allocation compute which freechunk
 *		list of the alloc set it belongs to.  Caller must have verified
 *		that size <= ALLOC_CHUNK_LIMIT.
 * ----------
 */
AllocSetFreeIndex
Depending on the size of an allocation compute which freechunk
list of the alloc set it belongs to.  Caller must have verified
that size <= ALLOC_CHUNK_LIMIT.
AllocSetFreeIndex Depending on the size of an allocation compute which freechunk list of the alloc set it belongs to . Caller must have verified that size < = ALLOC_CHUNK_LIMIT .
static inline int
AllocSetFreeIndex(Size size)
{
	int			idx;
	if (size > (1 << ALLOC_MINBITS))
	{
#ifdef HAVE__BUILTIN_CLZ
		idx = 31 - __builtin_clz((uint32) size - 1) - ALLOC_MINBITS + 1;
#else
		uint32		t,
					tsize;
		StaticAssertStmt(ALLOC_CHUNK_LIMIT < (1 << 16),
						 "ALLOC_CHUNK_LIMIT must be less than 64kB");
		tsize = size - 1;
		t = tsize >> 8;
		idx = t ? pg_leftmost_one_pos[t] + 8 : pg_leftmost_one_pos[tsize];
		idx -= ALLOC_MINBITS - 1;
#endif
		Assert(idx < ALLOCSET_NUM_FREELISTS);
	}
	else
		idx = 0;
	return idx;
}
static inline int AllocSetFreeIndex ( Size size ) { int idx ; if ( size > ( 1 << ALLOC_MINBITS ) ) { #ifdef HAVE__BUILTIN_CLZ idx = 31 - __builtin_clz ( ( uint32 ) size - 1 ) - ALLOC_MINBITS + 1 ; #else uint32 t , tsize ; StaticAssertStmt ( ALLOC_CHUNK_LIMIT < ( 1 << 16 ) , " " ) ; tsize = size - 1 ; t = tsize >> 8 ; idx = t ? pg_leftmost_one_pos [ t ] + 8 : pg_leftmost_one_pos [ tsize ] ; idx -= ALLOC_MINBITS - 1 ; #endif Assert ( idx < ALLOCSET_NUM_FREELISTS ) ; } else idx = 0 ; return idx ; }
AllocSetFreeIndex
              Depending on the size of an allocation compute which freechunk
              list of the alloc set it belongs to.
AllocSetFreeIndex Depending on the size of an allocation compute which freechunk list of the alloc set it belongs to .
/*----------
		 * At this point we must compute ceil(log2(size >> ALLOC_MINBITS)).
		 * This is the same as
		 *		pg_leftmost_one_pos32((size - 1) >> ALLOC_MINBITS) + 1
		 * or equivalently
		 *		pg_leftmost_one_pos32(size - 1) - ALLOC_MINBITS + 1
		 *
		 * However, rather than just calling that function, 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
		 * the last two bytes.
		 *
		 * Yes, this function is enough of a hot-spot to make it worth this
		 * much trouble.
		 *----------
		 */ /* Statically assert that we only have a 16-bit input value. */