G4.4.2 Check the Priority Encoders

MediumVerifyIcarus · browser samples / server checks8 hidden designsReview the topic

Write a bench that checks code and valid of a 4-input priority encoder on every pattern, and catches eight planted faults.

Hardware context: An interrupt line shared by four sensors, and a box of old priority encoders to sort. Write the bench that catches every planted fault in a priority encoder.

A team has eight versions of a 4-input priority encoder from an old project. Some are right and some are not, and their old bench only printed. You must write a bench that sorts them.

This is a Verify problem. You write the bench, not the encoder. Your bench drives the inputs r and reads code and valid. It adds 1 to errors for every input pattern where an output is wrong.

The check runs your bench on one correct encoder and on eight faulty ones. Several faults show on a single pattern only. You pass when errors stays 0 on the correct encoder and ends above 0 on every faulty one.

Signals in the Timeline

SignalWidthRole
variant4input of each check
Full specification
The bench you write (keep these ports)
module bench (
  output logic [3:0] r,        // you drive the four inputs of the encoder
  input  logic [1:0] code,     // its outputs
  input  logic       valid,
  output int         errors    // add 1 for every input pattern where an output is wrong
);
  // your initial block
endmodule
RuleDetail
The encodercode is the number of the highest active input of r; valid is 1 when any input is active.
No input activecode = 0 and valid = 0.
TimingThe encoder is plain gates. Wait 1 ns after you change r before you read the outputs.
Time limitYour bench must finish within 35 ns.
errorsStart at 0. Add 1 for each wrong pattern. Never count down.

For each encoder you get alarm = yes or no. The correct encoder must give no alarm. Each faulty encoder must give an alarm.

Examples

Example 1

The Correct Encoder Must Not Raise an Alarm
Input
Encoder: the correct design
Output
alarm = no

On the correct encoder every pattern matches, so errors must still be 0 at the end.

Example 2

An Encoder Where the Lowest Input Wins
Input
Encoder: Lowest input wins (with two or more inputs, the lowest one is encoded)
Output
alarm = yes

It agrees with the rule whenever one input is active. Only patterns with two or more inputs show the fault.

Example 3

An Encoder Whose Valid Is Stuck at 1
Input
Encoder: valid stuck at 1 (valid is 1 even when no input is active)
Output
alarm = yes

Every code is right. Only the pattern 0000, read through valid, shows the fault.

Constraints and Contract

  • Use only your ports. Names from the fixture, $root and instance names (%m) are refused before the run.
  • Drive r from one initial block, and finish within the time limit.

Hints

Hint 1

Four inputs have sixteen patterns. A loop from 0 to 15 visits them all, and a fault that shows on one pattern cannot hide.

Hint 2

Work out the expected code yourself. Walk the bits of r from 0 to 3 and keep the last one that is set. Do not forget 0000.

Hint 3

Check both outputs. A fault in valid alone leaves every code right.

What the grader checks: Your bench runs on one correct encoder and on eight encoders with one planted fault each. Six of the faults show on a single input pattern. Passing shows that your bench checks both outputs on every pattern and raises no false alarm.

9 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

The Correct Encoder Must Not Raise an Alarm

Input
Encoder: the correct design
Expected output
alarm = no

On the correct encoder every pattern matches, so errors must still be 0 at the end.

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

Icarus · browser samples / server checks