OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [rtl/] [src_noc/] [comb_spec2.v] - Blame information for rev 48

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
`timescale      1ns/1ps
2
 
3
/**********************************************************************
4
**      File: comb_spec2.v
5
**
6
**      Copyright (C) 2014-2017  Alireza Monemi
7
**
8
**      This file is part of ProNoC
9
**
10
**      ProNoC ( stands for Prototype Network-on-chip)  is free software:
11
**      you can redistribute it and/or modify it under the terms of the GNU
12
**      Lesser General Public License as published by the Free Software Foundation,
13
**      either version 2 of the License, or (at your option) any later version.
14
**
15
**      ProNoC is distributed in the hope that it will be useful, but WITHOUT
16
**      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
**      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
18
**      Public License for more details.
19
**
20
**      You should have received a copy of the GNU Lesser General Public
21
**      License along with ProNoC. If not, see <http:**www.gnu.org/licenses/>.
22
**
23
**
24
**      Description:
25
**      VC allocator combined with speculative switch allocator
26
**      where the free VC availability is checked in the middle
27
**      of switch allocator after first level of arbitration
28
**      (comb-spec2).
29
**
30
**************************************************************/
31
 
32
 
33
module  comb_spec2_allocator #(
34
    parameter V = 4,// Virtual chanel num per port
35
    parameter P = 5,
36
    parameter DEBUG_EN = 1,
37
    parameter SWA_ARBITER_TYPE = "WRRA",
38
    parameter MIN_PCK_SIZE=2, //minimum packet size in flits. The minimum value is 1.
39
    parameter SELF_LOOP_EN="NO"
40
)(
41
    dest_port_all,
42
    masked_ovc_request_all,
43
    ovc_is_assigned_all,
44
    ivc_request_all,
45
    assigned_ovc_not_full_all,
46
    ovc_allocated_all,
47
    granted_ovc_num_all,
48
    ivc_num_getting_ovc_grant,
49
    ivc_num_getting_sw_grant,
50
    spec_first_arbiter_granted_ivc_all,
51
    nonspec_first_arbiter_granted_ivc_all,
52
    granted_dest_port_all,
53
    nonspec_granted_dest_port_all,
54
    any_ivc_sw_request_granted_all,
55
    vc_weight_is_consumed_all,
56
    iport_weight_is_consumed_all,
57
    pck_is_single_flit_all,
58
    granted_dst_is_from_a_single_flit_pck,
59
    clk,reset
60
);
61
 
62
 
63
    localparam
64
        PV = V * P,
65
        VV = V * V,
66
        PVV = PV * V,
67
        P_1 = (SELF_LOOP_EN == "NO")?  P-1 : P,
68
        VP_1 = V * P_1,
69
        PP_1 = P_1 * P,
70
        PVP_1 = PV * P_1;
71
 
72
    input  [PVP_1-1 : 0] dest_port_all;
73
    input  [PVV-1 :  0] masked_ovc_request_all;
74
    input  [PV-1 : 0] ovc_is_assigned_all;
75
    input  [PV-1 : 0] ivc_request_all;
76
    input  [PV-1 : 0] assigned_ovc_not_full_all;
77
    input  [PV-1 : 0] vc_weight_is_consumed_all;
78
    input  [P-1 : 0] iport_weight_is_consumed_all;
79
 
80
    output [PV-1 : 0] ovc_allocated_all;
81
    output [PVV-1 : 0] granted_ovc_num_all;
82
    output [PV-1 : 0] ivc_num_getting_ovc_grant;
83
    output [PV-1 : 0] ivc_num_getting_sw_grant;
84
    output [PV-1 : 0] nonspec_first_arbiter_granted_ivc_all;
85
    output [PV-1 : 0] spec_first_arbiter_granted_ivc_all;
86
 
87
    output [PP_1-1 : 0] granted_dest_port_all;
88
    output [PP_1-1 : 0] nonspec_granted_dest_port_all;
89
    output [P-1 : 0] any_ivc_sw_request_granted_all;
90
 
91
    input  [PV-1 : 0] pck_is_single_flit_all;
92
    output [P-1 : 0] granted_dst_is_from_a_single_flit_pck;
93
    input  clk,reset;
94
 
95
    //internal wires switch allocator
96
 
97
    wire [PV-1 : 0] spec_first_arbiter_granted_ivc_all;
98
    wire [PP_1-1 : 0] spec_granted_dest_port_all;
99
    wire [P-1 : 0] spec_any_ivc_grant_valid;
100
    wire [PV-1 : 0]  valid_speculation;
101
 
102
 
103
 
104
    //speculative switch allocator 
105
    spec_sw_alloc2 #(
106
        .V (V),
107
        .P (P),
108
        .DEBUG_EN (DEBUG_EN),
109
        .SWA_ARBITER_TYPE (SWA_ARBITER_TYPE),
110
        .MIN_PCK_SIZE(MIN_PCK_SIZE)
111
    )
112
    speculative_sw_allocator
113
    (
114
        .ivc_granted_all(ivc_num_getting_sw_grant),
115
        .ivc_request_all(ivc_request_all),
116
        .ovc_is_assigned_all(ovc_is_assigned_all),
117
        .assigned_ovc_not_full_all(assigned_ovc_not_full_all),
118
        .dest_port_all(dest_port_all),
119
        .granted_dest_port_all(granted_dest_port_all),
120
        .nonspec_granted_dest_port_all(nonspec_granted_dest_port_all),
121
        .valid_speculation(valid_speculation),
122
        .spec_first_arbiter_granted_ivc_all(spec_first_arbiter_granted_ivc_all),
123
        .nonspec_first_arbiter_granted_ivc_all(nonspec_first_arbiter_granted_ivc_all),
124
        .spec_granted_dest_port_all(spec_granted_dest_port_all),
125
        .spec_any_ivc_grant_valid(spec_any_ivc_grant_valid),
126
        .any_ivc_sw_request_granted_all(any_ivc_sw_request_granted_all),
127
        .vc_weight_is_consumed_all(vc_weight_is_consumed_all),
128
        .iport_weight_is_consumed_all(iport_weight_is_consumed_all),
129
        .pck_is_single_flit_all(pck_is_single_flit_all),
130
        .granted_dst_is_from_a_single_flit_pck(granted_dst_is_from_a_single_flit_pck),
131
        .clk(clk),
132
        .reset(reset)
133
 
134
    );
135
 
136
    wire  [V-1 : 0] masked_non_assigned_request [PV-1 : 0];
137
    wire  [VV-1 : 0] masked_candidate_ovc_per_port [P-1 : 0];
138
    wire  [V-1 : 0] spec_first_arbiter_granted_ivc_per_port[P-1 : 0];
139
    wire  [V-1 : 0] spec_first_arbiter_ovc_request [P-1 : 0];
140
    wire  [V-1 : 0]  spec_first_arbiter_ovc_granted [P-1 : 0];
141
    wire  [P_1-1 : 0] spec_granted_dest_port_per_port [P-1 : 0];
142
    wire  [VP_1-1 : 0] cand_ovc_granted [P-1 : 0];
143
    wire  [P_1-1 : 0] ovc_allocated_all_gen [PV-1 : 0];
144
    wire  [V-1 : 0] granted_ovc_local_num_per_port [P-1 : 0];
145
    wire  [V-1 : 0] ivc_local_num_getting_ovc_grant [P-1 : 0];
146
 
147
    genvar i,j;
148
    generate
149
 
150
    // IVC loop
151
    for(i=0;i< PV;i=i+1) begin :total_vc_loop
152
 
153
        // mask unavailable ovc from requests
154
        assign masked_non_assigned_request    [i]     =   masked_ovc_request_all [(i+1)*V-1 :  i*V ];
155
        assign valid_speculation                [i]        = | masked_non_assigned_request    [i];
156
 
157
    end//for
158
 
159
    for(i=0;i< P;i=i+1) begin :port_loop3
160
            for(j=0;j< V;j=j+1) begin :vc_loop
161
                //merge masked_candidate_ovc in each port
162
                assign masked_candidate_ovc_per_port[i][(j+1)*V-1 : j*V]    =    masked_non_assigned_request    [i*V+j];
163
 
164
            end//for j
165
 
166
            assign spec_first_arbiter_granted_ivc_per_port[i]    =spec_first_arbiter_granted_ivc_all[(i+1)*V-1 : i*V];
167
            assign spec_granted_dest_port_per_port[i]                =spec_granted_dest_port_all[(i+1)*P_1-1 : i*P_1];
168
            // multiplex candidate OVC of first level switch allocatore winner
169
 
170
        one_hot_mux #(
171
            .IN_WIDTH (VV),
172
            .SEL_WIDTH (V)
173
        )
174
        multiplexer2
175
        (
176
            .mux_in(masked_candidate_ovc_per_port [i]),
177
            .mux_out(spec_first_arbiter_ovc_request [i]),
178
            .sel(spec_first_arbiter_granted_ivc_per_port [i])
179
 
180
        );
181
 
182
 
183
        //first level arbiter to candidate only one OVC 
184
        arbiter #(
185
            .ARBITER_WIDTH (V)
186
        )
187
        second_arbiter
188
        (
189
            .clk(clk),
190
            .reset(reset),
191
            .request(spec_first_arbiter_ovc_request[i]),
192
            .grant(spec_first_arbiter_ovc_granted[i]),
193
            .any_grant( )
194
        );
195
 
196
 
197
        //demultiplexer
198
        one_hot_demux #(
199
            .IN_WIDTH(V),
200
            .SEL_WIDTH(P_1)
201
        )
202
        demux1
203
        (
204
            .demux_sel(spec_granted_dest_port_per_port [i]),//selectore
205
            .demux_in(spec_first_arbiter_ovc_granted[i]),//repeated
206
            .demux_out(cand_ovc_granted[i])
207
        );
208
 
209
 
210
 
211
        //assign cand_ovc_granted [i]    =             (spec_any_ivc_grant_valid[i])?  cand_ovc_demuxed[i]: {VP_1{1'b0}};
212
        assign granted_ovc_local_num_per_port[i]=(spec_any_ivc_grant_valid[i])?  spec_first_arbiter_ovc_granted[i] : {V{1'b0}};
213
        assign ivc_local_num_getting_ovc_grant[i]= (spec_any_ivc_grant_valid[i])? spec_first_arbiter_granted_ivc_per_port [i] : {V{1'b0}};
214
        assign ivc_num_getting_ovc_grant[(i+1)*V-1 : i*V] = ivc_local_num_getting_ovc_grant[i];
215
        for(j=0;j<V;    j=j+1)begin: assign_loop3
216
            assign granted_ovc_num_all[(i*VV)+((j+1)*V)-1 : (i*VV)+(j*V)]=granted_ovc_local_num_per_port[i];
217
 
218
        end//j
219
    end//i
220
 
221
    //wire     [PORT_SEL-1 : 0]    ovc_allocated_all_gen    [PV-1 : 0];
222
    //wire    [VP_1-1 : 0] cand_ovc_granted    [P-1 : 0];
223
    wire [PV-1 : 0]    result;
224
    for(i=0;i< PV;i=i+1) begin :total_vc_loop2
225
        for(j=0;j<P;    j=j+1)begin: assign_loop2
226
            if((i/V)<j )begin: jj
227
                assign ovc_allocated_all_gen[i][j-1]    = cand_ovc_granted[j][i];
228
            end else if((i/V)>j) begin: hh
229
                assign ovc_allocated_all_gen[i][j]    = cand_ovc_granted[j][i-V];
230
 
231
            end
232
        end//j
233
 
234
        assign ovc_allocated_all [i] = |ovc_allocated_all_gen[i];
235
 
236
    //synthesis translate_off
237
    //synopsys  translate_off
238
    if(DEBUG_EN)begin :dbg
239
        check_single_bit_assertation #(
240
            .IN_WIDTH(P_1)
241
 
242
        )check_ovc_allocated
243
        (
244
            .in        (ovc_allocated_all_gen[i]),
245
            .result    (result[i])
246
 
247
        );
248
 
249
        always @(posedge clk ) begin
250
          if(~result[i]) $display("%t,Error: An OVC is assigned to more than one IVC %m",$time);
251
        end
252
     end //DEBUG
253
    //synopsys  translate_on
254
    //synthesis translate_on
255
 
256
    end//i
257
 
258
 
259
    endgenerate
260
 
261
endmodule
262
 
263
/***************************
264
 
265
speculative switch allocator for
266
        comb_spec2
267
 
268
****************************/
269
 
270
 
271
module spec_sw_alloc2 #(
272
    parameter V = 4,
273
    parameter P = 5,
274
    parameter DEBUG_EN = 1,
275
    parameter SWA_ARBITER_TYPE="RRA",
276
    parameter MIN_PCK_SIZE=2 //minimum packet size in flits. The minimum value is 1.       
277
)(
278
 
279
    ivc_granted_all,
280
    ivc_request_all,
281
    ovc_is_assigned_all,
282
    assigned_ovc_not_full_all,
283
    dest_port_all,
284
    nonspec_granted_dest_port_all,
285
    granted_dest_port_all,
286
    valid_speculation,
287
    spec_first_arbiter_granted_ivc_all,
288
    nonspec_first_arbiter_granted_ivc_all,
289
    spec_granted_dest_port_all,
290
    spec_any_ivc_grant_valid,
291
    any_ivc_sw_request_granted_all,
292
    vc_weight_is_consumed_all,
293
    iport_weight_is_consumed_all,
294
    pck_is_single_flit_all,
295
    granted_dst_is_from_a_single_flit_pck,
296
    clk,
297
    reset
298
 
299
);
300
 
301
 
302
    localparam  P_1         =   P-1,//assumed that no port request for itself!
303
                    PV              =   V       *   P,
304
                    VP_1            =   V       *   P_1,
305
                    PVP_1           =   P       *   VP_1,
306
                    PP_1            =   P_1 *   P;
307
 
308
    output [PV-1 :  0]  ivc_granted_all;
309
    input  [PV-1 :  0] ivc_request_all;
310
    input  [PV-1 :  0] ovc_is_assigned_all;
311
    input  [PV-1 :  0] assigned_ovc_not_full_all;
312
    input  [PVP_1-1 : 0]  dest_port_all;
313
    output [PP_1-1 :  0]  granted_dest_port_all;
314
    output [PP_1-1 :  0]  nonspec_granted_dest_port_all;
315
    input  [PV-1 :  0]  valid_speculation;
316
    output [PV-1 :  0]  spec_first_arbiter_granted_ivc_all;
317
    output [PV-1 :  0]  nonspec_first_arbiter_granted_ivc_all;
318
    output [PP_1-1 : 0]  spec_granted_dest_port_all;
319
    output [P-1 :  0]  spec_any_ivc_grant_valid;
320
    output [P-1 :  0]  any_ivc_sw_request_granted_all;
321
    input  [PV-1 : 0] vc_weight_is_consumed_all;
322
    input  [P-1 : 0] iport_weight_is_consumed_all;
323
    input  [PV-1 : 0] pck_is_single_flit_all;
324
    output [P-1 : 0] granted_dst_is_from_a_single_flit_pck;
325
 
326
    input clk,reset;
327
 
328
    //internal wire 
329
    wire  [PV-1 :  0]  spec_ivc_granted_all,nonspec_ivc_granted_all;
330
    wire  [PV-1 :  0] spec_ivc_request_all,nonspec_ivc_request_all;
331
    wire  [PV-1 :  0] spec_assigned_ovc_not_full_all,nonspec_assigned_ovc_not_full_all;
332
    wire  [PVP_1-1 :  0]  spec_dest_port_all,nonspec_dest_port_all;
333
    wire  [PP_1-1 :  0]  spec_granted_dest_port_all,spec_granted_dest_port_all_accepted;
334
    wire  [P-1 :  0]  nonspec_inport_granted_all,nonspec_outport_granted_all;
335
    wire  [PP_1-1 :  0]  spec_granted_dest_port_all_pre;
336
 
337
    wire  [P_1-1 :  0] nonspec_portsel_granted [P-1 :  0];
338
    wire  [PP_1-1 :  0] spec_request_acceptable;
339
    wire  [P_1-1 :  0] spec_request_accepted [P-1 :  0];
340
    wire  [P-1 :  0] any_spec_request_accepted;
341
    wire  [PV-1 :  0] spec_ivc_granted_all_accepted;
342
    wire  [P-1 :  0] spec_any_ivc_grant,nonspec_any_ivc_grant;
343
 
344
 
345
    spec_sw_alloc_sub2#(
346
        .V(V),
347
        .P(P),
348
        .SWA_ARBITER_TYPE(SWA_ARBITER_TYPE),
349
        .MIN_PCK_SIZE(MIN_PCK_SIZE)
350
    )
351
    speculative_alloc
352
    (
353
        .valid_speculation (valid_speculation),
354
        .ivc_granted_all (spec_ivc_granted_all),
355
        .ivc_request_all (spec_ivc_request_all),
356
        .assigned_ovc_not_full_all (spec_assigned_ovc_not_full_all),
357
        .dest_port_all (spec_dest_port_all),
358
        .granted_dest_port_all  (spec_granted_dest_port_all_pre),
359
        .first_arbiter_granted_ivc_all (spec_first_arbiter_granted_ivc_all),
360
        .first_arbiter_granted_port_all ( ),
361
        .any_ivc_grant (spec_any_ivc_grant),
362
        .vc_weight_is_consumed_all(vc_weight_is_consumed_all),
363
        .iport_weight_is_consumed_all(iport_weight_is_consumed_all),
364
        .pck_is_single_flit_all(pck_is_single_flit_all),
365
        .granted_dst_is_from_a_single_flit_pck(granted_dst_is_from_a_single_flit_pck),
366
        .inport_granted_all ( ),
367
        .outport_granted_all ( ),
368
        .clk (clk),
369
        .reset (reset)
370
    );
371
 
372
 
373
    sw_alloc_sub2#(
374
        .V (V),
375
        .P (P),
376
        .SWA_ARBITER_TYPE(SWA_ARBITER_TYPE),
377
        .MIN_PCK_SIZE(MIN_PCK_SIZE)
378
    )
379
    nonspeculative_alloc
380
    (
381
 
382
        .ivc_granted_all (nonspec_ivc_granted_all),
383
        .ivc_request_all (nonspec_ivc_request_all),
384
        .assigned_ovc_not_full_all (nonspec_assigned_ovc_not_full_all),
385
        .dest_port_all (nonspec_dest_port_all),
386
        .granted_dest_port_all (nonspec_granted_dest_port_all),
387
        .inport_granted_all (nonspec_inport_granted_all),
388
        .outport_granted_all (nonspec_outport_granted_all),
389
        .first_arbiter_granted_ivc_all (nonspec_first_arbiter_granted_ivc_all),
390
        .first_arbiter_granted_port_all ( ),
391
        .any_ivc_grant (nonspec_any_ivc_grant),
392
        .vc_weight_is_consumed_all(vc_weight_is_consumed_all),
393
        .iport_weight_is_consumed_all(iport_weight_is_consumed_all),
394
        .pck_is_single_flit_all( ),
395
        .granted_dst_is_from_a_single_flit_pck( ),
396
        .clk (clk),
397
        .reset (reset)
398
    );
399
 
400
    assign nonspec_ivc_request_all      = ivc_request_all &  ovc_is_assigned_all;
401
    assign spec_ivc_request_all         = ivc_request_all &  ~ovc_is_assigned_all;
402
    assign spec_assigned_ovc_not_full_all           = {PV{1'b1}};
403
    assign nonspec_assigned_ovc_not_full_all        = assigned_ovc_not_full_all;
404
    assign spec_dest_port_all               = dest_port_all;
405
    assign nonspec_dest_port_all            = dest_port_all;
406
 
407
    wire [P_1-1 :  0]  nonspec_check [P-1:0];
408
    wire [P_1-1 :  0]  spec_check [P-1:0];
409
 
410
    genvar i,j;
411
    generate
412
    for(i=0;i<P; i=i+1) begin :port_lp
413
        //remove non-spec inport from the nonspec_outport_granted_all
414
        for(j=0;j<P;    j=j+1)begin: port_loop2
415
            if(i<j)begin: jj
416
                assign nonspec_portsel_granted[i][j-1]  = nonspec_outport_granted_all[j];
417
            end else if(i>j)begin: hh
418
                assign nonspec_portsel_granted[i][j]        = nonspec_outport_granted_all [j];
419
            end
420
            //if(i==j) wires are left disconnected  
421
        end//j
422
        // an speculative grant is acceptable if the non-speculative request is not granted for both inport request and outport grant
423
        assign spec_request_acceptable[(i+1)*P_1-1 :  i*P_1] = (nonspec_inport_granted_all[i])? {P_1{1'b0}} : ~nonspec_portsel_granted[i];
424
        assign spec_request_accepted  [i]= spec_request_acceptable[(i+1)*P_1-1 :  i*P_1] & spec_granted_dest_port_all_pre[(i+1)*P_1-1 :  i*P_1];
425
        assign any_spec_request_accepted [i] = |spec_request_accepted  [i];
426
        assign spec_ivc_granted_all_accepted[(i+1)*V-1 :  i*V] = (any_spec_request_accepted [i] )? spec_ivc_granted_all[(i+1)*V-1 :  i*V]: {V{1'b0}};
427
        assign spec_granted_dest_port_all_accepted[(i+1)*P_1-1 :  i*P_1]= spec_request_accepted  [i];
428
 
429
        //synthesis translate_off
430
    //synopsys  translate_off
431
        if(DEBUG_EN)begin :dbg
432
            assign nonspec_check[i] = nonspec_granted_dest_port_all[(i+1)*P_1-1 :  i*P_1];
433
            assign spec_check[i]= spec_granted_dest_port_all_accepted[(i+1)*P_1-1 :  i*P_1];
434
            always @(posedge clk) begin
435
                if(nonspec_granted_dest_port_all[(i+1)*P_1-1 :  i*P_1] >0 && spec_granted_dest_port_all_accepted[(i+1)*P_1-1 :  i*P_1]>0 ) $display("%t: Error: Both speculative and nonspeculative is granted for one port",$time);
436
                if(nonspec_ivc_granted_all [(i+1)*V-1 :  i*V] >0 && spec_ivc_granted_all_accepted[(i+1)*V-1 :  i*V]>0 ) $display("%t: Error: Both speculative and nonspeculative is granted for one port",$time);
437
            end//always
438
        end // DEBUG
439
    //synopsys  translate_on
440
        //synthesis translate_on
441
 
442
 
443
    end//i
444
    endgenerate
445
 
446
    assign spec_any_ivc_grant_valid         = any_spec_request_accepted &  spec_any_ivc_grant;
447
    assign any_ivc_sw_request_granted_all   = nonspec_any_ivc_grant | spec_any_ivc_grant_valid;
448
 
449
 
450
 
451
    assign granted_dest_port_all                = nonspec_granted_dest_port_all | spec_granted_dest_port_all_accepted;
452
    assign ivc_granted_all                      = nonspec_ivc_granted_all         | spec_ivc_granted_all_accepted;
453
    assign spec_granted_dest_port_all       = spec_granted_dest_port_all_accepted;
454
 
455
 
456
 
457
endmodule
458
 
459
/*******************************************
460
*
461
*    speculative switch allocator
462
*
463
*******************************************/
464
 
465
 
466
module sw_alloc_sub2#(
467
    parameter V = 4,
468
    parameter P = 5,
469
    parameter SWA_ARBITER_TYPE="RRA",
470
     parameter MIN_PCK_SIZE=2 //minimum packet size in flits. The minimum value is 1.           
471
 
472
)(
473
    ivc_granted_all,
474
    ivc_request_all,
475
    assigned_ovc_not_full_all,
476
    dest_port_all,
477
    granted_dest_port_all,
478
    inport_granted_all,
479
    outport_granted_all,
480
    first_arbiter_granted_ivc_all,
481
    first_arbiter_granted_port_all,
482
    any_ivc_grant,
483
    vc_weight_is_consumed_all,
484
    iport_weight_is_consumed_all,
485
    pck_is_single_flit_all,
486
    granted_dst_is_from_a_single_flit_pck,
487
    clk,
488
    reset
489
 
490
);
491
 
492
    localparam
493
        P_1 = P-1,//assumed that no port request for itself!
494
        PV = V * P,
495
        VP_1 = V * P_1,
496
        PVP_1 = P * VP_1,
497
        PP_1 = P_1 * P,
498
        PP = P * P;
499
 
500
 
501
 
502
    output [PV-1 :  0]  ivc_granted_all;
503
    input  [PV-1 :  0] ivc_request_all;
504
    input  [PV-1 :  0] assigned_ovc_not_full_all;
505
    input  [PVP_1-1 :  0]  dest_port_all;
506
    output [PP_1-1 :  0]  granted_dest_port_all;
507
    output [P-1 :  0]  inport_granted_all;
508
    output [P-1 :  0]  outport_granted_all;
509
    output [PV-1 :  0]  first_arbiter_granted_ivc_all;
510
    output [PP_1-1 :  0]  first_arbiter_granted_port_all;
511
    output [P-1 :  0]  any_ivc_grant;
512
    input  [PV-1 : 0 ] vc_weight_is_consumed_all;
513
    input  [PV-1 : 0 ] iport_weight_is_consumed_all;
514
    input  [PV-1 : 0] pck_is_single_flit_all;
515
    output [P-1 : 0] granted_dst_is_from_a_single_flit_pck;
516
    input  clk;
517
    input  reset;
518
 
519
    //separte input per port
520
    wire [V-1 :  0]  ivc_granted [P-1 :  0];
521
    wire [V-1 :  0]  ivc_request [P-1 :  0];
522
    wire [V-1 :  0]  ivc_not_full [P-1 :  0];
523
    wire [VP_1-1 :  0] dest_port_ivc [P-1 :  0];
524
    wire [P_1-1 :  0]  granted_dest_port [P-1 :  0];
525
 
526
    // internal wires
527
    wire [V-1 :  0] ivc_masked [P-1 :  0];//output of mask and             
528
    wire [V-1 :  0] first_arbiter_grant [P-1 :  0];//output of first arbiter            
529
    wire [P_1-1 :  0]  dest_port [P-1 :  0];//output of multiplexer
530
    wire [P_1-1 :  0]  second_arbiter_request [P-1 :  0];
531
    wire [P_1-1 :  0]  second_arbiter_grant [P-1 :  0];
532
    wire [P_1-1 : 0] second_arbiter_weight_consumed [P-1 : 0];
533
    wire [V-1 : 0] vc_weight_is_consumed [P-1 : 0];
534
    wire [P-1 : 0] winner_weight_consumed;
535
 
536
    wire [P_1-1 : 0] single_flit_granted_dst [P-1 : 0];
537
    wire [PP-1 : 0] single_flit_granted_dst_all;
538
    wire [V-1 : 0] pck_is_single_flit [P-1 : 0];
539
    wire [P-1 : 0] single_flit_pck_local_grant;
540
 
541
    genvar i,j;
542
    generate
543
 
544
    for(i=0;i< P;i=i+1) begin :port_loop
545
        //assign in/out to the port based wires
546
        //output
547
        assign ivc_granted_all          [(i+1)*V-1 :  i*V]    =   ivc_granted [i];
548
        assign granted_dest_port_all    [(i+1)*P_1-1 :  i*P_1]      =   granted_dest_port[i];
549
        assign first_arbiter_granted_ivc_all[(i+1)*V-1 :  i*V]=           first_arbiter_grant[i];
550
        //input 
551
        assign ivc_request[i]       = ivc_request_all [(i+1)*V-1 :  i*V];
552
        assign ivc_not_full[i]      = assigned_ovc_not_full_all[(i+1)*V-1 :  i*V];
553
        assign dest_port_ivc[i]     = dest_port_all [(i+1)*VP_1-1 :  i*VP_1];
554
        assign vc_weight_is_consumed[i]  =  vc_weight_is_consumed_all [(i+1)*V-1 : i*V];
555
 
556
        //mask
557
        assign ivc_masked[i]    = ivc_request[i] & ivc_not_full[i];
558
 
559
 
560
         //first level arbiter        
561
        swa_input_port_arbiter #(
562
            .ARBITER_WIDTH(V),
563
            .EXT_P_EN(0),
564
            .ARBITER_TYPE(SWA_ARBITER_TYPE)
565
        )
566
        input_arbiter
567
        (
568
            .ext_pr_en_i(1'b1),// not used here anyway
569
            .request(ivc_masked [i]),
570
            .grant(first_arbiter_grant[i]),
571
            .any_grant( ),
572
            .clk(clk),
573
            .reset(reset),
574
            .vc_weight_is_consumed(vc_weight_is_consumed[i]),
575
            .winner_weight_consumed(winner_weight_consumed[i])
576
        );
577
 
578
 
579
        //destination port multiplexer
580
         one_hot_mux #(
581
            .IN_WIDTH (VP_1),
582
            .SEL_WIDTH(V)
583
        )
584
        multiplexer
585
        (
586
            .mux_in(dest_port_ivc [i]),
587
            .mux_out(dest_port [i]),
588
            .sel(first_arbiter_grant [i])
589
 
590
        );
591
        assign first_arbiter_granted_port_all[(i+1)*P_1-1 :  i*P_1]  = dest_port     [i];
592
    if(MIN_PCK_SIZE == 1) begin :single_flit_supported
593
         assign pck_is_single_flit[i] = pck_is_single_flit_all [(i+1)*V-1 : i*V];
594
            //single_flit req multiplexer
595
            one_hot_mux #(
596
                .IN_WIDTH       (V),
597
                .SEL_WIDTH      (V)
598
            )
599
            multiplexer2
600
            (
601
                .mux_in (pck_is_single_flit  [i]),
602
                .mux_out (single_flit_pck_local_grant[i]),
603
                .sel (first_arbiter_grant[i])
604
 
605
            );
606
 
607
            assign  single_flit_granted_dst[i] = (single_flit_pck_local_grant[i])?  granted_dest_port[i] : {P_1{1'b0}};
608
 
609
            add_sw_loc_one_hot #(
610
                .P(P),
611
                .SW_LOC(i)
612
            )
613
            add_sw_loc
614
            (
615
                .destport_in(single_flit_granted_dst[i]),
616
                .destport_out(single_flit_granted_dst_all[(i+1)*P-1 : i*P])
617
            );
618
 
619
        end else begin : single_flit_notsupported
620
            assign single_flit_pck_local_grant[i] = 1'b0;
621
            assign single_flit_granted_dst[i] = {P_1{1'b0}};
622
            assign single_flit_granted_dst_all[(i+1)*P-1 : i*P]={P{1'b0}};
623
        end
624
 
625
 
626
 
627
    //second arbiter input/output generate
628
    for(j=0;j<P;    j=j+1)begin: assign_loop
629
        if(i<j)begin: jj
630
                assign second_arbiter_request[i][j-1] = dest_port[j][i];
631
                //assign second_arbiter_weight_consumed[i][j-1]  = winner_weight_consumed[j];
632
                assign second_arbiter_weight_consumed[i][j-1]  = iport_weight_is_consumed_all[j];
633
                assign granted_dest_port[j][i] = second_arbiter_grant  [i][j-1];
634
        end else if(i>j)begin: hh
635
                assign second_arbiter_request[i][j] = dest_port [j][i-1];
636
               // assign second_arbiter_weight_consumed[i][j]  = winner_weight_consumed[j];
637
                assign second_arbiter_weight_consumed[i][j]  = iport_weight_is_consumed_all[j];
638
                assign granted_dest_port[j][i-1] = second_arbiter_grant  [i][j];
639
        end
640
            //if(i==j) wires are left disconnected      
641
    end
642
 
643
 
644
       //second level arbiter 
645
        swa_output_port_arbiter #(
646
            .ARBITER_WIDTH(P_1),
647
            .ARBITER_TYPE(SWA_ARBITER_TYPE) // RRA, WRRA
648
        )
649
        output_arbiter
650
        (
651
           .weight_consumed(second_arbiter_weight_consumed[i]),  // only used for WRRA
652
           .clk(clk),
653
           .reset(reset),
654
           .request(second_arbiter_request [i]),
655
           .grant(second_arbiter_grant [i]),
656
           .any_grant(outport_granted_all [i])
657
        );
658
 
659
 
660
 
661
        //any ivc 
662
        assign  any_ivc_grant[i] = | granted_dest_port[i];
663
 
664
        assign  ivc_granted[i] =  (any_ivc_grant[i]) ? first_arbiter_grant[i] : {V{1'b0}};
665
 
666
        assign      inport_granted_all[i]   =any_ivc_grant[i];
667
    end//for
668
    endgenerate
669
 
670
         custom_or #(
671
            .IN_NUM(P),
672
            .OUT_WIDTH(P)
673
         )
674
         or_dst
675
         (
676
            .or_in(single_flit_granted_dst_all),
677
            .or_out(granted_dst_is_from_a_single_flit_pck)
678
        );
679
 
680
 
681
 
682
endmodule
683
 
684
 
685
 
686
module spec_sw_alloc_sub2#(
687
    parameter V = 4,
688
    parameter P = 5,
689
    parameter SWA_ARBITER_TYPE="RRA",
690
    parameter MIN_PCK_SIZE=2 //minimum packet size in flits. The minimum value is 1.       
691
 
692
)(
693
    valid_speculation,
694
    ivc_granted_all,
695
    ivc_request_all,
696
    assigned_ovc_not_full_all,
697
    dest_port_all,
698
    granted_dest_port_all,
699
    inport_granted_all,
700
    outport_granted_all,
701
    first_arbiter_granted_ivc_all,
702
    first_arbiter_granted_port_all,
703
    vc_weight_is_consumed_all,
704
    iport_weight_is_consumed_all,
705
    any_ivc_grant,
706
    pck_is_single_flit_all,
707
    granted_dst_is_from_a_single_flit_pck,
708
    clk,
709
    reset
710
 
711
);
712
 
713
 
714
    localparam
715
        P_1 = P-1,//assumed that no port request for itself!
716
        PV = V * P,
717
        VP_1 = V * P_1,
718
        PVP_1 = P * VP_1,
719
        PP_1 = P_1 * P,
720
        PP = P * P;
721
 
722
    input  [PV-1 :  0] valid_speculation;
723
    output [PV-1 :  0]  ivc_granted_all;
724
    input  [PV-1 :  0] ivc_request_all;
725
    input  [PV-1 :  0] assigned_ovc_not_full_all;
726
    input  [PVP_1-1 :  0]  dest_port_all;
727
    output [PP_1-1 :  0]  granted_dest_port_all;
728
    output [P-1 :  0]  inport_granted_all;
729
    output [P-1 :  0]  outport_granted_all;
730
    output [PV-1 :  0]  first_arbiter_granted_ivc_all;
731
    output [PP_1-1 :  0]  first_arbiter_granted_port_all;
732
    output [P-1 :  0]  any_ivc_grant;
733
    input  [PV-1 : 0 ] vc_weight_is_consumed_all;
734
    input  [P-1 : 0 ] iport_weight_is_consumed_all;
735
    input  [PV-1 : 0] pck_is_single_flit_all;
736
    output [P-1 : 0] granted_dst_is_from_a_single_flit_pck;
737
    input  clk, reset;
738
 
739
    //separte input per port
740
    wire  [V-1 : 0] ivc_granted [P-1 :  0];
741
    wire  [V-1 : 0] ivc_request [P-1 :  0];
742
    wire  [V-1 : 0] ivc_not_full [P-1 :  0];
743
    wire  [VP_1-1 : 0] dest_port_ivc [P-1 :  0];
744
    wire  [P_1-1 : 0] granted_dest_port [P-1 :  0];
745
 
746
    // internal wires
747
    wire [V-1 :  0] ivc_masked [P-1 :  0];//output of mask and             
748
    wire [V-1 :  0] first_arbiter_grant  [P-1 :  0];//output of first arbiter    
749
    wire [V-1 :  0] first_arbiter_grant_masked [P-1 :  0];//output of first arbiter        
750
    wire [P_1-1 :  0] dest_port [P-1 :  0];//output of multiplexer
751
    wire [P_1-1 :  0] second_arbiter_request [P-1 :  0];
752
    wire [P_1-1 :  0] second_arbiter_grant  [P-1 :  0];
753
    wire [P_1-1 : 0] second_arbiter_weight_consumed [P-1 : 0];
754
    wire [V-1 : 0] vc_weight_is_consumed [P-1 : 0];
755
    wire [P-1 : 0] winner_weight_consumed;
756
 
757
    wire [P_1-1 : 0] single_flit_granted_dst [P-1 : 0];
758
    wire [PP-1 : 0] single_flit_granted_dst_all;
759
    wire [V-1 : 0] pck_is_single_flit [P-1 : 0];
760
    wire    [P-1 : 0] single_flit_pck_local_grant;
761
 
762
    genvar i,j;
763
    generate
764
 
765
    for(i=0;i< P;i=i+1) begin :port_loop
766
        //assign in/out to the port based wires
767
        //output
768
        assign ivc_granted_all [(i+1)*V-1 :  i*V] =   ivc_granted [i];
769
        assign granted_dest_port_all [(i+1)*P_1-1:  i*P_1] = granted_dest_port[i];
770
        assign first_arbiter_granted_ivc_all[(i+1)*V-1 :  i*V]  = first_arbiter_grant_masked[i];
771
        //input 
772
        assign ivc_request[i] = ivc_request_all [(i+1)*V-1 :  i*V];
773
        assign ivc_not_full[i] = assigned_ovc_not_full_all[(i+1)*V-1 :  i*V];
774
        assign dest_port_ivc[i] = dest_port_all [(i+1)*VP_1-1 :  i*VP_1];
775
        assign vc_weight_is_consumed[i]  =  vc_weight_is_consumed_all [(i+1)*V-1 : i*V];
776
 
777
        //mask
778
        assign ivc_masked[i] = ivc_request[i] & ivc_not_full[i];
779
 
780
 
781
         //first level arbiter        
782
        swa_input_port_arbiter #(
783
            .ARBITER_WIDTH(V),
784
            .EXT_P_EN(0),
785
            .ARBITER_TYPE(SWA_ARBITER_TYPE)
786
        )
787
        input_arbiter
788
        (
789
            .ext_pr_en_i(1'b1),// not used here anyway
790
            .request(ivc_masked [i]),
791
            .grant(first_arbiter_grant[i]),
792
            .any_grant( ),
793
            .clk(clk),
794
            .reset(reset),
795
            .vc_weight_is_consumed(vc_weight_is_consumed[i]),
796
            .winner_weight_consumed(winner_weight_consumed[i])
797
        );
798
 
799
 
800
    // mask unvalid speculation
801
        assign first_arbiter_grant_masked[i]= first_arbiter_grant[i] & valid_speculation [(i+1)*V-1 :  i*V];
802
 
803
         if(MIN_PCK_SIZE == 1) begin :single_flit_supported
804
         assign pck_is_single_flit[i] = pck_is_single_flit_all [(i+1)*V-1 : i*V];
805
            //single_flit req multiplexer
806
            one_hot_mux #(
807
                .IN_WIDTH       (V),
808
                .SEL_WIDTH      (V)
809
            )
810
            multiplexer2
811
            (
812
                .mux_in (pck_is_single_flit  [i]),
813
                .mux_out (single_flit_pck_local_grant[i]),
814
                .sel (first_arbiter_grant[i])
815
 
816
            );
817
 
818
            assign  single_flit_granted_dst[i] = (single_flit_pck_local_grant[i])?  granted_dest_port[i] : {P_1{1'b0}};
819
 
820
            add_sw_loc_one_hot #(
821
                .P(P),
822
                .SW_LOC(i)
823
            )
824
            add_sw_loc
825
            (
826
                .destport_in(single_flit_granted_dst[i]),
827
                .destport_out(single_flit_granted_dst_all[(i+1)*P-1 : i*P])
828
            );
829
 
830
        end else begin : single_flit_notsupported
831
            assign single_flit_pck_local_grant[i] = 1'b0;
832
            assign single_flit_granted_dst[i] = {P_1{1'b0}};
833
            assign single_flit_granted_dst_all[(i+1)*P-1 : i*P]={P{1'b0}};
834
        end
835
 
836
 
837
 
838
 
839
 
840
        //destination port multiplexer
841
         one_hot_mux #(
842
            .IN_WIDTH (VP_1),
843
            .SEL_WIDTH (V)
844
        )
845
        multiplexer
846
        (
847
            .mux_in (dest_port_ivc [i]),
848
            .mux_out (dest_port [i]),
849
            .sel (first_arbiter_grant_masked[i])
850
        );
851
        assign first_arbiter_granted_port_all[(i+1)*P_1-1 :  i*P_1]  = dest_port     [i];
852
 
853
 
854
        //second arbiter input/output generate
855
        for(j=0;j<P;    j=j+1)begin: assign_loop
856
            if(i<j)begin: jj
857
                assign second_arbiter_request[i][j-1]   = dest_port[j][i];
858
                //assign second_arbiter_weight_consumed[i][j-1]  =winner_weight_consumed[j] ;
859
                assign second_arbiter_weight_consumed[i][j-1]  = iport_weight_is_consumed_all[j] ;
860
                assign granted_dest_port[j][i]  = second_arbiter_grant  [i][j-1]    ;
861
            end else if(i>j)begin: hh
862
                assign second_arbiter_request[i][j] = dest_port [j][i-1];
863
                //assign second_arbiter_weight_consumed[i][j]  =winner_weight_consumed[j];
864
                assign second_arbiter_weight_consumed[i][j]  =iport_weight_is_consumed_all[j];
865
                assign granted_dest_port[j][i-1]    = second_arbiter_grant  [i][j]  ;
866
            end
867
            //if(i==j) wires are left disconnected         
868
        end
869
 
870
 
871
 
872
 
873
        //second level arbiter 
874
        swa_output_port_arbiter #(
875
            .ARBITER_WIDTH(P_1),
876
            .ARBITER_TYPE(SWA_ARBITER_TYPE) // RRA, WRRA
877
        )
878
        output_arbiter
879
        (
880
           .weight_consumed(second_arbiter_weight_consumed[i]),  // only used for WRRA
881
           .clk(clk),
882
           .reset(reset),
883
           .request(second_arbiter_request [i]),
884
           .grant(second_arbiter_grant [i]),
885
           .any_grant(outport_granted_all [i])
886
        );
887
 
888
 
889
 
890
        //any ivc 
891
        assign  any_ivc_grant[i] = | granted_dest_port[i];
892
 
893
        assign  ivc_granted[i] =  (any_ivc_grant[i]) ? first_arbiter_grant_masked[i] : {V{1'b0}};
894
 
895
        assign      inport_granted_all[i]   =any_ivc_grant[i];
896
    end//for
897
    endgenerate
898
 
899
      custom_or #(
900
            .IN_NUM(P),
901
            .OUT_WIDTH(P)
902
         )
903
         or_dst
904
         (
905
            .or_in(single_flit_granted_dst_all),
906
            .or_out(granted_dst_is_from_a_single_flit_pck)
907
        );
908
 
909
 
910
endmodule
911
 
912
 

powered by: WebSVN 2.1.0

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