p3p / pio-framework-arduino-lpc176x

10 stars 20 forks source link

Fix compiling with -flto by adding some missing volatile qualifiers #53

Closed mh-dm closed 1 month ago

mh-dm commented 1 month ago

Variables that are modified also within ISRs must be marked volatile otherwise the compiler wrongly assumes they don't change. With LTO (link time optimization) the compiler optimizes calls across translation units and that wrong assumption produces real effects.

Co-locate millis() and micros() with code updating _millis. Also optimize micros() (from 2 to 0 divisions) and switch to uint32_t _millis as nothing uses the higher bits.

For marlin, compiling with -flto results in a 10% smaller binary and very likely faster too but unfortunately increases incremental compile times by ~7s.