Index: /branches/reconfiguration/modules/dspin_local_crossbar/caba/source/include/dspin_local_crossbar.h
===================================================================
--- /branches/reconfiguration/modules/dspin_local_crossbar/caba/source/include/dspin_local_crossbar.h	(revision 976)
+++ /branches/reconfiguration/modules/dspin_local_crossbar/caba/source/include/dspin_local_crossbar.h	(revision 977)
@@ -5,21 +5,21 @@
   *
   * SOCLIB_LGPL_HEADER_BEGIN
-  * 
+  *
   * This file is part of SoCLib, GNU LGPLv2.1.
-  * 
+  *
   * SoCLib is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as published
   * by the Free Software Foundation; version 2.1 of the License.
-  * 
+  *
   * SoCLib is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
-  * 
+  *
   * You should have received a copy of the GNU Lesser General Public
   * License along with SoCLib; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   * 02110-1301 USA
-  * 
+  *
   * SOCLIB_LGPL_HEADER_END
   *
@@ -44,9 +44,9 @@
 
     template<size_t flit_width>
-	class DspinLocalCrossbar
-	: public soclib::caba::BaseModule
-	{
+    class DspinLocalCrossbar
+    : public soclib::caba::BaseModule
+    {
         // Input Port FSM
-        enum 
+        enum
         {
         INFSM_IDLE,
@@ -57,26 +57,26 @@
         };
 
-	    protected:
-	    SC_HAS_PROCESS(DspinLocalCrossbar);
+        protected:
+        SC_HAS_PROCESS(DspinLocalCrossbar);
 
-	    public:
+        public:
 
-	    // ports
-	    sc_in<bool>                     p_clk;
-	    sc_in<bool>                     p_resetn;
-	    DspinInput<flit_width>		    p_global_in;
-	    DspinOutput<flit_width>			p_global_out;
-	    DspinInput<flit_width>*		    p_local_in;
-	    DspinOutput<flit_width>*		p_local_out;
+        // ports
+        sc_in<bool>                     p_clk;
+        sc_in<bool>                     p_resetn;
+        DspinInput<flit_width>          p_global_in;
+        DspinOutput<flit_width>         p_global_out;
+        DspinInput<flit_width>*         p_local_in;
+        DspinOutput<flit_width>*        p_local_out;
 
         void      print_trace();
 
-	    // constructor / destructor
-	    DspinLocalCrossbar( sc_module_name      name, 
+        // constructor / destructor
+        DspinLocalCrossbar( sc_module_name      name,
                             const MappingTable  &mt,
                             const size_t        x,              // cluster x coordinate
                             const size_t        y,              // cluster y coordinate
                             const size_t        x_width,        // x field width
-                            const size_t        y_width,        // y field width        
+                            const size_t        y_width,        // y field width
                             const size_t        l_width,        // local field width
                             const size_t        nb_local_inputs,
@@ -90,8 +90,8 @@
         ~DspinLocalCrossbar();
 
-	    private:
+        private:
 
         // define the FIFO flit
-        typedef struct internal_flit_s 
+        typedef struct internal_flit_s
         {
             sc_uint<flit_width>  data;
@@ -99,27 +99,27 @@
         } internal_flit_t;
 
-	    // internal registers
-	    sc_signal<bool>			        *r_alloc_out;  // output port allocated
-	    sc_signal<size_t>               *r_index_out;  // owner input port index
+        // internal registers
+        sc_signal<bool>                 *r_alloc_out;  // output port allocated
+        sc_signal<size_t>               *r_index_out;  // owner input port index
         internal_flit_t                 *r_buf_in;     // input port fifo extension
         sc_signal<int>                  *r_fsm_in;     // input port state
-	    sc_signal<size_t>               *r_index_in;   // requested output port index
+        sc_signal<size_t>               *r_index_in;   // requested output port index
 
-	    // fifos
-	    soclib::caba::GenericFifo<internal_flit_t>*  r_fifo_in;
-	    soclib::caba::GenericFifo<internal_flit_t>*  r_fifo_out;
+        // fifos
+        soclib::caba::GenericFifo<internal_flit_t>*  r_fifo_in;
+        soclib::caba::GenericFifo<internal_flit_t>*  r_fifo_out;
 
-	    // structural parameters
-	    const size_t                            m_local_x;
-	    const size_t                            m_local_y;
-	    const size_t                            m_x_width;
-	    const size_t                            m_x_shift;
-	    const size_t                            m_x_mask;
-	    const size_t                            m_y_width;
-	    const size_t                            m_y_shift;
-	    const size_t                            m_y_mask;
-	    const size_t                            m_l_width;
-	    const size_t                            m_l_shift;
-	    const size_t                            m_l_mask;
+        // structural parameters
+        const size_t                            m_local_x;
+        const size_t                            m_local_y;
+        const size_t                            m_x_width;
+        const size_t                            m_x_shift;
+        const size_t                            m_x_mask;
+        const size_t                            m_y_width;
+        const size_t                            m_y_shift;
+        const size_t                            m_y_mask;
+        const size_t                            m_l_width;
+        const size_t                            m_l_shift;
+        const size_t                            m_l_mask;
         const size_t                            m_local_inputs;
         const size_t                            m_local_outputs;
@@ -133,13 +133,13 @@
         AddressDecodingTable<uint32_t, size_t>  m_rsp_rt;
 
-	    // methods 
-	    void      transition();
-	    void      genMoore();
+        // methods
+        void      transition();
+        void      genMoore();
         size_t    route( sc_uint<flit_width> data, size_t index );
         bool      is_broadcast( sc_uint<flit_width> data );
-	};
+    };
 
 }} // end namespace
