Skip to content

newlib: enabling floating point printf for cortex-m cpus#5094

Merged
kaspar030 merged 1 commit intoRIOT-OS:masterfrom
aabadie:printf_float_cortex-m
Mar 21, 2016
Merged

newlib: enabling floating point printf for cortex-m cpus#5094
kaspar030 merged 1 commit intoRIOT-OS:masterfrom
aabadie:printf_float_cortex-m

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented Mar 16, 2016

Addressing one of the comment from #5078.

@jnohlgard
Copy link
Copy Markdown
Member

could you do a buildsizes-diff summary?
https://github.com/RIOT-OS/RIOT/wiki/Comparing-build-sizes

You could do it for examples/hello-world and for your bmp180 driver test (which needs float printf in order to print anything)

@kaspar030
Copy link
Copy Markdown
Contributor

I would like to see this optional, bound to a printf_float pseudomodule.

@LudwigKnuepfer
Copy link
Copy Markdown
Member

I would like to see this optional, bound to a printf_float pseudomodule.

Isn't it easier then to just document the existence of this flag?

@kaspar030
Copy link
Copy Markdown
Contributor

We didn't need it until now. If we add it and suddenly all builds gain some kilobytes of code, that's bloat....

@LudwigKnuepfer
Copy link
Copy Markdown
Member

@kaspar030 I did not argue against making it optional.

@DipSwitch
Copy link
Copy Markdown
Member

I would prefer it in a module or as well. Or a build flag like USE_FLOAT_PRINTF and SCANF ofc

@DipSwitch
Copy link
Copy Markdown
Member

Which you can set in your application, and the BMP180 could check this flag to decide to printf float or val *1000 int

@DipSwitch DipSwitch added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: build system Area: Build system labels Mar 16, 2016
@DipSwitch DipSwitch added this to the Release 2016.04 milestone Mar 16, 2016
@DipSwitch DipSwitch self-assigned this Mar 16, 2016
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 17, 2016

Sorry for the (small) answer delay.

Here are the results based on the bmp180 test application with and without _printf_float activated.

text    data    bss dec BOARD/BINDIRBASE

6548    56  0   6604    cc2538dk
20136   132 2708    22976   without-float
26684   188 2708    29580   with-float

6548    56  0   6604    fox
18212   132 2804    21148   without-float
24760   188 2804    27752   with-float

6548    56  0   6604    frdm-k64f
18124   1156    3204    22484   without-float
24672   1212    3204    29088   with-float

6548    56  0   6604    iotlab-m3
18228   132 2804    21164   without-float
24776   188 2804    27768   with-float

6556    56  0   6612    limifrog-v1
19380   132 2796    22308   without-float
25936   188 2796    28920   with-float

6540    56  0   6596    msbiot
20524   132 2852    23508   without-float
27064   188 2852    30104   with-float

6540    56  0   6596    mulle
21008   1192    3272    25472   without-float
27548   1248    3272    32068   with-float

6548    56  0   6604    nucleo-f103
18212   132 2812    21156   without-float
24760   188 2812    27760   with-float

6540    56  0   6596    nucleo-f303
18412   132 2804    21348   without-float
24952   188 2804    27944   with-float

6540    56  0   6596    nucleo-f401
20156   132 2804    23092   without-float
26696   188 2804    29688   with-float

6556    56  0   6612    nucleo-l1
19244   132 2788    22164   without-float
25800   188 2788    28776   with-float

6548    56  0   6604    openmote-cc2538
20744   132 2964    23840   without-float
27292   188 2964    30444   with-float

6548    56  0   6604    pba-d-01-kw2x
18124   1156    3204    22484   without-float
24672   1212    3204    29088   with-float

6548    56  0   6604    remote
20768   132 2908    23808   without-float
27316   188 2908    30412   with-float

6884    56  0   6940    samr21-xpro
24676   132 2796    27604   without-float
31560   188 2796    34544   with-float

6540    56  0   6596    stm32f3discovery
18540   132 2804    21476   without-float
25080   188 2804    28072   with-float

6540    56  0   6596    stm32f4discovery
20452   132 2828    23412   without-float
26992   188 2828    30008   with-float

So there's indeed a significant memory overhead when activating this flag (~ 25%).
As suggest by @kaspar030, I can try in this PR to add a pseudo module which activate this (I'm +1 with this idea).

@DipSwitch
Copy link
Copy Markdown
Member

No problem for the delay! Take your time :)

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 17, 2016

Just pushed a commit adding a pseudo module for printf with float and added a small test application. It works on a SAMR21 board.

endif

ifneq (,$(filter printf_float,$(USEMODULE)))
export LINKFLAGS += -u _printf_float
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endif

@DipSwitch
Copy link
Copy Markdown
Member

Please add the two lines I inserted as comment. I don't know what the linker does if we call -u _printf_float and there is no nano.specs :)

@jnohlgard
Copy link
Copy Markdown
Member

@DipSwitch You suggested change will execute the link test for nano specs twice, once in sys and once in cortexm_common. It's better to set an environment variable in cortexm_common and check that from sys/Makefile.include.

@aabadie aabadie force-pushed the printf_float_cortex-m branch from 80663f7 to 521a3ee Compare March 17, 2016 14:31
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 17, 2016

I pushed a change with @gebart suggestion (not tested, I have no board with me).

* @}
*/

#include "stdlib.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use "<>" for system headers.

@aabadie aabadie force-pushed the printf_float_cortex-m branch from 701ea30 to 4ff3110 Compare March 17, 2016 15:20
int main(void)
{
double floating_point_value = 2016.0317;
char result[8] = {0};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabadie aabadie force-pushed the printf_float_cortex-m branch 2 times, most recently from 9787fe2 to 19bcefa Compare March 17, 2016 21:36
@DipSwitch
Copy link
Copy Markdown
Member

Looks good! Please squash and rename the commit to something like: arm/newlib: Add pseudomodule to enable floating point printf support

@aabadie aabadie force-pushed the printf_float_cortex-m branch from 19bcefa to 4c6b073 Compare March 17, 2016 22:11
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 17, 2016

@DipSwitch commits amended and squashed. Thanks !

@DipSwitch
Copy link
Copy Markdown
Member

Good buzy!

@DipSwitch DipSwitch added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 17, 2016
endif

ifneq (,$(filter printf_float,$(USEMODULE)))
ifdef USE_NANO_SPECS
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO ifeq (1,$(USE_NANO_SPECS)) is more flexible since we can set USE_NANO_SPECS=0 if we don't want it as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

----- Mail original -----

IMO ifeq (1,$(USE_NANO_SPECS)) is more flexible since we can set
USE_NANO_SPECS=0 if we don't want it as well.
Yes it sounds reasonable. I changed it.

@aabadie aabadie force-pushed the printf_float_cortex-m branch from 4c6b073 to cb69d5c Compare March 18, 2016 13:01
@jnohlgard
Copy link
Copy Markdown
Member

ACK

@DipSwitch
Copy link
Copy Markdown
Member

@DipSwitch DipSwitch added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 20, 2016
@aabadie aabadie force-pushed the printf_float_cortex-m branch from cb69d5c to 82e43c3 Compare March 21, 2016 10:46
@aabadie aabadie force-pushed the printf_float_cortex-m branch from 82e43c3 to e1fcee6 Compare March 21, 2016 10:48
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 21, 2016

All checks have passed, seems ready for merging :)

@kaspar030 kaspar030 changed the title Enabling floating point printf for cortex-m cpus newlib: enabling floating point printf for cortex-m cpus Mar 21, 2016
@kaspar030
Copy link
Copy Markdown
Contributor

&go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants