Skip to content

Commit 78a1097

Browse files
committed
Move round_up_to_next_pow2 function upwards
1 parent 76564dd commit 78a1097

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

include/pybind11/detail/internals.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ struct instance_map_shard {
151151

152152
static_assert(sizeof(instance_map_shard) % 64 == 0,
153153
"instance_map_shard size is not a multiple of 64 bytes");
154+
155+
inline uint64_t round_up_to_next_pow2(uint64_t x) {
156+
// Round-up to the next power of two.
157+
// See https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
158+
x--;
159+
x |= (x >> 1);
160+
x |= (x >> 2);
161+
x |= (x >> 4);
162+
x |= (x >> 8);
163+
x |= (x >> 16);
164+
x |= (x >> 32);
165+
x++;
166+
return x;
167+
}
154168
#endif
155169

156170
/// Internal data structure used to track registered instances and types.
@@ -456,20 +470,6 @@ inline object get_python_state_dict() {
456470
return state_dict;
457471
}
458472

459-
inline uint64_t round_up_to_next_pow2(uint64_t x) {
460-
// Round-up to the next power of two.
461-
// See https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
462-
x--;
463-
x |= (x >> 1);
464-
x |= (x >> 2);
465-
x |= (x >> 4);
466-
x |= (x >> 8);
467-
x |= (x >> 16);
468-
x |= (x >> 32);
469-
x++;
470-
return x;
471-
}
472-
473473
template <typename InternalsType>
474474
inline InternalsType **get_internals_pp_from_capsule_in_state_dict(dict &state_dict,
475475
char const *state_dict_key) {

0 commit comments

Comments
 (0)