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

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

reconf: add unitary test for the segment migration mechanism in the
dspin router.

File size: 28.7 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   |-------------------|BC |
39    //  |   5     |   5     |   5     |   5     | flit_width - 22   | 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    : soclib::caba::BaseModule(name),
64
65      p_clk( "p_clk" ),
66      p_resetn( "p_resetn" ),
67      p_in( alloc_elems<DspinInput<flit_width> >("p_in", 5) ),
68      p_out( alloc_elems<DspinOutput<flit_width> >("p_out", 5) ),
69
70      r_alloc_out( alloc_elems<sc_signal<bool> >("r_alloc_out", 5)),
71      r_index_out( soclib::common::alloc_elems<sc_signal<size_t> >("r_index_out", 5)),
72      r_fsm_in( alloc_elems<sc_signal<int> >("r_fsm_in", 5)),
73      r_index_in( alloc_elems<sc_signal<size_t> >("r_index_in", 5)),
74
75      m_local_x( x ),
76      m_local_y( y ),
77      m_x_width( x_width ),
78      m_x_shift( flit_width - x_width ),
79      m_x_mask( (0x1 << x_width) - 1 ),
80      m_y_width( y_width ),
81      m_y_shift( flit_width - x_width - y_width ),
82      m_y_mask( (0x1 << y_width) - 1 ),
83      m_broadcast_supported( broadcast_supported ),
84      m_disable_mask( 0 )
85    {
86        std::cout << "  - Building DspinRouter : " << name << std::endl;
87
88        SC_METHOD (transition);
89        dont_initialize();
90        sensitive << p_clk.pos();
91
92        SC_METHOD (genMoore);
93        dont_initialize();
94        sensitive  << p_clk.neg();
95
96        r_fifo_in  = (GenericFifo<internal_flit_t>*)
97                     malloc(sizeof(GenericFifo<internal_flit_t>) * 5);
98
99        r_fifo_out = (GenericFifo<internal_flit_t>*)
100                     malloc(sizeof(GenericFifo<internal_flit_t>) * 5);
101
102        r_buf_in   = (internal_flit_t*)
103                     malloc(sizeof(internal_flit_t) * 5);
104
105        for( size_t i = 0 ; i < 5 ; i++ )
106        {
107            std::ostringstream stri;
108            stri << "r_in_fifo_" << i;
109            new(&r_fifo_in[i])
110                GenericFifo<internal_flit_t >(stri.str(), in_fifo_depth);
111
112            std::ostringstream stro;
113            stro << "r_out_fifo_" << i;
114            new(&r_fifo_out[i])
115                GenericFifo<internal_flit_t >(stro.str(), out_fifo_depth);
116        }
117
118        p_recovery_cfg = NULL;
119    } //  end constructor
120
121    ///////////////////////////////////////////////////
122    tmpl(/**/)::~DspinRouter()
123    {
124        if ( p_recovery_cfg != NULL ) delete p_recovery_cfg;
125    }
126
127    ///////////////////////////////////////////////////
128    tmpl(int)::xfirst_route( size_t xdest, size_t ydest )
129    {
130        return (xdest < m_local_x ? REQ_WEST :
131               (xdest > m_local_x ? REQ_EAST :
132               (ydest < m_local_y ? REQ_SOUTH :
133               (ydest > m_local_y ? REQ_NORTH : REQ_LOCAL))));
134    }
135
136    ///////////////////////////////////////////////////
137    tmpl(void)::bind_recovery_port( sc_core::sc_signal<uint32_t> &s )
138    {
139        if (p_recovery_cfg == NULL) {
140            p_recovery_cfg = new sc_core::sc_in<uint32_t>;
141        }
142        (*p_recovery_cfg)(s);
143    }
144
145    ///////////////////////////////////////////////////
146    tmpl(bool)::need_reroute( size_t xdest, size_t ydest, int bhpos )
147    {
148        size_t xhole, yhole;
149        if (bhpos == BH_N) {
150            xhole = m_local_x;
151            yhole = m_local_y - 1;
152        }
153        else if (bhpos == BH_NW) {
154            xhole = m_local_x + 1;
155            yhole = m_local_y - 1;
156        }
157        else if (bhpos == BH_W) {
158            xhole = m_local_x + 1;
159            yhole = m_local_y;
160        }
161        else if (bhpos == BH_SW) {
162            xhole = m_local_x + 1;
163            yhole = m_local_y + 1;
164        }
165        else if (bhpos == BH_S) {
166            xhole = m_local_x;
167            yhole = m_local_y + 1;
168        }
169        else if (bhpos == BH_SE) {
170            xhole = m_local_x - 1;
171            yhole = m_local_y + 1;
172        }
173        else if (bhpos == BH_E) {
174            xhole = m_local_x - 1;
175            yhole = m_local_y;
176        }
177        else if (bhpos == BH_NE) {
178            xhole = m_local_x - 1;
179            yhole = m_local_y - 1;
180        }
181        else {
182            return false;
183        }
184
185        return ((xdest == xhole) && (ydest == yhole));
186    }
187
188    ///////////////////////////////////////////////////
189    tmpl(int)::recovery_route( size_t xdest, size_t ydest )
190    {
191        int bhpos = p_recovery_cfg->read() & 0xF;
192
193        // reroute the request if its destination is the blackhole (this is to
194        // implement the segment recovery mechanism)
195        if (need_reroute(xdest, ydest, bhpos)) {
196            int recovery_direction = (p_recovery_cfg->read() >> 4) & 0xF;
197
198#if SOCLIB_MODULE_DEBUG
199        std::cout << "<" << name() << "> reroute request to DIR = "
200                  << recovery_direction << std::endl;
201#endif
202
203            return recovery_direction;
204        }
205
206        if ( xdest > m_local_x ) {
207            if ( (bhpos == BH_NE) || (bhpos == BH_E) || (bhpos == BH_SE) ||
208                 (bhpos == BH_S) ) {
209                return REQ_EAST;
210            }
211            else if ( bhpos == BH_N ) {
212                if ( (m_local_y == 1) || (m_local_x == 0) || (ydest >= m_local_y) ||
213                     (xdest > (m_local_x + 1)) ) {
214                    return REQ_EAST;
215                }
216                else {
217                    return REQ_WEST;
218                }
219            }
220            else if ( bhpos == BH_NW ) {
221                if ( (m_local_y == 1) || (ydest >= m_local_y) ||
222                     (xdest > (m_local_x + 2)) ) {
223                    return REQ_EAST;
224                }
225                else {
226                    return REQ_SOUTH;
227                }
228            }
229            else if ( bhpos == BH_W ) {
230                if ( (m_local_y == 0) || (ydest > m_local_y)) {
231                    return REQ_NORTH;
232                }
233                else {
234                    return REQ_SOUTH;
235                }
236            }
237            else if ( bhpos == BH_SW ) {
238                if ( (ydest <= m_local_y) || (xdest > (m_local_x + 1)) ) {
239                    return REQ_EAST;
240                }
241                else {
242                    return REQ_NORTH;
243                }
244            }
245            std::cout << "error: unexpected condition in function "
246                      << __FILE__ << ":" << __func__ << " +" << __LINE__
247                      << std::endl;
248            exit(1);
249        }                    // end if (xdest > m_local_x)
250        else if ( xdest < m_local_x ) {
251            if ( (bhpos == BH_N) || (bhpos == BH_NW) || (bhpos == BH_W) ||
252                 (bhpos == BH_SW) || (bhpos == BH_S) ) {
253                return REQ_WEST;
254            }
255            else if ( bhpos == BH_NE ) {
256                if ( (xdest < (m_local_x - 1)) || (ydest >= m_local_y) ) {
257                    return REQ_WEST;
258                }
259                else {
260                    return REQ_SOUTH;
261                }
262            }
263            else if ( bhpos == BH_SE ) {
264                if ( (m_local_x == 1) && (ydest > (m_local_y + 1)) ) {
265                    return REQ_NORTH;
266                }
267                else {
268                    return REQ_WEST;
269                }
270            }
271            else if ( bhpos == BH_E ) {
272                if ( (m_local_y == 0) ||
273                    ((m_local_x == 1) && (ydest > m_local_y)) ) {
274                    return REQ_NORTH;
275                }
276                else {
277                    return REQ_SOUTH;
278                }
279            }
280            std::cout << "error: unexpected condition in function "
281                      << __FILE__ << ":" << __func__ << " +" << __LINE__
282                      << std::endl;
283            exit(1);
284        }                    // end if (xdest < m_local_x)
285        else if ( ydest > m_local_y ) {
286            if ( bhpos != BH_S ) {
287                return REQ_NORTH;
288            }
289            else if ( m_local_x != 0 ) {
290                return REQ_WEST;
291            }
292            else {
293                return REQ_EAST;
294            }
295        }                    // end if (ydest > m_local_y)
296        else if ( ydest < m_local_y ) {
297            if ( bhpos != BH_N ) {
298                return REQ_SOUTH;
299            }
300            else if ( m_local_x != 0) {
301                return REQ_WEST;
302            }
303            else {
304                return REQ_EAST;
305            }
306        }                    // end if (ydest < m_local_y)
307        return REQ_LOCAL;
308    }
309
310    ///////////////////////////////////////////////////
311    tmpl(int)::route( sc_uint<flit_width> data )
312    {
313        size_t xdest = (size_t)(data >> m_x_shift) & m_x_mask;
314        size_t ydest = (size_t)(data >> m_y_shift) & m_y_mask;
315        if ( p_recovery_cfg != NULL )
316        {
317            if ( (p_recovery_cfg->read() & 0xF) != BH_NONE )
318            {
319                return recovery_route(xdest, ydest);
320            }
321        }
322        return xfirst_route(xdest, ydest);
323    }
324
325    //////////////////////////////////////////////////////////////////////////
326    tmpl(int)::broadcast_route(int step, int source, sc_uint<flit_width> data)
327    {
328        int    sel  = REQ_NOP;
329        size_t xmin = (data >> (flit_width - 5 )) & 0x1F;
330        size_t xmax = (data >> (flit_width - 10)) & 0x1F;
331        size_t ymin = (data >> (flit_width - 15)) & 0x1F;
332        size_t ymax = (data >> (flit_width - 20)) & 0x1F;
333
334        switch(source) {
335        case REQ_LOCAL :
336            if      ( step == 1 )   sel = REQ_NORTH;
337            else if ( step == 2 )   sel = REQ_SOUTH;
338            else if ( step == 3 )   sel = REQ_EAST;
339            else if ( step == 4 )   sel = REQ_WEST;
340        break;
341        case REQ_NORTH :
342            if      ( step == 1 )   sel = REQ_SOUTH;
343            else if ( step == 2 )   sel = REQ_LOCAL;
344            else if ( step == 3 )   sel = REQ_NOP;
345            else if ( step == 4 )   sel = REQ_NOP;
346        break;
347        case REQ_SOUTH :
348            if      ( step == 1 )   sel = REQ_NORTH;
349            else if ( step == 2 )   sel = REQ_LOCAL;
350            else if ( step == 3 )   sel = REQ_NOP;
351            else if ( step == 4 )   sel = REQ_NOP;
352        break;
353        case REQ_EAST :
354            if      ( step == 1 )   sel = REQ_WEST;
355            else if ( step == 2 )   sel = REQ_NORTH;
356            else if ( step == 3 )   sel = REQ_SOUTH;
357            else if ( step == 4 )   sel = REQ_LOCAL;
358        break;
359        case REQ_WEST :
360            if      ( step == 1 )   sel = REQ_EAST;
361            else if ( step == 2 )   sel = REQ_NORTH;
362            else if ( step == 3 )   sel = REQ_SOUTH;
363            else if ( step == 4 )   sel = REQ_LOCAL;
364        break;
365        }
366        if      ( (sel == REQ_NORTH) && !(m_local_y < ymax) )   sel = REQ_NOP;
367        else if ( (sel == REQ_SOUTH) && !(m_local_y > ymin) )   sel = REQ_NOP;
368        else if ( (sel == REQ_EAST ) && !(m_local_x < xmax) )   sel = REQ_NOP;
369        else if ( (sel == REQ_WEST ) && !(m_local_x > xmin) )   sel = REQ_NOP;
370
371        return sel;
372    }
373
374    /////////////////////////////////////////////////////////
375    tmpl(inline bool)::is_broadcast(sc_uint<flit_width> data)
376    {
377        return ( (data & 0x1) != 0);
378    }
379
380    /////////////////////////
381    tmpl(void)::print_trace()
382    {
383        const char* port_name[] =
384        {
385            "N",
386            "S",
387            "E",
388            "W",
389            "L"
390        };
391
392        const char* infsm_str[] =
393        {
394            "IDLE",
395            "REQ",
396            "ALLOC",
397            "REQ_FIRST",
398            "ALLOC_FIRST",
399            "REQ_SECOND",
400            "ALLOC_SECOND",
401            "REQ_THIRD",
402            "ALLOC_THIRD",
403            "REQ_FOURTH",
404            "ALLOC_FOURTH"
405        };
406
407        std::cout << "DSPIN_ROUTER " << name();
408
409        for( size_t i = 0 ; i < 5 ; i++)  // loop on input ports
410        {
411            std::cout << " / infsm[" << port_name[i] << "] "
412                      << infsm_str[r_fsm_in[i].read()];
413        }
414
415        for ( size_t out=0 ; out<5 ; out++)  // loop on output ports
416        {
417            if ( r_alloc_out[out].read() )
418            {
419                int in = r_index_out[out];
420                std::cout << " / " << port_name[in] << " -> " << port_name[out] ;
421            }
422        }
423        std::cout << std::endl;
424    }
425
426    ////////////////////////
427    tmpl(void)::transition()
428    {
429        // Long wires connecting input and output ports
430        size_t              req_in[5];         // input ports  -> output ports
431        size_t              get_out[5];        // output ports -> input ports
432        bool                put_in[5];         // input ports  -> output ports
433        internal_flit_t     data_in[5];        // input ports  -> output ports
434
435        // control signals for the input fifos
436        bool                fifo_in_write[5];
437        bool                fifo_in_read[5];
438        internal_flit_t     fifo_in_wdata[5];
439
440        // control signals for the output fifos
441        bool                fifo_out_write[5];
442        bool                fifo_out_read[5];
443        internal_flit_t     fifo_out_wdata[5];
444
445        // Reset
446        if ( p_resetn == false )
447        {
448            for(size_t i = 0 ; i < 5 ; i++)
449            {
450                r_alloc_out[i] = false;
451                r_index_out[i] = 0;
452                r_index_in[i]  = 0;
453                r_fsm_in[i]    = INFSM_IDLE;
454                r_fifo_in[i].init();
455                r_fifo_out[i].init();
456            }
457            return;
458        }
459
460        // fifos signals default values
461        for(size_t i = 0 ; i < 5 ; i++)
462        {
463            fifo_in_read[i]        = false;
464
465            // do not write into the FIFO of disabled interfaces
466            fifo_in_write[i]       = p_in[i].write.read() &&
467                                     ((m_disable_mask & (1 << i)) == 0);
468
469            fifo_in_wdata[i].data  = p_in[i].data.read();
470            fifo_in_wdata[i].eop   = p_in[i].eop.read();
471
472            fifo_out_read[i]       = p_out[i].read.read();
473            fifo_out_write[i]      = false;
474        }
475
476        // loop on the output ports:
477        // compute get_out[j] depending on the output port state
478        // and combining fifo_out[j].wok and r_alloc_out[j]
479        for ( size_t j = 0 ; j < 5 ; j++ )
480        {
481            if( r_alloc_out[j].read() and (r_fifo_out[j].wok()) )
482            {
483                get_out[j] = r_index_out[j].read();
484            }
485            else
486            {
487                get_out[j] = 0xFFFFFFFF;
488            }
489        }
490
491        // loop on the input ports :
492        // The port state is defined by r_fsm_in[i], r_index_in[i] & r_buf_in[i]
493        // The req_in[i] computation implements the X-FIRST algorithm.
494        // data_in[i], put_in[i] and req_in[i] depend on the input port state.
495        // The fifo_in_read[i] is computed further...
496
497        for ( size_t i = 0 ; i < 5 ; i++ )
498        {
499            switch ( r_fsm_in[i].read() )
500            {
501                case INFSM_IDLE:    // no output port allocated
502                {
503                    put_in[i] = false;
504
505                    if ( r_fifo_in[i].rok() ) // packet available in input fifo
506                    {
507                        if ( is_broadcast( r_fifo_in[i].read().data ) and
508                             m_broadcast_supported )          // broadcast
509                        {
510                            fifo_in_read[i] = true;
511                            req_in[i]       = broadcast_route(1, i, r_fifo_in[i].read().data);
512                            r_buf_in[i]     = r_fifo_in[i].read();
513                            r_index_in[i]   = req_in[i];
514                            if( req_in[i] == REQ_NOP ) r_fsm_in[i] = INFSM_REQ_SECOND;
515                            else                       r_fsm_in[i] = INFSM_REQ_FIRST;
516                        }
517                        else                                  // unicast
518                        {
519                            req_in[i]       = route(r_fifo_in[i].read().data);
520                            r_index_in[i]   = req_in[i];
521                            r_fsm_in[i]     = INFSM_REQ;
522                        }
523                    }
524                    else
525                    {
526                        req_in[i] = REQ_NOP;
527                    }
528                    break;
529                }
530                case INFSM_REQ:   // not a broadcast / waiting output port allocation
531                {
532                    data_in[i]      = r_fifo_in[i].read();
533                    put_in[i]       = r_fifo_in[i].rok();
534                    req_in[i]       = r_index_in[i];
535                    fifo_in_read[i] = (get_out[r_index_in[i].read()] == i);
536                    if ( get_out[r_index_in[i].read()] == i ) // first flit transfered
537                    {
538                        if ( r_fifo_in[i].read().eop ) r_fsm_in[i] = INFSM_IDLE;
539                        else                           r_fsm_in[i] = INFSM_ALLOC;
540                    }
541                    break;
542                }
543                case INFSM_ALLOC:   // not a broadcast / output port allocated
544                {
545                    data_in[i]      = r_fifo_in[i].read();
546                    put_in[i]       = r_fifo_in[i].rok();
547                    req_in[i]       = REQ_NOP;                 // no request
548                    fifo_in_read[i] = (get_out[r_index_in[i].read()] == i);
549                    if ( r_fifo_in[i].read().eop and
550                         r_fifo_in[i].rok() and
551                         (get_out[r_index_in[i].read()] == i) ) // last flit transfered
552                    {
553                        r_fsm_in[i] = INFSM_IDLE;
554                    }
555                    break;
556                }
557                case INFSM_REQ_FIRST: // broacast / waiting first output port allocation
558                {
559                    data_in[i]    = r_buf_in[i];
560                    put_in[i]     = true;
561                    req_in[i]     = broadcast_route(1, i, r_buf_in[i].data);
562                    r_index_in[i] = req_in[i];
563                    if ( req_in[i] == REQ_NOP )   // no transfer for this step
564                    {
565                        r_fsm_in[i] = INFSM_REQ_SECOND;
566                    }
567                    else
568                    {
569                        if( get_out[req_in[i]] == i )  // header flit transfered
570                        {
571                            r_fsm_in[i] = INFSM_ALLOC_FIRST;
572                        }
573                    }
574                    break;
575                }
576                case INFSM_ALLOC_FIRST:  // broadcast / first output port allocated
577                {
578                    data_in[i] = r_fifo_in[i].read();
579                    put_in[i]  = r_fifo_in[i].rok();
580                    req_in[i]  = REQ_NOP;
581                    if( (get_out[r_index_in[i].read()] == i)
582                         and r_fifo_in[i].rok() )                 // data flit transfered
583                    {
584                        if ( not r_fifo_in[i].read().eop )
585                        {
586                            std::cout << "ERROR in DSPIN_ROUTER " << name()
587                                      << " : broadcast packet must be 2 flits" << std::endl;
588                        }
589                        r_fsm_in[i] = INFSM_REQ_SECOND;
590                    }
591                    break;
592                }
593                case INFSM_REQ_SECOND: // broacast / waiting second output port allocation
594                {
595                    data_in[i]    = r_buf_in[i];
596                    put_in[i]     = true;
597                    req_in[i]     = broadcast_route(2, i, r_buf_in[i].data);
598                    r_index_in[i] = req_in[i];
599                    if ( req_in[i] == REQ_NOP )  // no transfer for this step
600                    {
601                        r_fsm_in[i] = INFSM_REQ_THIRD;
602                    }
603                    else
604                    {
605                        if( get_out[req_in[i]] == i ) // header flit transfered
606                        {
607                            r_fsm_in[i] = INFSM_ALLOC_SECOND;
608                        }
609                    }
610                    break;
611                }
612                case INFSM_ALLOC_SECOND:  // broadcast / second output port allocated
613                {
614                    data_in[i] = r_fifo_in[i].read();
615                    put_in[i]  = r_fifo_in[i].rok();
616                    req_in[i]  = REQ_NOP;
617                    if( (get_out[r_index_in[i].read()] == i )
618                         and r_fifo_in[i].rok() )               // data flit transfered
619                    {
620                        if ( not r_fifo_in[i].read().eop )
621                        {
622                            std::cout << "ERROR in DSPIN_ROUTER " << name()
623                                      << " : broadcast packet must be 2 flits" << std::endl;
624                        }
625                        r_fsm_in[i] = INFSM_REQ_THIRD;
626                    }
627                    break;
628                }
629                case INFSM_REQ_THIRD: // broacast / waiting third output port allocation
630                {
631                    data_in[i]    = r_buf_in[i];
632                    put_in[i]     = true;
633                    req_in[i]     = broadcast_route(3, i, r_buf_in[i].data);
634                    r_index_in[i] = req_in[i];
635                    if ( req_in[i] == REQ_NOP )  // no transfer for this step
636                    {
637                        r_fsm_in[i] = INFSM_REQ_FOURTH;
638                    }
639                    else
640                    {
641                        if( get_out[req_in[i]] == i ) // header flit transfered
642                        {
643                            r_fsm_in[i] = INFSM_ALLOC_THIRD;
644                        }
645                    }
646                    break;
647                }
648                case INFSM_ALLOC_THIRD:  // broadcast / third output port allocated
649                {
650                    data_in[i] = r_fifo_in[i].read();
651                    put_in[i]  = r_fifo_in[i].rok();
652                    req_in[i]  = REQ_NOP;
653                    if( (get_out[r_index_in[i].read()] == i )
654                         and r_fifo_in[i].rok() )               // data flit transfered
655                    {
656                        if ( not r_fifo_in[i].read().eop )
657                        {
658                            std::cout << "ERROR in DSPIN_ROUTER " << name()
659                                      << " : broadcast packet must be 2 flits" << std::endl;
660                        }
661                        r_fsm_in[i] = INFSM_REQ_FOURTH;
662                    }
663                    break;
664                }
665                case INFSM_REQ_FOURTH: // broacast / waiting fourth output port allocation
666                {
667                    data_in[i]    = r_buf_in[i];
668                    put_in[i]     = true;
669                    req_in[i]     = broadcast_route(4, i, r_buf_in[i].data);
670                    r_index_in[i] = req_in[i];
671                    if ( req_in[i] == REQ_NOP )  // no transfer for this step
672                    {
673                        fifo_in_read[i] = true;
674                        r_fsm_in[i]     = INFSM_IDLE;
675                    }
676                    else
677                    {
678                        if( get_out[req_in[i]] == i )  // header flit transfered
679                        {
680                            r_fsm_in[i] = INFSM_ALLOC_FOURTH;
681                        }
682                    }
683                    break;
684                }
685                case INFSM_ALLOC_FOURTH:  // broadcast / fourth output port allocated
686                {
687                    data_in[i] = r_fifo_in[i].read();
688                    put_in[i]  = r_fifo_in[i].rok();
689                    req_in[i]  = REQ_NOP;
690                    if( (get_out[r_index_in[i].read()] == i )
691                         and r_fifo_in[i].rok() )                 // data flit transfered
692                    {
693                        if ( not r_fifo_in[i].read().eop )
694                        {
695                            std::cout << "ERROR in DSPIN_ROUTER " << name()
696                                      << " : broadcast packet must be 2 flits" << std::endl;
697                        }
698                        fifo_in_read[i] = true;
699                        r_fsm_in[i]     = INFSM_IDLE;
700                    }
701                    break;
702                }
703            } // end switch
704        } // end for input ports
705
706        // loop on the output ports :
707        // The r_alloc_out[j] and r_index_out[j] computation
708        // implements the round-robin allocation policy.
709        // These two registers implement a 10 states FSM.
710        for( size_t j = 0 ; j < 5 ; j++ )
711        {
712            if( not r_alloc_out[j].read() )  // not allocated: possible new allocation
713            {
714                for( size_t k = r_index_out[j].read() + 1 ;
715                     k < (r_index_out[j] + 6) ; k++)
716                {
717                    size_t i = k % 5;
718
719                    if( req_in[i] == j )
720                    {
721                        r_alloc_out[j] = true;
722                        r_index_out[j] = i;
723                        break;
724                    }
725                } // end loop on input ports
726            }
727            else                            // allocated: possible desallocation
728            {
729                if ( data_in[r_index_out[j]].eop and
730                     r_fifo_out[j].wok() and
731                     put_in[r_index_out[j]] )
732                {
733                    r_alloc_out[j] = false;
734                }
735            }
736        } // end loop on output ports
737
738        // loop on the output ports :
739        // The fifo_out_write[j] and fifo_out_wdata[j] computation
740        // implements the output port mux.
741        for( size_t j = 0 ; j < 5 ; j++ )
742        {
743            if( r_alloc_out[j] )  // output port allocated
744            {
745                fifo_out_write[j] = put_in[r_index_out[j]] &&
746                                    ((m_disable_mask & (1 << j)) == 0);
747                fifo_out_wdata[j] = data_in[r_index_out[j]];
748            }
749        }  // end loop on the output ports
750
751        //  FIFOS update
752        for(size_t i = 0 ; i < 5 ; i++)
753        {
754            r_fifo_in[i].update(fifo_in_read[i],
755                                fifo_in_write[i],
756                                fifo_in_wdata[i]);
757            r_fifo_out[i].update(fifo_out_read[i],
758                                 fifo_out_write[i],
759                                 fifo_out_wdata[i]);
760        }
761    } // end transition
762
763    ////////////////////////////////
764    //      genMoore
765    ////////////////////////////////
766    tmpl(void)::genMoore()
767    {
768        for(size_t i = 0 ; i < 5 ; i++)
769        {
770            // input ports : READ signals
771            p_in[i].read = r_fifo_in[i].wok();
772
773            // output ports : DATA & WRITE signals
774            p_out[i].data  = r_fifo_out[i].read().data;
775            p_out[i].eop   = r_fifo_out[i].read().eop;
776            p_out[i].write = r_fifo_out[i].rok();
777        }
778    } // end genMoore
779
780}} // end namespace
781
782// Local Variables:
783// tab-width: 4
784// c-basic-offset: 4
785// c-file-offsets:((innamespace . 0)(inline-open . 0))
786// indent-tabs-mode: nil
787// End:
788
789// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.