GCC for asm Experts (and C/C++ Intermediates) - Part 6
[ Atariscne.org - News ] GCC for asm Experts (and C/C++ Intermediates) - Part 6
← Fixing Post-Increment Addressing
DBRA and the Cost Model Balancing Act
When you write assembly for the m68k, dbra is just there. Put your count in a data register, end your loop with dbra dN,.label. Four bytes, twelve cycles per iteration on 68000, no flag dance, no comparison. Your loops naturally form around the instruction.
C/C++ does not work that way. The natural loop in C is for (i = 0; i < N; i++) or while (cond). Neither says "count down and exit when you wrap", well, while can. But a counted-up loop with an unsigned comparison is what the language naturally models, and that is what GIMPLE mostly produces. Turning that into a dbra is a backend job, and requires carefully written code. And GCC, for reasons we will get to, mostly stopped doing it for m68k.