move one of the memory tests into Memory.ship
[fleet.git] / ships / Alu3.ship
1 ship: Alu3
2
3 == Ports ===========================================================
4 data  in:   in1
5 data  in:   in2
6 data  in:   in3
7
8 data  out:  out1
9   shortcut to: in1
10 data  out:  out2
11   shortcut to: in2
12 data  out:  out3
13   shortcut to: in3
14 data  out:  outBits
15
16 == Constants ========================================================
17 == TeX ==============================================================
18
19 == Fleeterpreter ====================================================
20 int count = 74;
21 Bitfifo.BitStorage bits = new Bitfifo.BitStorage(74);
22 public void service() {
23   if (box_in1.dataReadyForShip() &&
24       box_in2.dataReadyForShip() &&
25       box_in3.dataReadyForShip() &&
26       bits.hasSpace(1) &&
27       box_out1.readyForDataFromShip() &&
28       box_out2.readyForDataFromShip() &&
29       box_out3.readyForDataFromShip()) {
30       long v1 = box_in1.removeDataForShip();
31       long v2 = box_in2.removeDataForShip();
32       long v3 = box_in3.removeDataForShip();
33       long o1, o2, o3;
34       if (count % 2 == 0) {
35         o1 = v1;
36         o2 = v2 >>> 1;
37         o3 = ((v2 & 0x1L) == 0) ? 0 : v1;
38       } else {
39         o1 = ((v1 & v2) | (v2 & v3) | (v1 & v3))/* << 1*/;
40         o2 = (v1 ^ v2 ^ v3) >> 1;
41         o3 = 0;
42         bits.add((v1 ^ v2 ^ v3) & 0x1L, 1);
43         System.out.println("size is now " + bits.size());
44       }
45       box_out1.addDataFromShip(o1);
46       box_out2.addDataFromShip(o2);
47       box_out3.addDataFromShip(o3);
48       count--;
49       // This should be removed
50       if (count == 0) {
51         for (int i = 0; i < 37; i++) {
52           v1 = o1;
53           v2 = o2;
54           v3 = o3;
55           o1 = ((v1 & v2) | (v2 & v3) | (v1 & v3))/* << 1*/;
56           o2 = (v1 ^ v2 ^ v3) >> 1;
57           o3 = 0;
58           bits.add((v1 ^ v2 ^ v3) & 0x1L, 1);
59           System.out.println("size is now " + bits.size());
60         }
61         count = 74;
62       }
63   }
64   if (box_outBits.readyForDataFromShip() &&
65       bits.size() >= 37) {
66       box_outBits.addDataFromShip(bits.get(37));
67   }
68 }
69
70 == FleetSim ==============================================================
71
72 == FPGA ==============================================================
73
74   reg                    have_a;
75   reg [(`DATAWIDTH-1):0] a;
76   reg                    have_b;
77   reg [(`DATAWIDTH-1):0] b;
78   reg                    have_c;
79   reg [(`DATAWIDTH-1):0] c;
80   reg                    have_out1;
81   reg                    have_out2;
82
83   always @(posedge clk) begin
84     if (have_out1) begin
85       `onwrite(out1_r, out1_a) have_out1 <= 0; end
86
87     end else if (have_out2) begin
88       `onwrite(out2_r, out2_a) have_out2 <= 0; end
89
90     end else if (!have_out1 && !have_out2) begin
91       if (!have_a) begin
92         `onread(in1_r, in1_a) have_a <= 1; a <= in1_d; end
93         end
94       if (!have_b) begin
95         `onread(in2_r, in2_a) have_b <= 1; b <= in2_d; end
96         end
97       if (!have_c) begin
98         `onread(in3_r, in3_a) have_c <= 1; c <= in3_d; end
99         end
100   
101       if (have_a && have_b && have_c) begin
102         out1_d    <= { { ((a & b) | (b & c) | (a & c)) } , 1'b0 };
103         out2_d    <= a ^ b ^ c;
104         have_a    <= 0;
105         have_b    <= 0;
106         have_c    <= 0;
107         have_out1 <= 1;
108         have_out2 <= 1;
109       end
110     end
111   end
112
113
114 == Test ========================================================================
115 #expect 25
116
117 #ship alu3 : Alu3
118 #ship debug : Debug
119
120 25: sendto debug.in;
121 debug.in: [*] take, deliver;
122
123
124 == Contributors =========================================================
125 Amir Kamil <kamil@cs.berkeley.edu>
126 Adam Megacz <megacz@cs.berkeley.edu>