File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1515#define CPyLong_FromSsize_t PyLong_FromSsize_t
1616#endif
1717
18+ #if defined(__GNUC__ ) || defined(__clang__ )
19+ # if defined(__x86_64__ ) || defined(_M_X64 ) || defined(__aarch64__ ) || (defined(__SIZEOF_POINTER__ ) && __SIZEOF_POINTER__ == 8 )
20+ # define CPY_CLZ (x ) __builtin_clzll((unsigned long long)(x))
21+ # define CPY_BITS 64
22+ # else
23+ # define CPY_CLZ (x ) __builtin_clz((unsigned int)(x))
24+ # define CPY_BITS 32
25+ # endif
26+ #endif
27+
28+
1829CPyTagged CPyTagged_FromSsize_t (Py_ssize_t value ) {
1930 // We use a Python object if the value shifted left by 1 is too
2031 // large for Py_ssize_t
@@ -596,7 +607,7 @@ CPyTagged CPyTagged_BitLength(CPyTagged self) {
596607 int bits = 0 ;
597608 if (absval ) {
598609#if defined(__GNUC__ ) || defined(__clang__ )
599- bits = (int )(sizeof ( absval ) * 8 ) - __builtin_clzll (( unsigned long long ) absval );
610+ bits = (int )(CPY_BITS - CPY_CLZ ( absval ) );
600611#else
601612 // Fallback to loop if no builtin
602613 while (absval ) {
You can’t perform that action at this time.
0 commit comments