summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-10-17 15:53:55 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-10-19 17:48:27 +0300
commit8ee153f23429b63878d740168695cde3fb2a1497 (patch)
treea9c35fdffa3f7998db0bd2e2303e404f73514abe /py
parentfd379db2868e43ccc103f75ea6ae9c33d3ad66f1 (diff)
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).
Diffstat (limited to 'py')
-rw-r--r--py/smallint.h4
1 files changed, 4 insertions, 0 deletions
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