From 5749f33808262ef468a910087ab3ea16fcb0a0bd Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 26 Jun 2008 08:45:26 +0100 Subject: [PATCH] lift sloppy getPathByAddr() implementation into FleetTwoFleet --- src/edu/berkeley/fleet/fpga/Fpga.java | 17 ----------------- .../berkeley/fleet/interpreter/Interpreter.java | 11 +++++------ .../fleet/interpreter/InterpreterDestination.java | 8 ++++++++ src/edu/berkeley/fleet/two/FleetTwoFleet.java | 20 +++++++++++++++++++- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/edu/berkeley/fleet/fpga/Fpga.java b/src/edu/berkeley/fleet/fpga/Fpga.java index ff59f5b..7b113ac 100644 --- a/src/edu/berkeley/fleet/fpga/Fpga.java +++ b/src/edu/berkeley/fleet/fpga/Fpga.java @@ -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) diff --git a/src/edu/berkeley/fleet/interpreter/Interpreter.java b/src/edu/berkeley/fleet/interpreter/Interpreter.java index 729f6cd..556650a 100644 --- a/src/edu/berkeley/fleet/interpreter/Interpreter.java +++ b/src/edu/berkeley/fleet/interpreter/Interpreter.java @@ -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; } diff --git a/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java b/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java index 6f709b4..6bb3971 100644 --- a/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java +++ b/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java @@ -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 */ diff --git a/src/edu/berkeley/fleet/two/FleetTwoFleet.java b/src/edu/berkeley/fleet/two/FleetTwoFleet.java index 2ec3680..d65d40c 100644 --- a/src/edu/berkeley/fleet/two/FleetTwoFleet.java +++ b/src/edu/berkeley/fleet/two/FleetTwoFleet.java @@ -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 { -- 1.7.10.4