update bitfile and list of tests that work
[fleet.git] / src / edu / berkeley / fleet / slipway / Slipway.java
index 02f9303..35b0fe5 100644 (file)
@@ -8,7 +8,6 @@ import java.lang.reflect.*;
 import edu.berkeley.sbp.chr.*;
 import edu.berkeley.sbp.misc.*;
 import edu.berkeley.sbp.meta.*;
-import edu.berkeley.sbp.bind.*;
 import edu.berkeley.sbp.util.*;
 import java.util.*;
 import java.io.*;
@@ -25,7 +24,7 @@ public class Slipway extends Fleet {
         new Slipway().dumpFabric(false);
     }
 
-    public Slipway() { this("valentine.bit"); }
+    public Slipway() { this("summer1.bit"); }
     public Slipway(String bitfile) {
         this.bitfile = bitfile;
         createShip("Debug",   "debug");
@@ -33,18 +32,21 @@ public class Slipway extends Fleet {
         createShip("Alu2",    "alu2b");
         createShip("Alu2",    "alu2c");
         createShip("Alu2",    "alu2d");
-        createShip("Execute", "execute");
         createShip("Fifo",    "fifo1");
         createShip("Fifo",    "fifo2");
         createShip("Fifo",    "fifo3");
         createShip("Fifo",    "fifo4");
-        // FIXME cant have less than two feeding the instruction horn or BUG
-        createShip("Iscratch",  "iscratch1");
-        createShip("Iscratch",  "iscratch2");
-        createShip("Dscratch",  "dscratch1");
-        createShip("Dscratch",  "dscratch2");
+        createShip("Execute", "execute");
+        createShip("Memory",    "Memory");
+        createShip("Memory",    "Memory");
         createShip("Lut3",      "lut3");
         createShip("Alu1",      "alu1");
+        createShip("Alu3",      "alu3");
+        createShip("Choice",    "Choice");
+        createShip("Choice",    "Choice");
+        createShip("Choice",    "Choice");
+        createShip("Choice",    "Choice");
+        createShip("Stack",     "Stack");
         dumpFabric(true);
     }
 
@@ -110,17 +112,17 @@ public class Slipway extends Fleet {
         
         if (quiet) return;
         System.out.println("`include \"macros.v\"");
-        System.out.println("module fabric(clk, data_Iscratch0_command_r, data_Iscratch0_command_a, data_Iscratch0_command,");
+        System.out.println("module fabric(clk, data_Memory0_command_r, data_Memory0_command_a, data_Memory0_command,");
         System.out.println("                   data_Debug0_out_r, data_Debug0_out_a, data_Debug0_out);");
         System.out.println("  input  clk;");
-        System.out.println("  input  data_Iscratch0_command_r;");
-        System.out.println("  output data_Iscratch0_command_a;");
+        System.out.println("  input  data_Memory0_command_r;");
+        System.out.println("  output data_Memory0_command_a;");
         System.out.println("  output data_Debug0_out_r;");
         System.out.println("  input  data_Debug0_out_a;");
         System.out.println("  output [(`PACKET_WIDTH-1):0]      data_Debug0_out;");
-        System.out.println("  input  [(`PACKET_WIDTH-1):0]      data_Iscratch0_command;");
-        //System.out.println("  wire   [(`INSTRUCTION_WIDTH-1):0] data_Iscratch0_ihorn;");
-        //System.out.println("  wire   [(`PACKET_WIDTH-1):0]      data_Iscratch0_dhorn;");
+        System.out.println("  input  [(`PACKET_WIDTH-1):0]      data_Memory0_command;");
+        //System.out.println("  wire   [(`INSTRUCTION_WIDTH-1):0] data_Memory0_ihorn;");
+        //System.out.println("  wire   [(`PACKET_WIDTH-1):0]      data_Memory0_dhorn;");
         System.out.println();
         
         System.out.println();
@@ -192,7 +194,7 @@ public class Slipway extends Fleet {
         System.out.println("funnel topfun(clk,"+
                            "              dest_r, dest_a, dest,"+
                            "              source_r, source_a, source,"+
-                           "              data_Iscratch0_dhorn_r, data_Iscratch0_dhorn_a, data_Iscratch0_dhorn);");
+                           "              data_Memory0_dhorn_r, data_Memory0_dhorn_a, data_Memory0_dhorn);");
         */
         System.out.println("assign instruction_r = ihorn_r;");
         System.out.println("assign ihorn_a = instruction_a;");
@@ -223,21 +225,37 @@ public class Slipway extends Fleet {
                 } else if (prefix.equals("dest")) {
                     p.addr = addr;
                     p.bits = bits;
-                    int count = 1;
+                    if (bits >= 11)
+                        throw new RuntimeException("too many benkoboxen!");
+                    int count = 0;
                     for(Destination d : p.getDestinations()) {
                         if (!(d instanceof SlipwayBenkoBox.VirtualPort)) continue;
                         SlipwayBenkoBox.VirtualPort vp = (SlipwayBenkoBox.VirtualPort)d;
-                        vp.addr = p.addr | (count << (bits+1));
+                        vp.addr = p.addr | (count << bits);
                         count++;
                     }
                 }
                 return p;
             }
             int len = end-start;
+            int count   = 0;
+            int count2  = 0;
+            int breakpt = 0;
+            if (end-start <= 2) {
+                breakpt = (start+end)/2;
+            } else {
+                for(int i=start; i<end; i++)
+                    count += count(ports[i].getDestinations());
+                for(int i=start; i<end-1; i++) {
+                    count2 += count(ports[i].getDestinations());
+                    breakpt = i;
+                    if (i>start && count2 >= count/2) break;
+                }
+            }
             return new Node(name,
                             component,
-                            mkNode(name+"_0", component, ports, start, start+len/2, addr, bits+1),
-                            mkNode(name+"_1", component, ports, start+len/2, end,   addr | (1 << bits), bits+1),
+                            mkNode(name+"_0", component, ports, start, breakpt, addr,               bits+1),
+                            mkNode(name+"_1", component, ports, breakpt, end,   addr | (1 << bits), bits+1),
                             addr,
                             bits);
         }
