Write the recorder that folds a bus waveform into SAIF totals: time at 0, at 1 and at X, and toggles.
Hardware context: Activity recorder on a bus, and recorded power reports of a multiplier. Turn waveforms into SAIF totals and judge how much of an estimate rests on recorded activity.
A power tool reads SAIF totals, not waveforms. Write saif_rec, a recorder for a bus of N bits. While run is 1 it keeps four totals for each bit. They are the nanoseconds at 0, at 1, and at X or Z, and the toggle count.
A toggle is a change from 0 to 1 or from 1 to 0. A change into or out of X or Z is not a toggle. tc_all is the sum of the toggle counts of all bits.
A rising edge of run clears every total and opens the window. A falling edge closes it, and the totals then hold their values. The value a bit has when the window opens counts from that moment.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
s | 4 | stimulus, the same for every design |
run | 1 | stimulus, the same for every design |
Full specification
module saif_rec #(parameter int N = 4) (
input logic [N-1:0] s, // the bus being recorded
input logic run, // the window: totals cover the time while run is 1
output logic [N-1:0][15:0] t0, // per bit: ns at 0 inside the window
output logic [N-1:0][15:0] t1, // per bit: ns at 1 inside the window
output logic [N-1:0][15:0] tx, // per bit: ns at X or Z inside the window
output logic [N-1:0][15:0] tc, // per bit: 0-to-1 and 1-to-0 changes inside the window
output logic [15:0] tc_all // the sum of tc over all bits
);
// your design
endmodule
| Event | What the recorder does |
|---|---|
| run rises | Every total goes to 0. Each bit starts a stretch at its present value. |
| A bit changes while run is 1 | The stretch that ends is added to T0, T1 or TX by its old value. A 0-1 or 1-0 change adds 1 to that bit's tc and to tc_all. |
| A bit changes while run is 0 | Nothing is added. |
| run falls | The stretch that ends is added for every bit. The totals hold until run rises again. |
The tests use N = 4 and timescale 1ns/1ps. Inputs change at whole nanoseconds, and s never changes at the same time as an edge of run. Each test plays a script of 120 ns and ends with run at 0. It then reads t0, t1, tx and tc of one bit, and tc_all.
Totals fit in 16 bits. One test may open more than one window.
Examples
Example 1
Clean Toggles Inside One Window- Input
bit 0; +1 ns 0000, +2 ns run, +5 ns 0001, +10 ns 0000, +10 ns 0001, +5 ns run
- Output
t0 = 15, t1 = 15, tx = 0, tc = 3, tc_all = 3
Bit 0 is 0 when the window opens at 3 ns. It is 1 from 8 to 18 ns and from 28 to 33 ns. So T0 = 15, T1 = 15 and TC = 3.
Example 2
X Before 1 Is Not a Toggle- Input
bit 1; +1 ns xxxx, +2 ns run, +8 ns 0010, +6 ns 00x0, +4 ns 0010, +10 ns 0000, +7 ns run
- Output
t0 = 7, t1 = 16, tx = 12, tc = 1, tc_all = 1
Bit 1 is X for the first 8 ns of the window. It is then 1, X for 4 ns, 1 again and finally 0. Only the last change is a toggle.
Example 3
Changes Before the Window Do Not Count- Input
bit 2; +2 ns 0100, +3 ns 0000, +3 ns 0100, +5 ns run, +9 ns 0000, +11 ns run, +4 ns 0100
- Output
t0 = 11, t1 = 9, tx = 0, tc = 1, tc_all = 1
Bit 2 changes three times before run rises at 13 ns, and none of those changes counts. In the window it is 1 for 9 ns and 0 for 11 ns, with one toggle.
Constraints and Contract
- Keep the module name, the parameter N and the ports.
- The recorder is a testbench model: it may use
$time, events and procedural code. It is not synthesized.
Hints
Hint 1
Keep, for each bit, its present value and the time it took that value. Each change closes one stretch: add its length to the total of the old value.
Hint 2
Use === to compare with 1'b0 and 1'b1. With ==, a comparison with X is X, and an if treats X as false.
Hint 3
Do not forget the stretch that is still open when run falls.
What the grader checks: Eight directed and eight seeded 120 ns scripts run on a 4-bit recorder. Each reads one bit's four totals and the bus toggle sum. An independent model of the SAIF rules (UPF 1.0 §7.3.3 and §7.3.4) gives the expected values. Changes happen at whole nanoseconds and never on an edge of run; zero-time glitches are not driven.
16 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