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/] [route_torus.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
`timescale 1ns/1ps
2
 
3
/**********************************************************************
4
**      File:  route_torus.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
**      Different routing algorithms (determinstic,partially adaptive and fully adaptive)
26
**      for 2D torus-based topology
27
**
28
**************************************************************/
29
 
30
 
31
/********************************************
32
                    Deterministic
33
*********************************************/
34
 
35
    /********************************************
36
                        TRANC
37
    *********************************************/
38
module tranc_xy_routing #(
39
    parameter NX   =    4,
40
    parameter NY   =    4
41
)
42
(
43
    current_x,
44
    current_y,
45
    dest_x,
46
    dest_y,
47
    destport_encoded
48
 
49
);
50
 
51
 
52
    function integer log2;
53
      input integer number; begin
54
         log2=(number <=1) ? 1: 0;
55
         while(2**log2<number) begin
56
            log2=log2+1;
57
         end
58
      end
59
    endfunction // log2 
60
 
61
    localparam  P           =   5,
62
                Xw          =   log2(NX),
63
                Yw          =   log2(NY),
64
                Pw          =   log2(P),
65
                DSTw        =   P-1;
66
 
67
 
68
    input   [Xw-1       :   0] current_x;
69
    input   [Yw-1       :   0] current_y;
70
    input   [Xw-1       :   0] dest_x;
71
    input   [Yw-1       :   0] dest_y;
72
    output  [DSTw -1    :   0] destport_encoded;
73
 
74
    localparam
75
        LOCAL   =   5'b00001,
76
        EAST    =   5'b00010,
77
        NORTH   =   5'b00100,
78
        WEST    =   5'b01000,
79
        SOUTH   =   5'b10000;
80
 
81
 
82
    wire tranc_x_plus,tranc_y_plus,tranc_x_min,tranc_y_min;
83
    wire same_x,same_y;
84
 
85
 
86
    tranc_dir #(
87
        .NX(NX),
88
        .NY(NY)
89
    )
90
    tranc_dir(
91
        .tranc_x_plus(tranc_x_plus),
92
        .tranc_x_min(tranc_x_min),
93
        .tranc_y_plus(tranc_y_plus),
94
        .tranc_y_min(tranc_y_min),
95
        .same_x(same_x),
96
        .same_y(same_y),
97
        .current_x(current_x),
98
        .current_y(current_y),
99
        .dest_x(dest_x),
100
        .dest_y(dest_y)
101
 
102
    );
103
 
104
        reg [P-1 : 0] dstport_one_hot;
105
 
106
 
107
    always@(*)begin
108
        if (same_x & same_y) dstport_one_hot= LOCAL;
109
        else    begin
110
            if            (tranc_x_plus)     dstport_one_hot= EAST;
111
            else if        (tranc_x_min)    dstport_one_hot= WEST;
112
            else if     (tranc_y_plus)    dstport_one_hot= SOUTH;
113
            else                        dstport_one_hot= NORTH;
114
        end
115
    end
116
 
117
    mesh_tori_encode_dstport conv(
118
        .dstport_one_hot(dstport_one_hot),
119
        .dstport_encoded(destport_encoded)
120
    );
121
 
122
 
123
 
124
 
125
    endmodule
126
 
127
/********************************************
128
                    Partial adaptive
129
*********************************************/
130
 
131
    /********************************************
132
                    TRANC West-First
133
    *********************************************/
134
 
135
 
136
    module tranc_west_first_routing #(
137
       parameter NX   =   4,
138
       parameter NY    =   4
139
    )
140
    (
141
        current_x,  // current router x address
142
        current_y,  // current router y address
143
        dest_x,     // destination x address
144
        dest_y,     // destination y address
145
        destport    // router output port
146
 
147
 
148
    );
149
 
150
 
151
 
152
 
153
    function integer log2;
154
      input integer number; begin
155
         log2=(number <=1) ? 1: 0;
156
         while(2**log2<number) begin
157
            log2=log2+1;
158
         end
159
      end
160
    endfunction // log2 
161
 
162
 
163
    localparam  P   =   5,
164
                P_1 =   P-1,
165
                Xw  =   log2(NX),
166
                Yw  =   log2(NY);
167
 
168
    input  [Xw-1        :0] current_x;
169
    input  [Yw-1        :0] current_y;
170
    input  [Xw-1        :0] dest_x;
171
    input  [Yw-1        :0] dest_y;
172
    output [P_1-1       :0] destport;
173
 
174
 
175
 
176
    localparam LOCAL=   3'd0;
177
    localparam EAST =   3'd1;
178
    localparam NORTH=   3'd2;
179
    localparam WEST =   3'd3;
180
    localparam SOUTH=   3'd4;
181
 
182
    wire tranc_x_plus,tranc_y_plus,tranc_x_min,tranc_y_min;
183
    wire same_x,same_y;
184
 
185
 
186
    tranc_dir #(
187
        .NX(NX),
188
        .NY(NY)
189
    )
190
    tranc_dir(
191
        .tranc_x_plus(tranc_x_plus),
192
        .tranc_x_min(tranc_x_min),
193
        .tranc_y_plus(tranc_y_plus),
194
        .tranc_y_min(tranc_y_min),
195
        .same_x(same_x),
196
        .same_y(same_y),
197
        .current_x(current_x),
198
        .current_y(current_y),
199
        .dest_x(dest_x),
200
        .dest_y(dest_y)
201
 
202
    );
203
 
204
    reg [P-1    :    0]    possible_out_port;
205
 
206
    always @(*)begin
207
        possible_out_port = 5'd0;
208
        if(same_x && same_y) begin
209
            possible_out_port [LOCAL]=1'b1;
210
        end
211
        else if       (tranc_x_min) begin
212
            possible_out_port [WEST]    = 1'b1;
213
        end
214
        else if (tranc_x_plus && tranc_y_min) begin
215
            possible_out_port [EAST]=1'b1;
216
            possible_out_port [NORTH]=1'b1;
217
        end
218
        else if(tranc_x_plus && tranc_y_plus) begin
219
            possible_out_port [EAST]=1'b1;
220
            possible_out_port [SOUTH]=1'b1;
221
        end
222
        else if( tranc_x_plus && same_y) begin
223
            possible_out_port [EAST]=1'b1;
224
        end
225
        else if(same_x && tranc_y_min) begin
226
            possible_out_port [NORTH]=1'b1;
227
        end
228
        else if(same_x && tranc_y_plus) begin
229
            possible_out_port [SOUTH]=1'b1;
230
        end
231
    end
232
 
233
    // code the destination port
234
    wire x,y,a,b;
235
    assign x = tranc_x_plus;
236
    assign y = tranc_y_plus;
237
    assign a = possible_out_port[EAST] | possible_out_port[WEST];
238
    assign b = possible_out_port[NORTH]| possible_out_port[SOUTH];
239
    assign destport = {x,y,a,b};
240
 
241
 
242
    endmodule
243
 
244
 
245
 
246
    /********************************************
247
                    TRANC North-Last
248
    *********************************************/
249
 
250
 
251
    module tranc_north_last_routing #(
252
       parameter NX   =   4,
253
       parameter NY    =   4
254
    )
255
    (
256
        current_x,  // current router x address
257
        current_y,  // current router y address
258
        dest_x,     // destination x address
259
        dest_y,     // destination y address
260
        destport    // router output port
261
 
262
 
263
    );
264
 
265
 
266
 
267
 
268
 
269
    function integer log2;
270
      input integer number; begin
271
         log2=(number <=1) ? 1: 0;
272
         while(2**log2<number) begin
273
            log2=log2+1;
274
         end
275
      end
276
    endfunction // log2 
277
 
278
 
279
    localparam  P   =   5,
280
                P_1 =   P-1,
281
                Xw  =   log2(NX),
282
                Yw  =   log2(NY);
283
 
284
    input  [Xw-1        :0] current_x;
285
    input  [Yw-1        :0] current_y;
286
    input  [Xw-1        :0] dest_x;
287
    input  [Yw-1        :0] dest_y;
288
    output [P_1-1       :0] destport;
289
 
290
 
291
 
292
    localparam LOCAL=   3'd0;
293
    localparam EAST =   3'd1;
294
    localparam NORTH=   3'd2;
295
    localparam WEST =   3'd3;
296
    localparam SOUTH=   3'd4;
297
 
298
    wire tranc_x_plus,tranc_y_plus,tranc_x_min,tranc_y_min;
299
    wire same_x,same_y;
300
 
301
 
302
    tranc_dir #(
303
        .NX(NX),
304
        .NY(NY)
305
    )
306
    tranc_dir(
307
        .tranc_x_plus(tranc_x_plus),
308
        .tranc_x_min(tranc_x_min),
309
        .tranc_y_plus(tranc_y_plus),
310
        .tranc_y_min(tranc_y_min),
311
        .same_x(same_x),
312
        .same_y(same_y),
313
        .current_x(current_x),
314
        .current_y(current_y),
315
        .dest_x(dest_x),
316
        .dest_y(dest_y)
317
 
318
    );
319
 
320
    reg [P-1    :   0]  possible_out_port;
321
 
322
     // north last routing algorithm does not allow turns from north to east or from north to west.
323
 
324
   always @(*)begin
325
        possible_out_port       = 5'd0;
326
        if(same_x &&  same_y) begin
327
            possible_out_port [LOCAL]=1'b1;
328
        end
329
        else if (tranc_x_min && tranc_y_min) begin
330
            possible_out_port   [WEST]= 1'b1;
331
           // possible_out_port   [NORTH]= 1'b1;
332
        end
333
        else if (tranc_x_min && tranc_y_plus) begin
334
            possible_out_port   [WEST]= 1'b1;
335
            possible_out_port   [SOUTH]= 1'b1;
336
        end
337
        else if (tranc_x_plus &&  tranc_y_min) begin
338
            possible_out_port   [EAST]= 1'b1;
339
           // possible_out_port   [NORTH]= 1'b1;
340
 
341
        end
342
        else if (tranc_x_plus &&  tranc_y_plus) begin
343
            possible_out_port   [EAST]= 1'b1;
344
            possible_out_port   [SOUTH]= 1'b1;
345
        end
346
        else if (tranc_x_min && same_y) begin
347
            possible_out_port   [WEST]= 1'b1;
348
        end
349
        else if (tranc_x_plus && same_y) begin
350
            possible_out_port   [EAST]= 1'b1;
351
        end
352
        else if (same_x && tranc_y_min) begin
353
            possible_out_port   [NORTH]= 1'b1;
354
        end
355
        else if (same_x && tranc_y_plus) begin
356
            possible_out_port   [SOUTH]= 1'b1;
357
        end
358
    end
359
 
360
    // code the destination port
361
    wire x,y,a,b;
362
    assign x = tranc_x_plus;
363
    assign y = tranc_y_plus;
364
    assign a = possible_out_port[EAST] | possible_out_port[WEST];
365
    assign b = possible_out_port[NORTH]| possible_out_port[SOUTH];
366
    assign destport = {x,y,a,b};
367
 
368
 
369
    endmodule
370
 
371
 
372
 
373
 
374
    /********************************************
375
                    TRANC North-Last
376
    *********************************************/
377
 
378
 
379
    module tranc_negetive_first_routing #(
380
       parameter NX   =   4,
381
       parameter NY   =   4
382
    )
383
    (
384
        current_x,  // current router x address
385
        current_y,  // current router y address
386
        dest_x,     // destination x address
387
        dest_y,     // destination y address
388
        destport    // router output port
389
 
390
 
391
    );
392
 
393
 
394
 
395
 
396
    function integer log2;
397
      input integer number; begin
398
         log2=(number <=1) ? 1: 0;
399
         while(2**log2<number) begin
400
            log2=log2+1;
401
         end
402
      end
403
    endfunction // log2 
404
 
405
 
406
    localparam  P   =   5,
407
                P_1 =   P-1,
408
                Xw  =   log2(NX),
409
                Yw  =   log2(NY);
410
 
411
    input  [Xw-1        :0] current_x;
412
    input  [Yw-1        :0] current_y;
413
    input  [Xw-1        :0] dest_x;
414
    input  [Yw-1        :0] dest_y;
415
    output [P_1-1       :0] destport;
416
 
417
 
418
 
419
    localparam LOCAL=   3'd0;
420
    localparam EAST =   3'd1;
421
    localparam NORTH=   3'd2;
422
    localparam WEST =   3'd3;
423
    localparam SOUTH=   3'd4;
424
 
425
    wire tranc_x_plus,tranc_y_plus,tranc_x_min,tranc_y_min;
426
    wire same_x,same_y;
427
 
428
 
429
    tranc_dir #(
430
        .NX(NX),
431
        .NY(NY)
432
    )
433
    tranc_dir(
434
        .tranc_x_plus(tranc_x_plus),
435
        .tranc_x_min(tranc_x_min),
436
        .tranc_y_plus(tranc_y_plus),
437
        .tranc_y_min(tranc_y_min),
438
        .same_x(same_x),
439
        .same_y(same_y),
440
        .current_x(current_x),
441
        .current_y(current_y),
442
        .dest_x(dest_x),
443
        .dest_y(dest_y)
444
 
445
    );
446
 
447
    reg [P-1    :   0]  possible_out_port;
448
 
449
     // The negetive fist routing algorithm does net allow turns from north to west or from east to south.
450
 
451
   always @(*)begin
452
        possible_out_port       = 5'd0;
453
        if(same_x &&  same_y) begin
454
            possible_out_port [LOCAL]=1'b1;
455
        end
456
        else if (tranc_x_min && tranc_y_min) begin
457
            possible_out_port   [WEST]= 1'b1;
458
           // possible_out_port   [NORTH]= 1'b1;
459
        end
460
        else if (tranc_x_min && tranc_y_plus) begin
461
            possible_out_port   [WEST]= 1'b1;
462
            possible_out_port   [SOUTH]= 1'b1;
463
        end
464
        else if (tranc_x_plus &&  tranc_y_min) begin
465
            possible_out_port   [EAST]= 1'b1;
466
            possible_out_port   [NORTH]= 1'b1;
467
 
468
        end
469
        else if (tranc_x_plus &&  tranc_y_plus) begin
470
           // possible_out_port   [EAST]= 1'b1;
471
            possible_out_port   [SOUTH]= 1'b1;
472
        end
473
        else if (tranc_x_min && same_y) begin
474
            possible_out_port   [WEST]= 1'b1;
475
        end
476
        else if (tranc_x_plus && same_y) begin
477
            possible_out_port   [EAST]= 1'b1;
478
        end
479
        else if (same_x && tranc_y_min) begin
480
            possible_out_port   [NORTH]= 1'b1;
481
        end
482
        else if (same_x && tranc_y_plus) begin
483
            possible_out_port   [SOUTH]= 1'b1;
484
        end
485
    end
486
 
487
    // code the destination port
488
    wire x,y,a,b;
489
    assign x = tranc_x_plus;
490
    assign y = tranc_y_plus;
491
    assign a = possible_out_port[EAST] | possible_out_port[WEST];
492
    assign b = possible_out_port[NORTH]| possible_out_port[SOUTH];
493
    assign destport = {x,y,a,b};
494
 
495
 
496
    endmodule
497
 
498
 
499
 
500
/***********************************
501
        fully adaptive
502
 
503
***********************************/
504
 
505
    /************************************
506
 
507
        Duato’s Fully Adaptive
508
 
509
    *************************************/
510
 
511
 
512
 
513
    module tranc_duato_routing #(
514
        parameter NX  =   4,
515
        parameter NY  =   4
516
    )
517
    (
518
        current_x,  // current router x address
519
        current_y,  // current router y address
520
        dest_x,     // destination x address
521
        dest_y,     // destination y address
522
        destport    // router output port
523
 
524
 
525
    );
526
 
527
 
528
 
529
 
530
    function integer log2;
531
      input integer number; begin
532
         log2=(number <=1) ? 1: 0;
533
         while(2**log2<number) begin
534
            log2=log2+1;
535
         end
536
      end
537
    endfunction // log2 
538
 
539
 
540
    localparam  P   =   5,
541
                P_1 =   P-1,
542
                Xw  =   log2(NX),
543
                Yw  =   log2(NY);
544
 
545
    input  [Xw-1        :0] current_x;
546
    input  [Yw-1        :0] current_y;
547
    input  [Xw-1        :0] dest_x;
548
    input  [Yw-1        :0] dest_y;
549
    output [P_1-1       :0] destport;
550
 
551
 
552
 
553
    localparam LOCAL=   3'd0;
554
    localparam EAST =   3'd1;
555
    localparam NORTH=   3'd2;
556
    localparam WEST =   3'd3;
557
    localparam SOUTH=   3'd4;
558
 
559
 
560
    wire tranc_x_plus,tranc_y_plus,tranc_x_min,tranc_y_min;
561
    wire same_x,same_y;
562
 
563
 
564
    tranc_dir #(
565
        .NX(NX),
566
        .NY(NY)
567
    )
568
    tranc_dir(
569
        .tranc_x_plus(tranc_x_plus),
570
        .tranc_x_min(tranc_x_min),
571
        .tranc_y_plus(tranc_y_plus),
572
        .tranc_y_min(tranc_y_min),
573
        .same_x(same_x),
574
        .same_y(same_y),
575
        .current_x(current_x),
576
        .current_y(current_y),
577
        .dest_x(dest_x),
578
        .dest_y(dest_y)
579
 
580
    );
581
 
582
 
583
    reg [P-1    :    0]    possible_out_port;
584
 
585
 
586
    always @(*)begin
587
        possible_out_port         = 5'd0;
588
        if(same_x &&  same_y) begin
589
            possible_out_port [LOCAL]=1'b1;
590
        end
591
        else if (tranc_x_min && tranc_y_min) begin
592
            possible_out_port     [WEST]= 1'b1;
593
            possible_out_port     [NORTH]= 1'b1;
594
        end
595
        else if (tranc_x_min && tranc_y_plus) begin
596
            possible_out_port     [WEST]= 1'b1;
597
            possible_out_port     [SOUTH]= 1'b1;
598
        end
599
        else if (tranc_x_min &&    same_y) begin
600
            possible_out_port     [WEST]= 1'b1;
601
        end
602
        else if (tranc_x_plus &&  tranc_y_min) begin
603
            possible_out_port     [EAST]= 1'b1;
604
            possible_out_port     [NORTH]= 1'b1;
605
 
606
        end
607
        else if (tranc_x_plus &&  tranc_y_plus) begin
608
            possible_out_port     [EAST]= 1'b1;
609
            possible_out_port     [SOUTH]= 1'b1;
610
        end
611
        else if (tranc_x_plus && same_y) begin
612
            possible_out_port     [EAST]= 1'b1;
613
        end
614
        else if (same_x && tranc_y_min) begin
615
            possible_out_port     [NORTH]= 1'b1;
616
        end
617
        else if (same_x && tranc_y_plus) begin
618
            possible_out_port     [SOUTH]= 1'b1;
619
        end
620
    end
621
 
622
    // code the destination port
623
    wire x,y,a,b;
624
    assign x = tranc_x_plus;
625
    assign y = tranc_y_plus;
626
    assign a = possible_out_port[EAST] | possible_out_port[WEST];
627
    assign b = possible_out_port[NORTH]| possible_out_port[SOUTH];
628
    assign destport = {x,y,a,b};
629
 
630
 
631
    endmodule
632
 
633
 
634
 
635
    /****************************************
636
 
637
       tranc_dir
638
 
639
 
640
    ****************************************/
641
 
642
module tranc_dir #(
643
    parameter NX   =    4,
644
    parameter NY   =    4
645
)(
646
    current_x,
647
    current_y,
648
    dest_x,
649
    dest_y,
650
    tranc_x_plus,
651
    tranc_x_min,
652
    tranc_y_plus,
653
    tranc_y_min,
654
    same_x,
655
    same_y
656
);
657
 
658
 
659
 
660
    function integer log2;
661
      input integer number; begin
662
         log2=(number <=1) ? 1: 0;
663
         while(2**log2<number) begin
664
            log2=log2+1;
665
         end
666
      end
667
    endfunction // log2 
668
 
669
    /* verilator lint_off WIDTH */
670
    localparam  Xw          =   log2(NX),
671
                Yw          =   log2(NY);
672
 
673
 
674
    output reg tranc_x_plus;
675
    output reg tranc_x_min;
676
    output reg tranc_y_plus;
677
    output reg tranc_y_min;
678
    output     same_x,same_y;
679
 
680
    input   [Xw-1       :   0] current_x;
681
    input   [Yw-1       :   0] current_y;
682
    input   [Xw-1       :   0] dest_x;
683
    input   [Yw-1       :   0] dest_y;
684
 
685
    localparam SIGNED_X_WIDTH   =  (Xw<3) ? 4 : Xw+1;
686
    localparam SIGNED_Y_WIDTH   =  (Yw<3) ? 4 : Yw+1;
687
 
688
    wire signed [SIGNED_X_WIDTH-1       :0] xc;//current 
689
    wire signed [SIGNED_X_WIDTH-1       :0] xd;//destination
690
    wire signed [SIGNED_Y_WIDTH-1       :0] yc;//current 
691
    wire signed [SIGNED_Y_WIDTH-1       :0] yd;//destination
692
    wire signed [SIGNED_X_WIDTH-1       :0] xdiff;
693
    wire signed [SIGNED_Y_WIDTH-1       :0] ydiff;
694
 
695
 
696
    assign  xc  ={{(SIGNED_X_WIDTH-Xw){1'b0}}, current_x [Xw-1      :0]};
697
    assign  yc  ={{(SIGNED_Y_WIDTH-Yw){1'b0}}, current_y [Yw-1      :0]};
698
    assign  xd  ={{(SIGNED_X_WIDTH-Xw){1'b0}}, dest_x};
699
    assign  yd  ={{(SIGNED_Y_WIDTH-Yw){1'b0}}, dest_y};
700
    assign  xdiff   = xd-xc;
701
    assign  ydiff   = yd-yc;
702
 
703
 
704
    always@ (*)begin
705
        tranc_x_plus    =1'b0;
706
        tranc_x_min     =1'b0;
707
        tranc_y_plus    =1'b0;
708
        tranc_y_min     =1'b0;
709
        if(xdiff!=0)begin
710
            if ((xdiff ==1) ||
711
                 (xdiff == (-NX+1)) ||
712
                 ((xc == (NX-4)) && (xd == (NX-2))) ||
713
                 ((xc >= (NX-2)) && (xd <= (NX-4))) ||
714
                 ((xdiff> 0) && (xd<= (NX-3))))
715
                    tranc_x_plus    = 1'b1;
716
            else    tranc_x_min     = 1'b1;
717
        end
718
        if(ydiff!=0)begin
719
            if ((ydiff ==1) ||
720
                (ydiff == (-NY+1)) ||
721
                ((yc == (NY-4)) && (yd == (NY-2))) ||
722
                ((yc    >= NY-2) && (yd<= NY-4)) ||
723
                ((ydiff > 0) && (yd<= NY-3)))
724
                    tranc_y_plus    = 1'b1;
725
            else    tranc_y_min     = 1'b1;
726
        end
727
    end//always
728
 
729
    assign same_x = (xdiff == 0);
730
    assign same_y = (ydiff == 0);
731
 
732
    /* verilator lint_on WIDTH */
733
 
734
endmodule
735
 
736
 

powered by: WebSVN 2.1.0

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