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?