Compile time for a switch with a case range rises steeply with the number of values in the range. The attached main.c has one range of N values (default 1024) and builds with both GCC and SDCC:
gcc -c -DN=1024 main.c
sdcc -mmcs51 --std-c2y -DN=1024 -c main.c
Compile time in seconds:
| N | gcc 14.2.0 | SDCC 4.6.0 mcs51 | SDCC r17016 mcs51 |
|---|---|---|---|
| 256 | 0.01 | < 0.1 | < 0.1 |
| 512 | 0.01 | 2.3 | 2.3 |
| 1024 | 0.01 | 16.0 | 16.2 |
| 2048 | 0.01 | > 60 (stopped) | > 60 (stopped) |
With r17016 at N=1024: z80 28.7 s, stm8 0.4 s.
Context: QMK keyboard firmware uses ranges such as case QK_MODS ... QK_MODS_MAX: (7936 values). With SDCC, these files do not finish compiling.
SDCC version (sdcc -v):
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/huc6280/f8/f8l TD- 4.6.4 #17016 (Linux)
published under GNU General Public License (GPL)
So for some targets (like stm8), SDCC uses a jump table, for others it uses an if-else chain. Neither is optimal here, but let's ignore that for now. A jump table would already be an improvement for z80.