An AI agent that tunes FPGA emulators, and rewrites the RTL when tuning runs out
FPGA emulators and prototypes are the slowest step in many SoC programmes. Every MHz lost in place and route means longer wall-clock time for every OS boot and test run. And every option the team never had time to try leaves performance unclaimed.
We built an agent that does this tuning work by itself, carefully and on real tools. We then let it go one step further: when configuration knobs stopped helping, it read the timing report and edited the CPU's Verilog. That doubled performance, and every patch was checked automatically for correctness.
How the agent works
The agent follows the same loop a good performance engineer does:
Measure a baseline before changing anything.
Form one hypothesis, grounded in mechanism. For example: "the critical path starts at the block-RAM output and runs through the load sign-extend logic, so moving that logic one stage later should raise Fmax".
Change one thing, rebuild, and measure over several place-and-route seeds.
Accept the change only if it beats the noise. Seeds alone move Fmax by a median 2.9% (up to 6% at the 90th percentile), so a change counts as an improvement only when it exceeds twice the standard error, and at least 1%.
Repeat within a budget, then write a report: what changed, why it worked, and what to try next.
Every number comes from a real build, and the agent cannot "win" by breaking the design. Each configuration runs a benchmark in cycle-accurate simulation, and a wrong checksum is a failed experiment.
The demo platform
We used a fully open-source flow so anyone can reproduce the results:
Design | PicoRV32 RISC-V (RV32IM) core in an emulation top with 16 KiB of on-chip RAM |
FPGA | Lattice ECP5-85F |
Tools | Yosys (synthesis), nextpnr (place & route), Icarus Verilog (cycle-accurate CPI) |
Workload | 3,008-instruction loop: shifts, ALU, multiply, load/store, branches |
Metric | MIPS = Fmax ÷ CPI, so clock speed and cycles per instruction are judged together |
The agent drives the platform through a small backend interface. The same agent can drive FireSim on AWS F2, AMD Vivado on a lab board, or a commercial emulator at a customer site.
Part 1: tuning the knobs
There are ten knobs: six RTL options (shifter, multiplier, ALU/compare staging, register file), two synthesis options, the router, and the clock target. To know the true answer, we first built every one of the 2,048 configurations, 3 seeds each (6,144 real builds).
Goal | Baseline | Agent's result | Experiments used | True optimum (exhaustive) |
Design performance (MIPS) | 11.4 | 17.4 (+52%) | 11 | 17.4 (+54%) |
Emulation speed (Fmax) | 86.7 MHz | no significant gain, as reported | 12 | 90.5 MHz (within seed noise) |
Build turnaround (seconds, Fmax ≥ 95% of baseline) | 9.4 s | 7.1 s (−25%) | 11 | 7.0 s (−24%) |
In 11 experiments, the agent reached the same MIPS as the best of all 2,048 configurations. Each run took about two minutes and about US$0.25 in model cost.

What it learned along the way:
The biggest lever was cycles, not clock speed. The DSP-based multiplier cut CPI from 7.59 to about 5.3, while Fmax actually dropped by about 6 MHz. MIPS rose anyway. Tuning for Fmax alone would have missed this.
Some knobs do nothing. Timing-driven ABC9 mapping and the clock-target setting gave identical results on this toolchain. The agent noticed and stopped spending budget on them.
Some knobs hurt. The alternative router cost about 9% of Fmax.
Knobs cannot move Fmax beyond the noise. On the emulation-speed goal, the agent honestly reported that no knob gives a significant gain. The exhaustive sweep confirms it: the "best" configuration is +5.5%, which is what you get by picking the luckiest of 2,048 noisy results.
Part 2: when knobs run out, fix the RTL
Next, we gave the agent the PicoRV32 source code. It got tools to read the Verilog, see the critical path (with RTL line numbers, straight from nextpnr), and apply small search-and-replace patches. It has no shell or file system access.
Every patch must pass a differential test before it is measured: random RV32IM programs run on the patched core and on the original core, across six parameter configurations, and the registers and memory must match bit for bit.
Fmax (MHz) | CPI | MIPS | LUT4 | |
Original PicoRV32 | 85.8 | 7.59 | 11.3 | 2,078 |
Best knob setting | 82.5 | 4.73 | 17.4 | 1,959 |
After the agent's RTL patch | 92.6 | 3.67 | 25.2 | 2,198 |
That is +123% over the original core, and +45% beyond the best possible knob setting. The run took 13 measured experiments, 17 minutes and about US$3.40 in model cost. A second, independent run (the Japanese-language demo) reached 24.5 MIPS (+117%) with a different patch, so the result is not a one-off. The agent used the critical path to drive each change, one at a time:

Replaced the 1-bit-per-cycle multiplier with DSP partial products (CPI 7.59 → 5.60).
Made the shifter single-cycle (CPI → 5.00).
Moved load byte-select and sign-extend off the block-RAM output path and into write-back (Fmax 81 → 91 MHz).
Captured load data in its own register, removing the RAM output from a wide mux (Fmax → 94.5 MHz).
Shortened the multiplier handshake (CPI → 4.73).
Issued the next-instruction fetch one stage earlier, so it completes during execute (CPI → 4.00).
Let the shift state consume that early fetch too (CPI → 3.80).
Removed a data mux from the RAM → opcode-decode path, and added static backward-taken branch prediction for loops (CPI → 3.67).

The agent's own report was careful about what it could prove. It noted that changes 7 and 8 together were within noise of change 6 alone, and kept them because CPI dropped deterministically with no Fmax loss. It also listed two ideas it tried and rejected.
How we checked the patch
A model that edits RTL needs more than "the tests passed". After the run, we stress-tested the final patch beyond what the agent saw:
4,800 differential tests, 0 failures: 24 parameter configurations (including compressed ISA, IRQs, divide, misalignment/illegal-instruction traps and counters, none of which the agent was tested on) × 200 random programs with forward branches and backward loops, half of them with random memory wait states.
Mutation check of the tests themselves. We planted two bugs in the patched core (a wrong ALU subtract and an inverted branch-mispredict check). Both were caught in every affected configuration.
The second run's patch went through the same 4,800-test campaign. This is strong simulation evidence, but not a formal proof. Before proposing the change upstream, we would run the official RISC-V compliance tests and formal verification (riscv-formal) on it. We would also split out changes 1–2: they overlap with PicoRV32's existing fast-multiplier and barrel-shifter options, which exist precisely to keep the default core small.
Why an agent, and not just a sweep?
Our demo design builds in seconds, so a brute-force sweep was affordable here. A real SoC emulator build takes hours, and its option space is far too large to enumerate. The second half of this demo, rewriting RTL, has no finite option space at all. The agent:
reasons from the timing report, so it spends its budget only on changes that can help;
respects trade-offs, and rejects a higher clock that costs more in CPI;
treats noise statistically instead of chasing lucky seeds;
explains every decision and produces a reviewable diff.
How it is built
Claude (Anthropic) through the Claude Agent SDK is the reasoning engine.
The agent can call only purpose-built tools (describe target, run experiment, read RTL, critical path, edit-and-measure, finish). Shell, file and web access are all switched off. Knob values and patches are checked before anything runs, and patches cannot add simulator system tasks.
Every measurement goes into an append-only results store. The demo site replays these recorded runs, and its live mode lets Claude reason in real time over the recorded builds.
Working with us
Whileone Techsoft builds performance-engineering tooling and services for silicon, systems and software teams: emulation and prototyping, simulator calibration, benchmarking and compilers. If your emulator boots too slowly, your prototype misses its clock target, or your team needs design-space answers faster, we can point this agent at your flow, your RTL and your platform.
Get in touch: rgadgil@whileone.in





Comments