-
Notifications
You must be signed in to change notification settings - Fork 380
/
leave_one_hot.sv
47 lines (34 loc) · 967 Bytes
/
leave_one_hot.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
//------------------------------------------------------------------------------
// leave_one_hot.v
// Konstantin Pavlov, pavlovconst@gmail.com
//------------------------------------------------------------------------------
// INFO -------------------------------------------------------------------------
// Completely combinational module that leaves only lowest hot bit
// compared to input vector
//
// For example 16'b1101_0000 becomes 8'b0001_0000
// 16'b1101_0010 becomes 8'b0000_0010
/* --- INSTANTIATION TEMPLATE BEGIN ---
leave_one_hot #(
.WIDTH( 32 )
) OH1 (
.in( ),
.out( )
);
--- INSTANTIATION TEMPLATE END ---*/
module leave_one_hot #( parameter
WIDTH = 32
)(
input [WIDTH-1:0] in,
output logic [WIDTH-1:0] out
);
genvar i;
generate
for( i=1; i<WIDTH; i++ ) begin : gen_for
always_comb begin
out[i] <= in[i] && ~( |in[(i-1):0] );
end
end // for i
endgenerate
assign out[0] = in[0];
endmodule