Open kervinck opened 5 years ago
Low priority
Two ideas to reduce the number of thunk functions in rt.py:
videoTable[1] = 0x60;
No need to let code do this: do this as a 1-byte segment somewhere in the .gt1 file (near the end?). Pixels then run from 0x60 to 0xff while code can live at offset 0 instead of 0xa0. This eliminates the need for thunk1. Adjust PutChar, Newline and ClearScreen accordingly. Actually, these become slightly simpler because testing for end of line is now simpler.
0500 2b tt STW tt
0502 11 00 08 LDW $0800
0505 2b 1a STW vLR
0507 21 tt LDW tt
0509 ff RET
In essence, the above eliminates four zero page bytes and one helper function.
(Sometimes the compiler even juggles the order of SUBW operands...)
Simplify. Same for CNSTI2(0) and MULU2, DIVXX etc
int main(void)
{
return 0;
}
Still gives an .gt1 file of more than 4 KB in size. It seems that references from other functions are not purged (e.g. div in rt.py references divu, and divu is never purged because of this?) Also some references come from the data space, such as the flush methods in the FILE objects of stdin.c/stdout.c).
See this comment for an example: https://github.com/kervinck/gigatron-rom/issues/76#issuecomment-497897449
This issue should be closed since glcc already does such optimizations (when they make sense in the new code)
[Note: This issue is an aggregation for optimisations of the emitted code. I want to park all ideas here for future reference. Regarding priorities in LCC the order should be 1. Correctness, 2. Usability, 3. Optimisations.]
Ideas (some simpler than others. some realistic, some are nonsense):