Introducing rg-cc: A 680x0-First C99 Compiler from Reservoir Gods
Back in the day, we used to write everything in 68000 assembly. Whilst fun, it could be painfully slow, so we moved to C for high-level game logic and assembly for the performance critical code.
When we started getting some of our abandoned old projects back up and running, we hit bugs and performance issues with VBCC. We considered either going back to Pure C, or working with one of the less 68k friendly modern compilers.
But then we had a thought. What if we could build a new C compiler, with all the modern features and optimisations of the latest compilers, but design it around the 68k architecture so it could produce the most optimal code for that CPU?
This idea became the design ethos behind a new C compiler. Instead of only caring about 68k instructions in the final backend pass, rg-cc infuses every layer of the compiler with deep knowledge of this CPU architecture.The intermediate representation that rg-cc uses during compilation isn't based around some generic RISC-like instruction set; instead, we use an IR modelled around the 680x0 feature set, registers, branching instructions and addressing modes. This means we can do high-level optimisations in "68k space" before we even get to assembly layout.
Our benchmarks were promising. Across the majority of our 1,000+ compiler tests, rg-cc outperforms GCC, Clang, Pure C, VBCC, and AHCC on both cycle count and binary size when making 680x0 executables.
But there are lies, damned lies and benchmarks - so taking these results with a big pinch of salt, it was time to do some real world testing.
First, we got all the legacy (and unreleased!) RG games running with this new compiler. And in every case, it outperformed our current default, VBCC.
Originally, we made this just to aid our internal development efforts, but it seemed it may have some value to other Atari users. So we expanded our testing.
The big question everyone asks about new technology: "Does it run Doom?" The answer is yes - and better than ever! Critical parts of Doom8088ST run over 20% faster than GCC, and the binary is over 20% smaller.
We measured performance against a range of other Atari games, tools and libraries, including Faster, HighWire and EmuTOS, and in every case there were clear advantages for rg-cc:
So the core design idea seemed sound, but we wanted this to be easy to use. We miss the simplicity of classic Atari software where you download one program and it just works. rg-cc has zero external dependencies. Compilation, assembly, and linking all happen with a single binary.
rg-cc works as a drop-in replacement for your existing C compiler in your Make or FASTBuild setup, and even supports Pure C .PRJ files. But we also built a new build system (RBS) that supports parallel compilation, content caching, and sharing of pre-parsed headers across translation units for optimal build times, so you can build all your projects without Make or any external build tools if you want.
Give it a spin! Feedback, feature requests, and bug reports are welcome:
Add comment