lift sloppy getPathByAddr() implementation into FleetTwoFleet
authoradam <adam@megacz.com>
Thu, 26 Jun 2008 07:45:26 +0000 (08:45 +0100)
committeradam <adam@megacz.com>
Thu, 26 Jun 2008 07:45:26 +0000 (08:45 +0100)
src/edu/berkeley/fleet/fpga/Fpga.java
src/edu/berkeley/fleet/interpreter/Interpreter.java
src/edu/berkeley/fleet/interpreter/InterpreterDestination.java
src/edu/berkeley/fleet/two/FleetTwoFleet.java

index ff59f5b..7b113ac 100644 (file)
@@ -26,11 +26,6 @@ public class Fpga extends FleetTwoFleet {
     }
 
     public int getWordWidth() { return 37; }
-    private static final BitVector SIGNAL_ZERO = new BitVector(1);
-    private static final BitVector SIGNAL_ONE  = new BitVector(1);
-    static {
-        SIGNAL_ONE.set(0,true);
-    }
 
     public Module top;
     public FabricElement top_horn;
@@ -249,18 +244,6 @@ public class Fpga extends FleetTwoFleet {
         public long getDestAddr(Path path) {
             return ((FpgaPath)path).toLong();
         }
-        public Path getPathByAddr(Dock source, long dest) {
-            for(Ship ship : Fpga.this)
-                for(Dock bb : ship) {
-                    for(Destination d : new Destination[] { bb.getInstructionDestination(), bb.getDataDestination() }) {
-                        for(BitVector signal : new BitVector[] { SIGNAL_ZERO, SIGNAL_ONE }) {
-                            FpgaPath p = (FpgaPath)source.getPath(d, signal);
-                            if (p.toLong() == dest) return p;
-                        }
-                    }
-                }
-            return null;
-        }
         public Dock getBoxByInstAddr(long dest) {
             for(Ship ship : Fpga.this)
                 for(Dock bb : ship)
index 729f6cd..556650a 100644 (file)
@@ -60,12 +60,11 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
     // Instruction Encoding /////////////////////////////////////////////////////////////////////////
 
     public long getDestAddr(Path path) {
-        // FIXME
-        throw new RuntimeException();
-    }
-    public Path getPathByAddr(Dock source, long dest) {
-        // FIXME
-        throw new RuntimeException();
+        long ret = ((InterpreterDestination)path.getDestination()).addr;
+        BitVector bv = path.getSignal();
+        if (bv.length() > 1) throw new RuntimeException();
+        if (bv.length() > 0 && bv.get(0)) ret |= 1;
+        return ret;
     }
 
 
index 6f709b4..6bb3971 100644 (file)
@@ -4,8 +4,16 @@ import java.util.*;
 
 class InterpreterDestination extends Destination {
 
+    private static int max_dest = 0;
+
+    int addr;
+
     public InterpreterDestination(InterpreterDock d, boolean isInstructionDestination) {
         super(d);
+        synchronized(InterpreterDestination.class) {
+            this.addr = max_dest;
+            max_dest += 2;
+        }
     }
 
     /** adds the included datum to the port from the switch fabric  side */
index 2ec3680..d65d40c 100644 (file)
@@ -91,9 +91,27 @@ public abstract class FleetTwoFleet extends Fleet {
     // FIXME this should use a BitVector not a long!
     protected abstract long getDestAddr(Path box);
 
+    private static final BitVector SIGNAL_ZERO = new BitVector(1);
+    private static final BitVector SIGNAL_ONE  = new BitVector(1);
+    static {
+        SIGNAL_ONE.set(0,true);
+    }
+
     /** decode a path, given the starting point and the bits that comprise it */
     // FIXME this should use a BitVector not a long!
-    protected abstract Path getPathByAddr(Dock source, long dest);
+    //protected abstract Path getPathByAddr(Dock source, long dest);
+    protected Path getPathByAddr(Dock source, long dest) {
+        for(Ship ship : this)
+            for(Dock bb : ship) {
+                for(Destination d : new Destination[] { bb.getInstructionDestination(), bb.getDataDestination() }) {
+                    for(BitVector signal : new BitVector[] { SIGNAL_ZERO, SIGNAL_ONE }) {
+                        Path p = (Path)source.getPath(d, signal);
+                        if (getDestAddr(p) == dest) return p;
+                    }
+                }
+            }
+        return null;
+    }
 
     /** read a machine-formatted instruction from a file (into a Java object) */
     public Instruction readInstruction(DataInputStream is, Dock dispatchFrom) throws IOException {