| name | rtl-opt |
| description | Critical path patterns with corresponding optimization strategies. Use this when users request optimize the RTL code based on the timing analysis results. |
| license | Complete terms in LICENSE.txt |
High-Confidence Strategies (>80% success)
1. One-Hot Pre-Decode for Control Signals
- Applies to: FSM-heavy designs with opcode/state signals that fan out to multiple comparisons
- Strategy: Pre-decode multi-bit control signals into one-hot signals (e.g.,
op_is_add, op_is_sub, state_is_idle) computed once and reused
- Expected improvement: WNS +5-15%, TNS +5-20%
- Area impact: Neutral to +3%
- Risk: Low
- Evidence: cpu_fsm.v0.2 (promoted), SPI.v0.5 (SEC pass), UART.v0.4 (promoted), DSP.v0.4 (SEC pass)
- Key insight: Reduces fanout loading and eliminates redundant parallel comparisons. Works especially well when same condition is checked in multiple places.
2. Condition Pre-Computation with Wire Extraction
- Applies to: Counter logic, FSM-controlled datapath, nested conditionals
- Strategy: Extract repeated comparisons to named wires (e.g.,
count_is_max, state_is_active), compute once, reuse across always blocks
- Expected improvement: WNS +0-10%, TNS +2-15%
- Area impact: Neutral to +2%
- Risk: Low
- Evidence: UART.v0.4 (promoted), SPI.v0.5 (SEC pass, WNS -0.26 to -0.23), cpu_fsm.v0.2 (promoted)
- Key insight: Conservative approach with very high SEC pass rate. Synthesis can share comparators. Original control flow preserved exactly.
3. Register Duplication for Signal Fanout Reduction
- Applies to: Control signals (soft_reset, enable) with high fanout across multiple modules
- Strategy: Duplicate high-fanout signals with local registered copies in consuming modules
- Expected improvement: WNS +5-10%, TNS +10-15%
- Area impact: +2-5%
- Risk: Low (adds 1 cycle latency to signal path)
- Evidence: router.v0.2 (promoted, WNS -0.52 to -0.47, TNS -290 to -263)
- Key insight: Breaks timing paths by adding local registers. Must verify that added latency is acceptable for design behavior.
4. FSM Output Registration
- Applies to: FSM with multiple output signals driving downstream combinational logic
- Strategy: Register FSM output signals to break timing paths from state register to downstream registers
- Expected improvement: WNS +5-10%, TNS +10-20%
- Area impact: +3-5%
- Risk: Low (adds 1 cycle latency)
- Evidence: router.v0.2 (promoted), router.v2.7 (promoted, score -0.1291)
- Key insight: Standard retiming technique. Effective when FSM outputs fan out to multiple datapath elements.
5. Input Signal Registration (Pipelining)
- Applies to: Signals crossing module boundaries with long combinational paths
- Strategy: Register input signals at module boundary to balance timing
- Expected improvement: WNS +5-15%, TNS +10-20%
- Area impact: +2-5%
- Risk: Low (predictable latency change)
- Evidence: router.v0.2 (promoted), router.v2.7 (promoted), SPI.v0.5 (SEC pass)
- Key insight: Most effective at module boundaries where control signals enter computation. SEC-safe when applied consistently.
Medium-Confidence Strategies (50-80% success)
6. Late Mux-Select with Unconditional Computation
- Applies to: Arithmetic paths gated by control signals (e.g.,
full, enable)
- Strategy: Compute both branches unconditionally (e.g.,
ptr+1, ptr+2), then select with late mux
- Expected improvement: WNS +5-15%, TNS +10-20%
- Area impact: +5-15% (duplicated computation)
- Risk: Medium (must verify all paths compute valid results)
- Evidence: FIFO.v1.2 (score -0.142), vending_machine.v0.5 (promoted, WNS -0.27 to -0.09)
- Key insight: Removes control signal from arithmetic critical path. Control signal now only drives final 2:1 mux.
7. Mux-Before-Adder Restructuring
- Applies to: Paths with
sel?(A+B):(C+D) structure
- Strategy: Restructure to
(sel?A:C)+(sel?B:D) - move mux before adder
- Expected improvement: WNS +30-60%, TNS +40-50%, Area -20-35%
- Area impact: Negative (fewer adders)
- Risk: Medium (must verify logical equivalence)
- Evidence: vending_machine.v0.2 (33% area reduction), vending_machine.v0.5 (promoted, combined with one-hot FSM)
- Key insight: Eliminates one adder from critical path while reducing area. Powerful when both paths require addition.
8. Hierarchical Case Decomposition (Lookup Tables)
- Applies to: Large case statements (>64 entries), encoder/decoder tables
- Strategy: Split monolithic case into smaller hierarchical sub-cases (e.g., 8b/10b: 5b->6b + 3b->4b)
- Expected improvement: WNS +30-40%, TNS +20-30%
- Area impact: -30-45% (smaller lookup tables)
- Risk: Medium (requires careful functional verification)
- Evidence: pcie.v0.9 (promoted, WNS -0.79 to -0.48, area -42%)
- Key insight: Reduces mux depth from O(log N) to O(log sqrt(N)) by exploiting hierarchical structure. Best for standard encodings.
9. Logic Tree Balancing in GF Arithmetic
- Applies to: Galois Field operations (AES S-box, error correction)
- Strategy: Restructure serial XOR/AND chains into balanced tree structure with explicit depth management
- Expected improvement: WNS +5-15%
- Area impact: Neutral to +5%
- Risk: Medium (complex transformations)
- Evidence: datapath.v0.4 (SEC pass), datapath.v3.4 (promoted, WNS -0.88 to -0.84)
- Key insight: Pre-compute all bit-level XORs in parallel at depth 1, combine in balanced tree. Requires careful analysis of dependencies.
10. Common Subexpression Elimination (CSE)
- Applies to: Designs with repeated arithmetic/comparison expressions
- Strategy: Extract shared subexpressions to named wires, compute once
- Expected improvement: WNS +2-10%, TNS +5-15%
- Area impact: Neutral to -5%
- Risk: Medium
- Evidence: SPI.v0.5 (SEC pass), cpu_fsm.v0.2 (promoted), datapath.v0.4 (SEC pass)
- Key insight: Synthesis often does CSE automatically, but explicit extraction can guide optimization. Most effective for redundant comparisons.
11. One-Hot FSM Encoding with Direct Bit Equations
- Applies to: FSM with 4+ states using binary encoding
- Strategy: Convert to one-hot encoding with direct AND-OR equations for next-state logic
- Expected improvement: WNS +30-60%, TNS +30-50%
- Area impact: Variable (-30% to +100% depending on state count)
- Risk: Medium (encoding change may fail SEC if not done carefully)
- Evidence: vending_machine.v0.3 (WNS -0.27 to -0.09, but area doubled), vending_machine.v0.5 (promoted with balanced area), ticket_machine.v0.8 (promoted)
- Key insight: Eliminates case statement decode depth. Best combined with mux restructuring to control area. May require careful output logic restructuring.
Low-Confidence / Risky (use with caution)
12. Parallel Evaluation with Logic Flattening
- Applies to: Priority-encoded if-else chains in FSM
- Strategy: Replace if-else priority chain with parallel AND-OR equations
- Expected improvement: WNS +30-40% when successful
- Area impact: Variable
- Risk: High (frequently fails SEC due to subtle priority differences)
- Evidence: ticket_machine.v0.1 (SEC FAILED despite 39% WNS improvement)
- Key insight: Priority semantics may be lost in transformation. If-else and case statements may not be functionally equivalent to AND-OR. Use only when priority is not required.
13. Count-Down Counter Restructuring
- Applies to: Counters with comparison to parameter (e.g.,
count == MAX_COUNT)
- Strategy: Convert count-up with comparison to count-down with zero-detect
- Expected improvement: Potentially significant (removes wide comparator)
- Area impact: Neutral
- Risk: High (changes counting behavior, frequently fails SEC)
- Evidence: UART.v0.1 (SEC FAILED), UART.v0.3 (SEC FAILED)
- Key insight: Zero-detect is simpler than N-bit equality, but behavior changes from counting 0->N to N->0. This changes when terminal count occurs relative to reload, often breaking equivalence.
14. Explicit Intermediate Wire Decomposition
- Applies to: Deeply nested expressions, cascaded multipliers
- Strategy: Decompose nested expressions into named intermediate wires for synthesis guidance
- Expected improvement: WNS +2-5%
- Area impact: Neutral
- Risk: Medium (depends heavily on synthesis tool behavior)
- Evidence: LSTM.v0.8 (SEC pass but minimal improvement), LSTM.v0.2 (score -0.108)
- Key insight: Conservative approach that rarely hurts but may not help. Synthesis may ignore wire decomposition. Most effective for very deep combinational chains.
15. Aggressive Mux Tree Restructuring
- Applies to: Wide 4:1 muxes, unbalanced mux trees
- Strategy: Convert flat 4:1 mux to balanced 2-level 2:1 mux tree
- Expected improvement: WNS +5-10%
- Area impact: +5-10%
- Risk: Medium (synthesis may undo restructuring)
- Evidence: DSP.v0.4 (SEC pass, score 0.020 - modest improvement)
- Key insight: Modern synthesis tools are good at mux optimization. Explicit restructuring may conflict with synthesis decisions.
Anti-Patterns (avoid)
A1. Changing Counter Direction (Count-Up to Count-Down)
- Problem: Changes when terminal count is generated relative to counter operations
- Evidence: UART.v0.1, UART.v0.3 (both SEC FAILED)
- Recommendation: Keep original counter direction. Instead, use pre-computed comparison wires.
A2. Aggressive Priority Chain Flattening
- Problem: If-else priority semantics may be lost when converted to parallel AND-OR
- Evidence: ticket_machine.v0.1 (SEC FAILED despite timing improvement)
- Recommendation: Preserve if-else structure when inputs can be active simultaneously. Only flatten when mutual exclusion is guaranteed.
A3. Pre-Registering Selector Signals in Mux Paths
- Problem: Adds latency to control path, changing when mux selection occurs
- Evidence: vending_machine.v0.4 (SEC FAILED - pre-registering sel caused latency change)
- Recommendation: Keep selector signals combinational. Register datapath signals instead.
A4. Modifying Memory Array Addressing
- Problem: Inherent fanout in memory address decode cannot be optimized without architectural changes
- Evidence: cpu_fsm (paths 2, 7 skipped as out-of-scope)
- Recommendation: Accept memory paths as fixed. Focus optimization on surrounding logic.
A5. Optimizing Register Self-Loop Paths
- Problem: Timing reports showing reg->reg paths are clock-to-Q + setup constraints, not logic paths
- Evidence: DSP (paths 7-10 skipped - register self-loop constraints)
- Recommendation: Ignore these paths in optimization. They require clock tree optimization, not RTL changes.
A6. Changing LFSR Feedback Structure
- Problem: LFSR polynomials are mathematically defined; structural changes break function
- Evidence: pcie (paths 3, 4 skipped - LFSR feedback paths)
- Recommendation: Accept LFSR timing as fixed. Optimize surrounding scrambler/descrambler logic instead.
Path Type to Strategy Mapping
| Path Characteristic | Recommended Strategy | Confidence |
|---|
| FSM state decode to output | One-hot pre-decode (#1), FSM output registration (#4) | High |
| Counter with comparison | Condition pre-computation (#2), wire extraction | High |
| High-fanout control signal | Register duplication (#3), input registration (#5) | High |
| Arithmetic gated by control | Late mux-select (#6), mux-before-adder (#7) | Medium |
| Large case/lookup table | Hierarchical decomposition (#8) | Medium |
| GF/crypto arithmetic | Logic tree balancing (#9), CSE (#10) | Medium |
| Binary-encoded FSM | One-hot encoding (#11) - with caution | Medium |
| Deeply nested ternary | Wire decomposition (#14) - modest benefit | Low |
| Priority-encoded chain | AVOID parallel flattening | Anti-pattern |
| Memory array paths | SKIP - out of scope | N/A |
Strategy Success by Design Type
| Design Type | Best Strategies | SEC Pass Rate |
|---|
| FSM-heavy (ticket_machine, vending_machine) | One-hot (#1, #11), mux-before-adder (#7) | 60% |
| Communication (UART, SPI, router) | Input registration (#5), FSM output reg (#4), condition pre-compute (#2) | 70% |
| Pipeline (router, FIFO) | Register duplication (#3), input registration (#5) | 80% |
| Datapath (DSP, LSTM, datapath) | Tree balancing (#9), CSE (#10), wire decomposition (#14) | 65% |
| Encoder/Decoder (pcie) | Hierarchical decomposition (#8) | 85% |
| Controller (cpu_fsm, controller) | One-hot pre-decode (#1), condition pre-compute (#2) | 90% |
Statistics
| Strategy | Attempts | Successes | Rate | Avg WNS Improvement |
|---|
| One-hot pre-decode | 12 | 11 | 92% | +8% |
| Condition pre-computation | 18 | 16 | 89% | +5% |
| Register duplication | 8 | 7 | 88% | +7% |
| FSM output registration | 10 | 9 | 90% | +8% |
| Input signal registration | 14 | 12 | 86% | +10% |
| Late mux-select | 6 | 4 | 67% | +12% |
| Mux-before-adder | 4 | 3 | 75% | +40% |
| Hierarchical decomposition | 5 | 4 | 80% | +35% |
| Logic tree balancing | 8 | 5 | 63% | +6% |
| CSE | 10 | 7 | 70% | +4% |
| One-hot FSM encoding | 8 | 5 | 63% | +35% |
| Parallel logic flattening | 6 | 2 | 33% | +35% (when successful) |
| Count direction change | 4 | 0 | 0% | N/A |
| Wire decomposition | 12 | 10 | 83% | +3% |
Design-Specific Observations
High-Success Designs (>70% SEC pass across iterations)
- cpu_fsm: 47/50 SEC pass (94%). Responds well to one-hot pre-decode, register file indexing optimization.
- FIFO: 48/50 SEC pass (96%). Pipeline-friendly; late mux-select and input registration work well.
- pcie: 48/50 SEC pass (96%). Hierarchical decoder decomposition highly effective.
- SPI: 49/50 SEC pass (98%). Conservative optimizations most successful.
- datapath: 45/50 SEC pass (90%). GF arithmetic tree balancing effective.
Medium-Success Designs (50-70% SEC pass)
- vending_machine: 38/50 SEC pass (76%). One-hot FSM works but area-sensitive.
- router: 35/50 SEC pass (70%). Sequential optimizations work; combinational changes risky.
- DSP: 37/50 SEC pass (74%). Multiplier-limited; mux restructuring helpful for non-multiplier paths.
- LSTM: 28/50 SEC pass (56%). Very deep combinational paths; conservative approaches needed.
Low-Success Designs (<50% SEC pass)
- UART: 24/50 SEC pass (48%). Counter logic very sensitive to restructuring.
- ticket_machine: 25/50 SEC pass (50%). FSM encoding changes frequently fail.
- simple_spi: 5/13 SEC pass (38%). Design appears highly optimized; aggressive changes cause synthesis failures.
- cpu_pipe: 22/50 SEC pass (44%). Complex pipeline timing; many SEC failures.
Lessons Learned
-
Conservative wins over aggressive: High SEC pass rate more important than large improvements. A 5% improvement that passes SEC beats a 30% improvement that fails.
-
Sequential optimizations are safer: Adding registers (strategies #3, #4, #5) rarely break SEC. Combinational restructuring is higher risk.
-
Pre-computation beats restructuring: Extracting conditions to wires (#1, #2) is safer than restructuring logic (#7, #11, #12).
-
Design complexity matters: Simple designs (FIFO, SPI) tolerate more aggressive optimization. Complex designs (LSTM, cpu_pipe) need conservative approaches.
-
Module-focused optimization works: Targeting specific modules (pcie decoder, datapath sBox) more successful than whole-design changes.
-
Diversity strategy helps discovery: Different path selection (endpoint clustering, high fanout, module-focused) finds different optimization opportunities.
-
Baseline sensitivity varies: Some designs (simple_spi) are already highly optimized; aggressive changes cause synthesis failures rather than SEC failures.
Recommended Workflow
- Start with low-risk strategies (#1, #2, #3, #4, #5) - high SEC pass rate
- Measure improvement before trying higher-risk strategies
- Module-focus when design has clear timing bottleneck
- Avoid anti-patterns - counter direction, priority flattening, selector registration
- Accept architectural limits - multipliers, memories, LFSRs
- Combine strategies when individual strategies plateau (e.g., one-hot + mux-before-adder)
RTL Optimization Skill Summary
This file merges and normalizes the uploaded skill libraries into one comprehensive reference. It organizes the skills into High-confidence, Medium-confidence, Low-confidence, and Do not use. Each skill is written in the format:
<pattern, strategy, example>
For every example, both before and after Verilog snippets are included.
High-confidence
1. <repeated comparisons / repeated control checks, pre-compute shared condition wires and reuse them, example>
2. <shared sub-conditions reused in multiple branches, build hierarchical shared condition wires before final checks, example>
3. <FSM / opcode / instruction decode used in many places, one-hot pre-decode encoded values before downstream logic, example>
4. <one-hot or bit-encoded state with direct bit meaning, replace full equality with direct bit indexing, example>
5. <repeated arithmetic / repeated partial products / repeated shared expressions, common subexpression elimination to a named wire, example>
6. <shared arithmetic across module instances, hoist common subexpression upward and fan out result, example>
- Pattern: identical intermediate arithmetic is recomputed in sibling instances or branches.
- Strategy: move the common computation to the parent or earlier stage and distribute the shared result.
- Example:
// BEFORE
child0 u0(.prod_in(a * b), .c(c0));
child1 u1(.prod_in(a * b), .c(c1));
// AFTER
wire [W-1:0] shared_mul = a * b;
child0 u0(.prod_in(shared_mul), .c(c0));
child1 u1(.prod_in(shared_mul), .c(c1));
7. <high-fanout control or registered signals, duplicate register/signal copies and split fanout cones, example>
8. <high-fanout combinational condition wire, replicate equivalent local wires for separate consumers, example>
9. <wide adder / deep carry chain, carry-select style split into blocks, example>
- Pattern: ripple-carry dominated arithmetic path, especially wide adders.
- Strategy: split into blocks, precompute upper block for carry-in 0/1, then select.
- Example:
// BEFORE
wire [31:0] sum = a + b;
// AFTER
wire [15:0] sum_lo = a[15:0] + b[15:0];
wire carry_lo = ({1'b0, a[15:0]} + {1'b0, b[15:0]})[16];
wire [15:0] sum_hi_c0 = a[31:16] + b[31:16];
wire [15:0] sum_hi_c1 = a[31:16] + b[31:16] + 1'b1;
wire [15:0] sum_hi = carry_lo ? sum_hi_c1 : sum_hi_c0;
wire [31:0] sum = {sum_hi, sum_lo};
10. <counter decrement / borrow chain with predictable structure, pre-compute borrow or lookahead-style signals, example>
11. <simple compare against power-of-two threshold / one-hot boundary, simplify wide comparison into bit-select or MSB check, example>
12. <FSM outputs driving long downstream logic, register or pipeline the boundary signal when extra latency is architecturally acceptable, example>
Medium-confidence
13. <nested ternary / nested mux / branch-dependent data path, compute candidate branch values in parallel and select late, example>
14. <arithmetic gated by control, compute both arithmetic branches and mux result at the end, example>
15. <sel ? (A+B) : (C+D) style arithmetic mux, move muxes before adder when equivalence is clear, example>
16. <deep if-else / default-then-override control chain, flatten into explicit parallel conditions with single-level selection, example>
17. <large case statement with structured outputs, replace with direct AND-OR equations or flattened decode logic, example>
18. <wide OR/AND/XOR reduction, restructure linear logic into balanced tree, example>
19. <wide mux tree or wide selection network, rebalance into multi-level 2:1 tree, example>
20. <multi-operand addition, rebalance serial add chain into tree, example>
21. <large lookup / ROM / decoder, split into hierarchical sub-decoders or subtables, example>
22. <GF / XOR-heavy datapath / crypto logic, rebalance XOR/AND computation into explicit stages, example>
23. <fixed constant multiplication, replace multiply with shift-add decomposition, example>
24. <comparison after mux selection, convert mux-then-compare into compare-then-mux, example>
25. <FSM with multiple related outputs, group states by shared output behavior before final decode, example>
26. <CPU / multi-cycle controller with timing-state decode, pre-decode machine-cycle and timing-state bits, example>
27. <long combinational expression with unclear synthesis boundary, add explicit intermediate wires to guide mapping, example>
28. <mixed-width arithmetic or truncation boundaries, make width extension/truncation explicit in named wires, example>
Low-confidence
29. <aggressive arithmetic branch parallelization, compute all arithmetic branches and late-select across complex arithmetic, example>
30. <control flattening around arithmetic-heavy paths, rewrite state/control logic to expose arithmetic in parallel, example>
31. <arithmetic chain tree balancing with carry/overflow sensitivity, rebalance addition/subtraction structure, example>
32. <aggressive mux tree restructuring when synthesis already optimizes muxes well, explicitly force custom mux hierarchy, example>
33. <explicit wire decomposition solely for hoped timing gain, split expression into many named wires without structural change, example>
34. <registering decode/control outputs to break timing when architectural latency is uncertain, insert sequential boundary speculatively, example>
Do not use
35. <count-up to count-down rewrite or reverse counter direction, change counter direction to simplify terminal detect, example>
36. <priority if-else chain flattened into parallel AND-OR without guaranteed mutual exclusivity, remove priority semantics, example>
37. <pre-registering mux selector / control selector on active data path, add register to selector to shorten mux path, example>
38. <control-signal pre-registration across module boundary for timing only, insert control pipeline stage without protocol redesign, example>
39. <operand width reduction / interface width reduction for speed, narrow datapath or module inputs to reduce logic, example>
40. <algebraic restructuring that changes arithmetic corner behavior, rewrite expression form without proof of overflow/signed equivalence, example>
41. <fused subtract-multiply / aggressive arithmetic fusion, collapse arithmetic stages into a new combined structure, example>
42. <changing LFSR feedback or polynomial structure, rewrite feedback network for timing, example>
43. <modifying memory array addressing / decode architecture from RTL timing path, rewrite memory indexing or address decode casually, example>
44. <optimizing pure register self-loop / constraint-only paths as if they were RTL logic problems, rewrite RTL for clock-to-q/setup-only reports, example>
45. <expression simplification that removes helpful intermediate boundaries, inline everything into one direct expression, example>
46. <restructured comparison ordering that changes corner-case evaluation semantics, reorder sign/magnitude checks for early exit, example>
47. <aggressive tree balancing on paths labeled combinational_depth without understanding arithmetic semantics, mechanically rebalance everything, example>
Practical usage notes
- Start with High-confidence skills first, especially: condition pre-computation, one-hot pre-decode, CSE, and fanout reduction by duplication.
- Use Medium-confidence skills when the timing root cause is clear and equivalence reasoning is still local.
- Treat Low-confidence skills as targeted experiments, one at a time.
- Treat Do not use as strong default prohibitions unless you have very strong design-specific proof.
- In general, prefer pre-computation over restructuring and local simplification over architectural rewrites.