Automatic Datapath Optimization using E-Graphs

Samuel Coward, George A. Constantinides, Theo Drane

Abstract

Hardware datapath optimization is a critical yet labor-intensive task in Register Transfer Level (RTL) design, often requiring manual intervention to overcome the limitations of standard synthesis tools. This paper presents an automated framework leveraging e-graphs and equality saturation to explore a vast space of equivalent circuit designs. By utilizing bitwidth-aware rewrite rules and Integer Linear Programming (ILP) for extraction, the proposed tool achieves significant area reductions—up to 71% on industrial kernels—while matching or exceeding the performance of manual expert optimizations. The results demonstrate that automated tools can effectively navigate the non-convex optimization landscapes of arithmetic circuits, identifying optimal architectures that vary based on data bitwidth.

Introduction

In hardware design, the Register Transfer Level (RTL) serves as the fundamental blueprint for data movement and processing within a chip. While modern synthesis tools are highly sophisticated, they frequently struggle with complex arithmetic datapaths—the segments of a circuit dedicated to mathematical and logical operations. To achieve peak performance and area efficiency, designers often resort to manual optimization, a process colloquially known as a "black art."

Researchers from Intel and Imperial College London have introduced a method to automate this process using a data structure known as an e-graph. By representing thousands of equivalent circuit designs simultaneously, this approach allows for the discovery of highly optimized architectures that standard tools often overlook.

The Challenge of Hardware Optimization

Standard logic synthesis tools excel at local optimizations but often fail to capture the "big picture" when arithmetic is intertwined with logic. Hardware optimization is notoriously non-convex; reaching a global optimum often requires applying a transformation that initially increases area or delay before a subsequent transformation yields a superior result. Human engineers use intuition to navigate these "valleys," whereas automated tools typically get stuck in local minima.

Furthermore, the optimal implementation of a circuit is often sensitive to bitwidth. For example, an 8-bit multiplier may be best implemented differently than a 32-bit one. Maintaining manual libraries for every possible bitwidth is impractical, leading to sub-optimal designs in generalized hardware libraries.

Methodology: Equality Saturation and E-Graphs

The researchers utilize Equality Saturation, powered by the egg (e-graphs good) library, to explore the design space without the need for destructive updates.

1. E-Graphs and Equivalence Classes

Unlike traditional expression trees, an e-graph represents a set of equivalent circuits. If $x + x$ is equivalent to $2 * x$, the e-graph stores both versions within the same "equivalence class." This allows the tool to maintain a massive pool of possibilities without prematurely choosing one over the other.

2. Bitwidth-Aware Rewrites

The framework employs a library of formal rewrite rules, including associativity, distributivity, and hardware-specific transforms like merging additions into "compressor trees." Crucially, these rules are conditional; they are only applied if specific bitwidth requirements are met, ensuring the validity of the hardware transformation.

3. Specialized Operators

To facilitate hardware-specific optimizations, the authors introduced specialized nodes:

  • SUM: Represents a multi-input addition tree.
  • MUXAR: Represents muxed multiplication arrays.

These operators allow the tool to recognize optimization opportunities that are not explicitly described in standard Verilog code.

4. ILP Extraction

Once the e-graph is "saturated"—meaning no further rules can be applied—the tool must select the single best circuit. This is achieved using Integer Linear Programming (ILP). The ILP solver selects the version of the circuit that minimizes a theoretical area cost model, accounting for shared components and common subexpressions to ensure the most efficient physical implementation.

Experimental Results

The tool was evaluated against several hardware-specific benchmarks, including an industrial Smoothing Kernel from Intel, FIR filters, and an ADPCM decoder.

Key Findings

  • Significant Area Savings: On the Smoothing Kernel, the tool achieved a 71% reduction in area compared to the unoptimized version. This result matched the manual optimization performed by a skilled engineer over the course of a week, but was completed in a fraction of the time.
  • Performance Gains: Although the primary objective was area optimization, the Smoothing Kernel also saw a 13% reduction in minimum achievable delay.
  • Architecture Shifts: The tool revealed that for a 4-tap FIR filter, the optimal architecture changes three times as the input bitwidth increases from 4 to 64 bits. This finding underscores the limitations of "one size fits all" manual designs.
  • Synthesis Noise Floor: By using "fuzzing" (making semantic-preserving changes like variable renaming), the researchers identified a ~5% area variation in standard synthesis tools. This "noise" justifies the use of a theoretical cost model to guide the e-graph optimizer toward truly superior designs.

Conclusion and Future Work

This research demonstrates that e-graphs and equality saturation can effectively automate the complex task of datapath optimization. By bypassing local minima and accounting for bitwidth-specific efficiencies, the tool matches expert-level manual design.

Future work aims to expand the extraction process to include multi-objective optimization (balancing area, delay, and power) and to extend the framework from combinational logic to sequential logic through techniques such as retiming. Additionally, addressing the exponential growth of e-graphs in very large designs remains a priority for scaling the technology to full-chip optimizations.

Summary updated

BibTeX
@inproceedings{coward2022automatic,
  author = {Samuel Coward and George A. Constantinides and Theo Drane},
  title = {{Automatic Datapath Optimization using E-Graphs}},
  booktitle = {ARITH},
  year = {2022},
  url = {https://openreview.net/forum?id=d3lm3wYFw3},
}
Figure