-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add support for 30-bit stuffed float #1516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This new object representation puts floats into the object word instead of on the heap, at the expense of reducing their precision to 30 bits. It only makes sense when the word size is 32-bits.
This saves around 1000 bytes (Thumb2 arch) because in repr "C" it is costly to check and extract a qstr. So making such check/extract a function instead of a macro saves lots of code space.
Ok, added a new commit (5th one above) which reduces code size of representation "C" by about 1k. So now, with just floats enabled (no complex numbers, no math/cmath modules), going from repr "A" to repr "C" costs less than 200 bytes code space. |
Nice! Didn't look into details yet, but from #1504, I guess it indeed would be a good exercise to come up with descriptive names for object representations rather than A, B, C. I'm not sure this will be possible though. E.g., this one could called exactly "float stuffing", but readable identifier would be rather long. And I'm not even sure how describe A and B difference in couple of words. Still, may be nice to go thru the exercise. |
The amount of code that is changed is rather minimal, so should be easy to review.
MICROPY_OBJ_REPR_STUFFED_FLOAT_32BIT would be suitable, and the actual identifier is not used very much in the code so isn't that bad having it long. |
Well, this is useful if we can do similar for "A" and "B" at the same time, otherwise having "A", "B", and "STUFFED_FLOAT_32BIT" doesn't feel to consistent. I guess, we should skip this for now after all. |
@dpgeorge : I believe Travis failed due to lack of some header, or something. |
Looks good, thanks! And given Microbit announcement, if you think it would be nice to changelog entry that mainline already has changes to support it, let's merge it for 1.5! |
Merged, ending in commit 04353cc. |
And these changes have now been pushed to microbit repo: bbcmicrobit/micropython@ed61dff |
The first 3 patches here make the float object representation configurable. The 4th patch adds a new object representation "C" which has 30-bit floats stuffed into the object word, so that floats don't need allocating on the heap.
See #1504 for discussion.
The first 3 patches are solid and don't change any functionality, they just make the object model more configurable.
The 4th patch is useful for ports that have little RAM but still want to use floats, and accept that 30-bit precision is enough. Unfortunately this "C" representation adds about 1400 bytes to the code size, due to the more complex way of packing, testing and unpacking qstrs. [In an alternative implementation that I tried, floats only had 29-bits and qstrs were much more efficient to pack/test/unpack, but 29-bit floats is really starting to degrade precision.]