---
title: "Advent of Hardcaml"
description: "Several Advent of Code 2024 puzzles were solved entirely on a small Lattice ECP5 FPGA (84K LUTs, 4 Mbits RAM) using Hardcaml, Jane Street's OCaml-embedded HDL, with the open-source Yosys + NextPNR toolchain."
url: "https://swe.quest/articles/advent-of-hardcaml-7a69fcd00d2b9f17"
canonical: "https://blog.janestreet.com/advent-of-hardcaml-2024/"
source: "Jane Street Tech Blog"
published: "2025-03-22"
difficulty: "hard"
kind: "Case study"
reading_minutes: 8
tags: ["hardware","functional-programming","algorithms"]
---

# Advent of Hardcaml

A post on [Jane Street Tech Blog](https://swe.quest/sources/jane-street.md), published 2025-03-22, 8 min read, Case study. Original: [https://blog.janestreet.com/advent-of-hardcaml-2024/](https://blog.janestreet.com/advent-of-hardcaml-2024/)

## Summary

Several Advent of Code 2024 puzzles were solved entirely on a small Lattice ECP5 FPGA (84K LUTs, 4 Mbits RAM) using Hardcaml, Jane Street's OCaml-embedded HDL, with the open-source Yosys + NextPNR toolchain. Day 4's word search becomes a convolution over a shift register holding the last four grid rows, with a higher-order function generating sliding windows of any dimensions. Day 7's operator search becomes a deep pipeline that evaluates one operator combination per clock cycle, testing hundreds of millions of combinations in seconds. OCaml's type system, functors and metaprogramming make unrolled, parametrized hardware concise and reusable, and the post closes by challenging other HDL communities to solve Advent of Code puzzles too.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Functional programming](https://swe.quest/tags/functional-programming.md) (Languages)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)

## Prerequisites

- FPGA and RTL basics
- OCaml ([easy posts on Functional programming](https://swe.quest/tags/functional-programming.md?difficulty=easy))
- hardware pipelining ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

Hardcaml, OCaml, Advent of Code, Lattice ECP5, Yosys, NextPNR, FPGA

## Related posts

- [Fun with Algebraic Effects - from Toy Examples to Hardcaml Simulations](https://swe.quest/articles/fun-with-algebraic-effects-from-toy-examples-to-hardcaml-simulations-5f2853fd03f84a3a.md): Jane Street Tech Blog · 2026-01-06 · Hard · 17 min read · Functional programming, Language design, Concurrency, Testing
  Algebraic effects in OCaml 5/OxCaml can replace monads for most uses, and Jane Street ported Hardcaml\_step\_testbench from a monadic API to effects.
- [Accelerating zk-SNARKs - MSM and NTT algorithms on FPGAs with Hardcaml](https://swe.quest/articles/accelerating-zk-snarks-msm-and-ntt-algorithms-on-fpgas-with-hardcaml-e0e40be298934874.md): Jane Street Tech Blog · 2022-12-07 · Hard · 8 min read · Hardware, Cryptography, Algorithms, Performance engineering, Functional programming
  A Hardcaml-built FPGA implementation of Pippenger's algorithm for multi-scalar multiplication on the BLS12-377 curve won first place in the ZPrize MSM track, computing a 2^26-point MSM in about 5.08s on an AWS f1.2xlarge at 52W.
- [What the interns have wrought, 2022 edition](https://swe.quest/articles/what-the-interns-have-wrought-2022-edition-0f4dcf7e53f3e8d4.md): Jane Street Tech Blog · 2022-08-25 · Medium · 8 min read · Functional programming, Testing, Performance engineering, Developer tools, Engineering culture
  Three Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%.
- [What the interns have wrought, 2023 edition](https://swe.quest/articles/what-the-interns-have-wrought-2023-edition-f070c30cff9e3c3e.md): Jane Street Tech Blog · 2023-09-12 · Medium · 9 min read · Functional programming, Observability, Developer tools, LLMs, Concurrency
  Three Jane Street intern projects, all in OCaml. The first is an SQL-like temporal query language, parsed with Angstrom and compiled onto a Linear Temporal Logic engine, for finding event sequences in Concord's transaction stream.
- [Writing a DSL for high performance parallel programming in OxCaml](https://swe.quest/articles/writing-a-dsl-for-high-performance-parallel-programming-in-oxcaml-5f7bd51c2038a2c3.md): Jane Street Tech Blog · 2026-11-06 · Hard · 17 min read · Compilers, Functional programming, Language design, Performance engineering, Hardware
  A Jane Street intern built a JIT compiler for an SPMD-style DSL in OxCaml so SIMD kernels for options pricing and risk checks can be written once as ordinary-looking OxCaml functions instead of architecture-specific C intrinsics.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
