Add delay to the short path of a two-stage circuit so a late capture clock stops breaking hold, while setup still holds.
Hardware context: A 1 GHz block with three flop-to-flop paths, and a two-stage circuit whose capture flop gets a late clock. Insert buffers on the short path until no flop sees a setup or hold violation.
Two input flops feed one capture flop through an XOR gate. The clock reaches the capture flop through four buffers, so it arrives four time units late. The short path from qa reaches the capture flop before that late edge, so qc takes each new value one cycle early.
This is a Fix problem. Keep the function and the clock tree. Add buffer cells so that no flop sees a setup or hold violation. The bench counts every violation, and qc must be a XOR b, two clock edges later.
Use only cell instances and wire or logic declarations without initial values. Operators, assignments and procedural code are refused before simulation. Use from 14 to 30 cells.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 16 | input of each check |
Full specification
module pair (
input logic clk,
input logic a, b,
output wire qc // registered a XOR b, one clock after a and b are registered
);
// your netlist
endmodule
// cells.sv: the cell library (read-only). Ports are (output, inputs...). Every gate takes 1 time unit.
module BUF (output wire y, input wire a); buf #1 (y, a); initial tb.cells++; endmodule
module INV (output wire y, input wire a); not #1 (y, a); initial tb.cells++; endmodule
module XOR2 (output wire y, input wire a, b); xor #1 (y, a, b); initial tb.cells++; endmodule
// DFF: clock-to-Q 1, setup 2, hold 2. A change of d inside the window is counted as a violation, and q goes x.
module DFF (output reg q, input wire d, input wire clk);
time t_d = 0, t_clk = 0;
initial tb.cells++;
always @(d) begin
t_d = $time;
if (tb.armed && $time - t_clk < 2) begin tb.hold_bad++; q <= #1 1'bx; end
end
always @(posedge clk) begin
t_clk = $time;
if (tb.armed) begin tb.flops++; if ($time == tb.t_edge) tb.on_clk++; else if ($time - tb.t_edge == 4) tb.on_tree++; else tb.off_tree++; end
if (tb.armed && $time - t_d < 2) begin tb.setup_bad++; q <= #1 1'bx; end
else q <= #1 d;
end
endmodule
| Rule | Detail |
|---|---|
| Clock | Period 12. a and b change 6 time units after each rising edge. |
| Flip-flop | Clock-to-Q 1, setup 2, hold 2, all in time units. |
| Clock tree | The capture flop fc keeps its clock through exactly four buffers; fa and fb stay on clk. The bench checks the clock delay of each flop, and that qc changes 5 units after an edge. |
| Function | qc after each edge is a XOR b of two edges before. |
| Cells | Only instances of the library cells, from 14 to 30 of them. |
Each case plays eight cycles of a and b after the pipeline has filled. The result shows qc for each cycle and the number of setup and hold violations. Two flags say whether the clock tree changed and whether the cell count is out of range.
Examples
Example 1
A Alone Toggles- Input
a b per cycle: 10 00 10 00 10 10 00 10
- Output
qc_cycle0 = yes, qc_cycle1 = no, qc_cycle2 = yes, qc_cycle3 = no, qc_cycle4 = yes, qc_cycle5 = yes, qc_cycle6 = no, qc_cycle7 = yes, setup_violations = 0, hold_violations = 0, clock_tree_changed = no, cell_count_out_of_range = no
b stays 0, so qc must repeat a, two edges later. Each change of qa travels the short path, the one that breaks hold.
Example 2
b Alone Toggles- Input
a b per cycle: 01 00 01 01 00 01 00 00
- Output
qc_cycle0 = yes, qc_cycle1 = no, qc_cycle2 = yes, qc_cycle3 = yes, qc_cycle4 = no, qc_cycle5 = yes, qc_cycle6 = no, qc_cycle7 = no, setup_violations = 0, hold_violations = 0, clock_tree_changed = no, cell_count_out_of_range = no
a stays 0. Each change of qb travels the long path through six inverters, the one that limits setup.
Example 3
Both Change Together- Input
a b per cycle: 11 01 10 00 11 10 01 11
- Output
qc_cycle0 = no, qc_cycle1 = yes, qc_cycle2 = yes, qc_cycle3 = no, qc_cycle4 = no, qc_cycle5 = yes, qc_cycle6 = yes, qc_cycle7 = no, setup_violations = 0, hold_violations = 0, clock_tree_changed = no, cell_count_out_of_range = no
Both paths are busy in the same cycle. qc is a XOR b, and there must be no violation of either kind.
Constraints and Contract
- a and b are known 0/1 values.
- Keep the module name and the ports, the three flip-flops and the four clock buffers.
Hints
Hint 1
Write both checks. Hold: the earliest change at fc must come no sooner than its late clock edge plus the hold time. Setup: the latest change must come before the next late edge minus the setup time.
Hint 2
The short path from qa has clock-to-Q 1 and one XOR: it changes 2 units after the edge. The capture edge comes 4 units after the edge, and hold lasts 2 more.
Hint 3
Delay only the short path. Each buffer adds one unit. The long path already takes 8 units and may take up to 14. So a small delay after the XOR would also work.
What the grader checks: Three directed and nine seeded scripts of eight cycles, after three cycles that fill the pipeline. qc is compared with a XOR b computed in JavaScript. Every flop counts its own setup and hold violations, and its clock delay is checked. Every cell takes one time unit; there are no wire delays.
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 2 steps and the final capstone