G4.11.3 Check the ALUs with a Vector File

MediumVerifyIcarus · browser samples / server checks8 hidden designsReview the topic

Write a bench that reads a vector file with $readmemh and checks every output of an ALU on every vector.

Hardware context: The ALU of a small controller that adds wide numbers in steps and branches on its flags. Check supplier ALU netlists against a vector file from the reference model.

A team received eight ALU netlists from a supplier, along with a file of test vectors made by the reference model. Some netlists are wrong, each in one rare corner. Only the vectors in the file reach those corners.

This is a Verify problem. You write the bench. It reads alu_vectors.hex with $readmemh and applies every vector to the ALU. It adds 1 to errors for each vector where y or a flag differs from the file.

The check runs your bench on one correct ALU and eight faulty ones. You pass when errors stays 0 on the correct ALU 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 [2:0] op,         // you drive the ALU's inputs
  output logic [7:0] a, b,
  input  logic [7:0] y,          // its outputs
  input  logic       z, n, c, v,
  output int         errors      // add 1 for every vector where an output is wrong
);
  // your initial block
endmodule
RuleDetail
The filealu_vectors.hex: 25 lines, one 8-digit hex word each. It exists from 1 ns on.
Inputs in a wordop in bits 30 to 28, a in 27 to 20, b in 19 to 12. Bit 31 is 0.
Expected outputsy in bits 11 to 4, then z, n, c and v in bits 3 to 0.
The ALUThe ALU of lesson G4.11: op 0 ADD, 1 SUB, 2 AND, 3 OR, 4 XOR, 5 SLT, 6 and 7 unused.
TimingThe ALU is plain logic. Wait 1 ns after you change its inputs before you read the outputs.
Time limitYour bench must finish within 55 ns.

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

Examples

Example 1

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

On the correct ALU every vector of the file matches, so errors must still be 0 at the end.

Example 2

An ALU That Loses the Carry of 256
Input
ALU: Carry lost on a sum of exactly 256 (ADD gives c = 0 when a + b = 256)
Output
alarm = yes

It is right everywhere except when the sum is exactly 256. The file holds ff + 01 and 80 + 80.

Example 3

An ALU Whose SLT Reads the Sign Alone
Input
ALU: SLT reads the sign alone (SLT gives N of a - b, without V)
Output
alarm = yes

It is right unless a − b overflows. Only the file's 7f against 80 and 80 against 7f show it.

Constraints and Contract

  • Use only your ports and the file. Names from the fixture, $root and instance names (%m) are refused before the run.
  • Read the file with $readmemh after 1 ns, and finish within the time limit.

Hints

Hint 1

Declare an array of 32-bit words, larger than the file. $readmemh fills it from word 0 on; words past the end of the file stay x.

Hint 2

Loop over the words until one is x. Split each word: the inputs are bits 30 to 12, and the expected outputs bits 11 to 0.

Hint 3

Compare y and all four flags at once with !==, so an x or a single wrong flag counts.

What the grader checks: Your bench runs on one correct ALU and on eight ALUs with one planted fault each. Every fault shows only on a few rare operand pairs, all of them in the file. Passing shows that your bench reads the file, applies every vector and checks every output. A bench that copied the vectors into its own code would also pass.

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 3 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 ALU Must Not Raise an Alarm

Input
ALU: the correct design
Expected output
alarm = no

On the correct ALU every vector of the file 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