anchor.diff:  endfunction
   
   
  -module mkNocArbitrate#(Vector#(n, Bit#(4)) id, Vector#(n, PipeOut#(a)) in, PipeIn#(a) out)(Empty);
  -   Arbiter_IFC#(n) arb <- mkArbiter(False);   
  -   for (Integer i = 0; i < valueOf(n); i = i + 1)
  +module mkNocArbitrate#(Vector#(n, Bit#(4)) id, Vector#(r, PipeOut#(a)) in, PipeIn#(a) out)(Empty)
  +/*   provisos(
  +      Add#(0,n,2),
  +      Add#(0,r,5)
  +      ) */ ;
  +   Arbiter_IFC#(r) arb <- mkArbiter(False);   
  +   for (Integer i = 0; i < valueOf(r); i = i + 1)
         rule send_request (out.notFull && in[i].notEmpty);
   	 arb.clients[i].request();
         endrule
  
positive.code:    endrule
  endmodule
  
  module mkDistribute#(Vector(n, Bit#(4)) id, PipeOut#(a) in, Vector#(n, PipeIn#(a)) out)(Empty);
     rule move;
        $display("distrib [%d,%d] to [%d,%d] v %x",
  	 name, id[0], id[1], in.first.address[0], in.first.address[1],
  	 in.first.payload);
        if (in.address[0] < id[0]) 
  	 move(in.first, out[0]);
        else if (in.address[0] > id[0]) 
  	 move(in.first, out[1]);
        else /* in.address[0] == id[0] */
  	 begin
  	    if (in.address[1] < id[1]) 
  	       move (in.first, out[2]);
  	    else if (in.address[1] > id[1]) 
  	       move (in.first, out[3]);
  	    else
  	       move(in.first, out[4]);
  	 end
        end
  
     endrule
  endmodule
  
  // This makes a FIFO which throws away data and is never ready to read
  module mkDiscard(FIFOF#(DataMessage));
     interface
        method Action enq(DataMessage d);
        endmethod
        method Bool notFull;
           return True;
        endmethod
        method DataMessage first() = ?;
        method Bool notEmpty();
           return False;
        endmethod
        method Action deq;
  	 if (False) noAction;
        endmethod
  endmodule
  
  
  module mkNocNode#(Vector(dim, Bit#(4)) id)(NocNode#(dim));
     Bit#(4) radix = (ValueOf(dim) * 2) + 1;
     
     // host Links
     FIFOF#(msg) fifofromhost <- mkSizedFIFOF(4);
     FIFOF#(DataMessage) fifotohost <- mkSizedFIFOF(4);
     PipeIn#(DataMessage) tohost = toPipeIn(fifotohost);
     PipeOut#(DataMessage) fromhost = toPipeOut(fifofromhost); 
  
negative.code: import Arbiter::*;
  
  typedef struct {
     Vector#(2, Bit#(4)) address;
     Bit#(32) payload;
     } DataMessage deriving(Bits);
  
  interface NocNode#(numeric type dim);
     interface PipeIn#(DataMessage) hosttonode;
     interface PipeOut#(DataMessage) nodetohost;
     interface Vector#(dim, PipeIn#(Bit#(1))) linkupin;
     interface Vector#(dim, PipeOut#(Bit#(1))) linkupout;
     interface Vector#(dim, PipeIn#(Bit#(1))) linkdownin;
     interface Vector#(dim, PipeOut#(Bit#(1))) linkdownout;
  endinterface
  	 
  function PipeOut#(Bit#(1)) selectoutput(SerialFIFOTX#(DataMessage) x);
  