[PATCH] Reduce RAM usage of floating point conversion functions

Federico Terraneo fede.tft@hotmail.it
Sun Jun 9 15:14:00 GMT 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Noticed a significant use of RAM tables in floating point conversion
routines while reviewing some newlib code, and thought to submit a patch.

This patch does three things:
- - Adds a const qualifier to a couple of constant tables in strtod.c,
  this saves 40 bytes of RAM on microcontrollers. Note that this
  required to make the fpi parameter of gethex() and hexnan() const as
  well. Both functions appear to be used only inside newlib, so this
  should not be an issue.
- - Adds a const qualifier to many constant tables in ldtoa.c, this
  required to mark many pointer parameters to functions inside the same
  file const, as in fact those functions never modify the passed
  parameters. Since all modified functions are static, this should
  not be an issue as well. This results in saving around 600 bytes
  (considering both data and bss) moving those tables to rodata,
  however this only benefits targets built using
  --enable-newlib-io-long-double, since otherwise _ldtoa_r() is not used
- - gethex() and hexnan(), which are use by both strtod() and _ldtoa_r()
  use a lookup table to test if a char is an hex digit, requiring
  256 bytes of RAM. The patch replaces this table with a function.
  As this may result in a performance penalty, this change is only
  enabled if PREFER_SIZE_OVER_SPEED, __OPTIMIZE_SIZE__ or _SMALL_HEXDIG
  is defined. The last macro was introduced to be able to selectively
  enable this change.

Let me know what you think.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJRtJvXAAoJECkLFtN5Xr9fYQwH+QE3D6J7Wpl2IMuKRjCaCYCl
rXHSB9ITF/BzL3H8nKHacUWm2wB6owT/HBm1E27ED6kU5WTFIhL6CUFP80kOdLaR
hG5qCBySeblM84Jxvo0brjnQauticrSWcLRmAtNE1Pe6AiKLtPpBI/LP5hTWisj9
ntACkKGwchBWrtXyvFrzsKRhRUdrKLC8N+dSTFh/+c31Tbz8RoCPiKr+P5I1M04x
aVw+EXacpdWT6OzB8BGCsJrnKJBViEe+ZCEU62a35m9n4prMmKBe0+6X0bpvGCvQ
M6iV6fNMZMEw1AA4FuKPkI8X9pk33lmHVfnH6iN5kyoOwtoxZV2Dm1DZ/bjOrbo=
=+HbO
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: float-conversion.patch
Type: text/x-patch
Size: 17569 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20130609/196cca58/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: float-conversion.patch.sig
Type: application/octet-stream
Size: 287 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20130609/196cca58/attachment.obj>


More information about the Newlib mailing list