--- /dev/null
+// A bubble sort implementation.
+// This only works for 6 input elements. To change the number of input
+// elements, modify the counts in the lines marked below.
+// Author: Amir Kamil <kamil@cs.berkeley.edu>
+// Date: 7/16/07
+
+#import edu.berkeley.fleet.ships
+#ship alu : Alu2b
+#ship blu : Alu2b
+#ship debug : Debug
+#ship fifo1 : Fifo
+#ship fifo2 : Fifo
+#ship fifo3 : Fifo
+#ship mem : Memory
+
+#expect 1
+#expect 2
+#expect 3
+#expect 9
+#expect 8
+#expect 11
+
+// for debugging; the solution should work with any set of numbers
+
+9: sendto fifo1.in;
+1: sendto fifo1.in;
+3: sendto fifo1.in;
+11: sendto fifo1.in;
+2: sendto fifo1.in;
+8: sendto fifo1.in;
+
+// basic setup
+
+fifo1.in: [*] take, deliver;
+fifo2.in: [*] take, deliver;
+debug.in: [*] take, deliver;
+alu.in1: [*] take, deliver;
+alu.in2: [*] take, deliver;
+blu.in1: [*] take, deliver;
+blu.in2: [*] take, deliver;
+fifo3.out: [*] wait, take, sendto mem.inCBD;
+mem.inCBD: [*] take, deliver;
+
+// one loop iteration
+// this code needs flow control
+
+ITER: {
+ fifo1.out: take, sendto alu.in1.max;
+ sendto blu.in1.min;
+ [*] nop;
+ (*) take, sendto alu.in2;
+ (*) sendto blu.in2;
+ kill*;
+ alu.out: [*] nop;
+ (*) take, sendto alu.in1.max;
+ (*) sendto blu.in1.min;
+ kill;
+ blu.out: [5] take, sendto fifo2.in; // count = num - 1
+ notify fifo3.out;
+}
+
+// iteration cleanup
+
+END: {
+ 0: sendto alu.in2; // flush
+ 0: sendto blu.in2; // flush
+ fifo1.out: kill;
+ kill;
+ alu.out: kill;
+ kill;
+ sendto fifo2.in;
+ dismiss;
+ blu.out: dismiss;
+ fifo2.out: [6] take, sendto fifo1.in; // count = num
+ notify fifo3.out;
+}
+
+// overall control
+
+SENDDONE: sendto fifo3.in;
+ITER: sendto fifo2.in;
+END: sendto fifo2.in;
+fifo2.out: wait;
+ [*] nop;
+ (6) take, sendto fifo3.in; // count = num
+ (6) sendto fifo2.in; // count = num
+ (6) take, sendto fifo3.in; // count = num
+ (6) sendto fifo2.in; // count = num
+ kill*;
+fifo3.in: take, deliver, notify fifo2.out;
+ [12] take, deliver; // count = 2 * num
+ notify fifo3.out;
+
+// send done cbd into fifo3
+
+SENDDONE: {
+ DONE: sendto fifo3.in;
+ fifo2.out: [2] dismiss;
+ notify fifo3.out;
+ fifo3.in: take, deliver;
+}
+
+// done cbd
+
+DONE: {
+ fifo1.out: [6] take, sendto debug.in; // count = num
+}