pouët.net

Go to bottom

Pre-processor for a hardware description language?

category: general [glöplog]
 
Hey all,

I'm having a little project at my university where we are looking into improving a hardware description language called Gezel. The compiler outputs VHDL code which can then by synthesized to run on a FPGA. It is easier to get started with than VHDL, so we use it as an introduction to hardware hacking in our embedded systems course.

However, the language is not really "done" yet, and there are some design flaws, but it is nice for what it is.

So, one of the improvements that I have been thinking about has been a code generation preprocessor. I was designing a chip for 1x1 matrix convolution*. I had to hard-code it to process 8 cells every other cycle, but I would really have liked to be able to use preprocessor to make generalized code for an arbitrary number of cells instead.
For example, I used an internal memory bandwidth of 64-bit to be able to read 8 cells of 8 bit every cycle. After processing these cells individually, I had to concatenate them into a single register like this:

Code:var = p0 | p1 << 8 | p2 << 16 | p3 << 24 | p4 << 32 | p5 << 40 | p6 << 48 | p7 << 56;


So, I would like to be able to write something like this instead:

Code:.for i = 0 to CELLS_PER_CYCLE - 1 prefix "i = " seperator " | " suffix ";" p'i' << 'i*8' .rof


In order to output:
Code:i = p0 << 0| p1 << 8 | p2 << 16 | p3 << 24 | p4 << 32 | p5 << 40 | p6 << 48 | p7 << 56 ;


The problem is that there are no for-loops. All registers and signals can only be written once per. cycle, so making a variable width loop is impossible.

So, can anyone suggest me a solution which can save me the hassle of writing my own pre-processor? While it is not a necessity to use this tool to get through the course, it would be a nice option to have. It has to be fairly straight-forward to use, and necesarrily super advanced.

Thanks.

*: Basically for(i = 0; i < size; i++) dst[i] += src[i] * weight;
What about GNU M4? It might do what you want (but it was year since I used it)

Also, perl, python and php (or any other "scripting language") might help you out there. PHP has the advantage that you explicitely start a code section and everything else is output verbatim. (And yes, there is a standalone commandline version of php)
added on the 2009-01-08 15:33:42 by Joghurt Joghurt
An example. I've taken a random python template engine (Cheetah) and implemented your example:
Code: i = #echo '|'.join(['p%i << %i' % (i, i*8) for i in range(10)]) ;

the result:
Code:i = p0 << 0|p1 << 8|p2 << 16|p3 << 24|p4 << 32|p5 << 40|p6 << 48|p7 << 56|p8 << 64|p9 << 72 ;

added on the 2009-01-08 15:46:57 by Joghurt Joghurt
Of course, you can also write the template in a different way, for example, by using #for (in cheetah). I guess what I'm trying to say is: choose your favorite high-level language and your favorite templating system for this language, and use this as a preprocessor.
added on the 2009-01-08 15:52:25 by Joghurt Joghurt
Ah, of course, template engines. I'll look into some to see if I can find one that is right for our needs. Thanks :)

login

Go to top