}
mem[addr] = val;
}
-/*
- public void dispatch(int addr, int size) {
- for(int i=addr; i<addr+size; i++) {
- Instruction instr = ((Interpreter)getFleet()).readInstruction(getFleet().getUniversalSource(), readMem(i));
- ((Interpreter)getFleet()).dispatch(instr, i);
- }
- }
- public void boot(byte[] instructions) {
- Interpreter fleet = (Interpreter)getFleet();
- // load the iscratch and take note of the 0-address INCBD
- long launch = 0;
- for(int i=0; i<instructions.length; i+=6) {
- long word = 0;
- for(int j=0; j<6; j++)
- word = (word << 8) | (instructions[i+j] & 0xff);
- writeMem(i/6, word);
- if (i==0) launch = word;
- }
-
- // dispatch the 0-address INCBD
- int base = (int)(launch >> 6);
- base = base & ~(0xffffffff << 18);
- int size = (int)launch;
- size = size & ~(0xffffffff << 6);
- dispatch(base, size);
- }
-*/
private long stride = 0;
private long count = 0;
private long addr = 0;
writing = false;
} else if (box_inAddrWrite.dataReadyForShip()) {
- addr = box_inAddrWrite.peekPacketForShip().value;
+// addr = box_inAddrWrite.peekPacketForShip().value;
box_inAddrWrite.removeDataForShip();
stride = 0;
count = 1;
if (box_inAmount.dataReadyForShip() && box_in.dataReadyForShip() && box_out.readyForDataFromShip()) {
long amount = box_inAmount.removeDataForShip();
long data = box_in.removeDataForShip();
- long mask = ~((-1L) << getInterpreter().getWordSize());
+ long mask = ~((-1L) << getInterpreter().getWordWidth());
data = data & mask;
- box_out.addDataFromShip(((data << amount) | (data >> (getInterpreter().getWordSize()-amount))) & mask);
+ box_out.addDataFromShip(((data << amount) | (data >> (getInterpreter().getWordWidth()-amount))) & mask);
}
}
} else {
dock = ((Interpreter)fleet).getUniversalSource();
}
- baseCodeBag.add(new Set(dock, false, IgnoreOLC, SetDest.DataLatch, (rootCodeBag.getFakeAddress())), true);
+ //baseCodeBag.add(new Set(dock, false, IgnoreOLC, SetDest.DataLatch, (rootCodeBag.getFakeAddress())), true);
Tree<String> parsed = (Tree<String>)parseIt(r);
walk(parsed, rootCodeBag);
count++;
}
}
+ long startcbd = 0;
+ for(int i=0; i<codeBags.size(); i++) {
+ if (codeBags.get(i)==rootCodeBag) {
+ long lit = 0;
+ lit = FleetTwoFleet.CBD_SIZE.setval(lit, codeBags.get(i).size());
+ lit = FleetTwoFleet.CBD_OFFSET.setval(lit, codeBagMap[i]);
+ startcbd = lit;
+ }
+ }
+ if (codeBags.size()<=2)
+ return (Instruction[])ret.toArray(new Instruction[0]);
+ return fixup((Instruction[])ret.toArray(new Instruction[0]), startcbd);
+ }
+
+ private Instruction[] fixup(Instruction[] instructions, long startcbd) {
+ ArrayList<Instruction> ret = new ArrayList<Instruction>();
+ Fleet fpga = fleet;
+
+ Dock us = null;
+ if (fleet instanceof Fpga) {
+ us = ((Fpga)fleet).getUniversalSource();
+ } else {
+ us = ((Interpreter)fleet).getUniversalSource();
+ }
+
+ Dock inAddrWrite = null;
+ Dock inDataWrite = null;
+ Dock inCBD = null;
+ Dock out = null;
+ Dock debugIn = null;
+ Dock ihorn = null;
+
+ for(Ship ship : fpga) {
+ if ("Memory".equals(ship.getType()) && ship.getOrdinal()==0) {
+ inAddrWrite = ship.getDock("inAddrWrite");
+ inDataWrite = ship.getDock("inDataWrite");
+ inCBD = ship.getDock("inCBD");
+ out = ship.getDock("out");
+ ihorn = ship.getDock("outIhorn");
+ }
+ if ("Debug".equals(ship.getType()) && ship.getOrdinal()==0) {
+ debugIn = ship.getDock("in");
+ }
+ }
+
+ for(int i=0; i<instructions.length; i++) {
+ Instruction inst = instructions[i];
+ /*
+ if (i==0) {
+ long lit = ((Instruction.Set)inst).immediate;
+ long offset = (lit >> 6) & ~(-1L << 10);
+ long size = (lit >> 0) & ~(-1L << 6);
+ //startcbd = (offset << 6) | size;
+ size = 0;
+ offset = 0;
+ continue;
+ }
+ */
+ long lit = ((Fpga)fpga).writeInstruction(instructions[i], us);
+ ret.add(discard(out));
+ ret.add(new Instruction.Shift(inDataWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(36, 19, lit))));
+ ret.add(new Instruction.Shift(inDataWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(18, 0, lit))));
+ ret.add(deliver(inDataWrite));
+ ret.add(new Instruction.Shift(inAddrWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(36, 19, i))));
+ ret.add(new Instruction.Shift(inAddrWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(18, 0, i))));
+ ret.add(deliver(inAddrWrite));
+ }
+ ret.add(new Instruction.Shift(inCBD, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(36, 19, startcbd))));
+ ret.add(new Instruction.Shift(inCBD, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(18, 0, startcbd))));
+ ret.add(wait(inCBD));
+ ret.add(deliver(inCBD));
+ ret.add(sendto(out, out.getPath(inCBD.getDataDestination(),null)));
+ ret.add(new Instruction.Set(ihorn, false, IgnoreOLC, SetDest.InnerLoopCounter, SetSource.Infinity));
+ ret.add(new Instruction.Move(ihorn, false, IgnoreOLC, false, null,false,true,true,true,true,false));
return (Instruction[])ret.toArray(new Instruction[0]);
}
public static interface FleetWithDynamicShips {
public Ship createShip(String shiptype, String shipname);
}
+
+ private static Move discard(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, false, true, false, false, false, false); }
+ private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, false, false, false, false, true, false); }
+ private static Move wait(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, true, false, false, false, false, false); }
+ private static Move sendto(Dock dock, Path path) { return new Move(dock, false, IgnoreOLC, false, path, false, false, false, false, true, false); }
}
} catch (Exception e) { e.printStackTrace(); }
}
- public Client(String bitfile, byte[] program) throws Exception {
+ private Fpga fpga;
+
+ public Client(Fpga fpga, String bitfile, Instruction[] instructions) throws Exception {
+ this.fpga = fpga;
+
s = new Socket(InetAddress.getByName("goliath.megacz.com"), 3133);
OutputStream os = new BufferedOutputStream(s.getOutputStream());
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
pw.print(Server.pass_string+" "+bitfile+"\n");
pw.flush();
-
- Fpga fpga = new Fpga();
- ByteArrayOutputStream newp = new ByteArrayOutputStream();
- DataOutputStream newpd = new DataOutputStream(newp);
- long startcbd = 0;
-
- Dock inAddrWrite = null;
- Dock inDataWrite = null;
- Dock inCBD = null;
- Dock out = null;
- Dock debugIn = null;
- Dock ihorn = null;
-
- for(Ship ship : fpga) {
- if ("Memory".equals(ship.getType()) && ship.getOrdinal()==0) {
- inAddrWrite = ship.getDock("inAddrWrite");
- inDataWrite = ship.getDock("inDataWrite");
- inCBD = ship.getDock("inCBD");
- out = ship.getDock("out");
- ihorn = ship.getDock("outIhorn");
- }
- if ("Debug".equals(ship.getType()) && ship.getOrdinal()==0) {
- debugIn = ship.getDock("in");
- }
- }
-
- for(int i=0; i<program.length; i+=6) {
- long lit = 0
- | ((program[i+0] & 0xffL) << 40)
- | ((program[i+1] & 0xffL) << 32)
- | ((program[i+2] & 0xffL) << 24)
- | ((program[i+3] & 0xffL) << 16)
- | ((program[i+4] & 0xffL) << 8)
- | ((program[i+5] & 0xffL) << 0);
- Instruction inst = fpga.readInstruction(lit, fpga.getUniversalSource());
- if (i==0) {
- long offset = (lit >> 6) & ~(-1L << 10);
- long size = (lit >> 0) & ~(-1L << 6);
- startcbd = (offset << 6) | size;
- size = 0;
- offset = 0;
- inst = new Instruction.Shift(fpga.getUniversalSource(), false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(0));
- } else {
- if (fpga.writeInstruction(inst, fpga.getUniversalSource()) != lit)
- throw new RuntimeException("no match: " + inst + " @"+(i/6)+"\n"+Long.toString(lit,16)+
- "\n"+Long.toString(fpga.writeInstruction(inst, fpga.getUniversalSource()),16));
- }
- //fpga.writeInstruction(newpd, fpga.getUniversalSource(), inst);
- }
-
- for(int i=0; i<program.length; i+=6) {
- long lit = 0
- | ((program[i+0] & 0xffL) << 40)
- | ((program[i+1] & 0xffL) << 32)
- | ((program[i+2] & 0xffL) << 24)
- | ((program[i+3] & 0xffL) << 16)
- | ((program[i+4] & 0xffL) << 8)
- | ((program[i+5] & 0xffL) << 0);
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), discard(out));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Shift(inDataWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(36, 19, lit))));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Shift(inDataWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(18, 0, lit))));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), deliver(inDataWrite));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Shift(inAddrWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(36, 19, i/6))));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Shift(inAddrWrite, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(18, 0, i/6))));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), deliver(inAddrWrite));
- }
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Shift(inCBD, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(36, 19, startcbd))));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Shift(inCBD, false, IgnoreOLC, new BitVector(fpga.getWordWidth()).set(getField(18, 0, startcbd))));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), wait(inCBD));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), deliver(inCBD));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), sendto(out, out.getPath(inCBD.getDataDestination(),null)));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(), new Instruction.Set(ihorn, false, IgnoreOLC, SetDest.InnerLoopCounter, SetSource.Infinity));
- fpga.writeInstruction(newpd, fpga.getUniversalSource(),
- new Instruction.Move(ihorn, false, IgnoreOLC, false, null,false,true,true,true,true,false));
-
- newpd.flush();
- program = newp.toByteArray();
-
- os.write(program);
- os.flush();
+ DataOutputStream dos = new DataOutputStream(os);
+ for(Instruction inst : instructions)
+ fpga.writeInstruction(dos, fpga.getUniversalSource(), inst);
+ dos.flush();
final InputStream is = new BufferedInputStream(s.getInputStream());
new Thread() {
}
}.start();
}
- /*
- public static void main(String[] args) throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buf = new byte[1024];
- while(true) {
- int numread = System.in.read(buf, 0, buf.length);
- if (numread==-1) break;
- baos.write(buf, 0, numread);
- }
- Client client = new Client(args.length==0 ? "main.bit" : args[0], baos.toByteArray());
- while(true) {
- long result = client.readWord();
- System.err.print(result);
- System.err.print(" 0x");
- System.err.print(Long.toString(result, 16));
- System.err.println();
- }
- }
- */
+
public void dispatchInstruction(Instruction i) { throw new RuntimeException(); }
private static Move discard(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, false, true, false, false, false, false); }
private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, false, false, false, false, true, false); }
public FleetProcess run(Instruction[] instructions) {
try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- for(Instruction i : instructions)
- writeInstruction(dos, getUniversalSource(), i);
- dos.flush();
- return new Client("none", baos.toByteArray());
+ return new Client(this, "none", instructions);
} catch (Exception e) { throw new RuntimeException(e); }
}
import static edu.berkeley.fleet.api.Instruction.*;
import static edu.berkeley.fleet.api.Predicate.*;
+/** common subclass for the "FleetTwo" generation of processors, all 37-bit wide, with AM33 encoding */
public abstract class FleetTwoFleet extends Fleet {
public static final Mask PACKET_TOKEN = new Mask("v.................................................");
public static final Mask SET_TAPL_FROM_IMMEDIATE = new Mask("................1000001.vvvvvvvvvvvvv");
+ // Misc //////////////////////////////////////////////////////////////////////////////
- public static final long DataLatch_WIDTH = SET_IMMEDIATE.valmaskmax-SET_IMMEDIATE.valmaskmin+1; // FIXME: this is an abstraction breakage
- private static final long mask = ~(-1L << DataLatch_WIDTH);
- public static boolean isSmallEnoughToFit(long immediate) {
- if ((immediate & ~mask) == 0) return true;
- if ((immediate | mask) == -1L) return true;
- return false;
- }
+ public static final long DataLatch_WIDTH = SET_IMMEDIATE.valmaskmax-SET_IMMEDIATE.valmaskmin+1; // FIXME: this is an abstraction breakage
+ private static final long mask = ~(-1L << DataLatch_WIDTH);
+ public static boolean isSmallEnoughToFit(long immediate) {
+ if ((immediate & ~mask) == 0) return true;
+ if ((immediate | mask) == -1L) return true;
+ return false;
+ }
+
+ public int getWordWidth() { return 37; }
+
+ //////////////////////////////////////////////////////////////////////////////
/** get the bits describing this box's location on the DESTINATION HORN */
+ // FIXME this should use a BitVector not a long!
protected abstract long getDestAddr(Path box);
/** 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);
/** FIXME: this is a hack for now */
}
return ret;
}
+
}