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

Subversion Repositories signed_integer_divider

[/] [signed_integer_divider/] [trunk/] [shifter.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 m99
module  shift_1b(
2
input   i_shift,
3
input   [31:0]i_data,
4
output  [31:0]o_data
5
);
6
assign  o_data=i_shift?{i_data[30:0],1'b0}:i_data;
7
 
8
endmodule
9
 
10
module  shift_3b(
11
input   [2:0]i_shift,
12
input   [31:0]i_data,
13
output  [31:0]o_data
14
);
15
wire    [31:0]data1;
16
assign  data1=i_shift[1]?{i_data[29:0],2'b0}:i_data;
17
wire    shift1;
18
assign  shift1=(i_shift[0]&i_shift[1])|(i_shift[2]^i_shift[1]);
19
shift_1b        shift_1b_0(
20
shift1,
21
data1,
22
o_data
23
);
24
endmodule
25
 
26
module  shift_7b(
27
input   [6:0]i_shift,
28
input   [31:0]i_data,
29
output  [31:0]o_data
30
);
31
wire    [31:0]data1;
32
assign  data1=i_shift[3]?{i_data[27:0],4'b0}:i_data;
33
wire    [2:0]shift1;
34
assign  shift1=(i_shift[2:0]&{3{i_shift[3]}})|(i_shift[6:4]^{3{i_shift[3]}});
35
 
36
shift_3b        shift_3b_0(
37
shift1,
38
data1,
39
o_data
40
);
41
 
42
endmodule
43
 
44
module  shift_15b(
45
input   [14:0]i_shift,
46
input   [31:0]i_data,
47
output  [31:0]o_data
48
);
49
wire    [31:0]data1;
50
assign  data1=i_shift[7]?{i_data[23:0],8'b0}:i_data;
51
wire    [6:0]shift1;
52
assign  shift1=(i_shift[6:0]&{7{i_shift[7]}})|(i_shift[14:8]^{7{i_shift[7]}});
53
 
54
shift_7b        shift_7b_0(
55
shift1,
56
data1,
57
o_data
58
);
59
 
60
endmodule
61
 
62
 
63
 
64
 
65
 
66
 
67
 
68
 
69
 
70
 
71
 
72
module  shifter(
73
input   [31:0]i_data,
74
output  [31:0]o_data,
75
output  [4:0]o_shifted
76
);
77
 
78
wire    [31:0]node_0;
79
assign  node_0=i_data[31]?i_data:~i_data;
80
 
81
// odd nodes tree
82
///////////////////////// layer 1 ////////////////////////////
83
wire    [15:0]onode_1;
84
assign  onode_1[0]=node_0[0]&node_0[1];
85
assign  onode_1[1]=node_0[2]&node_0[3];
86
assign  onode_1[2]=node_0[4]&node_0[5];
87
assign  onode_1[3]=node_0[6]&node_0[7];
88
assign  onode_1[4]=node_0[8]&node_0[9];
89
assign  onode_1[5]=node_0[10]&node_0[11];
90
assign  onode_1[6]=node_0[12]&node_0[13];
91
assign  onode_1[7]=node_0[14]&node_0[15];
92
assign  onode_1[8]=node_0[16]&node_0[17];
93
assign  onode_1[9]=node_0[18]&node_0[19];
94
assign  onode_1[10]=node_0[20]&node_0[21];
95
assign  onode_1[11]=node_0[22]&node_0[23];
96
assign  onode_1[12]=node_0[24]&node_0[25];
97
assign  onode_1[13]=node_0[26]&node_0[27];
98
assign  onode_1[14]=node_0[28]&node_0[29];
99
assign  onode_1[15]=node_0[30]&node_0[31];
100
///////////////////////// layer 2 ////////////////////////////
101
wire    [15:0]onode_2;
102
assign  onode_2[0]=onode_1[0]&onode_1[1];
103
assign  onode_2[1]=onode_1[1]&onode_1[2];
104
assign  onode_2[2]=onode_1[2]&onode_1[3];
105
assign  onode_2[3]=onode_1[3]&onode_1[4];
106
assign  onode_2[4]=onode_1[4]&onode_1[5];
107
assign  onode_2[5]=onode_1[5]&onode_1[6];
108
assign  onode_2[6]=onode_1[6]&onode_1[7];
109
assign  onode_2[7]=onode_1[7]&onode_1[8];
110
assign  onode_2[8]=onode_1[8]&onode_1[9];
111
assign  onode_2[9]=onode_1[9]&onode_1[10];
112
assign  onode_2[10]=onode_1[10]&onode_1[11];
113
assign  onode_2[11]=onode_1[11]&onode_1[12];
114
assign  onode_2[12]=onode_1[12]&onode_1[13];
115
assign  onode_2[13]=onode_1[13]&onode_1[14];
116
assign  onode_2[14]=onode_1[14]&onode_1[15];
117
assign  onode_2[15]=onode_1[15];
118
///////////////////////// layer 3 ////////////////////////////
119
wire    [15:0]onode_3;
120
assign  onode_3[0]=onode_2[0]&onode_2[2];
121
assign  onode_3[1]=onode_2[1]&onode_2[3];
122
assign  onode_3[2]=onode_2[2]&onode_2[4];
123
assign  onode_3[3]=onode_2[3]&onode_2[5];
124
assign  onode_3[4]=onode_2[4]&onode_2[6];
125
assign  onode_3[5]=onode_2[5]&onode_2[7];
126
assign  onode_3[6]=onode_2[6]&onode_2[8];
127
assign  onode_3[7]=onode_2[7]&onode_2[9];
128
assign  onode_3[8]=onode_2[8]&onode_2[10];
129
assign  onode_3[9]=onode_2[9]&onode_2[11];
130
assign  onode_3[10]=onode_2[10]&onode_2[12];
131
assign  onode_3[11]=onode_2[11]&onode_2[13];
132
assign  onode_3[12]=onode_2[12]&onode_2[14];
133
assign  onode_3[13]=onode_2[13]&onode_2[15];
134
assign  onode_3[14]=onode_2[14];
135
assign  onode_3[15]=onode_2[15];
136
///////////////////////// layer 4 ////////////////////////////
137
wire    [15:0]onode_4;
138
assign  onode_4[0]=onode_3[0]&onode_3[4];
139
assign  onode_4[1]=onode_3[1]&onode_3[5];
140
assign  onode_4[2]=onode_3[2]&onode_3[6];
141
assign  onode_4[3]=onode_3[3]&onode_3[7];
142
assign  onode_4[4]=onode_3[4]&onode_3[8];
143
assign  onode_4[5]=onode_3[5]&onode_3[9];
144
assign  onode_4[6]=onode_3[6]&onode_3[10];
145
assign  onode_4[7]=onode_3[7]&onode_3[11];
146
assign  onode_4[8]=onode_3[8]&onode_3[12];
147
assign  onode_4[9]=onode_3[9]&onode_3[13];
148
assign  onode_4[10]=onode_3[10]&onode_3[14];
149
assign  onode_4[11]=onode_3[11]&onode_3[15];
150
assign  onode_4[12]=onode_3[12];
151
assign  onode_4[13]=onode_3[13];
152
assign  onode_4[14]=onode_3[14];
153
assign  onode_4[15]=onode_3[15];
154
///////////////////////// layer 5 ////////////////////////////
155
wire    [15:0]onode_5;
156
assign  onode_5[0]=onode_4[0]&onode_4[8];
157
assign  onode_5[1]=onode_4[1]&onode_4[9];
158
assign  onode_5[2]=onode_4[2]&onode_4[10];
159
assign  onode_5[3]=onode_4[3]&onode_4[11];
160
assign  onode_5[4]=onode_4[4]&onode_4[12];
161
assign  onode_5[5]=onode_4[5]&onode_4[13];
162
assign  onode_5[6]=onode_4[6]&onode_4[14];
163
assign  onode_5[7]=onode_4[7]&onode_4[15];
164
assign  onode_5[8]=onode_4[8];
165
assign  onode_5[9]=onode_4[9];
166
assign  onode_5[10]=onode_4[10];
167
assign  onode_5[11]=onode_4[11];
168
assign  onode_5[12]=onode_4[12];
169
assign  onode_5[13]=onode_4[13];
170
assign  onode_5[14]=onode_4[14];
171
assign  onode_5[15]=onode_4[15];
172
 
173
 
174
// even nodes
175
wire    [14:0]enode;
176
assign  enode[14]=onode_5[15]&node_0[29];
177
assign  enode[13]=onode_5[14]&node_0[27];
178
assign  enode[12]=onode_5[13]&node_0[25];
179
assign  enode[11]=onode_5[12]&node_0[23];
180
assign  enode[10]=onode_5[11]&node_0[21];
181
assign  enode[9]=onode_5[10]&node_0[19];
182
assign  enode[8]=onode_5[9]&node_0[17];
183
assign  enode[7]=onode_5[8]&node_0[15];
184
assign  enode[6]=onode_5[7]&node_0[13];
185
assign  enode[5]=onode_5[6]&node_0[11];
186
assign  enode[4]=onode_5[5]&node_0[9];
187
assign  enode[3]=onode_5[4]&node_0[7];
188
assign  enode[2]=onode_5[3]&node_0[5];
189
assign  enode[1]=onode_5[2]&node_0[3];
190
assign  enode[0]=onode_5[1]&node_0[1];
191
 
192
// shift amount genration
193
wire    shift_1;
194
assign  shift_1=onode_5[15];
195
wire    [1:0]shift_2;
196
assign  shift_2[0]=onode_5[14];
197
assign  shift_2[1]=enode[14];
198
wire    [1:0]shift_3;
199
assign  shift_3[0]=onode_5[13];
200
assign  shift_3[1]=enode[13];
201
wire    [3:0]shift_4;
202
assign  shift_4[0]=onode_5[11];
203
assign  shift_4[1]=enode[11];
204
assign  shift_4[2]=onode_5[12];
205
assign  shift_4[3]=enode[12];
206
wire    [7:0]shift_5;
207
assign  shift_5[0]=onode_5[7];
208
assign  shift_5[1]=enode[7];
209
assign  shift_5[2]=onode_5[8];
210
assign  shift_5[3]=enode[8];
211
assign  shift_5[4]=onode_5[9];
212
assign  shift_5[5]=enode[9];
213
assign  shift_5[6]=onode_5[10];
214
assign  shift_5[7]=enode[10];
215
wire    [13:0]shift_6;
216
assign  shift_6[0]=onode_5[0];
217
assign  shift_6[1]=enode[0];
218
assign  shift_6[2]=onode_5[1];
219
assign  shift_6[3]=enode[1];
220
assign  shift_6[4]=onode_5[2];
221
assign  shift_6[5]=enode[2];
222
assign  shift_6[6]=onode_5[3];
223
assign  shift_6[7]=enode[3];
224
assign  shift_6[8]=onode_5[4];
225
assign  shift_6[9]=enode[4];
226
assign  shift_6[10]=onode_5[5];
227
assign  shift_6[11]=enode[5];
228
assign  shift_6[12]=onode_5[6];
229
assign  shift_6[13]=enode[6];
230
 
231
// shift tree
232
 
233
wire    [31:0]data_1,data_2,data_3,data_4,data_5;
234
shift_1b        shift_1b_0(
235
shift_1,
236
i_data,
237
data_1
238
);
239
 
240
shift_3b        shift_3b_0(
241
{shift_2,1'b0},
242
data_1,
243
data_2
244
);
245
 
246
shift_3b        shift_3b_1(
247
{shift_3,1'b0},
248
data_2,
249
data_3
250
);
251
 
252
shift_7b        shift_7b_0(
253
{shift_4,3'b0},
254
data_3,
255
o_data
256
);
257
/*
258
shift_7b        shift_7b_0(
259
{shift_4,3'b0},
260
data_3,
261
data_4
262
);
263
 
264
shift_15b       shift_15b_0(
265
{shift_5,7'b0},
266
data_4,
267
data_5
268
);
269
 
270
shift_15b       shift_15b_1(
271
{shift_6,1'b0},
272
data_5,
273
o_data
274
);
275
*/
276
// number of shifted bits determination
277
wire    [4:0]shifted_1,shifted_2,shifted_3,shifted_4,shifted_5;
278
assign  shifted_1=shift_1?1:0;
279
assign  shifted_2=      (shift_2==2'b11)?3:
280
                        (shift_2==2'b10)?2:shifted_1;
281
assign  shifted_3=      (shift_3==2'b11)?5:
282
                        (shift_3==2'b10)?4:shifted_2;
283
 
284
assign  o_shifted=      (shift_4==4'b1111)?9:
285
                        (shift_4==4'b1110)?8:
286
                        (shift_4==4'b1100)?7:
287
                        (shift_4==4'b1000)?6:shifted_3;
288
 
289
/*
290
assign  shifted_4=      (shift_4==4'b1111)?9:
291
                        (shift_4==4'b1110)?8:
292
                        (shift_4==4'b1100)?7:
293
                        (shift_4==4'b1000)?6:shifted_3;
294
assign  shifted_5=      (shift_5==8'b11111111)?17:
295
                        (shift_5==8'b11111110)?16:
296
                        (shift_5==8'b11111100)?15:
297
                        (shift_5==8'b11111000)?14:
298
                        (shift_5==8'b11110000)?13:
299
                        (shift_5==8'b11100000)?12:
300
                        (shift_5==8'b11000000)?11:
301
                        (shift_5==8'b10000000)?10:shifted_4;
302
assign  o_shifted=      (shift_6==14'b11111111111111)?31:
303
                        (shift_6==14'b11111111111110)?30:
304
                        (shift_6==14'b11111111111100)?29:
305
                        (shift_6==14'b11111111111000)?28:
306
                        (shift_6==14'b11111111110000)?27:
307
                        (shift_6==14'b11111111100000)?26:
308
                        (shift_6==14'b11111111000000)?25:
309
                        (shift_6==14'b11111110000000)?24:
310
                        (shift_6==14'b11111100000000)?23:
311
                        (shift_6==14'b11111000000000)?22:
312
                        (shift_6==14'b11110000000000)?21:
313
                        (shift_6==14'b11100000000000)?20:
314
                        (shift_6==14'b11000000000000)?19:
315
                        (shift_6==14'b10000000000000)?18:shifted_5;
316
*/
317
 
318
 
319
endmodule

powered by: WebSVN 2.1.0

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