5b9d0cbcc7e88f8d797b4d255868ca63342c8151
[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 boolean mode = false;
21 Bitfifo.BitStorage outBits = new Bitfifo.BitStorage(74);
22 public void service() {
23   if (box_in1.dataReadyForShip() &&
24       box_in2.dataReadyForShip() &&
25       box_in3.dataReadyForShip() &&
26       outBits.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 (!mode) {
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         outBits.add((v1 ^ v2 ^ v3) & 0x1L, 1);
43       }
44       box_out1.addDataFromShip(o1);
45       box_out2.addDataFromShip(o2);
46       box_out3.addDataFromShip(o3);
47       mode = !mode;
48   }
49   if (box_outBits.readyForDataFromShip() &&
50       outBits.size() >= 37) {
51       box_outBits.addDataFromShip(outBits.get(37));
52   }
53 }
54
55 == FleetSim ==============================================================
56
57 == FPGA ==============================================================
58
59   reg                    have_a;
60   reg [(`DATAWIDTH-1):0] a;
61   reg                    have_b;
62   reg [(`DATAWIDTH-1):0] b;
63   reg                    have_c;
64   reg [(`DATAWIDTH-1):0] c;
65   reg                    have_out1;
66   reg                    have_out2;
67
68   always @(posedge clk) begin
69     if (have_out1) begin
70       `onwrite(out1_r, out1_a) have_out1 <= 0; end
71
72     end else if (have_out2) begin
73       `onwrite(out2_r, out2_a) have_out2 <= 0; end
74
75     end else if (!have_out1 && !have_out2) begin
76       if (!have_a) begin
77         `onread(in1_r, in1_a) have_a <= 1; a <= in1_d; end
78         end
79       if (!have_b) begin
80         `onread(in2_r, in2_a) have_b <= 1; b <= in2_d; end
81         end
82       if (!have_c) begin
83         `onread(in3_r, in3_a) have_c <= 1; c <= in3_d; end
84         end
85   
86       if (have_a && have_b && have_c) begin
87         out1_d    <= { { ((a & b) | (b & c) | (a & c)) } , 1'b0 };
88         out2_d    <= a ^ b ^ c;
89         have_a    <= 0;
90         have_b    <= 0;
91         have_c    <= 0;
92         have_out1 <= 1;
93         have_out2 <= 1;
94       end
95     end
96   end
97
98
99 == Test ========================================================================
100 #expect 100488372224
101 #expect 8
102
103
104 #ship alu3  : Alu3
105 #ship debug : Debug
106
107 1000000:       sendto alu3.in1;
108 1200000:       sendto alu3.in2;
109 0:             sendto alu3.in3;
110 0:             sendto alu3.in1;
111 0:             sendto alu3.in2;
112 alu3.in1:      [*] take, deliver;
113 alu3.in2:      [*] take, deliver;
114 alu3.in3:      [*] take, deliver;
115 alu3.out1:     [74] take, sendto alu3.in1;
116                [74] take, sendto alu3.in1;
117 alu3.out2:     [74] take, sendto alu3.in2;
118                [74] take, sendto alu3.in2;
119 alu3.out3:     [74] take, sendto alu3.in3;
120                [74] take, sendto alu3.in3;
121 alu3.outBits:  [2] take, sendto debug.in;
122 debug.in:      [*] take, deliver;
123
124
125 == Contributors =========================================================
126 Amir Kamil <kamil@cs.berkeley.edu>
127 Adam Megacz <megacz@cs.berkeley.edu>