6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Apr 28, 2024 11:29 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sat Mar 25, 2023 8:24 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3346
Location: Ontario, Canada
on Hacker News. Here's the article, and here's the HN discussion. :)
Quote:
Explaining my fast 6502 code generator

To learn how optimizing compilers are made, I built one targeting the 6502 architecture. In a bizarre twist, my compiler generates faster code than GCC, LLVM, and every other compiler I compared it to.

I reckon my compiler isn't doing more when it comes to high-level optimizations, so the gains must be from the code generation side. This makes sense, as most compilers are multi-target, with backends designed for modern RISC-like systems, not the ancient 6502. It doesn't matter how good GCC or LLVM's high-level optimizations are if they falter at the last leg of the race.

Still, my compiler also beats those designed for retro and embedded systems, like VBCC, SDCC, and KickC. For this reason, it seemed like a good idea to write about my technique.

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 25, 2023 8:43 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1399
Location: Scotland
Dr Jefyll wrote:
on Hacker News. Here's the article, and here's the HN discussion. :)
Quote:
Explaining my fast 6502 code generator

To learn how optimizing compilers are made, I built one targeting the 6502 architecture. In a bizarre twist, my compiler generates faster code than GCC, LLVM, and every other compiler I compared it to.

I reckon my compiler isn't doing more when it comes to high-level optimizations, so the gains must be from the code generation side. This makes sense, as most compilers are multi-target, with backends designed for modern RISC-like systems, not the ancient 6502. It doesn't matter how good GCC or LLVM's high-level optimizations are if they falter at the last leg of the race.

Still, my compiler also beats those designed for retro and embedded systems, like VBCC, SDCC, and KickC. For this reason, it seemed like a good idea to write about my technique.


Intersting stuff.

Just some random points:
  • It's a cross compiler.
  • It's not a C compiler, but a language with C-like features.
  • It won't work on a 65C02. (The compiler deliberately outputs "illegal" opcodes)
  • Seems to specifically target the NES platform, but I suspect that may be changeable by hacking the source code.
  • Er: Division is unsupported.
  • Looks like you can't do separate compilation, but you can compile several files at once - like concatenation, I think.

But it's nice to see something new. Maybe the existing C compiler people can look and adapt some of their stuff?

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 26, 2023 3:42 am 
Offline

Joined: Wed Jan 09, 2019 1:15 pm
Posts: 7
I've found his write-up on how it's done, and the principles underneath enlightening and very useful.

For the past few years I've been writing a large 6502 application framework and a number of techniques used to squeeze out more performance mirror the ones he's described. He explains simply and concisely those concepts that I have been struggling with in frustration. A great find, Dr Jefyll!


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 28, 2023 4:12 pm 
Offline
User avatar

Joined: Sun Dec 27, 2020 11:12 pm
Posts: 94
Location: France
I read that post and wondered if some of the later steps where the generated assembly is refined could be applied to hand-written assembly code. I have not been able to find the source code for the compiler though, and most of the algorithms in the post seem way above my head.

Anyone know if the source of this compiler is available? And what do you think about using these techniques to optimize existing assembly code?

_________________
Jonathan Foucher

Take a look at the Planck 6502 computer.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 28, 2023 5:51 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
I think this is the source
https://github.com/pubby/nesfab


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: