aboutsummaryrefslogtreecommitdiff
path: root/py/obj.h
diff options
context:
space:
mode:
authorDamien George2017-12-11 22:39:12 +1100
committerDamien George2017-12-11 22:39:12 +1100
commit2759bec8587b0c0b7da1fa3a013e4f1b1530ad27 (patch)
tree42d424cc8f3a3024cc020cdcc3aee6e2bd9593e4 /py/obj.h
parent9c027073568d9be43bd1aabcac60a6ff208c4299 (diff)
py: Extend nan-boxing config to have 47-bit small integers.
The nan-boxing representation has an extra 16-bits of space to store small-int values, and making use of it allows to create and manipulate full 32-bit positive integers (ie up to 0xffffffff) without using the heap.
Diffstat (limited to 'py/obj.h')
-rw-r--r--py/obj.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/py/obj.h b/py/obj.h
index 31c3ce95c..10cb48961 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -170,8 +170,8 @@ static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
{ return ((((mp_int_t)(o)) & 0xffff000000000000) == 0x0001000000000000); }
-#define MP_OBJ_SMALL_INT_VALUE(o) (((intptr_t)(o)) >> 1)
-#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((uintptr_t)(small_int)) << 1) | 0x0001000000000001)
+#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)((o) << 16)) >> 17)
+#define MP_OBJ_NEW_SMALL_INT(small_int) (((((uint64_t)(small_int)) & 0x7fffffffffff) << 1) | 0x0001000000000001)
static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
{ return ((((mp_int_t)(o)) & 0xffff000000000000) == 0x0002000000000000); }