(01-27-2021, 06:35 PM)patters Wrote: Is it a good idea to use -O3? I know typically there are trade-offs - like loop unrolling can make code bigger in order to become faster. Is there much of a difference for ZX Basic between -O2 and -O3? Am I better off sticking to the default -O2 since it's more tried and tested?
Or since I'm not yet running into memory limits should I use -O3 while I can?
ZX Basic supports -O3 and -O4 but this is compiler specific (i.e. -O3 in GCC is not the same as -O3 here).
You should try -O3 and -O4. There's currently no loop unrolling implemented, and no trade-off (memory vs speed) implemented either.
Beware -O4 is very aggressive and (for the moment) it also optimizes (aka removes and caches) VOLATILE variables (variables whose value change out of BASIC, like in an interruption, or within an ASM block). I.e. the input routine might fail with -O4 as it uses ROM KEYIN Peek value.
O3 and O4 are related to the peephole optimizer which, starting from -O3 creates the asm basic block DAGs, etc, and perform more efficient assembling instructions.
To sum up: -O3 should work always. -O4 might fail if you use volatile variables.