We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1e10c40 commit be93fe7Copy full SHA for be93fe7
mypyc/lib-rt/int_ops.c
@@ -594,9 +594,16 @@ CPyTagged CPyTagged_BitLength(CPyTagged self) {
594
Py_ssize_t val = CPyTagged_ShortAsSsize_t(self);
595
Py_ssize_t absval = val < 0 ? -val : val;
596
int bits = 0;
597
- while (absval) {
598
- absval >>= 1;
599
- bits++;
+ if (absval) {
+#if defined(__GNUC__) || defined(__clang__)
+ bits = (int)(sizeof(absval) * 8) - __builtin_clzll((unsigned long long)absval);
600
+#else
601
+ // Fallback to loop if no builtin
602
+ while (absval) {
603
+ absval >>= 1;
604
+ bits++;
605
+ }
606
+#endif
607
}
608
return bits << 1;
609
0 commit comments