File tree Expand file tree Collapse file tree 2 files changed +19
-17
lines changed Expand file tree Collapse file tree 2 files changed +19
-17
lines changed Original file line number Diff line number Diff line change 35
35
36
36
#include "py/mpstate.h"
37
37
#include "py/asmthumb.h"
38
-
39
- #ifdef _MSC_VER
40
- #include <intrin.h>
41
-
42
- static uint32_t mp_clz (uint32_t x ) {
43
- unsigned long lz = 0 ;
44
- return _BitScanReverse (& lz , x ) ? (sizeof (x ) * 8 - 1 ) - lz : 0 ;
45
- }
46
-
47
- static uint32_t mp_ctz (uint32_t x ) {
48
- unsigned long tz = 0 ;
49
- return _BitScanForward (& tz , x ) ? tz : 0 ;
50
- }
51
- #else
52
- #define mp_clz (x ) __builtin_clz(x)
53
- #define mp_ctz (x ) __builtin_ctz(x)
54
- #endif
38
+ #include "py/misc.h"
55
39
56
40
#define UNSIGNED_FIT5 (x ) ((uint32_t)(x) < 32)
57
41
#define UNSIGNED_FIT7 (x ) ((uint32_t)(x) < 128)
Original file line number Diff line number Diff line change @@ -334,4 +334,22 @@ typedef const char *mp_rom_error_text_t;
334
334
// For now, forward directly to MP_COMPRESSED_ROM_TEXT.
335
335
#define MP_ERROR_TEXT (x ) (mp_rom_error_text_t)MP_COMPRESSED_ROM_TEXT(x)
336
336
337
+ // Portable implementations of CLZ and CTZ intrinsics
338
+ #ifdef _MSC_VER
339
+ #include <intrin.h>
340
+
341
+ static uint32_t mp_clz (uint32_t x ) {
342
+ unsigned long lz = 0 ;
343
+ return _BitScanReverse (& lz , x ) ? (sizeof (x ) * 8 - 1 ) - lz : 0 ;
344
+ }
345
+
346
+ static uint32_t mp_ctz (uint32_t x ) {
347
+ unsigned long tz = 0 ;
348
+ return _BitScanForward (& tz , x ) ? tz : 0 ;
349
+ }
350
+ #else
351
+ #define mp_clz (x ) __builtin_clz(x)
352
+ #define mp_ctz (x ) __builtin_ctz(x)
353
+ #endif
354
+
337
355
#endif // MICROPY_INCLUDED_PY_MISC_H
You can’t perform that action at this time.
0 commit comments