johnwbyrd wrote:
laoo wrote:
The other thing that might be a problem when treating zp as a register file: when programming in assembly by hand we really seldom treat it as registers. There are virtually no scenarios where a data from memory would be transferred to zp, manipulated and then written back - and that's the way registers work. We even don't have special instructions that does stuff on zp explicitly. It's just a memory that is faster and has additional usage - to store pointers. So I'm afraid that tuning the compiler to tread zp as registers could produce ridiculous scenarios of transferring data between zp and memory hence and forth.
For most compilers, this is an entirely valid concern. However, LLVM has a fairly advanced algorithm for keeping active variables in registers. Our strategy is to try to get LLVM to keep as much as possible in virtual registers (e.g. zero page) at all times.
In practice this does mean that LLVM generated code will move all code from 16-bit memory to 8-bit memory before doing math operations on it and then pushing it back to 16 bit memory. However, I'm expecting that giving LLVM a plentiful range of virtual registers, should allow it to be smarter about what to cache there, and will hopefully avoid thrashing.
I assume you're meaning "all data" is being moved?
Quote:
Really, this is no different from what most modern 6502 programmers do: they move memory to zero page before multiplying or doing multi-byte operations anyway. Although it seems wasteful to move memory back and forth, it works out to a net performance win because the instructions are so much faster and smaller when working on zero page.
Is that what "modern" programmers do? Maybe I'm old
On the other hand, when I have an optimized library routine this uses zeropage and you'd have to copy data there.
I'd keep the "fast variables" in zeropage, without needing to copy them back and forth. Maybe there is a way to "pin" these "registers" so backing storage in 16bit is not needed?
Other stuff that does not need to be as fast, I keep in 16bit memory even, without the need for copying it around.
Quote:
If it does turn out that the memory thrashing is pessimal in some usage cases, I'm sure we can create an LLVM pass to reduce it. But we should deal with that problem when it becomes a bottleneck and not before. Premature optimization and all.
Link-time code generation will, I strongly suspect, be incredibly important for the 6502. As many others have recognized, C stack operations are performance killers on the 6502. In principle, LLVM can simply optimize most or all of them away, if it's able to see the entire program at once at link time.
I'm looking forward to the results of your analysis! Should be very interesting!
_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content:
http://6502.org/users/andre/