-
Notifications
You must be signed in to change notification settings - Fork 383
/
priority_enc.sv
executable file
·72 lines (56 loc) · 1.6 KB
/
priority_enc.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//------------------------------------------------------------------------------
// priority_enc.sv
// Konstantin Pavlov, pavlovconst@gmail.com
//------------------------------------------------------------------------------
// INFO -------------------------------------------------------------------------
// Completely combinational priority_encoder
//
// See also round_robin_enc.sv
// See also round_robin_performance_enc.sv
//
/* --- INSTANTIATION TEMPLATE BEGIN ---
priority_enc #(
.WIDTH( 32 ) // WIDTH must be >=2
) PE1 (
.id( ),
.od_valid( ),
.od_filt( ),
.od_bin( )
);
--- INSTANTIATION TEMPLATE END ---*/
module priority_enc #( parameter
WIDTH = 32,
WIDTH_W = $clogb2(WIDTH)
)(
input [WIDTH-1:0] id, // input data bus
output od_valid, // output valid (some bits are active)
output [WIDTH-1:0] od_filt, // filtered data (only one priority bit active)
output [WIDTH_W-1:0] od_bin // priority bit binary index
);
// reversed id[] data
// conventional operation of priority encoder is when MSB bits have a priority
logic [WIDTH-1:0] id_r;
reverse_vector #(
.WIDTH( WIDTH ) // WIDTH must be >=2
) reverse_b (
.in( id[WIDTH-1:0] ),
.out( id_r[WIDTH-1:0] )
);
leave_one_hot #(
.WIDTH( WIDTH )
) one_hot_b (
.in( id_r[WIDTH-1:0] ),
.out( od_filt[WIDTH-1:0] )
);
logic err_no_hot;
assign od_valid = ~err_no_hot;
pos2bin #(
.BIN_WIDTH( WIDTH_W )
) pos2bin_b (
.pos( od_filt[WIDTH-1:0] ),
.bin( od_bin[WIDTH_W-1:0] ),
.err_no_hot( err_no_hot ),
.err_multi_hot( )
);
`include "clogb2.svh"
endmodule