mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 20:50:14 +01:00
py: Adjust object repr C (30-bit stuffed float) to reduce code size.
This patch adds/subtracts a constant from the 30-bit float representation so that str/qstr representations are favoured: they now have all the high bits set to zero. This makes encoding/decoding qstr strings more efficient (and they are used more often than floats, which are now slightly less efficient to encode/decode). Saves about 300 bytes of code space on Thumb 2 arch.
This commit is contained in:
@@ -63,14 +63,17 @@
|
||||
// - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
|
||||
#define MICROPY_OBJ_REPR_B (1)
|
||||
|
||||
// A MicroPython object is a machine word having the following form:
|
||||
// A MicroPython object is a machine word having the following form (called R):
|
||||
// - iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int with 31-bit signed value
|
||||
// - x1111111 1qqqqqqq qqqqqqqq qqqqq110 str with 20-bit qstr value
|
||||
// - 01111111 1qqqqqqq qqqqqqqq qqqqq110 str with 20-bit qstr value
|
||||
// - s1111111 10000000 00000000 00000010 +/- inf
|
||||
// - s1111111 1xxxxxxx xxxxxxxx xxxxx010 nan, x != 0
|
||||
// - seeeeeee efffffff ffffffff ffffff10 30-bit fp, e != 0xff
|
||||
// - pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
|
||||
// Str and float stored as O = R + 0x80800000, retrieved as R = O - 0x80800000.
|
||||
// This makes strs easier to encode/decode as they have zeros in the top 9 bits.
|
||||
// This scheme only works with 32-bit word size and float enabled.
|
||||
|
||||
#define MICROPY_OBJ_REPR_C (2)
|
||||
|
||||
#ifndef MICROPY_OBJ_REPR
|
||||
|
||||
Reference in New Issue
Block a user