W1.6.1 Balance the Paths

MediumOptimizeIcarus · browser samples / server checksReview the topic

A six-operand adder gives the right sum, but its output bits change about twelve times for every change they need. Rebuild it from the same cells so that it glitches far less, in the same cycle.

Hardware context: Multi-operand adder built from gates with unit delays. Restructure the logic so outputs settle with fewer glitch toggles, at the same function and latency.

A filter adds six bytes in every clock cycle. The sum block uses gate-level ripple-carry adders, the cells of lesson W1.6. Each gate answers 1 ns after its inputs change.

The shipped block adds the operands one after another. Its sum is right, but its eleven output bits change about twelve times for every change the sum needs. Each extra change charges a wire for nothing.

Rebuild sum6 from the rca or fa cells. Keep the sum and keep it in the same cycle. The output bits may change at most 8 times as often as the sum needs.

Signals in the Timeline

SignalWidthRole
seed32input of each check
Full specification
The block (keep the module name and the ports)
module sum6 (
  input  logic        clk,                  // the clock of the registers around the block
  input  logic [7:0]  a, b, c, d, e, f,     // six operands, from flops clocked by clk
  output logic [10:0] y                     // a + b + c + d + e + f, in the same cycle
);
  // rca and fa instances only
endmodule
The cells, compiled before your file (read-only)
// The cells (read-only). Each gate answers 1 ns after its inputs change.
module fa (input a, b, c, output s, co);
  wire x, g, p;
  xor #1 x1 (x, a, b);
  xor #1 x2 (s, x, c);
  and #1 a1 (g, a, b);
  and #1 a2 (p, x, c);
  or  #1 o1 (co, g, p);
  initial tb.fa_cells = tb.fa_cells + 1;   // the fixture counts the full adders at time 0
  logic used = 1'b0;                       // and the full adders whose inputs move while it counts
  always @(a or b or c) if (tb.counting && !used) begin used = 1'b1; tb.fa_used = tb.fa_used + 1; end
endmodule
module rca #(parameter N = 8) (input [N-1:0] a, b, output [N:0] s);   // s = a + b
  wire [N:0] c;
  assign c[0] = 1'b0;
  for (genvar i = 0; i < N; i++) begin : bit_
    fa u (a[i], b[i], c[i], s[i], c[i+1]);
  end
  assign s[N] = c[N];
endmodule
CheckRuleHow the fixture measures it
wrong_sums0In each of 128 cycles, y must equal the sum of that cycle's operands 38 ns after they change.
within_glitch_budgettrueThe bits of y may change at most 8 times as often as their settled changes, counting every instant. A settled change is one from a checked value to the next.
no_zero_delay_pathtruey must never change at the same instant as the operands: the sum must come through the gates.
built_from_adder_cellstrueThe design must hold at least 40 full adders (the fa cell, counted by the fixture). At least 40 of them must see their inputs change.

Each case starts with all operands at 0 for one cycle, then applies 128 cycles of six random bytes. The operands change 1 ns after a rising edge of clk, as flops would drive them. The log prints the change counts of every case.

Examples

Example 1

Operand Set 1
Input
128 random cycles, seed 12345678
Output
wrong_sums = 0, within_glitch_budget = yes, no_zero_delay_path = yes, built_from_adder_cells = yes

A passing block gets every sum right and stays inside the budget of 8 changes per settled change. It builds the sum from at least 40 full adders. The shipped chain gets every sum right and fails the budget.

Example 2

Operand Set 2
Input
128 random cycles, seed ace12345
Output
wrong_sums = 0, within_glitch_budget = yes, no_zero_delay_path = yes, built_from_adder_cells = yes

The same rules on other operands. The log line shows how far below the budget a design stays.

Example 3

Operand Set 3
Input
128 random cycles, seed 0badf00d
Output
wrong_sums = 0, within_glitch_budget = yes, no_zero_delay_path = yes, built_from_adder_cells = yes

A third seed. A tree that balances only some adders may pass one seed and fail another. Every seed must stay inside the budget.

Constraints and Contract

  • Use only instances of rca and fa, wires and plain assignments of wires (no arithmetic operators, no delays of your own).
  • Keep the module name sum6 and its ports. Do not redefine fa or rca.

Hints

Hint 1

Run the starter and read the log: how many changes does each case make, and how many are settled?

Hint 2

An adder glitches when its two inputs arrive at different times. In the chain, the last adder waits for four adders on one input and none on the other.

Hint 3

Try to give every adder two inputs of about the same depth. With six operands, how many adders deep must the sum be at least?

What the grader checks: Twelve cases of 128 random cycles each. The fixture checks the sum once per cycle against an independent integer sum. It counts every change of y in the gate-level simulation, with an inertial delay of 1 ns per gate. Real cells have other delays for each cell, load and edge. So the counts are a model of glitching, not a SKY130 power figure.

12 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Operand Set 1

Input
128 random cycles, seed 12345678
Expected output
wrong_sums = 0, within_glitch_budget = yes, no_zero_delay_path = yes, built_from_adder_cells = yes

A passing block gets every sum right and stays inside the budget of 8 changes per settled change. It builds the sum from at least 40 full adders. The shipped chain gets every sum right and fails the budget.

Run samples executes all 3 public checks. Check all tests runs 12 checks on the server.

Icarus · browser samples / server checks