[PATCH] Reduce RAM usage of floating point conversion functions

Federico Terraneo fede.tft@hotmail.it
Mon Jun 10 09:12:00 GMT 2013


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

On 06/10/2013 09:43 AM, Freddie Chopin wrote:
> W dniu 2013-06-09 17:14, Federico Terraneo pisze:
>> - - 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.
> 
> Couldn't this lookup table be made "static const" instead,
> removing the alleged speed penalty, but keeping the reduced RAM 
> requirement?

I did think about that, but this moves 256 bytes of .bss to 256 bytes
of .rodata, i.e. it would take up that amount of FLASH on a
microcontroller, and the table is mostly filled with zeros, which
still seems a waste.
Here is a patch that goes in that direction:
if PREFER_SIZE_OVER_SPEED, __OPTIMIZE_SIZE__ or _SMALL_HEXDIG are
defined, the table is still replaced with a function, otherwise the
table is made const (but not static, since it's used also in another
file). In this way in both cases 256 bytes of RAM are saved, and in
the former also 256 bytes of FLASH.

> 
> 4\/3!!
> 
> 

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

iQEcBAEBAgAGBQJRtZhjAAoJECkLFtN5Xr9fSlwH+QEwd2ZLUuDI59ny2Wvuyslf
bdAvyvNMU+/Hzsc7yWqoJmrrv8mn3smXE8l+BXzSpwo5rO8OEvVpL3OV7+ch7kLC
q9j1L8yfatwMTsDrB03igKC/1OBa16eqqlkqViN5NhDt3k6F+8kHE7OSLMQiNmU6
p0DGX/3KUlQRmrg3KaMqM31ITFRDmhQLWh86ZyozdePIgMIu2Gd2XzowSfHgNE18
gbUcpS8s27Nz1bJLQAvU1lGrbVTR+WCFiIpeHWuMHZDNT1z9BT7DZpPg5qdgXsf6
5/FIP2ORVO6UpkCqyBmdZbGGCAbI0fRF31wPE3fDEjakXOGcnzndwM3iBoZYHt0=
=UyQM
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: float-conversion2.patch
Type: text/x-patch
Size: 17554 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20130610/09e792eb/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: float-conversion2.patch.sig
Type: application/octet-stream
Size: 287 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20130610/09e792eb/attachment.obj>


More information about the Newlib mailing list