drcjt / CSharp-80

C# AOT compiler for Z80 based computers including the TRS-80 and ZX Spectrum
https://drcjt.github.io/CSharp-80/
GNU General Public License v3.0
51 stars 3 forks source link

optimization #476

Closed SaymanNsk closed 5 hours ago

SaymanNsk commented 3 months ago

what about register optimization? When calling some functions, it is not necessary to perform a series of pushes. if this is not dynamic loading of arguments or if this is not a large number of arguments, then they can be passed in registers. I would also like to see the assembly in the form of an asm text file. for example, to evaluate code, its correctness and optimality. To be honest, right now this compiler is not very usable. In addition, there is no possibility to create “custom” load options and usability (for other systems).

drcjt commented 3 months ago

Thanks for your interest in this project.

Firstly the compiler does produce asm text files, look for files called .dasm in the output folders, for example CSharp-80\Samples\CalcPi\bin\Trs80\Debug\net8.0\CalcPi.dasm. The compiler works by producing assembly code which is then assembled by a z80 assembler. The list file from the assembler is also produced in the output folders, e.g. CSharp-80\Samples\CalcPi\bin\Trs80\Debug\net8.0\CalcPi.lst

Using registers rather that the stack to hold local variables, intermediate calculations etc.. is something I have considered. However, the z80 processor has a very limited set of registers and almost every non trivial method would likely end up having to spill data stored in the registers a lot. Note that the compiler will pass parameters in registers in certain limited cases such as when calling intrinsic methods. It is likely that I'll look at inlining before register allocation as this will have much more impact on the ability to use very small methods in C#.

It's not clear to me what you mean by "custom" load profiles? There are some compiler options - see the details in ConfigurationOptions class.

The compiler is quite usable for the use cases as described in the main readme as is demonstrated by the samples including fully functioning snake game and wumpus game that work on the TRS-80. I'm not sure what you were expecting to be able to accomplish with an 8-bit processor and 64k of addressable RAM but to be honest the compiler has far surpassed what I expected would be possible.

SaymanNsk commented 3 months ago

Modern 8bit computers have memory more than 64kb. ZX-Sprinter (Sprinter-2000) have 4096kb. Or ZX-Evo have 4096kb too. With MMU. 16kb pages (256 pages). ZX-Spectrum 128 have 128kb of RAM, with 0x7ffd memory port for switch pages in 3 cpu window (0xc000 - 0xffff area). How i can use this MMU`s in your compiler?

drcjt commented 3 months ago

@SaymanNsk, CSharp-80 doesn't currently have any support for bank switching or other advanced memory models. I have added some information about the memory map here - https://github.com/drcjt/CSharp-80/wiki/Memory-Models.

drcjt commented 3 months ago

@SaymanNsk I've added two separate issues for register allocation and advanced memory models: