File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 55#include <Python.h>
66#include "CPy.h"
77
8+ #ifdef _MSC_VER
9+ #include <intrin.h>
10+ #endif
11+
812#ifndef _WIN32
913// On 64-bit Linux and macOS, ssize_t and long are both 64 bits, and
1014// PyLong_FromLong is faster than PyLong_FromSsize_t, so use the faster one
@@ -606,7 +610,19 @@ CPyTagged CPyTagged_BitLength(CPyTagged self) {
606610 Py_ssize_t absval = val < 0 ? - val : val ;
607611 int bits = 0 ;
608612 if (absval ) {
609- #if defined(__GNUC__ ) || defined(__clang__ )
613+ #if defined(_MSC_VER )
614+ #if defined(_WIN64 )
615+ unsigned long idx ;
616+ if (_BitScanReverse64 (& idx , (unsigned __int64 )absval )) {
617+ bits = (int )(idx + 1 );
618+ }
619+ #else
620+ unsigned long idx ;
621+ if (_BitScanReverse (& idx , (unsigned long )absval )) {
622+ bits = (int )(idx + 1 );
623+ }
624+ #endif
625+ #elif defined(__GNUC__ ) || defined(__clang__ )
610626 bits = (int )(CPY_BITS - CPY_CLZ (absval ));
611627#else
612628 // Fallback to loop if no builtin
You can’t perform that action at this time.
0 commit comments