The STM8 backend for SDCC has improved a lot since the release of version 3.6.0 in June 2016. But due to the very small number of registers the code size will almost always be bigger than for the AVR. Depending on the exact application the difference is anywhere between negligible and factor two.
Comparing code size with the original AVR Arduino
Benchmarking the original Arduino examples from Arduino 1.0.5. The simple Blinky compiles to 57 bytes of code, the total binary including the sduino libraries is 1868 Bytes (0x74c).
So far, wiring_analog depends on wiring_digital, even when analogWrite is not used. This could be solved by compiling the sduino functions separately into a library.
|Name||Code||Total||Linked files other than main and wiring|
|AnalogReadSerial||205||3452||digital, analog, serial, print|
|DigitalReadSerial||57||3160||digital, serial, print|
|ReadAnalogVoltage||float not yet implemented|
Floating point arithmetics is supported by the SDCC standard library, but it comes at a pretty high cost in terms of code space and CPU load. This is how much the generated code grows by using a single float operation compared to using a long int:
|Floating point operation||approx. code size|
|sinf() or cosf()||3346 Bytes|
The Arduino standard example '01. Basics/ReadAnalogVoltage' is a very simple simple program with only very little floating point arithmetics. But it already uses 7336 bytes of flash. A similar sketch using integer arithmetics results in much more compact code occuping only 3791 bytes.
Float does work, but is better to be avoided and replaced by fixed point arithmetics whenever possible.