putMemoryShipInDispatchMode() now puts both out and inCBD in infinite-recieve mode
authormegacz <adam@megacz.com>
Sun, 15 Mar 2009 04:27:01 +0000 (21:27 -0700)
committermegacz <adam@megacz.com>
Sun, 15 Mar 2009 04:27:01 +0000 (21:27 -0700)
src/edu/berkeley/fleet/loops/CodeBag.java
src/edu/berkeley/fleet/loops/MemoryUtils.java
src/edu/berkeley/fleet/loops/Program.java

index e14ed17..6478802 100644 (file)
@@ -40,13 +40,14 @@ public class CodeBag {
      *  Memory ship memoryShip at the address given by baseAddress.
      */
     CodeBag(Program program, Instruction[] instructions, long baseAddress) {
+        int MAX_BAG_SIZE = (1<<7)-1;
+        if (instructions.length > MAX_BAG_SIZE)
+            throw new RuntimeException("warning: code bag size is "+instructions.length+
+                                       ", which exceeds maximum of "+MAX_BAG_SIZE+
+                                       "; breaking into multiple bags");
         this.program = program;
         this.instructions = instructions;
         this.baseAddress = baseAddress;
-
-        // FIXME
-        if (instructions.length >= (1<<7))
-            throw new RuntimeException("code bag size is "+instructions.length+", which exceeds maximum of "+((1<<7)-1));
     }
 
 }
index 78d80f0..f8c5163 100644 (file)
@@ -117,15 +117,23 @@ public class MemoryUtils {
     public static void putMemoryShipInDispatchMode(FleetProcess fp, Ship memoryShip) {
         Context ctx = new Context(fp.getFleet());
         LoopFactory lf;
+
         lf = new LoopFactory(ctx, memoryShip.getDock("out"), 0);
         lf.abortLoopIfTorpedoPresent();
         lf.collectPacket();
         lf.sendWord(null);
+
+        lf = new LoopFactory(ctx, memoryShip.getDock("inCBD"), 0);
+        lf.abortLoopIfTorpedoPresent();
+        lf.recvWord();
+        lf.deliver();
+
         ctx.dispatch(fp);
     }
 
     public static void removeMemoryShipFromDispatchMode(FleetProcess fp, Ship memoryShip) {
         fp.sendToken(memoryShip.getDock("out").getInstructionDestination());
+        fp.sendToken(memoryShip.getDock("inCBD").getInstructionDestination());
     }
 
     public static void main(String[] s) throws Exception {
index f32fecb..66d10a7 100644 (file)
@@ -27,10 +27,8 @@ public class Program {
         System.out.println("invoking...");
         Context ctx = new Context(fleet);
         LoopFactory lf;
-        lf = new LoopFactory(ctx, memoryShip.getDock("inCBD"), 1);
-        lf.literal( (run.baseAddress<<6) | run.instructions.length );
-        lf.deliver();
-        ctx.dispatch(fp);
+        fp.sendWord(memoryShip.getDock("inCBD").getDataDestination(),
+                    new BitVector(fleet.getWordWidth()).set( (run.baseAddress<<6) | run.instructions.length ));
         System.out.println("invoked.");
     }
 
@@ -46,12 +44,30 @@ public class Program {
     }
 
     public CodeBag makeCodeBag(Context ctx) {
-        Instruction[] instructions = ctx.emit();
-        CodeBag codeBag = new CodeBag(this, instructions, leastUnallocatedAddress);
-        System.out.println("instructions.length="+instructions.length);
-        leastUnallocatedAddress += instructions.length;
-        codeBags.add(codeBag);
-        return codeBag;
+        return makeCodeBag(ctx.emit());
+    }
+
+    public CodeBag makeCodeBag(Instruction[] instructions) {
+        int MAX_BAG_SIZE = (1<<7)-1;
+        if (instructions.length > MAX_BAG_SIZE) {
+            System.out.println("warning: code bag size is "+instructions.length+
+                               ", which exceeds maximum of "+MAX_BAG_SIZE+
+                               "; breaking into multiple bags");
+            ArrayList<CodeBag> subBags = new ArrayList<CodeBag>();
+            for(int block=0; block<instructions.length; block+=MAX_BAG_SIZE) {
+                Instruction[] inst = new Instruction[Math.min(instructions.length-block, MAX_BAG_SIZE)];
+                System.arraycopy(instructions, block, inst, 0, inst.length);
+                subBags.add(makeCodeBag(inst));
+            }
+            throw new RuntimeException("FIXME: not done");
+
+        } else {
+            CodeBag codeBag = new CodeBag(this, instructions, leastUnallocatedAddress);
+            System.out.println("instructions.length="+instructions.length);
+            leastUnallocatedAddress += instructions.length;
+            codeBags.add(codeBag);
+            return codeBag;
+        }
     }
 
 }
\ No newline at end of file