Skip to content

Consider using the circuitpython/lib/libm math library instead of -libm to save space #325

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
dhalbert opened this issue Oct 14, 2017 · 10 comments
Assignees
Milestone

Comments

@dhalbert
Copy link
Collaborator

dhalbert commented Oct 14, 2017

The atmel-samd boards currently use -libm. This is supplied as part of glibc in the arm-none-eabi toolchain. Various functions there such as powf and sqrtf end up using the double-precision float arithmetic routines (__aeabi_dadd, dsub, etc.), which occupy a few thousand bytes.

There is an alternate simpler libm which is in our source tree which does not use doubles and is simpler in other ways. It's used for some other ports, including esp8266. I assume it might be numerically different as well, probably less precise.

When I tested switching atmel-samd to use the libm in our tree instead of -libm, the Gemma M0 firmware got smaller by 8780 bytes (!). This would give us the freedom to add a lot more stuff to the non-Express boards, and completely solves the current space squeeze (e.g., #322).

@tannewt @ladyada Do you have an opinion on this? Should we try to use the same libm across all atmel-samd boards (the size matters less for Express and M4).

The internal libm needs some work to remove compile warnings. Our -Werror errors out on all warnings.

@dhalbert dhalbert self-assigned this Oct 14, 2017
@dhalbert dhalbert added this to the 2.x milestone Oct 14, 2017
@ladyada
Copy link
Member

ladyada commented Oct 14, 2017

!!!! lets try libm for gemma/trinket/non-exp for now since its the most useful!

@dhalbert
Copy link
Collaborator Author

Gemma build using internal libm, complex arithmetic turned off, and -finline-limit disabled has 8312 bytes free.
Adding back complex uses 1576 bytes.
Re-enabling -finline-limit=50` (as an example) gains back about 1900 bytes, so there is headroom to use that again if necessary.

We could enable other stuff that might be useful even in small builds: #193 (MICROPY_PY_ARRAY_SLICE_ASSIGN, turned off in both builds), reversed(), etc. That's another discussion.

@ladyada
Copy link
Member

ladyada commented Oct 15, 2017

#1 most useful thing in small builds would be pwm/timer support.

@dhalbert
Copy link
Collaborator Author

Turning on pulseio takes uses 7168 bytes, bringing free bytes down to 1092. Substantial, but it fits! I'll turn that on and add it to the pull request or make a separate one.

@ladyada
Copy link
Member

ladyada commented Oct 15, 2017

its worth it for sure, we can work around SLICE or reversed(), but if we dont have pwm support, we can't do servos, LED dimming, and a bunch of other things!

@ladyada
Copy link
Member

ladyada commented Oct 15, 2017

(if ya toss me a uf2 i will do a bunch of testing!)

@dhalbert
Copy link
Collaborator Author

gemma and trinket uf2's attached in a zip
pulseio-uf2-gemma-trinket.zip

@dhalbert
Copy link
Collaborator Author

Limor suggested just the smaller builds, but happy to be consistent. Might be easier to support and test. I'll try to fix #331 before the merge anyway.

@tannewt
Copy link
Member

tannewt commented Oct 16, 2017 via email

dhalbert added a commit to dhalbert/circuitpython that referenced this issue Oct 16, 2017
@dhalbert
Copy link
Collaborator Author

Accomplished by #329.

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

No branches or pull requests

3 participants