add more ship files
authoradam <adam@megacz.com>
Mon, 12 Feb 2007 11:24:19 +0000 (12:24 +0100)
committeradam <adam@megacz.com>
Mon, 12 Feb 2007 11:24:19 +0000 (12:24 +0100)
ships/Alu1.ship [new file with mode: 0644]
ships/Alu2.ship [new file with mode: 0644]
ships/Debug.ship [new file with mode: 0644]
ships/Dscratch.ship [new file with mode: 0644]
ships/Execute.ship [new file with mode: 0644]
ships/Fifo.ship [new file with mode: 0644]
ships/Halt.ship [new file with mode: 0644]
ships/Iscratch.ship [new file with mode: 0644]
ships/Lut.ship [new file with mode: 0644]
ships/Shift.ship [new file with mode: 0644]

diff --git a/ships/Alu1.ship b/ships/Alu1.ship
new file mode 100644 (file)
index 0000000..10170f7
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Alu2.ship b/ships/Alu2.ship
new file mode 100644 (file)
index 0000000..1314407
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Debug.ship b/ships/Debug.ship
new file mode 100644 (file)
index 0000000..0c3120a
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Dscratch.ship b/ships/Dscratch.ship
new file mode 100644 (file)
index 0000000..9b05a11
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Execute.ship b/ships/Execute.ship
new file mode 100644 (file)
index 0000000..0946121
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Fifo.ship b/ships/Fifo.ship
new file mode 100644 (file)
index 0000000..8c96494
--- /dev/null
@@ -0,0 +1,24 @@
+ship: Fifo
+
+== Ports ===========================================================
+data  in:   in
+data  out:  out
+
+== Constants ========================================================
+== TeX ==============================================================
+== Fleeterpreter ====================================================
+    private Queue<Integer> fifo = new LinkedList<Integer>();
+    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 <megacz@cs.berkeley.edu>
diff --git a/ships/Halt.ship b/ships/Halt.ship
new file mode 100644 (file)
index 0000000..49c2ce4
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Iscratch.ship b/ships/Iscratch.ship
new file mode 100644 (file)
index 0000000..a09290c
--- /dev/null
@@ -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<addr+size; i++) {
+            Instruction instr = ((Interpreter)getFleet()).readInstruction(readMem(i));
+            ((Interpreter)getFleet()).dispatch(instr, i);
+        }
+    }
+
+    public void service() {
+        if (box_cbd.dataReadyForShip()) {
+            int val = box_cbd.removeDataForShip();
+            int addr = val >> 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<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 CBD
+        int base = (int)(launch >> 6);
+        base = base & ~(0xffffffff << 18);
+        int size = (int)launch;
+        size = size & ~(0xffffffff <<  6);
+        dispatch(base, size);
+    }
+
+== Constants ========================================================
+== TeX ==============================================================
+== ArchSim ==============================================================
+== FPGA ==============================================================
+
+== Contributors =========================================================
+Adam Megacz <megacz@cs.berkeley.edu>
diff --git a/ships/Lut.ship b/ships/Lut.ship
new file mode 100644 (file)
index 0000000..e920c9d
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>
diff --git a/ships/Shift.ship b/ships/Shift.ship
new file mode 100644 (file)
index 0000000..8450c78
--- /dev/null
@@ -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 <megacz@cs.berkeley.edu>