Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3225399

Browse files
committed
Extend size_t support in pg_bitutils.h.
Use a more compact notation that allows us to add more size_t variants as required. This will be used by a later commit. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CA%2BhUKG%2B7dSX1XF8yFGmYk-%3D48dbjH2kmzZj16XvhbrWP-9BzRg%40mail.gmail.com
1 parent a4f09ef commit 3225399

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/include/port/pg_bitutils.h

+12-20
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,6 @@ pg_nextpower2_64(uint64 num)
175175
return ((uint64) 1) << (pg_leftmost_one_pos64(num) + 1);
176176
}
177177

178-
/*
179-
* pg_nextpower2_size_t
180-
* Returns the next higher power of 2 above 'num', for a size_t input.
181-
*/
182-
#if SIZEOF_SIZE_T == 4
183-
#define pg_nextpower2_size_t(num) pg_nextpower2_32(num)
184-
#else
185-
#define pg_nextpower2_size_t(num) pg_nextpower2_64(num)
186-
#endif
187-
188178
/*
189179
* pg_prevpower2_32
190180
* Returns the next lower power of 2 below 'num', or 'num' if it's
@@ -211,16 +201,6 @@ pg_prevpower2_64(uint64 num)
211201
return ((uint64) 1) << pg_leftmost_one_pos64(num);
212202
}
213203

214-
/*
215-
* pg_prevpower2_size_t
216-
* Returns the next lower power of 2 below 'num', for a size_t input.
217-
*/
218-
#if SIZEOF_SIZE_T == 4
219-
#define pg_prevpower2_size_t(num) pg_prevpower2_32(num)
220-
#else
221-
#define pg_prevpower2_size_t(num) pg_prevpower2_64(num)
222-
#endif
223-
224204
/*
225205
* pg_ceil_log2_32
226206
* Returns equivalent of ceil(log2(num))
@@ -299,4 +279,16 @@ pg_rotate_left32(uint32 word, int n)
299279
return (word << n) | (word >> (32 - n));
300280
}
301281

282+
/* size_t variants of the above, as required */
283+
284+
#if SIZEOF_SIZE_T == 4
285+
#define pg_leftmost_one_pos_size_t pg_leftmost_one_pos32
286+
#define pg_nextpower2_size_t pg_nextpower2_32
287+
#define pg_prevpower2_size_t pg_prevpower2_32
288+
#else
289+
#define pg_leftmost_one_pos_size_t pg_leftmost_one_pos64
290+
#define pg_nextpower2_size_t pg_nextpower2_64
291+
#define pg_prevpower2_size_t pg_prevpower2_64
292+
#endif
293+
302294
#endif /* PG_BITUTILS_H */

0 commit comments

Comments
 (0)