source: branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp @ 997

Last change on this file since 997 was 997, checked in by cfuguet, 9 years ago

reconf: improve the recovery broadcast replication policy

  • Improve the validation scripts for this replication policy.
File size: 33.3 KB
Line 
1/* -*- c++ -*-
2  *
3  * File : dspin_router.cpp
4  * Copyright (c) UPMC, Lip6
5  * Authors : Alain Greiner, Abbas Sheibanyrad, Ivan Miro, Zhen Zhang
6  *
7  * SOCLIB_LGPL_HEADER_BEGIN
8  *
9  * This file is part of SoCLib, GNU LGPLv2.1.
10  *
11  * SoCLib is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License as published
13  * by the Free Software Foundation; version 2.1 of the License.
14  *
15  * SoCLib is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with SoCLib; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA
24  *
25  * SOCLIB_LGPL_HEADER_END
26  *
27  */
28
29    ///////////////////////////////////////////////////////////////////////////
30    // Implementation Note :
31    // The xfirst_route(), broadcast_route() and is_broadcast() functions
32    // defined below are used to decode the DSPIN first flit format:
33    // - In case of a non-broadcast packet :
34    //  |   X     |   Y     |---------------------------------------|BC |
35    //  | x_width | y_width |  flit_width - (x_width + y_width + 2) | 0 |
36    //
37    //  - In case of a broacast
38    //  |  XMIN   |  XMAX   |  YMIN   |  YMAX   |----------------|SP|BC |
39    //  |   5     |   5     |   5     |   5     | flit_width - 21| 1| 1 |
40    ///////////////////////////////////////////////////////////////////////////
41
42#include "../include/dspin_router.h"
43#include "dspin_router_config.h"
44
45namespace soclib { namespace caba {
46
47using namespace soclib::common;
48using namespace soclib::caba;
49
50#define tmpl(x) template<int flit_width> x DspinRouter<flit_width>
51
52    ////////////////////////////////////////////////
53    //              constructor
54    ////////////////////////////////////////////////
55    tmpl(/**/)::DspinRouter( sc_module_name name,
56                             const size_t   x,
57                             const size_t   y,
58                             const size_t   x_width,
59                             const size_t   y_width,
60                             const size_t   in_fifo_depth,
61                             const size_t   out_fifo_depth,
62                             const bool     broadcast_supported,
63                             const bool     configuration_supported)
64    : soclib::caba::BaseModule(name),
65
66      p_clk( "p_clk" ),
67      p_resetn( "p_resetn" ),
68      p_in( alloc_elems<DspinInput<flit_width> >("p_in", 5) ),
69      p_out( alloc_elems<DspinOutput<flit_width> >("p_out", 5) ),
70      p_recovery_cfg(NULL),
71
72      r_alloc_out( alloc_elems<sc_signal<bool> >("r_alloc_out", 5)),
73      r_index_out( soclib::common::alloc_elems<sc_signal<size_t> >("r_index_out", 5)),
74      r_fsm_in( alloc_elems<sc_signal<int> >("r_fsm_in", 5)),
75      r_index_in( alloc_elems<sc_signal<size_t> >("r_index_in", 5)),
76
77      m_local_x( x ),
78      m_local_y( y ),
79      m_x_width( x_width ),
80      m_x_shift( flit_width - x_width ),
81      m_x_mask( (0x1 << x_width) - 1 ),
82      m_y_width( y_width ),
83      m_y_shift( flit_width - x_width - y_width ),
84      m_y_mask( (0x1 << y_width) - 1 ),
85      m_broadcast_supported( broadcast_supported ),
86      m_disable_mask( 0 )
87    {
88        std::cout << "  - Building DspinRouter : " << name << std::endl;
89
90        SC_METHOD (transition);
91        dont_initialize();
92        sensitive << p_clk.pos();
93
94        SC_METHOD (genMoore);
95        dont_initialize();
96        sensitive  << p_clk.neg();
97
98        r_fifo_in  = (GenericFifo<internal_flit_t>*)
99                     malloc(sizeof(GenericFifo<internal_flit_t>) * 5);
100
101        r_fifo_out = (GenericFifo<internal_flit_t>*)
102                     malloc(sizeof(GenericFifo<internal_flit_t>) * 5);
103
104        r_buf_in   = (internal_flit_t*)
105                     malloc(sizeof(internal_flit_t) * 5);
106
107        for( size_t i = 0 ; i < 5 ; i++ )
108        {
109            std::ostringstream stri;
110            stri << "r_in_fifo_" << i;
111            new(&r_fifo_in[i])
112                GenericFifo<internal_flit_t >(stri.str(), in_fifo_depth);
113
114            std::ostringstream stro;
115            stro << "r_out_fifo_" << i;
116            new(&r_fifo_out[i])
117                GenericFifo<internal_flit_t >(stro.str(), out_fifo_depth);
118        }
119
120        if (configuration_supported) {
121            p_recovery_cfg = new sc_core::sc_in<uint32_t> ("p_recovery_cfg");
122        }
123    } //  end constructor
124
125    ///////////////////////////////////////////////////
126    tmpl(/**/)::~DspinRouter()
127    {
128        if ( is_reconfigurable() ) delete p_recovery_cfg;
129    }
130
131    ///////////////////////////////////////////////////
132    tmpl(int)::blackhole_position()
133    {
134        if ( is_reconfigurable() ) {
135            return p_recovery_cfg->read() & 0xF;
136        }
137        return BH_NONE;
138    }
139
140    ///////////////////////////////////////////////////
141    tmpl(void)::bind_recovery_port(sc_signal<uint32_t> &s)
142    {
143        if (!is_reconfigurable()) {
144            std::cerr << "Error in " << name()
145                      << ": router configuration not supported." << std::endl
146                      << "Enable it during router instantiation." << std::endl;
147            exit(1);
148        }
149        (*p_recovery_cfg)(s);
150    }
151
152    ///////////////////////////////////////////////////
153    tmpl(int)::xfirst_route( size_t xdest, size_t ydest )
154    {
155        return (xdest < m_local_x ? REQ_WEST :
156               (xdest > m_local_x ? REQ_EAST :
157               (ydest < m_local_y ? REQ_SOUTH :
158               (ydest > m_local_y ? REQ_NORTH : REQ_LOCAL))));
159    }
160
161    ///////////////////////////////////////////////////
162    tmpl(bool)::is_destination_blackhole( size_t xdest, size_t ydest, int bhpos )
163    {
164        size_t xhole, yhole;
165        switch (bhpos) {
166            case BH_N:
167                xhole = m_local_x;
168                yhole = m_local_y - 1;
169                break;
170            case BH_NW:
171                xhole = m_local_x + 1;
172                yhole = m_local_y - 1;
173                break;
174            case BH_W:
175                xhole = m_local_x + 1;
176                yhole = m_local_y;
177                break;
178            case BH_SW:
179                xhole = m_local_x + 1;
180                yhole = m_local_y + 1;
181                break;
182            case BH_S:
183                xhole = m_local_x;
184                yhole = m_local_y + 1;
185                break;
186            case BH_SE:
187                xhole = m_local_x - 1;
188                yhole = m_local_y + 1;
189                break;
190            case BH_E:
191                xhole = m_local_x - 1;
192                yhole = m_local_y;
193                break;
194            case BH_NE:
195                xhole = m_local_x - 1;
196                yhole = m_local_y - 1;
197                break;
198            default:
199                return false;
200        }
201
202        return ((xdest == xhole) && (ydest == yhole));
203    }
204
205    ///////////////////////////////////////////////////
206    tmpl(int)::recovery_route( size_t xdest, size_t ydest )
207    {
208        int bhpos = blackhole_position();
209
210        if ( xdest > m_local_x ) {
211            if ( (bhpos == BH_NE) || (bhpos == BH_E) || (bhpos == BH_SE) ||
212                 (bhpos == BH_S) ) {
213                return REQ_EAST;
214            }
215            else if ( bhpos == BH_N ) {
216                if ( (m_local_y == 1) || (m_local_x == 0) || (ydest >= m_local_y) ||
217                     (xdest > (m_local_x + 1)) ) {
218                    return REQ_EAST;
219                }
220                else {
221                    return REQ_WEST;
222                }
223            }
224            else if ( bhpos == BH_NW ) {
225                if ( (m_local_y == 1) || (ydest >= m_local_y) ||
226                     (xdest > (m_local_x + 2)) ) {
227                    return REQ_EAST;
228                }
229                else {
230                    return REQ_SOUTH;
231                }
232            }
233            else if ( bhpos == BH_W ) {
234                if ( (m_local_y == 0) || (ydest > m_local_y)) {
235                    return REQ_NORTH;
236                }
237                else {
238                    return REQ_SOUTH;
239                }
240            }
241            else if ( bhpos == BH_SW ) {
242                if ( (ydest <= m_local_y) || (xdest > (m_local_x + 1)) ) {
243                    return REQ_EAST;
244                }
245                else {
246                    return REQ_NORTH;
247                }
248            }
249            std::cout << "error: unexpected condition in function "
250                      << __FILE__ << ":" << __func__ << " +" << __LINE__
251                      << std::endl;
252            exit(1);
253        }                    // end if (xdest > m_local_x)
254        else if ( xdest < m_local_x ) {
255            if ( (bhpos == BH_N) || (bhpos == BH_NW) || (bhpos == BH_W) ||
256                 (bhpos == BH_SW) || (bhpos == BH_S) ) {
257                return REQ_WEST;
258            }
259            else if ( bhpos == BH_NE ) {
260                if ( (xdest < (m_local_x - 1)) || (ydest >= m_local_y) ) {
261                    return REQ_WEST;
262                }
263                else {
264                    return REQ_SOUTH;
265                }
266            }
267            else if ( bhpos == BH_SE ) {
268                if ( (m_local_x == 1) && (ydest > (m_local_y + 1)) ) {
269                    return REQ_NORTH;
270                }
271                else {
272                    return REQ_WEST;
273                }
274            }
275            else if ( bhpos == BH_E ) {
276                if ( (m_local_y == 0) ||
277                    ((m_local_x == 1) && (ydest > m_local_y)) ) {
278                    return REQ_NORTH;
279                }
280                else {
281                    return REQ_SOUTH;
282                }
283            }
284            std::cout << "error: unexpected condition in function "
285                      << __FILE__ << ":" << __func__ << " +" << __LINE__
286                      << std::endl;
287            exit(1);
288        }                    // end if (xdest < m_local_x)
289        else if ( ydest > m_local_y ) {
290            if ( bhpos != BH_S ) {
291                return REQ_NORTH;
292            }
293            else if ( m_local_x != 0 ) {
294                return REQ_WEST;
295            }
296            else {
297                return REQ_EAST;
298            }
299        }                    // end if (ydest > m_local_y)
300        else if ( ydest < m_local_y ) {
301            if ( bhpos != BH_N ) {
302                return REQ_SOUTH;
303            }
304            else if ( m_local_x != 0) {
305                return REQ_WEST;
306            }
307            else {
308                return REQ_EAST;
309            }
310        }                    // end if (ydest < m_local_y)
311        return REQ_LOCAL;
312    }
313
314    ///////////////////////////////////////////////////
315    tmpl(int)::route( sc_uint<flit_width> data )
316    {
317        size_t xdest = (size_t)(data >> m_x_shift) & m_x_mask;
318        size_t ydest = (size_t)(data >> m_y_shift) & m_y_mask;
319        if ( blackhole_position() != BH_NONE )
320        {
321            // reroute the request if its destination is the blackhole (this
322            // is to implement the segment recovery mechanism)
323            if ( is_destination_blackhole(xdest, ydest, blackhole_position()) )
324            {
325                int dir = migration_route();
326
327#if SOCLIB_MODULE_DEBUG
328                std::cout << "<" << name() << "> migration: "
329                          << "route request to DIR = " << dir << std::endl;
330#endif
331                return dir;
332            }
333
334            if (is_network_recovery_enable())
335            {
336                int dir = recovery_route(xdest, ydest);
337
338#if SOCLIB_MODULE_DEBUG
339                std::cout << "<" << name() << "> network recovery: "
340                          << "route request to DIR = " << dir << std::endl;
341#endif
342                return dir;
343            }
344        }
345        return xfirst_route(xdest, ydest);
346    }
347
348    ///////////////////////////////////////////////////
349    tmpl(int)::broadcast_route(int step, int source, sc_uint<flit_width> data)
350    {
351        const size_t lx   = m_local_x;
352        const size_t ly   = m_local_y;
353        const size_t xmin = (data >> (flit_width - 5 )) & 0x1F;
354        const size_t xmax = (data >> (flit_width - 10)) & 0x1F;
355        const size_t ymin = (data >> (flit_width - 15)) & 0x1F;
356        const size_t ymax = (data >> (flit_width - 20)) & 0x1F;
357        const int    bh   = blackhole_position();
358
359        int  sel = REQ_NOP;
360        bool special = ((data & 0x2) != 0);
361
362        switch(source) {
363        case REQ_LOCAL :
364            if      ( step == 1 ) sel = REQ_NORTH;
365            else if ( step == 2 ) sel = REQ_SOUTH;
366            else if ( step == 3 ) {
367                if ( (bh == BH_N) && (lx != 0) && (ly != 1) ) {
368                    sel = REQ_NOP;
369                    break;
370                }
371                sel = REQ_EAST;
372            }
373            else if ( step == 4 ) {
374                if ( (bh == BH_NE) && (lx != 1) && (ly != 1) ) {
375                    sel = REQ_NOP;
376                    break;
377                }
378                sel = REQ_WEST;
379            }
380        break;
381        case REQ_NORTH :
382            if      ( step == 1 ) sel = REQ_SOUTH;
383            else if ( step == 2 ) sel = REQ_LOCAL;
384            else if ( step == 3 ) {
385                if ( bh == BH_SW ) {
386                    sel = REQ_EAST;
387                    break;
388                }
389                sel = REQ_NOP;
390            }
391            else if ( step == 4 ) {
392                if ( (bh == BH_SE) && (!special || (lx == 1))) {
393                    sel = REQ_WEST;
394                    break;
395                }
396                sel = REQ_NOP;
397            }
398        break;
399        case REQ_SOUTH :
400            if      ( step == 1 ) sel = REQ_NORTH;
401            else if ( step == 2 ) sel = REQ_LOCAL;
402            else if ( step == 3 ) {
403                if ( bh == BH_NW ) {
404                    sel = REQ_EAST;
405                    break;
406                }
407                if ( (bh == BH_NE) && ((lx == 1) || (ly == 1)) ) {
408                    sel = REQ_WEST;
409                    break;
410                }
411                sel = REQ_NOP;
412            }
413            else if ( step == 4 ) sel = REQ_NOP;
414        break;
415        case REQ_EAST :
416            if ( step == 1 ) {
417                if ( (bh == BH_NE) && (lx != 1) && (ly != 1) ) {
418                    sel = REQ_NOP;
419                    break;
420                }
421                sel = REQ_WEST;
422            }
423            else if ( step == 2 ) sel = REQ_NORTH;
424            else if ( step == 3 ) sel = REQ_SOUTH;
425            else if ( step == 4 ) sel = REQ_LOCAL;
426        break;
427        case REQ_WEST :
428            if ( step == 1 ) {
429                if ( (bh == BH_N) && (ly != 1) ) {
430                    sel = REQ_NOP;
431                    break;
432                }
433                if ( (bh == BH_S) && special ) {
434                    sel = REQ_NOP;
435                    break;
436                }
437                sel = REQ_EAST;
438            }
439            else if ( step == 2 ) sel = REQ_NORTH;
440            else if ( step == 3 ) sel = REQ_SOUTH;
441            else if ( step == 4 ) sel = REQ_LOCAL;
442        break;
443        }
444
445        if      ( (sel == REQ_NORTH) && !(ly < ymax) ) sel = REQ_NOP;
446        else if ( (sel == REQ_SOUTH) && !(ly > ymin) ) sel = REQ_NOP;
447        else if ( (sel == REQ_EAST ) && !(lx < xmax) ) sel = REQ_NOP;
448        else if ( (sel == REQ_WEST ) && !(lx > xmin) ) sel = REQ_NOP;
449
450#if 0
451        /* This code can be used if we want to inhibit requests to the
452         * blackhole. However, it is not strictly necessary because the
453         * blackhole will consume the request and will do nothing with it */
454
455        if      ( (sel == REQ_NORTH) && (bh == BH_S) ) sel = REQ_NOP;
456        else if ( (sel == REQ_SOUTH) && (bh == BH_N) ) sel = REQ_NOP;
457        else if ( (sel == REQ_EAST ) && (bh == BH_W) ) sel = REQ_NOP;
458        else if ( (sel == REQ_WEST ) && (bh == BH_E) ) sel = REQ_NOP;
459#endif
460
461        return sel;
462    }
463
464    /////////////////////////////////////////////////////////
465    tmpl(bool)::is_broadcast(sc_uint<flit_width> data)
466    {
467        return ( (data & 0x1) != 0);
468    }
469
470    /////////////////////////////////////////////////////////
471    tmpl(sc_uint<flit_width>)::compute_broadcast_header(int source)
472    {
473        const int bh = blackhole_position();
474        sc_uint<flit_width> header = r_fifo_in[source].read().data;
475        sc_uint<flit_width> special = 0x2;
476        switch (source) {
477            case REQ_NORTH:
478                if ( (bh == BH_NW) || (bh == BH_NE) ) {
479                    header |= special;
480                }
481                break;
482
483            /* Make sure that broadcast transactions do not enter the DSPIN
484             * network with the special bit set. This can arrive if an initiator
485             * or a local interconnect uses the broadcast header reserved bits
486             * internally and don't reset them */
487            case REQ_LOCAL:
488                header &= ~special;
489                break;
490        }
491        return header;
492    }
493
494    /////////////////////////
495    tmpl(void)::print_trace()
496    {
497        const char* port_name[] =
498        {
499            "N",
500            "S",
501            "E",
502            "W",
503            "L"
504        };
505
506        const char* infsm_str[] =
507        {
508            "IDLE",
509            "REQ",
510            "ALLOC",
511            "REQ_FIRST",
512            "ALLOC_FIRST",
513            "REQ_SECOND",
514            "ALLOC_SECOND",
515            "REQ_THIRD",
516            "ALLOC_THIRD",
517            "REQ_FOURTH",
518            "ALLOC_FOURTH"
519        };
520
521        const char* bh_str[] =
522        {
523            "BH_NONE",
524            "BH_N",
525            "BH_NE",
526            "BH_E",
527            "BH_SE",
528            "BH_S",
529            "BH_SW",
530            "BH_W",
531            "BH_NW"
532        };
533
534        std::cout << "DSPIN_ROUTER " << name();
535        std::cout << " / bh = " << bh_str[blackhole_position()];
536
537        for( size_t i = 0 ; i < 5 ; i++)  // loop on input ports
538        {
539            std::cout << " / infsm[" << port_name[i] << "] "
540                      << infsm_str[r_fsm_in[i].read()];
541        }
542
543        for ( size_t out=0 ; out<5 ; out++)  // loop on output ports
544        {
545            if ( r_alloc_out[out].read() )
546            {
547                int in = r_index_out[out];
548                std::cout << " / " << port_name[in] << " -> " << port_name[out] ;
549            }
550        }
551        std::cout << std::endl;
552    }
553
554    ////////////////////////
555    tmpl(void)::transition()
556    {
557        // Long wires connecting input and output ports
558        size_t              req_in[5];         // input ports  -> output ports
559        size_t              get_out[5];        // output ports -> input ports
560        bool                put_in[5];         // input ports  -> output ports
561        internal_flit_t     data_in[5];        // input ports  -> output ports
562
563        // control signals for the input fifos
564        bool                fifo_in_write[5];
565        bool                fifo_in_read[5];
566        internal_flit_t     fifo_in_wdata[5];
567
568        // control signals for the output fifos
569        bool                fifo_out_write[5];
570        bool                fifo_out_read[5];
571        internal_flit_t     fifo_out_wdata[5];
572
573        // Reset
574        if ( p_resetn == false )
575        {
576            for(size_t i = 0 ; i < 5 ; i++)
577            {
578                r_alloc_out[i] = false;
579                r_index_out[i] = 0;
580                r_index_in[i]  = 0;
581                r_fsm_in[i]    = INFSM_IDLE;
582                r_fifo_in[i].init();
583                r_fifo_out[i].init();
584            }
585            return;
586        }
587
588        // fifos signals default values
589        for(size_t i = 0 ; i < 5 ; i++)
590        {
591            fifo_in_read[i]        = false;
592
593            // do not write into the FIFO of disabled interfaces
594            fifo_in_write[i]       = p_in[i].write.read() &&
595                                     ((m_disable_mask & (1 << i)) == 0);
596
597            fifo_in_wdata[i].data  = p_in[i].data.read();
598            fifo_in_wdata[i].eop   = p_in[i].eop.read();
599
600            fifo_out_read[i]       = p_out[i].read.read();
601            fifo_out_write[i]      = false;
602        }
603
604        // loop on the output ports:
605        // compute get_out[j] depending on the output port state
606        // and combining fifo_out[j].wok and r_alloc_out[j]
607        for ( size_t j = 0 ; j < 5 ; j++ )
608        {
609            if( r_alloc_out[j].read() and (r_fifo_out[j].wok()) )
610            {
611                get_out[j] = r_index_out[j].read();
612            }
613            else
614            {
615                get_out[j] = 0xFFFFFFFF;
616            }
617        }
618
619        // loop on the input ports :
620        // The port state is defined by r_fsm_in[i], r_index_in[i] & r_buf_in[i]
621        // The req_in[i] computation implements the X-FIRST algorithm.
622        // data_in[i], put_in[i] and req_in[i] depend on the input port state.
623        // The fifo_in_read[i] is computed further...
624
625        for ( size_t i = 0 ; i < 5 ; i++ )
626        {
627            switch ( r_fsm_in[i].read() )
628            {
629                case INFSM_IDLE:    // no output port allocated
630                {
631                    put_in[i] = false;
632
633                    if ( r_fifo_in[i].rok() ) // packet available in input fifo
634                    {
635                        if ( is_broadcast( r_fifo_in[i].read().data ) and
636                             m_broadcast_supported )          // broadcast
637                        {
638                            if ( r_fifo_in[i].read().eop )
639                            {
640                                std::cout << "ERROR in DSPIN_ROUTER " << name()
641                                          << " : broadcast packet must be 2 flits" << std::endl;
642                                exit(1);
643                            }
644
645                            internal_flit_t header;
646                            header.eop  = false;
647                            header.data = compute_broadcast_header(i);
648
649                            fifo_in_read[i] = true;
650                            req_in[i]       = broadcast_route(1, i, header.data);
651                            r_buf_in[i]     = header;
652                            r_index_in[i]   = req_in[i];
653                            if( req_in[i] == REQ_NOP ) r_fsm_in[i] = INFSM_REQ_SECOND;
654                            else                       r_fsm_in[i] = INFSM_REQ_FIRST;
655                        }
656                        else                                  // unicast
657                        {
658                            req_in[i]       = route(r_fifo_in[i].read().data);
659                            r_index_in[i]   = req_in[i];
660                            r_fsm_in[i]     = INFSM_REQ;
661                        }
662                    }
663                    else
664                    {
665                        req_in[i] = REQ_NOP;
666                    }
667                    break;
668                }
669                case INFSM_REQ:   // not a broadcast / waiting output port allocation
670                {
671                    data_in[i]      = r_fifo_in[i].read();
672                    put_in[i]       = r_fifo_in[i].rok();
673                    req_in[i]       = r_index_in[i];
674                    fifo_in_read[i] = (get_out[r_index_in[i].read()] == i);
675                    if ( get_out[r_index_in[i].read()] == i ) // first flit transfered
676                    {
677                        if ( r_fifo_in[i].read().eop ) r_fsm_in[i] = INFSM_IDLE;
678                        else                           r_fsm_in[i] = INFSM_ALLOC;
679                    }
680                    break;
681                }
682                case INFSM_ALLOC:   // not a broadcast / output port allocated
683                {
684                    data_in[i]      = r_fifo_in[i].read();
685                    put_in[i]       = r_fifo_in[i].rok();
686                    req_in[i]       = REQ_NOP;                 // no request
687                    fifo_in_read[i] = (get_out[r_index_in[i].read()] == i);
688                    if ( r_fifo_in[i].read().eop and
689                         r_fifo_in[i].rok() and
690                         (get_out[r_index_in[i].read()] == i) ) // last flit transfered
691                    {
692                        r_fsm_in[i] = INFSM_IDLE;
693                    }
694                    break;
695                }
696                case INFSM_REQ_FIRST: // broacast / waiting first output port allocation
697                {
698                    data_in[i]    = r_buf_in[i];
699                    put_in[i]     = true;
700                    req_in[i]     = broadcast_route(1, i, r_buf_in[i].data);
701                    r_index_in[i] = req_in[i];
702                    if ( req_in[i] == REQ_NOP )   // no transfer for this step
703                    {
704                        r_fsm_in[i] = INFSM_REQ_SECOND;
705                    }
706                    else
707                    {
708                        if( get_out[req_in[i]] == i )  // header flit transfered
709                        {
710                            r_fsm_in[i] = INFSM_ALLOC_FIRST;
711                        }
712                    }
713                    break;
714                }
715                case INFSM_ALLOC_FIRST:  // broadcast / first output port allocated
716                {
717                    data_in[i] = r_fifo_in[i].read();
718                    put_in[i]  = r_fifo_in[i].rok();
719                    req_in[i]  = REQ_NOP;
720                    if( (get_out[r_index_in[i].read()] == i)
721                         and r_fifo_in[i].rok() )                 // data flit transfered
722                    {
723                        if ( not r_fifo_in[i].read().eop )
724                        {
725                            std::cout << "ERROR in DSPIN_ROUTER " << name()
726                                      << " : broadcast packet must be 2 flits" << std::endl;
727                        }
728                        r_fsm_in[i] = INFSM_REQ_SECOND;
729                    }
730                    break;
731                }
732                case INFSM_REQ_SECOND: // broacast / waiting second output port allocation
733                {
734                    data_in[i]    = r_buf_in[i];
735                    put_in[i]     = true;
736                    req_in[i]     = broadcast_route(2, i, r_buf_in[i].data);
737                    r_index_in[i] = req_in[i];
738                    if ( req_in[i] == REQ_NOP )  // no transfer for this step
739                    {
740                        r_fsm_in[i] = INFSM_REQ_THIRD;
741                    }
742                    else
743                    {
744                        if( get_out[req_in[i]] == i ) // header flit transfered
745                        {
746                            r_fsm_in[i] = INFSM_ALLOC_SECOND;
747                        }
748                    }
749                    break;
750                }
751                case INFSM_ALLOC_SECOND:  // broadcast / second output port allocated
752                {
753                    data_in[i] = r_fifo_in[i].read();
754                    put_in[i]  = r_fifo_in[i].rok();
755                    req_in[i]  = REQ_NOP;
756                    if( (get_out[r_index_in[i].read()] == i )
757                         and r_fifo_in[i].rok() )               // data flit transfered
758                    {
759                        if ( not r_fifo_in[i].read().eop )
760                        {
761                            std::cout << "ERROR in DSPIN_ROUTER " << name()
762                                      << " : broadcast packet must be 2 flits" << std::endl;
763                        }
764                        r_fsm_in[i] = INFSM_REQ_THIRD;
765                    }
766                    break;
767                }
768                case INFSM_REQ_THIRD: // broacast / waiting third output port allocation
769                {
770                    data_in[i]    = r_buf_in[i];
771                    put_in[i]     = true;
772                    req_in[i]     = broadcast_route(3, i, r_buf_in[i].data);
773                    r_index_in[i] = req_in[i];
774                    if ( req_in[i] == REQ_NOP )  // no transfer for this step
775                    {
776                        r_fsm_in[i] = INFSM_REQ_FOURTH;
777                    }
778                    else
779                    {
780                        if( get_out[req_in[i]] == i ) // header flit transfered
781                        {
782                            r_fsm_in[i] = INFSM_ALLOC_THIRD;
783                        }
784                    }
785                    break;
786                }
787                case INFSM_ALLOC_THIRD:  // broadcast / third output port allocated
788                {
789                    data_in[i] = r_fifo_in[i].read();
790                    put_in[i]  = r_fifo_in[i].rok();
791                    req_in[i]  = REQ_NOP;
792                    if( (get_out[r_index_in[i].read()] == i )
793                         and r_fifo_in[i].rok() )               // data flit transfered
794                    {
795                        if ( not r_fifo_in[i].read().eop )
796                        {
797                            std::cout << "ERROR in DSPIN_ROUTER " << name()
798                                      << " : broadcast packet must be 2 flits" << std::endl;
799                        }
800                        r_fsm_in[i] = INFSM_REQ_FOURTH;
801                    }
802                    break;
803                }
804                case INFSM_REQ_FOURTH: // broacast / waiting fourth output port allocation
805                {
806                    data_in[i]    = r_buf_in[i];
807                    put_in[i]     = true;
808                    req_in[i]     = broadcast_route(4, i, r_buf_in[i].data);
809                    r_index_in[i] = req_in[i];
810                    if ( req_in[i] == REQ_NOP )  // no transfer for this step
811                    {
812                        fifo_in_read[i] = true;
813                        r_fsm_in[i]     = INFSM_IDLE;
814                    }
815                    else
816                    {
817                        if( get_out[req_in[i]] == i )  // header flit transfered
818                        {
819                            r_fsm_in[i] = INFSM_ALLOC_FOURTH;
820                        }
821                    }
822                    break;
823                }
824                case INFSM_ALLOC_FOURTH:  // broadcast / fourth output port allocated
825                {
826                    data_in[i] = r_fifo_in[i].read();
827                    put_in[i]  = r_fifo_in[i].rok();
828                    req_in[i]  = REQ_NOP;
829                    if( (get_out[r_index_in[i].read()] == i )
830                         and r_fifo_in[i].rok() )                 // data flit transfered
831                    {
832                        if ( not r_fifo_in[i].read().eop )
833                        {
834                            std::cout << "ERROR in DSPIN_ROUTER " << name()
835                                      << " : broadcast packet must be 2 flits" << std::endl;
836                        }
837                        fifo_in_read[i] = true;
838                        r_fsm_in[i]     = INFSM_IDLE;
839                    }
840                    break;
841                }
842            } // end switch
843        } // end for input ports
844
845        // loop on the output ports :
846        // The r_alloc_out[j] and r_index_out[j] computation
847        // implements the round-robin allocation policy.
848        // These two registers implement a 10 states FSM.
849        for( size_t j = 0 ; j < 5 ; j++ )
850        {
851            if( not r_alloc_out[j].read() )  // not allocated: possible new allocation
852            {
853                for( size_t k = r_index_out[j].read() + 1 ;
854                     k < (r_index_out[j] + 6) ; k++)
855                {
856                    size_t i = k % 5;
857
858                    if( req_in[i] == j )
859                    {
860                        r_alloc_out[j] = true;
861                        r_index_out[j] = i;
862                        break;
863                    }
864                } // end loop on input ports
865            }
866            else                            // allocated: possible desallocation
867            {
868                if ( data_in[r_index_out[j]].eop and
869                     r_fifo_out[j].wok() and
870                     put_in[r_index_out[j]] )
871                {
872                    r_alloc_out[j] = false;
873                }
874            }
875        } // end loop on output ports
876
877        // loop on the output ports :
878        // The fifo_out_write[j] and fifo_out_wdata[j] computation
879        // implements the output port mux.
880        for( size_t j = 0 ; j < 5 ; j++ )
881        {
882            if( r_alloc_out[j] )  // output port allocated
883            {
884                fifo_out_write[j] = put_in[r_index_out[j]] &&
885                                    ((m_disable_mask & (1 << j)) == 0);
886                fifo_out_wdata[j] = data_in[r_index_out[j]];
887            }
888        }  // end loop on the output ports
889
890        //  FIFOS update
891        for(size_t i = 0 ; i < 5 ; i++)
892        {
893            r_fifo_in[i].update(fifo_in_read[i],
894                                fifo_in_write[i],
895                                fifo_in_wdata[i]);
896            r_fifo_out[i].update(fifo_out_read[i],
897                                 fifo_out_write[i],
898                                 fifo_out_wdata[i]);
899        }
900    } // end transition
901
902    ////////////////////////////////
903    //      genMoore
904    ////////////////////////////////
905    tmpl(void)::genMoore()
906    {
907        for(size_t i = 0 ; i < 5 ; i++)
908        {
909            // input ports : READ signals
910            p_in[i].read = r_fifo_in[i].wok();
911
912            // output ports : DATA & WRITE signals
913            p_out[i].data  = r_fifo_out[i].read().data;
914            p_out[i].eop   = r_fifo_out[i].read().eop;
915            p_out[i].write = r_fifo_out[i].rok();
916        }
917    } // end genMoore
918
919}} // end namespace
920
921// Local Variables:
922// tab-width: 4
923// c-basic-offset: 4
924// c-file-offsets:((innamespace . 0)(inline-open . 0))
925// indent-tabs-mode: nil
926// End:
927
928// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.