Tuesday, September 3, 2013

Simulation in the browser

tl;dr: The simulation on the beta site now works with regular browsers and not just Dartium, but please don't overuse it just yet :)

When I started to develop the simulation for PSHDL I always thought that it would be a really cool idea to be able to run it in the browser. The reason is simple: If you don't have to install anything, and can get a quick success within a few minutes (seconds), people would be more likely to take a closer second look. Especially when I was teaching the FPGA 101 lecture at the 29C3 last year, I noticed that there is a resilience towards downloading and installing gigabytes of tooling just to get started with a blinking LED on an FPGA.

As JavaScript is probably my second most hated language (directly following VHDL), I didn't want to write a dedicated code generator for JavaScript. As I was generating Dart, which has many advantages over JavaScript, I simply use the dart2js tool. So when you hit the simulate button the following actions are triggered:

  • PSHDL code parsing and validation
  • ExecutableModel generation (this is the byte code form for simulation)
  • Dart code is generated from the ExecutableModel
  • dart2js is invoked on the Dart code

When you hit the simulate button on a Dart enabled browser (Dartium), the first three steps, including the upload and download of the generated source takes about 34ms. But when you do the same in a regular browser it takes 3,5s. Most of that time is the time it takes for dart2js to generate the JavaScript code. This is awfully long, but right now out of my hand. I really don't want to a JavaScript output generator :) Maybe one day I will have the muse to do just that, but right now I won't.

While Dart has arbitrary precision integers, and so you can simulate any bit width PSHDL code, the generated JavaScript is limited to 32 bits :( I will work around this limitation somewhen in the near future, but for now that is how it is.

So if you want to get started with some blinking LEDs, head over to the beta editor and try this code:

module BlinkinLED{
  register uint<28> counter=counter+1;
  //Change the 21 until you are happy with the blinking frequency
  out bit led=counter{21};

Have fun!

No comments:

Post a Comment