RVSCC/test/Test_PriorityEncoder.sv

25 lines
791 B
Systemverilog
Raw Normal View History

2023-01-01 22:28:56 +00:00
`timescale 1ns / 1ps
module Test_PriorityEncoder();
logic[7:0] data_in;
logic[2:0] data_out;
2023-02-01 16:20:37 +00:00
logic valid;
PriorityEncoder#(.N(3)) encoder(
.data_in(data_in),
.data_out(data_out),
.valid(valid)
);
2023-01-01 22:28:56 +00:00
initial begin
data_in = 'b00000001;
for (int i = 0; i < 8; i++) begin
2023-02-19 20:59:12 +00:00
#1 assert (data_out == i[2:0] && valid == 1) else $error("Failed one-hot to index check at iteration %0d, %d", i, data_out);
2023-01-01 22:28:56 +00:00
data_in = data_in << 'd1;
end
data_in = 'b00101111;
2023-02-19 20:59:12 +00:00
#1 assert (data_out == 'd5) else $error("Incorrect result with input %b", data_in);
2023-01-01 22:28:56 +00:00
data_in = 'b10101010;
2023-02-19 20:59:12 +00:00
#1 assert (data_out == 'd7) else $error("Incorrect result with input %b", data_in);
2023-02-01 16:20:37 +00:00
$finish;
2023-01-01 22:28:56 +00:00
end
endmodule