summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-02-04 16:39:09 +1100
committerDamien George <damien@micropython.org>2021-02-04 22:46:42 +1100
commitad4656b861f94277bed9647ca176e662ce5119e3 (patch)
tree58ebc0b0a631c735e6d56a8815b85b3fdbccb8c1 /py
parent7e956fae28e4e3fdea30f834d448eacfc4429de7 (diff)
all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD.
The "word" referred to by BYTES_PER_WORD is actually the size of mp_obj_t which is not always the same as the size of a pointer on the target architecture. So rename this config value to better reflect what it measures, and also prefix it with MP_. For uses of BYTES_PER_WORD in setting the stack limit this has been changed to sizeof(void *), because the stack usually grows with machine-word sized values (eg an nlr_buf_t has many machine words in it). Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py')
-rw-r--r--py/binary.c4
-rw-r--r--py/emitbc.c2
-rw-r--r--py/gc.c2
-rw-r--r--py/mpconfig.h10
-rw-r--r--py/persistentcode.c2
5 files changed, 10 insertions, 10 deletions
diff --git a/py/binary.c b/py/binary.c
index 1847894b7..5c098b223 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -321,7 +321,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
double f;
} fp_dp;
fp_dp.f = mp_obj_get_float_to_d(val_in);
- if (BYTES_PER_WORD == 8) {
+ if (MP_BYTES_PER_OBJ_WORD == 8) {
val = fp_dp.i64;
} else {
int be = struct_type == '>';
@@ -342,7 +342,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
val = mp_obj_get_int(val_in);
// zero/sign extend if needed
- if (BYTES_PER_WORD < 8 && size > sizeof(val)) {
+ if (MP_BYTES_PER_OBJ_WORD < 8 && size > sizeof(val)) {
int c = (mp_int_t)val < 0 ? 0xff : 0x00;
memset(p, c, size);
if (struct_type == '>') {
diff --git a/py/emitbc.c b/py/emitbc.c
index c74b7fbc4..d7e8e05f0 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -36,7 +36,7 @@
#if MICROPY_ENABLE_COMPILER
-#define BYTES_FOR_INT ((BYTES_PER_WORD * 8 + 6) / 7)
+#define BYTES_FOR_INT ((MP_BYTES_PER_OBJ_WORD * 8 + 6) / 7)
#define DUMMY_DATA_SIZE (BYTES_FOR_INT)
struct _emit_t {
diff --git a/py/gc.c b/py/gc.c
index be35dc2cc..53a0d9da4 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -49,7 +49,7 @@
// detect untraced object still in use
#define CLEAR_ON_SWEEP (0)
-#define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD)
+#define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / MP_BYTES_PER_OBJ_WORD)
#define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK)
// ATB = allocation table byte
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 3a0c5fb6e..e87c52f2b 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -126,7 +126,7 @@
// Number of bytes in memory allocation/GC block. Any size allocated will be
// rounded up to be multiples of this.
#ifndef MICROPY_BYTES_PER_GC_BLOCK
-#define MICROPY_BYTES_PER_GC_BLOCK (4 * BYTES_PER_WORD)
+#define MICROPY_BYTES_PER_GC_BLOCK (4 * MP_BYTES_PER_OBJ_WORD)
#endif
// Number of words allocated (in BSS) to the GC stack (minimum is 1)
@@ -1530,9 +1530,9 @@ typedef double mp_float_t;
#define STATIC static
#endif
-// Number of bytes in a word
-#ifndef BYTES_PER_WORD
-#define BYTES_PER_WORD (sizeof(mp_uint_t))
+// Number of bytes in an object word: mp_obj_t, mp_uint_t, mp_uint_t
+#ifndef MP_BYTES_PER_OBJ_WORD
+#define MP_BYTES_PER_OBJ_WORD (sizeof(mp_uint_t))
#endif
// Number of bits in a byte
@@ -1540,7 +1540,7 @@ typedef double mp_float_t;
#define MP_BITS_PER_BYTE (8)
#endif
// mp_int_t value with most significant bit set
-#define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
+#define WORD_MSBIT_HIGH (((mp_uint_t)1) << (MP_BYTES_PER_OBJ_WORD * MP_BITS_PER_BYTE - 1))
// Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
// defined and that they are the opposite of each other.
diff --git a/py/persistentcode.c b/py/persistentcode.c
index 084632a60..ac523990c 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -595,7 +595,7 @@ STATIC void mp_print_bytes(mp_print_t *print, const byte *data, size_t len) {
print->print_strn(print->data, (const char *)data, len);
}
-#define BYTES_FOR_INT ((BYTES_PER_WORD * 8 + 6) / 7)
+#define BYTES_FOR_INT ((MP_BYTES_PER_OBJ_WORD * 8 + 6) / 7)
STATIC void mp_print_uint(mp_print_t *print, size_t n) {
byte buf[BYTES_FOR_INT];
byte *p = buf + sizeof(buf);