OpenCores
URL https://opencores.org/ocsvn/raptor64/raptor64/trunk

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [rtl/] [verilog/] [cntlz.v] - Blame information for rev 41

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 41 robfinch
// ============================================================================
2
//      (C) 2012  Robert Finch
3
//      robfinch@<remove>opencores.org
4
//
5
// This source file is free software: you can redistribute it and/or modify 
6
// it under the terms of the GNU Lesser General Public License as published 
7
// by the Free Software Foundation, either version 3 of the License, or     
8
// (at your option) any later version.                                      
9
//                                                                          
10
// This source file is distributed in the hope that it will be useful,      
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
13
// GNU General Public License for more details.                             
14
//                                                                          
15
// You should have received a copy of the GNU General Public License        
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
17
//
18
// ============================================================================
19
//
20
module cntlz8(
21
        input clk,
22
        input [7:0] i,
23
        output reg [3:0] o
24
);
25
 
26
always @(posedge clk)
27
        casex (i)
28
        8'b00000000:    o = 8;
29
        8'b00000001:    o = 7;
30
        8'b0000001x:    o = 6;
31
        8'b000001xx:    o = 5;
32
        8'b00001xxx:    o = 4;
33
        8'b0001xxxx:    o = 3;
34
        8'b001xxxxx:    o = 2;
35
        8'b01xxxxxx:    o = 1;
36
        8'b1xxxxxxx:    o = 0;
37
        endcase
38
 
39
endmodule
40
 
41
 
42
module cntlz16(
43
        input clk,
44
        input [15:0] i,
45
        output reg [4:0] o
46
);
47
        wire [3:0] cnt1, cnt2;
48
 
49
        cntlz8 u1 (clk,i[ 7:0],cnt1);
50
        cntlz8 u2 (clk,i[15:8],cnt2);
51
 
52
        always @(posedge clk)
53
                o <= cnt2[3] ? cnt1 + 4'h8 : cnt2;
54
 
55
endmodule
56
 
57
 
58
// 88 slices / 154 LUTs / 22.5 ns
59
module cntlz64(
60
        input clk,
61
        input [63:0] i,
62
        output reg [6:0] o
63
);
64
 
65
        wire [4:0] cnt1, cnt2, cnt3, cnt4;
66
 
67
        cntlz16 u1 (clk,i[15: 0],cnt1);
68
        cntlz16 u2 (clk,i[31:16],cnt2);
69
        cntlz16 u3 (clk,i[47:32],cnt3);
70
        cntlz16 u4 (clk,i[63:48],cnt4);
71
 
72
        always @(posedge clk)
73
                o <=
74
                        !cnt4[4] ? cnt4 :
75
                        !cnt3[4] ? cnt3 + 7'd16 :
76
                        !cnt2[4] ? cnt2 + 7'd32 :
77
                         cnt1 + 7'd48;
78
 
79
endmodule
80
 
81
 
82
 
83
// 5 slices / 10 LUTs / 7.702 ns
84
module cntlo8(
85
        input clk,
86
        input [7:0] i,
87
        output [3:0] o
88
);
89
 
90
cntlz8 u1 (clk,~i,o);
91
 
92
endmodule
93
 
94
 
95
module cntlo16(
96
        input clk,
97
        input [15:0] i,
98
        output [4:0] o
99
);
100
 
101
cntlz16 u1 (clk,~i,o);
102
 
103
endmodule
104
 
105
 
106
// 59 slices / 99 LUTs / 14.065 ns
107
module cntlo64(
108
        input clk,
109
        input [63:0] i,
110
        output [6:0] o
111
);
112
 
113
cntlz64 u1 (clk,~i,o);
114
 
115
endmodule
116
 
117
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.