speeduino icon indicating copy to clipboard operation
speeduino copied to clipboard

Remove -floop-unroll: no perf impact, reduce code size

Open adbancroft opened this issue 3 years ago • 3 comments

Remove the -floop-unroll flag from the megaatmega2560 environment.

  • This has no performance impact (my tests show a 0.5% increase in loops/s, but that's margin of error territory).
  • This reduces flash usage by ~15Kb. Useful since we're now above 80% flash usage,

I also removed -ffast-math: this only applies to floating point calcs which we don't do.

adbancroft avatar Dec 31 '21 17:12 adbancroft

I'll test these out again as I haven't reviewed their impact on recent code versions. In the past they definitely made a measurable difference though.

-ffast-math definitely does a lot more than just floating point optimisations from memory. Whether we WANT those things happening is another question (As it certainly breaks strict IEEE compliance) but I'll have a play around again and see how much difference it's making

noisymime avatar Dec 31 '21 21:12 noisymime

Sure. I'd be interested to hear the results, especially if I need to improve/change performance testing.

BTW, a couple of Ardustim log compares. Bright green is master, light green is this PR.

4G63 @ 3700 rpm: No Loop Unroll 3700

4G63 1000-8000, 300 rpm/s: No Loop Unroll 1000-8000

adbancroft avatar Dec 31 '21 22:12 adbancroft

may as well drop -std=c99 and -Wall too, the std mega pio env sets -Wall and -std=gnu++11

with and without --fast-math I get the same sha1sum for firmware.hex (on master https://github.com/noisymime/speeduino/commit/770158a5fe2fddc9d83b7ff5abf21e63bebff196) b8a6c8a89845e2c10eb699bedd70318e824bb3ca but not for firmware.elf 0469bbcb9a18d3408e01eedb599654d91f2cc345 and 41d47542451d015fdaf9a17c56473c4735b6162e1

seems like a symbol name changes but nothing else, idk why

--- fast-math/firmware.elf
+++ std/firmware.elf
├── readelf --wide --symbols {}
│ @@ -314,15 +314,15 @@
│     310: 0000003e     0 NOTYPE  LOCAL  DEFAULT  ABS __SP_H__
│     311: 0000003d     0 NOTYPE  LOCAL  DEFAULT  ABS __SP_L__
│     312: 0000003f     0 NOTYPE  LOCAL  DEFAULT  ABS __SREG__
│     313: 0000003b     0 NOTYPE  LOCAL  DEFAULT  ABS __RAMPZ__
│     314: 00000000     0 NOTYPE  LOCAL  DEFAULT  ABS __tmp_reg__
│     315: 00000001     0 NOTYPE  LOCAL  DEFAULT  ABS __zero_reg__
│     316: 00028f5e   242 FUNC    LOCAL  DEFAULT    2 turnOffPWM
│ -   317: 000318ce  2146 FUNC    LOCAL  DEFAULT    2 _GLOBAL__I_65535_0_comms.cpp.o.8709
│ +   317: 000318ce  2146 FUNC    LOCAL  DEFAULT    2 _GLOBAL__I_65535_0_comms.cpp.o.8710
│     318: 00800284    18 OBJECT  LOCAL  DEFAULT    1 _ZTV14HardwareSerial
│     319: 000020fc    70 OBJECT  LOCAL  DEFAULT    2 digital_pin_to_timer_PGM
│     320: 00801f20     1 OBJECT  LOCAL  DEFAULT    3 timer0_fract
│     321: 00000000     0 FILE    LOCAL  DEFAULT  ABS _clear_bss.o
│     322: 00002178     0 NOTYPE  LOCAL  DEFAULT    2 .do_clear_bss_start
│     323: 00002176     0 NOTYPE  LOCAL  DEFAULT    2 .do_clear_bss_loop
│     324: 00000000     0 FILE    LOCAL  DEFAULT  ABS _divmodhi4.o
├── strings --all --bytes=8 {}
│ @@ -524,15 +524,15 @@
│  ignition7StartAngle
│  ignition8StartAngle
│  rollingCutLastRev
│  rollingCutCounter
│  cancmdfail
│  _ZL9loadTablePv12table_type_ti
│  turnOffPWM
│ -_GLOBAL__I_65535_0_comms.cpp.o.8709
│ +_GLOBAL__I_65535_0_comms.cpp.o.8710
│  _ZTV14HardwareSerial
│  digital_pin_to_timer_PGM
│  timer0_fract
│  _clear_bss.o
│  .do_clear_bss_start
│  .do_clear_bss_loop
│  _divmodhi4.o
├── readelf --wide --decompress --hex-dump=.strtab {}
│ @@ -350,15 +350,15 @@
│    0x000015b0 7600726f 6c6c696e 67437574 436f756e v.rollingCutCoun
│    0x000015c0 74657200 63616e63 6d646661 696c0047 ter.cancmdfail.G
│    0x000015d0 64617461 00476869 6768005f 5a4c396c data.Ghigh._ZL9l
│    0x000015e0 6f616454 61626c65 50763132 7461626c oadTablePv12tabl
│    0x000015f0 655f7479 70655f74 69007475 726e4f66 e_type_ti.turnOf
│    0x00001600 6650574d 005f474c 4f42414c 5f5f495f fPWM._GLOBAL__I_
│    0x00001610 36353533 355f305f 636f6d6d 732e6370 65535_0_comms.cp
│ -  0x00001620 702e6f2e 38373039 005f5a54 56313448 p.o.8709._ZTV14H
│ +  0x00001620 702e6f2e 38373130 005f5a54 56313448 p.o.8710._ZTV14H
│    0x00001630 61726477 61726553 65726961 6c006469 ardwareSerial.di
│    0x00001640 67697461 6c5f7069 6e5f746f 5f74696d gital_pin_to_tim
│    0x00001650 65725f50 474d0074 696d6572 305f6672 er_PGM.timer0_fr
│    0x00001660 61637400 5f636c65 61725f62 73732e6f act._clear_bss.o
│    0x00001670 002e646f 5f636c65 61725f62 73735f73 ..do_clear_bss_s
│    0x00001680 74617274 002e646f 5f636c65 61725f62 tart..do_clear_b
│    0x00001690 73735f6c 6f6f7000 5f646976 6d6f6468 ss_loop._divmodh

dantob avatar Jan 01 '22 08:01 dantob