-               
+
 #endif // DSPIN_LOCAL_CROSSBAR_H_
 
Index: /branches/reconfiguration/modules/dspin_local_crossbar/caba/source/src/dspin_local_crossbar.cpp
===================================================================
--- /branches/reconfiguration/modules/dspin_local_crossbar/caba/source/src/dspin_local_crossbar.cpp	(revision 976)
+++ /branches/reconfiguration/modules/dspin_local_crossbar/caba/source/src/dspin_local_crossbar.cpp	(revision 977)
@@ -6,16 +6,16 @@
   *
   * SOCLIB_LGPL_HEADER_BEGIN
-  * 
+  *
   * This file is part of SoCLib, GNU LGPLv2.1.
-  * 
+  *
   * SoCLib is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as published
   * by the Free Software Foundation; version 2.1 of the License.
-  * 
+  *
   * SoCLib is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
-  * 
+  *
   * You should have received a copy of the GNU Lesser General Public
   * License along with SoCLib; if not, write to the Free Software
@@ -39,5 +39,5 @@
 //                  constructor
 //////////////////////////////////////////////////////////
-tmpl(/**/)::DspinLocalCrossbar( sc_module_name       name, 
+tmpl(/**/)::DspinLocalCrossbar( sc_module_name       name,
                                 const MappingTable   &mt,
                                 const size_t         x,
@@ -123,5 +123,5 @@
         r_fifo_in  = (GenericFifo<internal_flit_t>*)
         malloc(sizeof(GenericFifo<internal_flit_t>) * (m_local_inputs + 1));
-        
+
         r_fifo_out = (GenericFifo<internal_flit_t>*)
         malloc(sizeof(GenericFifo<internal_flit_t>) * (m_local_outputs + 1));
@@ -179,5 +179,5 @@
     ////////////////////////////////////////////////////////////////////////////
     tmpl(size_t)::route( sc_uint<flit_width> data,     // first flit
-                         size_t              input )   // input port index 
+                         size_t              input )   // input port index
     {
         size_t   output;   // selected output port
@@ -185,6 +185,13 @@
         size_t   y_dest  = (size_t)(data >> m_y_shift) & m_y_mask;
 
-        if ( (x_dest == m_local_x) and (y_dest == m_local_y) and
-             (m_local_outputs > 0) )          // local dest
+        // there are two types of local request:
+        //  - when destination coordinates correspond to local coordinates
+        //  - when there is a segment reallocation and the new host is local
+        // to support the second case, the locality of the global-to-local
+        // requests is not checked.
+        bool local_dest = ((x_dest == m_local_x) and (y_dest == m_local_y)) or
+                           (input == m_local_inputs);
+
+        if ( local_dest and (m_local_outputs > 0) )             // local dest
         {
             if ( m_use_routing_table )
@@ -194,12 +201,12 @@
                 {
                     uint64_t address;
-                    if (flit_width >= m_addr_width) 
+                    if (flit_width >= m_addr_width)
                         address = data>>(flit_width - m_addr_width);
-                    else                          
+                    else
                         address = data<<(m_addr_width - flit_width);
                     output = m_cmd_rt[ address ];
                 }
                 else
-                {   
+                {
                     uint32_t srcid = data >> m_l_shift;
                     output = m_rsp_rt[ srcid ];
@@ -209,5 +216,5 @@
             {
                 output = (size_t)(data >> m_l_shift) & m_l_mask;
- 
+
                 if ( output >= m_local_outputs )
                 {
@@ -218,13 +225,6 @@
             }
         }
-        else                                                            // global dest
-        {
-            if ( input  == m_local_inputs )
-            {
-                std::cout << "ERROR in DSPIN_LOCAL_CROSSBAR: " << name()
-                          << " illegal global to global request" << std::endl;
-                exit(0);
-            }
-
+        else                                                    // global dest
+        {
             output = m_local_outputs;
         }
@@ -243,9 +243,9 @@
         const char* infsm_str[] = { "IDLE", "REQ", "ALLOC", "REQ_BC", "ALLOC_BC" };
 
-        std::cout << "DSPIN_LOCAL_CROSSBAR " << name() << std::hex; 
+        std::cout << "DSPIN_LOCAL_CROSSBAR " << name() << std::hex;
 
         for( size_t i = 0 ; i <= m_local_inputs ; i++)  // loop on input ports
         {
-            std::cout << " / infsm[" << std::dec << i 
+            std::cout << " / infsm[" << std::dec << i
                       << "] = " << infsm_str[r_fsm_in[i].read()];
         }
@@ -257,5 +257,5 @@
                 size_t in = r_index_out[out];
                 std::cout << " / in[" << in << "] -> out[" << out << "]";
-            }   
+            }
         }
         std::cout << std::endl;
@@ -273,5 +273,5 @@
         // control signals for the input fifos
         bool                fifo_in_write[m_local_inputs+1];
-        bool                fifo_in_read[m_local_inputs+1];    
+        bool                fifo_in_read[m_local_inputs+1];
         internal_flit_t     fifo_in_wdata[m_local_inputs+1];
 
@@ -281,8 +281,8 @@
         internal_flit_t     fifo_out_wdata[m_local_outputs+1];
 
-        // reset 
-        if ( p_resetn.read() == false ) 
-        {
-            for(size_t j = 0 ; j <= m_local_outputs ; j++) 
+        // reset
+        if ( p_resetn.read() == false )
+        {
+            for(size_t j = 0 ; j <= m_local_outputs ; j++)
             {
                 r_alloc_out[j] = false;
@@ -290,5 +290,5 @@
                 r_fifo_out[j].init();
             }
-            for(size_t i = 0 ; i <= m_local_inputs ; i++) 
+            for(size_t i = 0 ; i <= m_local_inputs ; i++)
             {
                 r_index_in[i]  = 0;
@@ -300,7 +300,7 @@
 
         // fifo_in signals default values
-        for(size_t i = 0 ; i < m_local_inputs ; i++) 
-        {
-            fifo_in_read[i]        = false;   
+        for(size_t i = 0 ; i < m_local_inputs ; i++)
+        {
+            fifo_in_read[i]        = false;
             fifo_in_write[i]       = p_local_in[i].write.read();
             fifo_in_wdata[i].data  = p_local_in[i].data.read();
@@ -313,11 +313,11 @@
 
         // fifo_out signals default values
-        for(size_t j = 0 ; j < m_local_outputs ; j++) 
+        for(size_t j = 0 ; j < m_local_outputs ; j++)
         {
             fifo_out_read[j]  = p_local_out[j].read.read();
-            fifo_out_write[j] = false;  
+            fifo_out_write[j] = false;
         }
         fifo_out_read[m_local_outputs]  = p_global_out.read.read();
-        fifo_out_write[m_local_outputs] = false;     
+        fifo_out_write[m_local_outputs] = false;
 
         // loop on the output ports:
@@ -326,17 +326,17 @@
         for ( size_t j = 0 ; j <= m_local_outputs ; j++ )
         {
-            if( r_alloc_out[j].read() and (r_fifo_out[j].wok()) ) 
+            if( r_alloc_out[j].read() and (r_fifo_out[j].wok()) )
             {
                 get_out[j] = r_index_out[j].read();
             }
             else
-            {                       
-                get_out[j] = 0xFFFFFFFF;  
-            }
-        }
-
-        // loop on the input ports (including global input port, 
+            {
+                get_out[j] = 0xFFFFFFFF;
+            }
+        }
+
+        // loop on the input ports (including global input port,
         // with the convention index[global] = m_local_inputs)
-        // The port state is defined by r_fsm_in[i], r_index_in[i] 
+        // The port state is defined by r_fsm_in[i], r_index_in[i]
         // The req_in[i] computation uses the route() function.
         // Both put_in[i] and req_in[i] depend on the input port state.
@@ -351,5 +351,5 @@
                     if ( r_fifo_in[i].rok() ) // packet available in input fifo
                     {
-                        if ( is_broadcast(r_fifo_in[i].read().data ) and 
+                        if ( is_broadcast(r_fifo_in[i].read().data ) and
                              m_broadcast_supported )   // broadcast required
                         {
@@ -398,5 +398,5 @@
                     req_in[i]  = 0xFFFFFFFF;                // no request
                     if ( r_fifo_in[i].read().eop and
-                         r_fifo_in[i].rok() and 
+                         r_fifo_in[i].rok() and
                          (get_out[r_index_in[i].read()] == i) )  // last flit transfered
                     {
@@ -416,5 +416,5 @@
                     break;
                 }
-                case INFSM_ALLOC_BC:  // output port allocated         
+                case INFSM_ALLOC_BC:  // output port allocated
                 {
                     data_in[i] = r_fifo_in[i].read();
@@ -422,8 +422,8 @@
                     req_in[i]  = 0xFFFFFFFF;                // no request
 
-                    if ( r_fifo_in[i].rok() and 
+                    if ( r_fifo_in[i].rok() and
                          get_out[r_index_in[i].read()] == i )  // last flit transfered
                     {
-                        if ( not r_fifo_in[i].read().eop ) 
+                        if ( not r_fifo_in[i].read().eop )
                         {
                             std::cout << "ERROR in DSPIN_LOCAL_CROSSBAR " << name()
@@ -438,21 +438,21 @@
             } // end switch
         } // end for input ports
-                                   
-        // loop on the output ports (including global output port, 
+
+        // loop on the output ports (including global output port,
         // with the convention index[global] = m_local_outputs)
         // The r_alloc_out[j] and r_index_out[j] computation
         // implements the round-robin allocation policy.
         // These two registers implement a 2*N states FSM.
-        for( size_t j = 0 ; j <= m_local_outputs ; j++ ) 
+        for( size_t j = 0 ; j <= m_local_outputs ; j++ )
         {
             if( not r_alloc_out[j].read() )  // not allocated: possible new allocation
             {
-                for( size_t k = r_index_out[j].read() + 1 ; 
-                     k <= (r_index_out[j].read() + m_local_inputs + 1) ; 
-                     k++ ) 
-                { 
+                for( size_t k = r_index_out[j].read() + 1 ;
+                     k <= (r_index_out[j].read() + m_local_inputs + 1) ;
+                     k++ )
+                {
                     size_t i = k % (m_local_inputs + 1);
 
-                    if( req_in[i] == j ) 
+                    if( req_in[i] == j )
                     {
                         r_alloc_out[j] = true;
@@ -461,10 +461,10 @@
                     }
                 } // end loop on input ports
-            } 
+            }
             else                            // allocated: possible desallocation
             {
                 if ( data_in[r_index_out[j]].eop and
-                     r_fifo_out[j].wok() and 
-                     put_in[r_index_out[j]] ) 
+                     r_fifo_out[j].wok() and
+                     put_in[r_index_out[j]] )
                 {
                     r_alloc_out[j] = false;
@@ -474,9 +474,9 @@
 
         // loop on input ports :
-        // fifo_in_read[i] computation 
+        // fifo_in_read[i] computation
         // (computed here because it depends on get_out[])
-        for( size_t i = 0 ; i <= m_local_inputs ; i++ ) 
-        {
-            if ( (r_fsm_in[i].read() == INFSM_REQ) or 
+        for( size_t i = 0 ; i <= m_local_inputs ; i++ )
+        {
+            if ( (r_fsm_in[i].read() == INFSM_REQ) or
                  (r_fsm_in[i].read() == INFSM_ALLOC) or
                  ((r_fsm_in[i].read() == INFSM_ALLOC_BC) and (r_index_in[i].read() == 0)))
@@ -485,6 +485,6 @@
             }
             if ( (r_fsm_in[i].read() == INFSM_IDLE) and
-                 is_broadcast( r_fifo_in[i].read().data ) and 
-                 m_broadcast_supported )   
+                 is_broadcast( r_fifo_in[i].read().data ) and
+                 m_broadcast_supported )
             {
                 fifo_in_read[i] = true;
@@ -495,5 +495,5 @@
         // The fifo_out_write[j] and fifo_out_wdata[j] computation
         // implements the output port mux
-        for( size_t j = 0 ; j <= m_local_outputs ; j++ ) 
+        for( size_t j = 0 ; j <= m_local_outputs ; j++ )
         {
             if( r_alloc_out[j] )  // output port allocated
@@ -505,5 +505,5 @@
 
         //  input FIFOs update
-        for(size_t i = 0 ; i <= m_local_inputs ; i++) 
+        for(size_t i = 0 ; i <= m_local_inputs ; i++)
         {
             r_fifo_in[i].update(fifo_in_read[i],
@@ -514,5 +514,5 @@
         //  output FIFOs update
         for(size_t j = 0 ; j <= m_local_outputs ; j++)
-        { 
+        {
             r_fifo_out[j].update(fifo_out_read[j],
                                  fifo_out_write[j],
@@ -525,5 +525,5 @@
     {
         // input ports
-        for(size_t i = 0 ; i < m_local_inputs ; i++) 
+        for(size_t i = 0 ; i < m_local_inputs ; i++)
         {
             p_local_in[i].read = r_fifo_in[i].wok();
@@ -532,5 +532,5 @@
 
         // output ports
-        for(size_t j = 0 ; j < m_local_outputs ; j++) 
+        for(size_t j = 0 ; j < m_local_outputs ; j++)
         {
             p_local_out[j].write = r_fifo_out[j].rok();
