blob: 80bea46468e57cb370ace8e6f6897b995782e10a (
plain) (
blame)
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
|
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 12/19/2018 10:51:52 AM
// Design Name:
// Module Name: pop_count4
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module pop_count4(
input [3:0] in,
output [2:0] out
);
reg [2:0] out_r;
always @* begin
out_r = 3'd0;
case(in)
4'b0000:
out_r = 3'd0;
4'b0001:
out_r = 3'd1;
4'b0010:
out_r = 3'd1;
4'b0011:
out_r = 3'd2;
4'b0100:
out_r = 3'd1;
4'b0101:
out_r = 3'd2;
4'b0110:
out_r = 3'd2;
4'b0111:
out_r = 3'd3;
4'b1000:
out_r = 3'd1;
4'b1001:
out_r = 3'd2;
4'b1010:
out_r = 3'd2;
4'b1011:
out_r = 3'd3;
4'b1100:
out_r = 3'd2;
4'b1101:
out_r = 3'd3;
4'b1111:
out_r = 3'd4;
endcase
end
assign out = out_r;
endmodule
|