File tree 2 files changed +19
-22
lines changed
2 files changed +19
-22
lines changed Original file line number Diff line number Diff line change 29
29
#include <string.h>
30
30
31
31
#include "py/emit.h"
32
+ #include "py/misc.h"
32
33
#include "py/mpconfig.h"
33
34
34
35
// wrapper around everything in this file
43
44
#define DEBUG_printf (...) (void)0
44
45
#endif
45
46
46
- #ifndef MP_POPCOUNT
47
- #ifdef _MSC_VER
48
- #include <intrin.h>
49
- #define MP_POPCOUNT __popcnt
50
- #else
51
- #if defined __has_builtin
52
- #if __has_builtin (__builtin_popcount )
53
- #define MP_POPCOUNT __builtin_popcount
54
- #endif
55
- #else
56
- static uint32_t fallback_popcount (uint32_t value ) {
57
- value = value - ((value >> 1 ) & 0x55555555 );
58
- value = (value & 0x33333333 ) + ((value >> 2 ) & 0x33333333 );
59
- value = (value + (value >> 4 )) & 0x0F0F0F0F ;
60
- return value * 0x01010101 ;
61
- }
62
- #define MP_POPCOUNT fallback_popcount
63
- #endif
64
- #endif
65
- #endif
66
-
67
47
#define INTERNAL_TEMPORARY ASM_RV32_REG_S0
68
48
#define AVAILABLE_REGISTERS_COUNT 32
69
49
@@ -249,7 +229,7 @@ static void adjust_stack(asm_rv32_t *state, mp_int_t stack_size) {
249
229
// stack to hold all the tainted registers and an arbitrary amount of space
250
230
// for locals.
251
231
static void emit_function_prologue (asm_rv32_t * state , mp_uint_t registers ) {
252
- mp_uint_t registers_count = MP_POPCOUNT (registers );
232
+ mp_uint_t registers_count = mp_popcount (registers );
253
233
state -> stack_size = (registers_count + state -> locals_count ) * sizeof (uint32_t );
254
234
mp_uint_t old_saved_registers_mask = state -> saved_registers_mask ;
255
235
// Move stack pointer up.
Original file line number Diff line number Diff line change @@ -370,12 +370,29 @@ static inline uint32_t mp_ctz(uint32_t x) {
370
370
static inline bool mp_check (bool value ) {
371
371
return value ;
372
372
}
373
+
374
+ static inline uint32_t mp_popcount (uint32_t x ) {
375
+ return __popcnt (x );
376
+ }
373
377
#else
374
378
#define mp_clz (x ) __builtin_clz(x)
375
379
#define mp_clzl (x ) __builtin_clzl(x)
376
380
#define mp_clzll (x ) __builtin_clzll(x)
377
381
#define mp_ctz (x ) __builtin_ctz(x)
378
382
#define mp_check (x ) (x)
383
+ #if defined __has_builtin
384
+ #if __has_builtin (__builtin_popcount )
385
+ #define mp_popcount (x ) __builtin_popcount(x)
386
+ #endif
387
+ #endif
388
+ #if !defined(mp_popcount )
389
+ static inline uint32_t mp_popcount (uint32_t x ) {
390
+ x = x - ((x >> 1 ) & 0x55555555 );
391
+ x = (x & 0x33333333 ) + ((x >> 2 ) & 0x33333333 );
392
+ x = (x + (x >> 4 )) & 0x0F0F0F0F ;
393
+ return x * 0x01010101 ;
394
+ }
395
+ #endif
379
396
#endif
380
397
381
398
// mp_int_t can be larger than long, i.e. Windows 64-bit, nan-box variants
You can’t perform that action at this time.
0 commit comments