5 ms·
> You basically need a whole-program (compiler-linker) to generate good code for these CPUs. Modern compilers can do this, 'link time optimisation'.
by MaxBarraclough 6y ago
> You basically need a whole-program (compiler-linker) to generate good code for these CPUs.
Modern compilers can do this, 'link time optimisation'.
- loeg 6y agoSee also the GCC flag, "-fwhole-program."
- eqvinox 6y agoTo my knowledge, none of the compilers that support these architectures support LTO... bit of a chicken and egg; since C historically wasn't a great fit, support never grew to that point where it'd fit better.
- Someone 6y agoThat’s true, but I don’t think they do to the extent that is needed to generate good Z80 or 6502 code. They won’t move local variables to global locations, for example. That often is essential on 6502 because of the limited stack space. I also doubt they’ll use status flags to return data from functions. Such micro-optimizations just aren’t that useful on heavily pipelined CPUs with zillions of registers. But yes, a link-time optimizer would work, but it would have to be built for these architectures, not, as in gcc’s or LLVM’s case, for the intermediate language. Edit: for stuff that I don’t see a traditional link time optimizer do, look at CHRGET and CHRGOT in http://unusedino.de/ec64/technical/project64/mapping_c64.html http://unusedino.de/ec64/technical/project64/mapping_c64.htm.... Semi-equivalent C code (leaving out returning info in the status flags) is: void * addr; void * CHRGOT() { return addr; } void * CHRGET() { while(shouldSkip(++addr)); return addr;} The assembly code uses self-modifying code for speed, and makes CHRGET fall-through into CHRGOT, adding an unnecessary while-loop to CHRGOT. Also, there’s the choice as to what flags to use for returning info.