From 8ee153f23429b63878d740168695cde3fb2a1497 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 17 Oct 2015 15:53:55 +0300 Subject: unix/modtime: Implement ticks_ms(), ticks_us() and ticks_diff(). All of these functions return positive small int, thus range is 2 bits less than word size (30 bit on 32-bit systems, 62 bit on 64-bit systems). --- py/smallint.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'py') diff --git a/py/smallint.h b/py/smallint.h index 7bdf405a8..19b5209ec 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -36,11 +36,15 @@ #define MP_SMALL_INT_MIN ((mp_int_t)(((mp_int_t)WORD_MSBIT_HIGH) >> 1)) #define MP_SMALL_INT_FITS(n) ((((n) ^ ((n) << 1)) & WORD_MSBIT_HIGH) == 0) +// Mask to truncate mp_int_t to positive value +#define MP_SMALL_INT_POSITIVE_MASK ~(WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1)) #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B #define MP_SMALL_INT_MIN ((mp_int_t)(((mp_int_t)WORD_MSBIT_HIGH) >> 2)) #define MP_SMALL_INT_FITS(n) ((((n) & MP_SMALL_INT_MIN) == 0) || (((n) & MP_SMALL_INT_MIN) == MP_SMALL_INT_MIN)) +// Mask to truncate mp_int_t to positive value +#define MP_SMALL_INT_POSITIVE_MASK ~(WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1) | (WORD_MSBIT_HIGH >> 2)) #endif -- cgit v1.2.3