get rid of ChainControls
[fleet.git] / ships / Lut3.ship
1 ship: Lut3
2
3 == Ports ===========================================================
4 data  in:   in1
5 data  in:   in2
6 data  in:   in3
7 data  in:   inLut
8
9 data  out:  out
10
11 == Constants ========================================================
12
13 AND
14 OR
15 XOR
16 NAND
17 NOR
18
19 == TeX ==============================================================
20
21 This ship implements a bitwise 3-input {\bf L}ook {\bf U}p {\bf
22 T}able.  The least significant eight bits of the {\tt inLut} value
23 form a truth table with three inputs and one output.
24
25 When values are available at all four inputs they are consumed and a
26 value is produced at {\tt out}.  Each bit of {\tt out} is produced by
27 looking up the corresponding bits of {\tt in1}, {\tt in2}, and {\tt
28 in3} in the {\tt inLut} truth table.
29
30 In particular, the bits {\tt in1}, {\tt in2}, {\tt in3} are
31 concatenated to form a three-bit number, with {\tt in3} as the {\it
32 most significant} bit and {\tt in1} as the {\it least significant
33 bit}.  This three-bit number, ranging from 0 to 7 (decimal), is used
34 as a bit index into {\tt inLut}'s value (whose least significant bit
35 is considered ``bit zero'').
36
37
38 == Fleeterpreter ====================================================
39   public void service() {
40       if (box_in1.dataReadyForShip() &&
41           box_in2.dataReadyForShip() &&
42           box_in3.dataReadyForShip() &&
43           box_inLut.dataReadyForShip() &&
44           box_out.readyForDataFromShip()) {
45           long a      = box_in1.removeDataForShip();
46           long b      = box_in2.removeDataForShip();
47           long c      = box_in3.removeDataForShip();
48           long lut    = box_inLut.removeDataForShip();
49           long ret = 0;
50           ret |= ((lut & (1<<0))==0) ? 0 : (~a) & (~b) & (~c);
51           ret |= ((lut & (1<<1))==0) ? 0 : ( a) & (~b) & (~c);
52           ret |= ((lut & (1<<2))==0) ? 0 : (~a) & ( b) & (~c);
53           ret |= ((lut & (1<<3))==0) ? 0 : ( a) & ( b) & (~c);
54           ret |= ((lut & (1<<4))==0) ? 0 : (~a) & (~b) & ( c);
55           ret |= ((lut & (1<<5))==0) ? 0 : ( a) & (~b) & ( c);
56           ret |= ((lut & (1<<6))==0) ? 0 : (~a) & ( b) & ( c);
57           ret |= ((lut & (1<<7))==0) ? 0 : ( a) & ( b) & ( c);
58           box_out.addDataFromShip(ret);
59       }
60   }
61
62 == FleetSim ==============================================================
63 == FPGA ==============================================================
64
65   reg          out_draining;
66   wire [7:0]              lut;
67
68   genvar i;
69   generate
70     for(i=0; i<`WORDWIDTH; i=i+1) begin : OUT
71       assign out_d_[i] = lut[{in3_d[i], in2_d[i], in1_d[i]}];
72     end
73   endgenerate
74
75   assign lut = inLut_d[7:0];
76
77   always @(posedge clk) begin
78     if (rst) begin
79       `reset
80       out_draining <= 0;
81     end else begin
82       `cleanup
83       if (out_draining && `out_empty) begin
84          `drain_in1
85          `drain_in2
86          `drain_in3
87          `drain_inLut
88          out_draining <= 0;
89       end
90       if (!out_draining && `in1_full && `in2_full && `in3_full && `inLut_full && `out_empty) begin
91          `fill_out
92          out_draining <= 1;
93       end
94     end
95   end
96
97
98 == Test =================================================================
99 #expect  0
100 #expect  -128
101 #expect  64
102 #expect  -64
103 #expect  32
104 #expect  -96
105 #expect  96
106 #expect  -32
107 #expect  16
108 #expect  -112
109 #expect  80
110 #expect  -48
111 #expect  48
112 #expect  -80
113 #expect  112
114 #expect  -16
115 #expect  8
116 #expect  -120
117 #expect  72
118 #expect  -56
119 #expect  40
120 #expect  -88
121 #expect  104
122 #expect  -24
123 #expect  24
124 #expect  -104
125 #expect  88
126 #expect  -40
127 #expect  56
128 #expect  -72
129 #expect  120
130 #expect  -8
131 #expect  4
132 #expect  -124
133 #expect  68
134 #expect  -60
135 #expect  36
136 #expect  -92
137 #expect  100
138 #expect  -28
139 #expect  20
140 #expect  -108
141 #expect  84
142 #expect  -44
143 #expect  52
144 #expect  -76
145 #expect  116
146 #expect  -12
147 #expect  12
148 #expect  -116
149 #expect  76
150 #expect  -52
151 #expect  44
152 #expect  -84
153 #expect  108
154 #expect  -20
155 #expect  28
156 #expect  -100
157 #expect  92
158 #expect  -36
159 #expect  60
160 #expect  -68
161 #expect  124
162 #expect  -4
163 #expect  2
164 #expect  -126
165 #expect  66
166 #expect  -62
167 #expect  34
168 #expect  -94
169 #expect  98
170 #expect  -30
171 #expect  18
172 #expect  -110
173 #expect  82
174 #expect  -46
175 #expect  50
176 #expect  -78
177 #expect  114
178 #expect  -14
179 #expect  10
180 #expect  -118
181 #expect  74
182 #expect  -54
183 #expect  42
184 #expect  -86
185 #expect  106
186 #expect  -22
187 #expect  26
188 #expect  -102
189 #expect  90
190 #expect  -38
191 #expect  58
192 #expect  -70
193 #expect  122
194 #expect  -6
195 #expect  6
196 #expect  -122
197 #expect  70
198 #expect  -58
199 #expect  38
200 #expect  -90
201 #expect  102
202 #expect  -26
203 #expect  22
204 #expect  -106
205 #expect  86
206 #expect  -42
207 #expect  54
208 #expect  -74
209 #expect  118
210 #expect  -10
211 #expect  14
212 #expect  -114
213 #expect  78
214 #expect  -50
215 #expect  46
216 #expect  -82
217 #expect  110
218 #expect  -18
219 #expect  30
220 #expect  -98
221 #expect  94
222 #expect  -34
223 #expect  62
224 #expect  -66
225 #expect  126
226 #expect  -2
227 #expect  1
228 #expect  -127
229 #expect  65
230 #expect  -63
231 #expect  33
232 #expect  -95
233 #expect  97
234 #expect  -31
235 #expect  17
236 #expect  -111
237 #expect  81
238 #expect  -47
239 #expect  49
240 #expect  -79
241 #expect  113
242 #expect  -15
243 #expect  9
244 #expect  -119
245 #expect  73
246 #expect  -55
247 #expect  41
248 #expect  -87
249 #expect  105
250 #expect  -23
251 #expect  25
252 #expect  -103
253 #expect  89
254 #expect  -39
255 #expect  57
256 #expect  -71
257 #expect  121
258 #expect  -7
259 #expect  5
260 #expect  -123
261 #expect  69
262 #expect  -59
263 #expect  37
264 #expect  -91
265 #expect  101
266 #expect  -27
267 #expect  21
268 #expect  -107
269 #expect  85
270 #expect  -43
271 #expect  53
272 #expect  -75
273 #expect  117
274 #expect  -11
275 #expect  13
276 #expect  -115
277 #expect  77
278 #expect  -51
279 #expect  45
280 #expect  -83
281 #expect  109
282 #expect  -19
283 #expect  29
284 #expect  -99
285 #expect  93
286 #expect  -35
287 #expect  61
288 #expect  -67
289 #expect  125
290 #expect  -3
291 #expect  3
292 #expect  -125
293 #expect  67
294 #expect  -61
295 #expect  35
296 #expect  -93
297 #expect  99
298 #expect  -29
299 #expect  19
300 #expect  -109
301 #expect  83
302 #expect  -45
303 #expect  51
304 #expect  -77
305 #expect  115
306 #expect  -13
307 #expect  11
308 #expect  -117
309 #expect  75
310 #expect  -53
311 #expect  43
312 #expect  -85
313 #expect  107
314 #expect  -21
315 #expect  27
316 #expect  -101
317 #expect  91
318 #expect  -37
319 #expect  59
320 #expect  -69
321 #expect  123
322 #expect  -5
323 #expect  7
324 #expect  -121
325 #expect  71
326 #expect  -57
327 #expect  39
328 #expect  -89
329 #expect  103
330 #expect  -25
331 #expect  23
332 #expect  -105
333 #expect  87
334 #expect  -41
335 #expect  55
336 #expect  -73
337 #expect  119
338 #expect  -9
339 #expect  15
340 #expect  -113
341 #expect  79
342 #expect  -49
343 #expect  47
344 #expect  -81
345 #expect  111
346 #expect  -17
347 #expect  31
348 #expect  -97
349 #expect  95
350 #expect  -33
351 #expect  63
352 #expect  -65
353 #expect  127
354 #expect  -1
355
356 #ship debug        : Debug
357 #ship lut          : Lut3
358 #ship alu          : Alu
359
360 lut.in1:   set word= 85; set ilc=*;  deliver;
361 lut.in2:   set word= 51; set ilc=*;  deliver;
362 lut.in3:   set word= 15; set ilc=*;  deliver;
363 lut.out:   set ilc=*;  collect, send to debug.in;
364
365 // cycle through truth tables using alu as INC
366 alu.in2:
367    set word= 1;
368    set ilc=*;  deliver;
369 alu.inOp:
370    set word= Alu.inOp[ADD];
371    set ilc=*;  deliver;
372 alu.in1:
373    set word= 0;
374    deliver;
375    set ilc=*;  recv, deliver;
376 alu.out:
377   set olc=2;
378   head;
379   recv token, collect, send to lut.inLut;
380   send to alu.in1;
381   tail;
382
383 lut.inLut:
384   set word= 0;
385   deliver;
386   set ilc=*;  recv, deliver;
387
388 // acks from debug ship trigger new truth tables
389 debug.in:
390   set ilc=63;
391   recv, deliver, send token to alu.out;
392   set ilc=63;
393   recv, deliver, send token to alu.out;
394   set ilc=63;
395   recv, deliver, send token to alu.out;
396   set ilc=63;
397   recv, deliver, send token to alu.out;
398   set ilc=4;
399   recv, deliver, send token to alu.out;
400
401
402
403 == Contributors =========================================================
404 Adam Megacz <megacz@cs.berkeley.edu>