add FpgaDestination.getPathLength() for measuring hop counts
authormegacz <adam@megacz.com>
Mon, 6 Apr 2009 18:33:24 +0000 (11:33 -0700)
committermegacz <adam@megacz.com>
Mon, 6 Apr 2009 18:33:24 +0000 (11:33 -0700)
src/edu/berkeley/fleet/fpga/FabricElement.java
src/edu/berkeley/fleet/fpga/Fpga.java
src/edu/berkeley/fleet/fpga/FpgaDestination.java
src/edu/berkeley/fleet/fpga/FpgaDock.java
src/edu/berkeley/fleet/fpga/FunnelModule.java
src/edu/berkeley/fleet/fpga/HornModule.java

index bcf44b7..c340c99 100644 (file)
@@ -16,6 +16,7 @@ import static edu.berkeley.fleet.fpga.verilog.Verilog.*;
 public interface FabricElement {
 
     public FpgaPath getPath(FpgaDestination dest, BitVector signal);
+    public int      getPathLength(FpgaDestination dest);
 
     public void addInput(FabricElement in, Module.Port inPort);
     public void addOutput(FabricElement out, Module.Port outPort);
@@ -25,6 +26,7 @@ public interface FabricElement {
 
     public static abstract class AbstractFabricElement implements FabricElement {
         public abstract FpgaPath getPath(FpgaDestination dest, BitVector signal);
+        public abstract int getPathLength(FpgaDestination dest);
         public void addInput(FabricElement in, Module.Port inPort) { throw new RuntimeException(); }
         public void addOutput(FabricElement out, Module.Port outPort) { throw new RuntimeException(); }
         public Module.SourcePort getOutputPort() { throw new RuntimeException(); }
index 46ff045..372b9fb 100644 (file)
@@ -135,6 +135,7 @@ public class Fpga extends FleetTwoFleet {
                 final Module.SourcePort sp = sp0;
                 sources.add(new FabricElement.AbstractFabricElement() {
                         private FabricElement upstream;
+                        public int      getPathLength(FpgaDestination dest) { return upstream.getPathLength(dest); }
                         public FpgaPath getPath(FpgaDestination dest, BitVector signal) { return upstream.getPath(dest, signal); }
                         public void addOutput(FabricElement out, Module.Port outPort) {
                             this.upstream = out;
index 79eb4bd..37677ce 100644 (file)
@@ -32,6 +32,12 @@ public class FpgaDestination extends Destination implements FabricElement {
     public Module.Port getInputPort()  { throw new RuntimeException(); }
     public void addOutput(FabricElement out, Module.Port outPort) { throw new RuntimeException(); }
 
+    public int      getPathLength(FpgaDestination dest) {
+        if (dest==this) {
+            return isInstructionDestination ? 0 : FpgaDock.DATA_FIFO_SIZE;
+        }
+        return 0;
+    }
     public FpgaPath getPath(FpgaDestination dest, BitVector signal) {
         if (dest==this) return FpgaPath.emptyPath(this, signal);
         return null;
index b7212e8..d8bbef1 100644 (file)
@@ -21,7 +21,7 @@ public class FpgaDock extends FleetTwoDock implements FabricElement {
     private static final int INSTRUCTION_FIFO_SIZE = 12;
     private static final int EPILOGUE_FIFO_SIZE    = 0;
     //private static final int DATA_FIFO_SIZE        = 4;
-    private static final int DATA_FIFO_SIZE        = 8;
+    static final int DATA_FIFO_SIZE        = 8;
         
     private FpgaDestination dataDestination;
     private FpgaDestination instructionDestination;
@@ -58,6 +58,7 @@ public class FpgaDock extends FleetTwoDock implements FabricElement {
     public Module.Port getInputPort()  { throw new RuntimeException(); }
     public Path getPath(Destination dest,BitVector signal) { return getPath((FpgaDestination)dest, signal); }
     public FpgaPath getPath(FpgaDestination dest,BitVector signal) { return upstream.getPath(dest, signal); }
+    public int      getPathLength(FpgaDestination dest) { return upstream.getPathLength(dest)-1; }
     public void addInput(FabricElement in, Module.Port inPort) { throw new RuntimeException(); }
     public void addOutput(FabricElement out, Module.Port outPort) {
         this.upstream = out;
index 08f3f5e..7593133 100644 (file)
@@ -55,6 +55,7 @@ public class FunnelModule extends Module {
         public void addInput(FabricElement in, Module.Port source) {
             throw new RuntimeException("cannot add inputs to a funnel once constructed");
         }
+        public int      getPathLength(FpgaDestination dest) { return out.getPathLength(dest)+1; }
         public FpgaPath getPath(FpgaDestination dest, BitVector signal) {
             return out.getPath(dest, signal);
         }
index 44b8be5..1b62922 100644 (file)
@@ -61,6 +61,13 @@ public class HornModule extends Module {
             out1.addInput(this, getOutputPort("out1"));
         }
         public void addOutput(FabricElement out, Module.Port outPort) { throw new RuntimeException(); }
+        public int      getPathLength(FpgaDestination dest) {
+            FpgaPath path0 = out0==null ? null : out0.getPath(dest, null);
+            FpgaPath path1 = out1==null ? null : out1.getPath(dest, null);
+            if (path0==null) return out1.getPathLength(dest)+1;
+            if (path1==null) return out0.getPathLength(dest)+1;
+            return Math.min(out1.getPathLength(dest)+1, out0.getPathLength(dest)+1);
+        }
         public FpgaPath getPath(FpgaDestination dest, BitVector signal) {
             FpgaPath path0 = out0==null ? null : out0.getPath(dest, signal);
             FpgaPath path1 = out1==null ? null : out1.getPath(dest, signal);