1 |
2 |
guangxi.li |
//------------------------------------------------------------------------------
|
2 |
|
|
//
|
3 |
|
|
// gng_lzd.v
|
4 |
|
|
//
|
5 |
|
|
// This file is part of the Gaussian Noise Generator IP Core
|
6 |
|
|
//
|
7 |
|
|
// Description
|
8 |
|
|
// Leading zero detector of 61-bit number.
|
9 |
|
|
//
|
10 |
|
|
//------------------------------------------------------------------------------
|
11 |
|
|
//
|
12 |
|
|
// Copyright (C) 2014, Guangxi Liu <guangxi.liu@opencores.org>
|
13 |
|
|
//
|
14 |
|
|
// This source file may be used and distributed without restriction provided
|
15 |
|
|
// that this copyright statement is not removed from the file and that any
|
16 |
|
|
// derivative work contains the original copyright notice and the associated
|
17 |
|
|
// disclaimer.
|
18 |
|
|
//
|
19 |
|
|
// This source file is free software; you can redistribute it and/or modify it
|
20 |
|
|
// under the terms of the GNU Lesser General Public License as published by
|
21 |
|
|
// the Free Software Foundation; either version 2.1 of the License,
|
22 |
|
|
// or (at your option) any later version.
|
23 |
|
|
//
|
24 |
|
|
// This source is distributed in the hope that it will be useful, but
|
25 |
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
26 |
|
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
27 |
|
|
// License for more details.
|
28 |
|
|
//
|
29 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
30 |
|
|
// along with this source; if not, download it from
|
31 |
|
|
// http://www.opencores.org/lgpl.shtml
|
32 |
|
|
//
|
33 |
|
|
//------------------------------------------------------------------------------
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
`timescale 1 ns / 1 ps
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
module gng_lzd (
|
40 |
|
|
// Data interface
|
41 |
|
|
input [60:0] data_in, // input data
|
42 |
|
|
output [5:0] data_out // output number of leading zeros
|
43 |
|
|
);
|
44 |
|
|
|
45 |
|
|
// Local variables
|
46 |
|
|
wire [63:0] d;
|
47 |
|
|
wire p1 [31:0];
|
48 |
|
|
wire [31:0] v1;
|
49 |
|
|
wire [1:0] p2 [15:0];
|
50 |
|
|
wire [15:0] v2;
|
51 |
|
|
wire [2:0] p3 [7:0];
|
52 |
|
|
wire [7:0] v3;
|
53 |
|
|
wire [3:0] p4 [3:0];
|
54 |
|
|
wire [3:0] v4;
|
55 |
|
|
wire [4:0] p5 [1:0];
|
56 |
|
|
wire [1:0] v5;
|
57 |
|
|
wire [5:0] p6;
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
// Parallel structure
|
61 |
|
|
assign d = {data_in, 3'b111}; // fill last 3 bits with '1'
|
62 |
|
|
|
63 |
|
|
assign p1[0 ] = ~d[1 ];
|
64 |
|
|
assign p1[1 ] = ~d[3 ];
|
65 |
|
|
assign p1[2 ] = ~d[5 ];
|
66 |
|
|
assign p1[3 ] = ~d[7 ];
|
67 |
|
|
assign p1[4 ] = ~d[9 ];
|
68 |
|
|
assign p1[5 ] = ~d[11];
|
69 |
|
|
assign p1[6 ] = ~d[13];
|
70 |
|
|
assign p1[7 ] = ~d[15];
|
71 |
|
|
assign p1[8 ] = ~d[17];
|
72 |
|
|
assign p1[9 ] = ~d[19];
|
73 |
|
|
assign p1[10] = ~d[21];
|
74 |
|
|
assign p1[11] = ~d[23];
|
75 |
|
|
assign p1[12] = ~d[25];
|
76 |
|
|
assign p1[13] = ~d[27];
|
77 |
|
|
assign p1[14] = ~d[29];
|
78 |
|
|
assign p1[15] = ~d[31];
|
79 |
|
|
assign p1[16] = ~d[33];
|
80 |
|
|
assign p1[17] = ~d[35];
|
81 |
|
|
assign p1[18] = ~d[37];
|
82 |
|
|
assign p1[19] = ~d[39];
|
83 |
|
|
assign p1[20] = ~d[41];
|
84 |
|
|
assign p1[21] = ~d[43];
|
85 |
|
|
assign p1[22] = ~d[45];
|
86 |
|
|
assign p1[23] = ~d[47];
|
87 |
|
|
assign p1[24] = ~d[49];
|
88 |
|
|
assign p1[25] = ~d[51];
|
89 |
|
|
assign p1[26] = ~d[53];
|
90 |
|
|
assign p1[27] = ~d[55];
|
91 |
|
|
assign p1[28] = ~d[57];
|
92 |
|
|
assign p1[29] = ~d[59];
|
93 |
|
|
assign p1[30] = ~d[61];
|
94 |
|
|
assign p1[31] = ~d[63];
|
95 |
|
|
assign v1[0 ] = d[0 ] | d[1 ];
|
96 |
|
|
assign v1[1 ] = d[2 ] | d[3 ];
|
97 |
|
|
assign v1[2 ] = d[4 ] | d[5 ];
|
98 |
|
|
assign v1[3 ] = d[6 ] | d[7 ];
|
99 |
|
|
assign v1[4 ] = d[8 ] | d[9 ];
|
100 |
|
|
assign v1[5 ] = d[10] | d[11];
|
101 |
|
|
assign v1[6 ] = d[12] | d[13];
|
102 |
|
|
assign v1[7 ] = d[14] | d[15];
|
103 |
|
|
assign v1[8 ] = d[16] | d[17];
|
104 |
|
|
assign v1[9 ] = d[18] | d[19];
|
105 |
|
|
assign v1[10] = d[20] | d[21];
|
106 |
|
|
assign v1[11] = d[22] | d[23];
|
107 |
|
|
assign v1[12] = d[24] | d[25];
|
108 |
|
|
assign v1[13] = d[26] | d[27];
|
109 |
|
|
assign v1[14] = d[28] | d[29];
|
110 |
|
|
assign v1[15] = d[30] | d[31];
|
111 |
|
|
assign v1[16] = d[32] | d[33];
|
112 |
|
|
assign v1[17] = d[34] | d[35];
|
113 |
|
|
assign v1[18] = d[36] | d[37];
|
114 |
|
|
assign v1[19] = d[38] | d[39];
|
115 |
|
|
assign v1[20] = d[40] | d[41];
|
116 |
|
|
assign v1[21] = d[42] | d[43];
|
117 |
|
|
assign v1[22] = d[44] | d[45];
|
118 |
|
|
assign v1[23] = d[46] | d[47];
|
119 |
|
|
assign v1[24] = d[48] | d[49];
|
120 |
|
|
assign v1[25] = d[50] | d[51];
|
121 |
|
|
assign v1[26] = d[52] | d[53];
|
122 |
|
|
assign v1[27] = d[54] | d[55];
|
123 |
|
|
assign v1[28] = d[56] | d[57];
|
124 |
|
|
assign v1[29] = d[58] | d[59];
|
125 |
|
|
assign v1[30] = d[60] | d[61];
|
126 |
|
|
assign v1[31] = d[62] | d[63];
|
127 |
|
|
|
128 |
|
|
assign p2[0 ] = {~v1[1 ], (v1[1 ] ? p1[1 ] : p1[0 ])};
|
129 |
|
|
assign p2[1 ] = {~v1[3 ], (v1[3 ] ? p1[3 ] : p1[2 ])};
|
130 |
|
|
assign p2[2 ] = {~v1[5 ], (v1[5 ] ? p1[5 ] : p1[4 ])};
|
131 |
|
|
assign p2[3 ] = {~v1[7 ], (v1[7 ] ? p1[7 ] : p1[6 ])};
|
132 |
|
|
assign p2[4 ] = {~v1[9 ], (v1[9 ] ? p1[9 ] : p1[8 ])};
|
133 |
|
|
assign p2[5 ] = {~v1[11], (v1[11] ? p1[11] : p1[10])};
|
134 |
|
|
assign p2[6 ] = {~v1[13], (v1[13] ? p1[13] : p1[12])};
|
135 |
|
|
assign p2[7 ] = {~v1[15], (v1[15] ? p1[15] : p1[14])};
|
136 |
|
|
assign p2[8 ] = {~v1[17], (v1[17] ? p1[17] : p1[16])};
|
137 |
|
|
assign p2[9 ] = {~v1[19], (v1[19] ? p1[19] : p1[18])};
|
138 |
|
|
assign p2[10] = {~v1[21], (v1[21] ? p1[21] : p1[20])};
|
139 |
|
|
assign p2[11] = {~v1[23], (v1[23] ? p1[23] : p1[22])};
|
140 |
|
|
assign p2[12] = {~v1[25], (v1[25] ? p1[25] : p1[24])};
|
141 |
|
|
assign p2[13] = {~v1[27], (v1[27] ? p1[27] : p1[26])};
|
142 |
|
|
assign p2[14] = {~v1[29], (v1[29] ? p1[29] : p1[28])};
|
143 |
|
|
assign p2[15] = {~v1[31], (v1[31] ? p1[31] : p1[30])};
|
144 |
|
|
assign v2[0 ] = v1[1 ] | v1[0 ];
|
145 |
|
|
assign v2[1 ] = v1[3 ] | v1[2 ];
|
146 |
|
|
assign v2[2 ] = v1[5 ] | v1[4 ];
|
147 |
|
|
assign v2[3 ] = v1[7 ] | v1[6 ];
|
148 |
|
|
assign v2[4 ] = v1[9 ] | v1[8 ];
|
149 |
|
|
assign v2[5 ] = v1[11] | v1[10];
|
150 |
|
|
assign v2[6 ] = v1[13] | v1[12];
|
151 |
|
|
assign v2[7 ] = v1[15] | v1[14];
|
152 |
|
|
assign v2[8 ] = v1[17] | v1[16];
|
153 |
|
|
assign v2[9 ] = v1[19] | v1[18];
|
154 |
|
|
assign v2[10] = v1[21] | v1[20];
|
155 |
|
|
assign v2[11] = v1[23] | v1[22];
|
156 |
|
|
assign v2[12] = v1[25] | v1[24];
|
157 |
|
|
assign v2[13] = v1[27] | v1[26];
|
158 |
|
|
assign v2[14] = v1[29] | v1[28];
|
159 |
|
|
assign v2[15] = v1[31] | v1[30];
|
160 |
|
|
|
161 |
|
|
assign p3[0] = {~v2[1 ], (v2[1 ] ? p2[1 ] : p2[0 ])};
|
162 |
|
|
assign p3[1] = {~v2[3 ], (v2[3 ] ? p2[3 ] : p2[2 ])};
|
163 |
|
|
assign p3[2] = {~v2[5 ], (v2[5 ] ? p2[5 ] : p2[4 ])};
|
164 |
|
|
assign p3[3] = {~v2[7 ], (v2[7 ] ? p2[7 ] : p2[6 ])};
|
165 |
|
|
assign p3[4] = {~v2[9 ], (v2[9 ] ? p2[9 ] : p2[8 ])};
|
166 |
|
|
assign p3[5] = {~v2[11], (v2[11] ? p2[11] : p2[10])};
|
167 |
|
|
assign p3[6] = {~v2[13], (v2[13] ? p2[13] : p2[12])};
|
168 |
|
|
assign p3[7] = {~v2[15], (v2[15] ? p2[15] : p2[14])};
|
169 |
|
|
assign v3[0] = v2[1 ] | v2[0 ];
|
170 |
|
|
assign v3[1] = v2[3 ] | v2[2 ];
|
171 |
|
|
assign v3[2] = v2[5 ] | v2[4 ];
|
172 |
|
|
assign v3[3] = v2[7 ] | v2[6 ];
|
173 |
|
|
assign v3[4] = v2[9 ] | v2[8 ];
|
174 |
|
|
assign v3[5] = v2[11] | v2[10];
|
175 |
|
|
assign v3[6] = v2[13] | v2[12];
|
176 |
|
|
assign v3[7] = v2[15] | v2[14];
|
177 |
|
|
|
178 |
|
|
assign p4[0] = {~v3[1], (v3[1] ? p3[1] : p3[0])};
|
179 |
|
|
assign p4[1] = {~v3[3], (v3[3] ? p3[3] : p3[2])};
|
180 |
|
|
assign p4[2] = {~v3[5], (v3[5] ? p3[5] : p3[4])};
|
181 |
|
|
assign p4[3] = {~v3[7], (v3[7] ? p3[7] : p3[6])};
|
182 |
|
|
assign v4[0] = v3[1] | v3[0];
|
183 |
|
|
assign v4[1] = v3[3] | v3[2];
|
184 |
|
|
assign v4[2] = v3[5] | v3[4];
|
185 |
|
|
assign v4[3] = v3[7] | v3[6];
|
186 |
|
|
|
187 |
|
|
assign p5[0] = {~v4[1], (v4[1] ? p4[1] : p4[0])};
|
188 |
|
|
assign p5[1] = {~v4[3], (v4[3] ? p4[3] : p4[2])};
|
189 |
|
|
assign v5[0] = v4[1] | v4[0];
|
190 |
|
|
assign v5[1] = v4[3] | v4[2];
|
191 |
|
|
|
192 |
|
|
assign p6 = {~v5[1], (v5[1] ? p5[1] : p5[0])};
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
// Output data
|
196 |
|
|
assign data_out = p6;
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
endmodule
|