by Lionel Debroux » 06 Feb 2019, 12:50
A partir du code de float_make_new(), qui est juste au-dessous de float_print() dans objfloat.c, j'ai cherché la définition de mp_obj_new_float(), et je suis tombé sur les différentes définitions de cette fonction en fonction de la représentation des objets MicroPython. Il y en a 4, MICROPY_OBJ_REPR_A à _D. CircuitPython pour cette target utilise MICROPY_OBJ_REPR_C .
Les différentes valeurs possibles sont décrites en détail dans mpconfig.h:
- Code: Select all
// A MicroPython object is a machine word having the following form (called R):
// - iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int with 31-bit signed 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.
[b]// This scheme only works with 32-bit word size and float enabled.[/b]
#define MICROPY_OBJ_REPR_C (2)
Bref. Il y a peut-être des problèmes additionnels, qu'il faudra découvrir ultérieurement, mais l'utilisation de la représentation C est largement suffisante pour que mp_float_t == double plutôt que float se passe très mal

La représentation D n'est manifestement pas faite pour les plate-formes 32 bits:
- Code: Select all
// A MicroPython object is a 64-bit word having the following form (called R):
// - seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 64-bit fp, e != 0x7ff
// - s1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 +/- inf
// - 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000 normalised nan
// - 01111111 11111101 iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int
// - 01111111 11111110 00000000 00000000 qqqqqqqq qqqqqqqq qqqqqqqq qqqqqqq1 str
// - 01111111 11111100 00000000 00000000 pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
// Stored as O = R + 0x8004000000000000, retrieved as R = O - 0x8004000000000000.
// This makes pointers have all zeros in the top 32 bits.
// Small-ints and strs have 1 as LSB to make sure they don't look like pointers
// to the garbage collector.
#define MICROPY_OBJ_REPR_D (3)
et de toute façon, j'ai très vite des erreurs de compilation si je tente de l'utiliser.
La représentation B:
- Code: Select all
// A MicroPython object is a machine word having the following form:
// - xxxx...xx01 : a small int, bits 2 and above are the value
// - xxxx...xx11 : a qstr, bits 2 and above are the value
// - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
#define MICROPY_OBJ_REPR_B (1)
compile du premier coup, sans nécessiter de modifs supplémentaires du code, et le binaire produit est à peine plus gros qu'avec la représentation C:
- Code: Select all
LINK build-trinket_m0/firmware.elf
1080 bytes free in flash out of 188416 bytes ( 184.0 kb ).
26060 bytes free in ram for stack out of 32768 bytes ( 32.0 kb ).
Create build-trinket_m0/firmware.bin
Create build-trinket_m0/firmware.uf2
Converting to uf2, output size: 374784, start address: 0x2000
Wrote 374784 bytes to build-trinket_m0/firmware.uf2.
A vous de tester, merci d'avance

You do not have the required permissions to view the files attached to this post.