RVSCC/rtl/priority_encoder.sv
Mario Romero 24a5622103
Some checks are pending
continuous-integration/drone/push Build is pending
Add 5 stage pipeline test and move timescale to include
2023-02-27 23:22:34 -03:00

20 lines
415 B
Systemverilog

`include "timescale.sv"
// 2**N to N Priority encoder
module priority_encoder #(
parameter int N = 4
) (
input logic [2**N - 1:0] data_in,
output logic [N - 1:0] data_out,
output logic valid
);
always_comb begin
data_out = 3'dx;
for (int i = 0; i < 2 ** N; i++) begin
if (data_in[i]) data_out = i[N-1:0];
end
if (data_in == 0) valid = 0;
else valid = 1;
end
endmodule