r/Compilers • u/zlfn • 18d ago
Introduce LLVM Z80 Backend
Hello, I'm posting here because I think many people might be interested in our project.
We are developing a complete Z80 backend for LLVM. It currently supports the Z80 and SM83 (Game Boy CPU) and offers performance and stability comparable to existing compilers for Z80.
You can check the benchmark here (though I made it, so it may not be completely fair) :
https://zlfn.github.io/z80-bench/
And you can also try it out on godbolt: https://godbolt.org/z/4v19Gjd9E
Our goal is to create a modern and efficient Z80 compiler that can be used as a toolchain for various retro computing projects.
We are looking for users and contributors for our project! If you like the project, feel free to try it out, and if you have any suggestions for improvement, please let us know through project issues or discussions. Thanks!
13
u/Hjalfi 18d ago
Do you know about the llvm-mos65 project, which is doing the same for the 6502? If not you should probably talk to them --- they have done lots of 8-bit specific optimisations like moving locals into globals where safe. While the Z80 is a little more C-friendly than the 6502, it still hates stack frames, so this would be useful for you?
21
u/realrealvantheman 18d ago edited 18d ago
PLEASE dont be slop this actually looks cool edit: its vibecoded
2
u/amgdev9 18d ago
That means rust for gameboy? 👀
6
u/theangryepicbanana 18d ago
a z80 llvm backend already exists, get your vibecoded slop outta here
2
u/[deleted] 18d ago
This is great, finally I can compare my own Z80 backend (for my language). This was done last year to test out my Z80 emulator.
I have the 'sieve' benchmark too (also from the BYTE article!). The results compared to the first two columns in that link are:
So not that great, but then mine is not an optimising compiler: it more or less just directly translates stack-IL code. However it is roughly on a par with some of those other products.
1
u/nicholas_hubbard 18d ago edited 18d ago
I helped create a Sega Genesis emulator a long time ago for a retro game company. The Sega Genesis uses a Z80 for audio processing. We used an existing Z80 emulator that I had to hook up to the rest of the system. I remember the hell of hours of reading Z80 instruction backtrace to debug bad audio in some cases. It drove me a bit insane.
I'm going to see if I can help out on this since I have some prior experience with Z80 assembly.
1
u/whizzter 17d ago
Actually stumbled upon this project a few weeks back when researching due to feeling shortcomings of SDCC for a game, felt a tad too much AI vibe and a bit unclear on how well supported GBZ80 is but seeing life in trying to get a community is a good indicator.
Got started on tinkering on a C compiler to compile my game demo but might give this a stab at compiling it first (The generated code size increase vs SDCC in that other comment did give me a bit of a pause though).
1
u/Classic-Ad5752 18d ago
Damn, my development board has an 8085 processor!
1
u/rocco_himel 17d ago
Please give me a good reason why LLVMs are good.
1
u/Slow-Sweet7991 16d ago
Looking to contribute to a new llvm backend or new npu target in IREE or any MLIR-based compiler. If anyone is doing any open-source project, please let me know.
0
u/True_Locksmith2751 18d ago
Hi! I’d like to join to the project. Is contributing to the code should be manually or using Claude code is ok?
0
u/[deleted] 17d ago
The scale of this project is huge. I tried downloading it, but gave up after 30 minutes when it had only extracted 60,000 of the 200,000 files from the download.
How many of those 200K files are specific to Z80, and how many of the latter were machine-generated? How big is a standalone compiler binary?
Just trying to get a sense of it (as the stuff I do is on a tiny scale by comparison).