How fast will a fictitious 8-bit micro run in an FPGA?

In which my friend Joe Farr poses a question to ponder with regard to the effective speed he might obtain if he were to implement an 8-bit micro of his own devising in an FPGA

I'm sure that you will recall my mentioning my friend Joe Farr in previous blogs. Joe is an all-round expert in software and hardware – and he's a mega-expert on anything to do with PIC microcontrollers. On many occasions Joe has helped me out by designing and building small custom circuit boards carrying PIC microcontrollers and other "stuff" to complement whatever weird and wacky hobby project I'm working on at the time.

As an aside, Joe lives outside London and he works in the city itself as a consultant to whoever needs his services the most at that time. I'm currently in the UK visiting with my mom for a few days. Tomorrow, as I pen these words, I'm flying down to London to speak at the Embedded Live conference. Joe is going to swing by my hotel after work and we're planning on quaffing a few pints of good old English Beer ("quaffing" is similar to regular drinking, except you tend to spill more down your chest).

Anyway, Joe came up with an FPGA-related question and I thought I'd see what other folks had to say. Let's start with Joe's original email:

Joe:Hey Max, question for you. I've never played with FPGAs and can't seem to find a straight answer. Do you think that an FPGA can be programmed to act like a CPU (like a small 8-bit Z80 for example) and run at a reasonable speed? A Z80 can execute a Jump in around 3 clock cycles and has a max clock speed of around 4 MHz and these were running multi user CP/M machines in their day.

My own PIC based CPU emulations are coming in well short of the mark. With a PIC running at 64 MHz it's still taking 30us just for a simple jump and anything complicated and it starts getting very slow. My average speed is equiv to a 300 KHz clock rate. Just thought you may have some thoughts on this.

Now, of course, it is certainly possible to create a soft core 8-bit microprocessor in an FPGA, but the sort of performance you are going to receive depends on all sorts of factors like the instruction set and addressing modes and the architecture of the machine itself (number of pipeline stages, for example). So I replied as follows:

Max:Hi Joe, can you can give me a bit more detail about what you’re doing – what you are using the 8-bit micro for – what sort of performance you need (fixed-point 8-bit arithmetic or floating-point)? Just give me some background stuff and I can write a blog about it [that would be this blog] and get a bunch of FPGA gurus to sink their teeth into it and offer advice...

I then dropped my computer and smashed my screen while travelling, so it took me a little while to get back on the net, at which time I saw Joe's response as follows:

Joe: Simply put, it’s an emulation of a fictitious 8-bit CPU. It’s very similar to your own DIY Calculator CPU [see www.DIYCalculator.com] except that it’s got my own personal instruction set instead of yours. It also has 24-bit addressing instead of 16-bit, but basically it’s the same. So there’s no floating point or anything like that… all very simple and basic.

The emulation has to generate all the normal signals, data bus = 8 bits, address bus (24 bits), read, write, and a few other signals. As for what type of performance… as fast as possible :-)

So there you have it. Imagine a simple 8-bit CPU with simple addressing modes (say implied, immediate, and absolute). There is, of course, a tremendous variety of FPGA fabrics with very different characteristics. So, using your knowledge of the FPGAs you are working with, what sort of performance might Joe expect if he implemented his CPU on those devices?

Currently available FPGAs are big chips with lots of pins and will also consume more power compared to the tiny PICs. So unless you already have to use lots of gates in your project FPGAs just for the sake of running CPUs are not that attractive

You are welcome Joe.
Yes, definitely there is lack of some good and short descriptions of FPGAs. Even the page in Wikipedia it is not especially friendly in this respect. Here is a better example of such description http://www.andraka.com/whatisan.htm
I cannot recommend any books because from my side as I just have briefly read one, and I am still just a beginner. Personally I read on the Internet some peaces, looked at the examples, syntax description and then just combined my programming knowledge with my digital electronics (hobby) knowledge :)
But here is one advice. It is better to acquire a book that describes the language that you will use for the FPGA development (Verilog or VHDL or other) and the development tools for particular vendor of the FPGA chips (Xilinx or Altera - most popular) and if possible - even your chosen FPGA development board that you will use.
But with the last one there is a chance that there exists some better and more attractive hardware (price/performance) then what is described in the books.

Hi Joe -- I've heard good things about the book "FPGA Prototyping with Verilog Examples" (http://amzn.to/d4gyRY) -- this uses the Xilinx Spartan-3 FPGA development board which is very affordable (unfortunately the book itself isn't cheap) -- Max

Thanks for the very constructive and informative comments everybody.
@DarXsaS, I think you've probably summed up in a couple of sentences what I've been trying to grasp from reading pages of blurb... thanks for that.
From whatís been said, it looks like my CPU (and itís just a personal project) would do a lot better being hosted in the FPGA world, and thereís no better motivator to do battle with a new technology than personal need, so, can anybody recommend a good book to start with (Iím old fashioned and still like a book in my hand to read)?

If this is a "just for fun" project, then by all means enjoy learning about FPGAs, how to design hardware in Verilog or VHDL, how to drive synthesis tools, etc. If, however, this is a commercial project, then it seems to me that you'd probably be better off buying an off-the-shelf 16-bit microcontroller, and spending your effort in porting your existing code to the new device. Either way - have fun!

There is an open source version of the Z80 for FPGA see www.opencores.org in the projects area as well as many more classic CPUs and goodies. As for the PicoBlaze this small cpu can be dropped multiple times into the same chip to essentially remove the stack swapping and realtime machine code headaches of PIC programming. As an ex-PIC user I never went back after discovering Xilinx FPGAs and the Free WebPack ISE development IDE. (Shameless plug ) However other vendors like Altera etc are probably just as good.

Hi Joe. Think of the FPGA chip as of a PCB that is full of all kind of basic and a bit more complex logic units (and, or, not, xor, triggers, lookup tables, sum etc.) - from a 10000 to about a half a million of them (depending on the FPGA chip).
Then add to this picture a matrix of connections between all of these blocks. All these connections in this matrix can be configured ("programmed") to be on or off (instead of using a soldering iron in a real PCB).
This is a very simplified picture, but I hope it gives the general impression...