Author Topic: Best RETARGETABLE C compiler for FPGA CPU projects?  (Read 11168 times)

0 Members and 1 Guest are viewing this topic.

Offline Berry Straw

  • Newbie
  • Posts: 1
  • Country: au
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #50 on: June 17, 2024, 02:28:32 pm »
 

Offline trossin

  • Contributor
  • Posts: 10
  • Country: us
    • Demoboy
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #51 on: June 17, 2024, 07:36:52 pm »
I’m not sure if this was said but instead of creating your own instruction set, reinvent the wheel and design your own implementation of a vintage processor. This way a C compiler will already exist. You can make it fun by amping up the implementation by adding multi-level caching, out of order execution and branch prediction logic. A killer 68000 would be fun as it at least has a large address space compared to a 6502.

Years ago I created a cycle and speed accurate hardware emulator of a 1970s vintage 1802 processor using a PIC microprocessor all in assembler. That was a fun project. I also wrote a toy C compiler for it which I’ll admit was painful.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4533
  • Country: nz
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #52 on: June 17, 2024, 11:27:02 pm »
I’m not sure if this was said but instead of creating your own instruction set, reinvent the wheel and design your own implementation of a vintage processor. This way a C compiler will already exist.

Absolutely the path of least resistance. But vintage processors are often not well supported by modern compilers -- or just are very difficult to support. It's easier to implement RISC-V RV32I than 6502. Or Arm, for that matter, but you can publish your RISC-V CPU without getting sued.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2463
  • Country: us
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #53 on: August 09, 2024, 09:18:48 pm »
You could grab an older version of gcc and add a machine description (.md) and other bits and pieces needed for your target.  You'd also need a version of binutils and do the same for gas since older gcc's generate assembly that needs to be assembled.  But presumably you want an assembler anyway.  You also need to add support to libbfd and few other libraries.  The most elementary .md for gcc is pretty straightforward (I added several in the 90s when I worked on those versions of gcc on the GNU Project at FSF, just for testing purposes, using completely invented architectures, for example with only subtraction, complement, and increment, but no addition so it would be forced to exercise my changes), and then you can address obvious shortcomings as they crop up and bother you.  This is assuming you're inventing a GPR-based architecture with linear memory; anything else and C is not going to be a good option.
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4247
  • Country: gb
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #54 on: August 09, 2024, 10:34:58 pm »
A couple of man-weeks to design and implement a CPU in an FPGA but from what I see, man-years to retarget the compiler.

myC has been 8 years in the making, there is no optimization layer yet and the machine layer only includes MIPS32 and MIPS5++ (prototype).

I personally spent some time on myC too to do some personal development and research and see what could be done to improve C.

Not much, I tried and... honestly, I tried so many ideas in the last 8 years, almost all of them miserably failed, except the latest approach that is giving me satisfaction, but not so much if we consider the generated code.

I think it's basically a matter of trade-offs, but finding the right balance in a C compiler, written from scratch and mutated, or simply cloned and retargeted, always requires experience and a lot of time and dedication.

Does it make sense? It depends, but if the goal is to run Doom, then I think it's better to take a risc-v core, a { binutils, gcc, gdb, musl } toolchain, and digest them as is.

The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4247
  • Country: gb
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #55 on: August 09, 2024, 10:43:44 pm »
That was a fun project. I also wrote a toy C compiler for it which I’ll admit was painful.

This remembers me when I tried to add M56000 to gcc-v2.95 :o :o :o

It's an old Motorola DSP.
There are no C compilers for it.
563xx has a few, 56000 has none.

The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4247
  • Country: gb
Re: Best RETARGETABLE C compiler for FPGA CPU projects?
« Reply #56 on: August 09, 2024, 10:50:56 pm »
People seem enthralled by C.  I'm not such a big fan.  I much prefer to work in forth.  But then, I'm not trying to port C code. 
A forth oriented CPU is very easy to make in an fpga.  They can be small and if you know how to design in an HDL, they can be very fast. 

GameDuino-v1. Basically a Forth-CPU on a Spartan3-250.
(v2 is completely different)
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf