Running the CHDL CPU Example
CHDL example 6, a simulated MIPS-esque CPU with a 5-stage pipeline running a Sieve of Eratosthenes program finally works. This example can be loaded and simulated and will surely provide an important test case for future modifications to CHDL. For those of you interested in seeing CHDL run for yourself, I will provide a (very) brief tutorial on building and running the examples.
Step 1: Getting CHDL
CHDL is hosted on github, which (among other things) means that it must be accessed using a git client, like so:
$ git clone git://github.com/cdkersey/chdl.git
Step 2: Building CHDL
Once you have downloaded CHDL, building it should just be a matter of running make in the root source directory. There are a lot of compilation units, so if you’re on a multicore machine don’t forget to use the -j option to speed up the build.
$ cd chdl $ make -j 8
Step 3: Building and Running the Examples
Once you have built the core CHDL library, you can build the examples in the examples/ directory.
$ cd examples $ make -j 8
Once this finishes, you will have a set of files called example[i].vcd, for i in 1 through 7. These are waveform files, containing the state of every node (or bit vector) tapped with the “TAP()” macro, and viewable in waveform viewers like the free gtkwave. If you do not have a waveform viewer installed, go ahead and obtain gtkwave.
$ sudo aptitude install gtkwave
If you’re not on Debian, and/or do not have aptitude installed, you’re beyond help.
Step 4: Viewing the Waveforms
The waveform files can then be viewed with gtkwave:
$ gtkwave example6.vcd
The TAP()s from the source code are listed along the left side of the window and can be dragged to the viewing area.
In the above figure, the fetch program counter is being viewed in “analog” mode, showing the path taken through the program memory over time. Note that after the program is finished executing, the processor enters a tight loop. The output of the program is the series of prime numbers in register 12 (a good test case because it’s a simple program whose results are hard to produce accidentally). Happy hacking!