Timing: 15 s (total 0:15)
I usually write software. Recently I have been playing with digital
circuits built in OCaml. Today I will show you a simple way to try it
yourself right away.
Timing: 25 s (total 0:40)
Hardcaml is a library developed by Jane Street. It is not HLS that turns
an OCaml program directly into hardware; you describe RTL structure with
OCaml functions. Today I will show how to try it without an FPGA.
Timing: 25 s (total 1:05)
First install opam and create an OCaml 5.3.0 environment. Then install
the required libraries and utop together. Installation takes time, so I
will not run it live; this is a recipe to take home and try later.
I do not pin the Docker image or exact library versions here. Some
environments may need additional build dependencies.
Timing: 20 s (total 1:25)
utop is OCaml's interactive REPL. We load the libraries so that the
circuit-building functions become available. From here on we use the
same utop session.
Timing: 55 s (total 2:20)
Create a 1-bit input signal called clock. reg_fb builds a register with
feedback. It is 5 bits wide and stores d + 1 at the next clock. Finally,
connect count to an output port to create the Circuit. The first fun
part is that calling OCaml functions creates a circuit. I only wrapped
long lines from the original log; the circuit definition is unchanged.
Timing: 35 s (total 2:55)
Hardcaml can generate Verilog. Here I omit the generated code with many
intermediate signals and show concise Verilog with the same behavior.
The 5-bit register updates on every rising clock edge. This example has
no reset or explicit initial value. The initial value of 0 in Cyclesim
does not guarantee the power-up value of this Verilog on real hardware.
Timing: 55 s (total 3:50)
Cyclesim.create builds a simulator, and Waveform.create records
waveforms as well. Each call to cycle advances one clock. out_port reads
the count output, Bits.to_int converts it to an integer, and we print
it. Because it is 5 bits, 31 is followed by 0. There is no need to
generate Verilog or start another simulator. The numeric output is
wrapped for projection.
Timing: 40 s (total 4:30)
Because the earlier loop also recorded the waveform, no re-simulation is
needed. The waveform is shown in hex and starts at 00. The values
printed earlier are outputs after advancing a clock, so they start at 1.
In this way we described, ran, and observed a circuit in the REPL. That
is today's introduction. The real utop output uses box-drawing
characters; this slide shows an ASCII redrawing to keep the repository
ASCII-only.
Timing: 30 s (total 5:00)
That is how I built and tested circuits with Hardcaml and had fun with
AI. Then I built a RISC-V CPU in Hardcaml and got Linux running. If you
are interested, please look at GitHub. Thank you.
The specifications and REPL output strings follow README.md in the
repository. When presenting, you may add a board photo or boot log if
needed, but keep this slide self-contained.