W2.6.1 Bus-Invert the Data Bus

MediumImplementIcarus · browser samples / server checksReview the topic

Write a bus-invert encoder and decoder that pick, for every word, the choice that changes the fewest wires, the invert line included.

Hardware context: Data bus encoder and decoder, and a ring pointer counter. Cut the toggles per transfer with bus-invert and Gray coding without losing a word.

A 12-bit bus runs across the chip to a slow peripheral. Each wire change costs energy, so the bus uses bus-invert coding. Each word goes out plain or inverted, and an extra wire inv says which.

Lesson W2.6 inverts when more than half of the data wires would change. That rule ignores the inv wire itself. This encoder must count all 13 wires and drive whichever choice changes fewer of them. On a tie it keeps inv where it is.

Write bi_enc, a registered encoder, and bi_dec, the combinational decoder at the far end. The tests also run a 9-bit copy.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
valid1stimulus, the same for every design
data12stimulus, the same for every design
bus12stimulus, the same for every design
inv1stimulus, the same for every design
Full specification
The two modules you write (keep the names, the parameter and the ports)
module bi_enc #(parameter int W = 12) (
  input  logic         clk,
  input  logic         rst_n,      // asynchronous, active-low
  input  logic         valid,      // 1: send data at this edge
  input  logic [W-1:0] data,
  output logic [W-1:0] bus,        // the bus wires
  output logic         inv         // the invert line: 1 when bus carries ~data
);
  // your encoder
endmodule

module bi_dec #(parameter int W = 12) (
  input  logic [W-1:0] bus,
  input  logic         inv,
  output logic [W-1:0] data
);
  // your decoder
endmodule
RuleDefinition
Resetbus = 0 and inv = 0.
valid = 0 at an edgebus and inv hold: no wire changes.
valid = 1 at an edgeCount the changes of {inv, bus} for two choices: plain (bus = data, inv = 0) and inverted (bus = ~data, inv = 1). Drive the choice with fewer changes.
A tieDrive the choice whose inv equals the current inv.
bi_decdata = bus when inv is 0, and ~bus when inv is 1. No clock.

Each case resets the encoder, then runs 16 rising edges with valid and data set before each. After every edge the fixture counts the wires of {inv, bus} that changed. After a valid edge it feeds bus and inv to bi_dec and compares the result with the word sent. The result shows rt_ok (every word came back) and the total and worst wire changes over the 16 edges. It also shows inv and bus after the last edge.

Examples

Example 1

All Ones, Then All Zeros, 12 Bits
Input
W = 12, 16 words in 16 edges: fff, 000, fff, 000, ...
Output
rt_ok = yes, total_changes = 16, worst_changes = 1, inv = no, bus = 0x0

fff against 000 would change 12 wires, so it goes out as 000 with inv rising: one change. From then on the word swaps each time and only inv moves.

Example 2

Half the Wires Each Time, 12 Bits
Input
W = 12, 16 words in 16 edges: 03f, fc0, 0ff, f0f, ...
Output
rt_ok = yes, total_changes = 63, worst_changes = 6, inv = yes, bus = 0x0

Many words change exactly six data wires. If inv is 1 then, the inverted word costs one change less than going back to plain.

Example 3

Five or Four Wires Each Time, 9 Bits
Input
W = 9, 16 words in 16 edges: 01f, 1e0, 00f, 1f0, ...
Output
rt_ok = yes, total_changes = 42, worst_changes = 5, inv = no, bus = 0x0

With 9 data wires, five changes plain cost the same as four changes inverted plus the inv wire. The rule keeps inv where it is.

Constraints and Contract

  • valid and data are known 0/1 values, set before each edge.
  • Keep the module names, the parameter W and the ports. Both modules go in your file.

Hints

Hint 1

Changes are always counted against what the wires hold now, bus and inv, not against the previous data word.

Hint 2

Plain costs ones(data ^ bus), plus one if inv is 1 now. Inverted costs ones(~data ^ bus), plus one if inv is 0 now.

Hint 3

With W = 12 the two costs add up to 13, so they never tie. With W = 9 they tie when five data wires would change plain and inv is 0. Which choice leaves inv alone?

What the grader checks: Seven directed and nine seeded scripts of 16 edges run on 12-bit and 9-bit copies. Some words tie on purpose, and some edges have valid at 0. Totals, the worst edge and the final bus are compared with an independent model of the rule. Every word sent is decoded and compared. The cost of the encoder logic itself is not graded.

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

Report a problem with this page

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

All Ones, Then All Zeros, 12 Bits

Input
W = 12, 16 words in 16 edges: fff, 000, fff, 000, ...
Expected output
rt_ok = yes, total_changes = 16, worst_changes = 1, inv = no, bus = 0x0

fff against 000 would change 12 wires, so it goes out as 000 with inv rising: one change. From then on the word swaps each time and only inv moves.

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

Icarus · browser samples / server checks