@@ -317,6 +335,13 @@ public class Slipway extends Fleet {
         return ship.getType() + ship.getOrdinal();
     }
 
+    private static int count(Iterable<Destination> it) {
+        int ret = 0;
+        for(Destination d : it)
+            ret++;
+        return ret;
+    }
+
     public void expand(ShipDescription sd) {
         try {
             String filename = sd.getName().toLowerCase();
@@ -326,7 +351,7 @@ public class Slipway extends Fleet {
             FileOutputStream out = new FileOutputStream(outf);
             PrintWriter pw = new PrintWriter(out);
 
-            boolean auto = filename.equals("alu2") || filename.equals("alu1") || filename.equals("lut3");
+            boolean auto = filename.equals("alu2") || filename.equals("alu1") || filename.equals("alu2b") || filename.equals("lut3") || filename.equals("choice") || filename.equals("alu3") || filename.equals("stack") || filename.equals("mul");
             if (auto) {
                 pw.println("`include \"macros.v\"");
                 pw.println();
@@ -356,7 +381,7 @@ public class Slipway extends Fleet {
                                    bb_name+"_r,  "+
                                    bb_name+"_a,  "+
                                    bb_name+"_a_, "+
-                                   "[(`DATAWIDTH-1):0],"+
+                                   "[(`PACKET_WIDTH-1):0],"+
                                    bb_name+"_d)"
                                    );
                     } else {
@@ -364,12 +389,12 @@ public class Slipway extends Fleet {
                                    bb_name+"_r,  "+
                                    bb_name+"_r_, "+
                                    bb_name+"_a,  "+
-                                   "[(`DATAWIDTH-1):0],"+
+                                   "[(`PACKET_WIDTH-1):0],"+
                                    bb_name+"_d_)"
                                    );
                         pw.println("`defreg(" +
                                    bb_name+"_d_,  "+
-                                   "[(`DATAWIDTH-1):0],"+
+                                   "[(`PACKET_WIDTH-1):0],"+
                                    bb_name+"_d)"
                                    );
                     }
@@ -397,24 +422,14 @@ public class Slipway extends Fleet {
     public void writeInstruction(DataOutputStream os, Instruction d) throws IOException { iie.writeInstruction(os, d); }
 
     private class SlipwayInstructionEncoder extends InstructionEncoder {
-        public long getDestAddr(Destination box) {
-            long ret;
-            if (box instanceof SlipwayBenkoBox)
-                ret = ((SlipwayBenkoBox)box).addr;
-            else
-                ret = ((SlipwayBenkoBox.VirtualPort)box).addr;
-            return ret;
-        }
+        public long getDestAddr(Destination box) { return ((SlipwayBenkoBox.VirtualPort)box).addr; }
         public long getBoxInstAddr(BenkoBox box) { return ((SlipwayBenkoBox)box).instr_addr; }
         public Destination getDestByAddr(long dest) {
             for(Ship ship : Slipway.this)
-                for(BenkoBox bb : ship.getBenkoBoxes()) {
-                    if (((SlipwayBenkoBox)bb).addr == dest)
-                        return bb;
+                for(BenkoBox bb : ship.getBenkoBoxes())
                     for(Destination d : bb.getDestinations())
                         if (getDestAddr(d)==dest)
                             return d;
-                }
             return null;
         }
         public BenkoBox getBoxByInstAddr(long dest) {