From eac37cd0d8008155d6333f6904b6597a8d2b26f7 Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 12 Feb 2007 12:24:19 +0100 Subject: [PATCH] add more ship files --- ships/Alu1.ship | 37 ++++++++++++++++++++++++++ ships/Alu2.ship | 50 ++++++++++++++++++++++++++++++++++ ships/Debug.ship | 21 +++++++++++++++ ships/Dscratch.ship | 44 ++++++++++++++++++++++++++++++ ships/Execute.ship | 17 ++++++++++++ ships/Fifo.ship | 24 +++++++++++++++++ ships/Halt.ship | 23 ++++++++++++++++ ships/Iscratch.ship | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ ships/Lut.ship | 31 +++++++++++++++++++++ ships/Shift.ship | 25 +++++++++++++++++ 10 files changed, 346 insertions(+) create mode 100644 ships/Alu1.ship create mode 100644 ships/Alu2.ship create mode 100644 ships/Debug.ship create mode 100644 ships/Dscratch.ship create mode 100644 ships/Execute.ship create mode 100644 ships/Fifo.ship create mode 100644 ships/Halt.ship create mode 100644 ships/Iscratch.ship create mode 100644 ships/Lut.ship create mode 100644 ships/Shift.ship diff --git a/ships/Alu1.ship b/ships/Alu1.ship new file mode 100644 index 0000000..10170f7 --- /dev/null +++ b/ships/Alu1.ship @@ -0,0 +1,37 @@ +ship: Alu1 + +== Ports =========================================================== +data in: in +data in: inOp + +data out: out + +== Constants ======================================================== +== TeX ============================================================== +== Fleeterpreter ==================================================== + public void service() { +/* + if (in.dataReadyForShip() && op.dataReadyForShip()) { + int data = in.removeDataForShip(); + int opcode = in.removeDataForShip(); + switch(opcode) { + case 0: out.addDataFromShip(-1 * data); // NEG + break; + case 1: out.addDataFromShip(data+1); // INC + break; + case 2: out.addDataFromShip(data-1); // DEC + break; + case 3: out.addDataFromShip(Math.abs(data)); // ABS + break; + default: out.addDataFromShip(0); + break; + } + } +*/ + } + +== ArchSim ============================================================== +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Alu2.ship b/ships/Alu2.ship new file mode 100644 index 0000000..1314407 --- /dev/null +++ b/ships/Alu2.ship @@ -0,0 +1,50 @@ +ship: Alu2 + +== Ports =========================================================== +data in: a +data in: b +data in: op + +data out: out + +== Constants ======================================================== +ADD: add the two arguments; treat link as carry +SUB: subtract the two arguments; treat link as carry + +== TeX ============================================================== +This ship is a two-input arithmetic unit. It features several +opcodes, such as {\tt ADD} and {\tt SUB}. In my opinion, it is +niftycool. + +== Fleeterpreter ==================================================== +public void service() { + if (box_a.dataReadyForShip() && + box_b.dataReadyForShip() && + box_op.dataReadyForShip() && + box_out.readyForItemFromShip()) { + int a = box_a.removeDataForShip(); + int b = box_b.removeDataForShip(); + int op = box_op.removeDataForShip(); + switch(op) { + case 0: box_out.addDataFromShip(a+b); // ADD + break; + case 1: box_out.addDataFromShip(a-b); // SUB + break; + case 2: box_out.addDataFromShip(a*b); // MUL + break; + case 3: box_out.addDataFromShip(a/b); // DIV + break; + case 4: box_out.addDataFromShip(a%b); // REM + break; + default: box_out.addDataFromShip(0); + break; + } + } +} + +== ArchSim ============================================================== + +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Debug.ship b/ships/Debug.ship new file mode 100644 index 0000000..0c3120a --- /dev/null +++ b/ships/Debug.ship @@ -0,0 +1,21 @@ +ship: Debug + +== Ports =========================================================== +data in: data + +== Constants ======================================================== + +== TeX ============================================================== + +== Fleeterpreter ==================================================== +public void service() { + if (box_data.dataReadyForShip()) + ((Interpreter)getFleet()).debug(box_data.removeDataForShip()); +} + +== ArchSim ============================================================== + +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Dscratch.ship b/ships/Dscratch.ship new file mode 100644 index 0000000..9b05a11 --- /dev/null +++ b/ships/Dscratch.ship @@ -0,0 +1,44 @@ +ship: Dscratch + +== Ports =========================================================== +data in: read_addr +data out: read_data + +data in: write_addr +data in: write_data +token out: write_done + +== Fleeterpreter ==================================================== + private long[] mem = new long[0]; + public long readMem(int addr) { return mem[addr]; } + public void writeMem(int addr, long val) { + if (addr >= mem.length) { + long[] newmem = new long[addr * 2 + 1]; + System.arraycopy(mem, 0, newmem, 0, mem.length); + mem = newmem; + } + mem[addr] = val; + } + + public void service() { + if (box_read_addr.dataReadyForShip() && + box_read_data.readyForItemFromShip()) { + box_read_data.addDataFromShip((int)readMem(box_read_addr.removeDataForShip())); + } + + if (box_write_addr.dataReadyForShip() && + box_write_data.dataReadyForShip() && + box_write_done.readyForItemFromShip()) { + writeMem(box_write_addr.removeDataForShip(), + box_write_data.removeDataForShip()); + box_write_done.addTokenFromShip(); + } + } + +== ArchSim ============================================================== +== FPGA ============================================================== +== Constants ======================================================== +== TeX ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Execute.ship b/ships/Execute.ship new file mode 100644 index 0000000..0946121 --- /dev/null +++ b/ships/Execute.ship @@ -0,0 +1,17 @@ +ship: Execute + +== Ports =========================================================== +data in: in + +== Constants ======================================================== +== TeX ============================================================== +== Fleeterpreter ==================================================== + public void service() { + //throw new Error("the Execute ship is only for FPGA simulations"); + } + +== ArchSim ============================================================== +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Fifo.ship b/ships/Fifo.ship new file mode 100644 index 0000000..8c96494 --- /dev/null +++ b/ships/Fifo.ship @@ -0,0 +1,24 @@ +ship: Fifo + +== Ports =========================================================== +data in: in +data out: out + +== Constants ======================================================== +== TeX ============================================================== +== Fleeterpreter ==================================================== + private Queue fifo = new LinkedList(); + public void service() { + if (box_in.dataReadyForShip()) { + fifo.add(box_in.removeDataForShip()); + } + if (box_out.readyForDataFromShip() && fifo.size() > 0) { + box_out.addDataFromShip(fifo.remove()); + } + } + +== ArchSim ============================================================== +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Halt.ship b/ships/Halt.ship new file mode 100644 index 0000000..49c2ce4 --- /dev/null +++ b/ships/Halt.ship @@ -0,0 +1,23 @@ +ship: Halt + +== Ports =========================================================== +token in: in + +== Constants ======================================================== + +== TeX ============================================================== + +== Fleeterpreter ==================================================== +public void service() { + if (!box_in.tokenReadyForShip()) return; + box_in.removeTokenForShip(); + ((Interpreter)getInterpreter()).halt = true; + Log.println(Log.yellow(" HALT: ====== halt ship got a token; halting the fleet ======")); +} + +== ArchSim ============================================================== + +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Iscratch.ship b/ships/Iscratch.ship new file mode 100644 index 0000000..a09290c --- /dev/null +++ b/ships/Iscratch.ship @@ -0,0 +1,74 @@ +ship: Iscratch + +== Ports =========================================================== +data in: write_addr +data in: write_data +token out: write_done + +data in: cbd + +== Fleeterpreter ==================================================== + + private long[] mem = new long[0]; + public long readMem(int addr) { return mem[addr]; } + public void writeMem(int addr, long val) { + if (addr >= mem.length) { + long[] newmem = new long[addr * 2 + 1]; + System.arraycopy(mem, 0, newmem, 0, mem.length); + mem = newmem; + } + mem[addr] = val; + } + + public void dispatch(int addr, int size) { + for(int i=addr; i> 6; + int size = val & 0x3f; + dispatch(addr, size); + } + + if (box_write_addr.dataReadyForShip() && + box_write_data.dataReadyForShip() && + box_write_done.readyForItemFromShip()) { + Interpreter f = (Interpreter)getFleet(); + f.writeMem(box_write_addr.removeDataForShip(), + box_write_data.removeDataForShip()); + box_write_done.addTokenFromShip(); + } + } + + public void boot(byte[] instructions) { + Interpreter fleet = (Interpreter)getFleet(); + // load the iscratch and take note of the 0-address CBD + long launch = 0; + for(int i=0; i> 6); + base = base & ~(0xffffffff << 18); + int size = (int)launch; + size = size & ~(0xffffffff << 6); + dispatch(base, size); + } + +== Constants ======================================================== +== TeX ============================================================== +== ArchSim ============================================================== +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Lut.ship b/ships/Lut.ship new file mode 100644 index 0000000..e920c9d --- /dev/null +++ b/ships/Lut.ship @@ -0,0 +1,31 @@ +ship: Lut + +== Ports =========================================================== +data in: a +data in: b +data in: lut + +data out: out + +== Constants ======================================================== +== TeX ============================================================== +== Fleeterpreter ==================================================== + public void service() { + if (box_a.dataReadyForShip() && box_b.dataReadyForShip() && box_lut.dataReadyForShip()) { + int a = box_a.removeDataForShip(); + int b = box_b.removeDataForShip(); + int lut = box_lut.removeDataForShip(); + int ret = 0; + if ((lut & 1) != 0) ret |= (~a) & (~b); + if ((lut & 2) != 0) ret |= (a) & (~b); + if ((lut & 4) != 0) ret |= (~a) & (b); + if ((lut & 8) != 0) ret |= a & b; + box_out.addDataFromShip(ret); + } + } + +== ArchSim ============================================================== +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz diff --git a/ships/Shift.ship b/ships/Shift.ship new file mode 100644 index 0000000..8450c78 --- /dev/null +++ b/ships/Shift.ship @@ -0,0 +1,25 @@ +ship: Shift + +== Ports =========================================================== +data in: val +data in: shamt +data out: out + +== Constants ======================================================== +== TeX ============================================================== +== Fleeterpreter ==================================================== + public void service() { + if (box_val.dataReadyForShip() && box_shamt.dataReadyForShip()) { + int val = box_val.removeDataForShip(); + int shamt = box_shamt.removeDataForShip(); + if (shamt < 0) val = val >> (-1 * shamt); + else val = val << shamt; + box_out.addDataFromShip(val); + } + } + +== ArchSim ============================================================== +== FPGA ============================================================== + +== Contributors ========================================================= +Adam Megacz -- 1.7.10.4