diff options
author | Damien George <damien.p.george@gmail.com> | 2015-10-17 23:20:57 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-10-20 12:38:54 +0100 |
commit | 183edefddd8c08dd989fa7bec2d33d8b4130e1dc (patch) | |
tree | 530b4807c22868f556da2ce87f987e38bded7c25 /py/obj.h | |
parent | aedb8591778a8dc4097eb4ffd2891dd5730efdde (diff) |
py: Add object repr "C", where 30-bit floats are stuffed in obj word.
This new object representation puts floats into the object word instead
of on the heap, at the expense of reducing their precision to 30 bits.
It only makes sense when the word size is 32-bits.
Diffstat (limited to 'py/obj.h')
-rw-r--r-- | py/obj.h | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -123,6 +123,41 @@ mp_obj_t mp_obj_new_float(mp_float_t value); static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o) { return ((((mp_int_t)(o)) & 1) == 0); } +#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C + +static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o) + { return ((((mp_int_t)(o)) & 1) != 0); } +#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1) +#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1)) + +#define mp_const_float_e ((mp_obj_t)((0x402df854 & ~3) | 2)) +#define mp_const_float_pi ((mp_obj_t)((0x40490fdb & ~3) | 2)) + +static inline bool mp_obj_is_float(mp_const_obj_t o) + { return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0x7f800004) != 0x7f800004; } +static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) { + union { + mp_float_t f; + mp_uint_t u; + } num = {.u = (mp_uint_t)o & ~3}; + return num.f; +} +static inline mp_obj_t mp_obj_new_float(mp_float_t f) { + union { + mp_float_t f; + mp_uint_t u; + } num = {.f = f}; + return (mp_obj_t)((num.u & ~0x3) | 2); +} + +static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o) + { return (((mp_uint_t)(o)) & 0x7f800007) == 0x7f800006; } +#define MP_OBJ_QSTR_VALUE(o) ((((mp_uint_t)(o)) >> 3) & 0xfffff) +#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 0x7f800006)) + +static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o) + { return ((((mp_int_t)(o)) & 3) == 0); } + #endif // Macros to convert between mp_obj_t and concrete object types. |