Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

dpgeorge
Copy link
Member

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.]

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.
@dpgeorge
Copy link
Member Author

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.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 18, 2015

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.

@dpgeorge
Copy link
Member Author

The amount of code that is changed is rather minimal, so should be easy to review.

I guess it indeed would be a good exercise to come up with descriptive names for object representations

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.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 20, 2015

MICROPY_OBJ_REPR_STUFFED_FLOAT_32BIT would be suitable

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.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 20, 2015

@dpgeorge : I believe Travis failed due to lack of some header, or something.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 20, 2015

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!

@dpgeorge
Copy link
Member Author

Merged, ending in commit 04353cc.

@dpgeorge dpgeorge closed this Oct 20, 2015
@dpgeorge dpgeorge deleted the stuffed-float branch October 20, 2015 11:41
@dpgeorge
Copy link
Member Author

And these changes have now been pushed to microbit repo: bbcmicrobit/micropython@ed61dff

tannewt added a commit to tannewt/circuitpython that referenced this pull request Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants