<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: davis</title>
    <description>The latest articles on DEV Community by davis (@changchinjung).</description>
    <link>https://dev.to/changchinjung</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4258219%2Fc6f49f65-712b-4da1-88bb-0b16bca606c9.png</url>
      <title>DEV Community: davis</title>
      <link>https://dev.to/changchinjung</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/changchinjung"/>
    <language>en</language>
    <item>
      <title>Pipelining raised Fmax 62% but made latency worse</title>
      <dc:creator>davis</dc:creator>
      <pubDate>Sun, 22 Nov 2026 04:06:56 +0000</pubDate>
      <link>https://dev.to/changchinjung/pipelining-raised-fmax-62-but-made-latency-worse-4l1l</link>
      <guid>https://dev.to/changchinjung/pipelining-raised-fmax-62-but-made-latency-worse-4l1l</guid>
      <description>&lt;p&gt;A short case study from an FPGA limit order book prototype. All numbers are post-route estimates from Yosys + nextpnr on a Lattice ECP5 (LFE5U-85F), not vendor sign-off.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap: Fmax is a proxy, not a goal
&lt;/h2&gt;

&lt;p&gt;I kept optimizing for Fmax because that was the number in my acceptance criteria. Then I computed the actual latency:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Stages&lt;/th&gt;
&lt;th&gt;Fmax&lt;/th&gt;
&lt;th&gt;Latency&lt;/th&gt;
&lt;th&gt;Throughput&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Single-stage&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;95.65 MHz&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;10.45 ns&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;95.7 M/s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Two-stage&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;154.58 MHz&lt;/td&gt;
&lt;td&gt;12.94 ns&lt;/td&gt;
&lt;td&gt;77.3 M/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Three-stage&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;155.86 MHz&lt;/td&gt;
&lt;td&gt;19.25 ns&lt;/td&gt;
&lt;td&gt;51.9 M/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Frequency went up 62%. Latency and throughput both got worse.&lt;/p&gt;

&lt;p&gt;The reason is simple arithmetic: latency = stages x period. Splitting the logic shortened the critical path by 1.6x, but the cycle count doubled. 2 / 154.58 MHz = 12.94 ns, which is worse than 1 / 95.65 MHz = 10.45 ns.&lt;/p&gt;

&lt;p&gt;Placement seeds varied by only a few MHz (95.82 / 91.75 / 93.43), so this is logic depth, not placement luck.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do instead
&lt;/h2&gt;

&lt;p&gt;Split only if every stage shrinks by more than the stage count grows. Otherwise you are trading latency for a number that does not matter.&lt;/p&gt;

&lt;p&gt;The three-stage version was especially instructive: after splitting the 16-bit adder into two 8-bit halves, the critical path report showed 3.1 ns of logic and 3.3 ns of routing. On this device the bottleneck had moved from logic to wires.&lt;/p&gt;

&lt;h2&gt;
  
  
  Second finding: O(log N) is not free
&lt;/h2&gt;

&lt;p&gt;To reach 1,024 price levels I tried an occupancy bitmap with priority encoding.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Fmax&lt;/th&gt;
&lt;th&gt;LUT4&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Linear scan (64-way + 16-way chains)&lt;/td&gt;
&lt;td&gt;66.49 MHz&lt;/td&gt;
&lt;td&gt;4,490&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tree (4-4-4)&lt;/td&gt;
&lt;td&gt;81.45 MHz&lt;/td&gt;
&lt;td&gt;4,510&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Only 22% faster. The critical path moved to the wide mux that selects one word out of 64, not the scan itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Third finding: an asynchronous read kills BRAM inference
&lt;/h2&gt;

&lt;p&gt;Moving the 1,024 x 16 quantity array to block RAM looked obvious. It did not work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wire cur_q = bid_q[cmd_level];  // asynchronous read for read-modify-write
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the read has to be combinational, synthesis could not infer BRAM. The array became 32,768 flip-flops plus write decoders and read muxes: 102k LUT4, 122% of the device, and place-and-route did not finish in 20 minutes.&lt;/p&gt;

&lt;p&gt;The fix is architectural: split command processing into S1 (issue the memory read), S2 (compute), S3 (write back). That is the pipeline the spec asked for from the beginning.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this project is (and is not)
&lt;/h2&gt;

&lt;p&gt;It is a level-indexed price ladder with best bid/ask, a Python reference model, invariants in the testbench, and a mutation-testing script. 30 mutants, 100% score after fixing two real gaps in the tests.&lt;/p&gt;

&lt;p&gt;It is not a trading system: no per-order FIFO, no queue position, no feed parsing.&lt;/p&gt;

&lt;p&gt;The verification part was more interesting than the RTL. Two mutants survived during development, and both pointed at holes in the tests, not the design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Removing the &lt;code&gt;cmd_valid&lt;/code&gt; gate changed nothing, because the testbench had never issued an idle cycle.&lt;/li&gt;
&lt;li&gt;An 8-bit truncation on the ask side survived, because the ask side had never been tested with large quantities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mutation testing is the only technique I have found that measures whether tests have teeth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Repository: &lt;a href="https://github.com/chang-chinjung/fpga-order-book" rel="noopener noreferrer"&gt;https://github.com/chang-chinjung/fpga-order-book&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Longer write-up: &lt;a href="https://github.com/chang-chinjung/fpga-order-book/blob/main/docs/ARTICLE_EN.md" rel="noopener noreferrer"&gt;https://github.com/chang-chinjung/fpga-order-book/blob/main/docs/ARTICLE_EN.md&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have done timing closure on small ECP5 designs and disagree with the routing numbers, I would like to hear it.&lt;/p&gt;

</description>
      <category>fpga</category>
      <category>verilog</category>
      <category>hardware</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
