eliminate use of the `XXX_draining macro
[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       `flush
83       `cleanup
84       if (out_draining && `out_empty) begin
85          `drain_in1
86          `drain_in2
87          `drain_in3
88          `drain_inLut
89          out_draining <= 0;
90       end
91       if (!out_draining && `in1_full && `in2_full && `in3_full && `inLut_full && `out_empty) begin
92          `fill_out
93          out_draining <= 1;
94       end
95     end
96   end
97
98
99 == Test =================================================================
100 #expect  0
101 #expect  -128
102 #expect  64
103 #expect  -64
104 #expect  32
105 #expect  -96
106 #expect  96
107 #expect  -32
108 #expect  16
109 #expect  -112
110 #expect  80
111 #expect  -48
112 #expect  48
113 #expect  -80
114 #expect  112
115 #expect  -16
116 #expect  8
117 #expect  -120
118 #expect  72
119 #expect  -56
120 #expect  40
121 #expect  -88
122 #expect  104
123 #expect  -24
124 #expect  24
125 #expect  -104
126 #expect  88
127 #expect  -40
128 #expect  56
129 #expect  -72
130 #expect  120
131 #expect  -8
132 #expect  4
133 #expect  -124
134 #expect  68
135 #expect  -60
136 #expect  36
137 #expect  -92
138 #expect  100
139 #expect  -28
140 #expect  20
141 #expect  -108
142 #expect  84
143 #expect  -44
144 #expect  52
145 #expect  -76
146 #expect  116
147 #expect  -12
148 #expect  12
149 #expect  -116
150 #expect  76
151 #expect  -52
152 #expect  44
153 #expect  -84
154 #expect  108
155 #expect  -20
156 #expect  28
157 #expect  -100
158 #expect  92
159 #expect  -36
160 #expect  60
161 #expect  -68
162 #expect  124
163 #expect  -4
164 #expect  2
165 #expect  -126
166 #expect  66
167 #expect  -62
168 #expect  34
169 #expect  -94
170 #expect  98
171 #expect  -30
172 #expect  18
173 #expect  -110
174 #expect  82
175 #expect  -46
176 #expect  50
177 #expect  -78
178 #expect  114
179 #expect  -14
180 #expect  10
181 #expect  -118
182 #expect  74
183 #expect  -54
184 #expect  42
185 #expect  -86
186 #expect  106
187 #expect  -22
188 #expect  26
189 #expect  -102
190 #expect  90
191 #expect  -38
192 #expect  58
193 #expect  -70
194 #expect  122
195 #expect  -6
196 #expect  6
197 #expect  -122
198 #expect  70
199 #expect  -58
200 #expect  38
201 #expect  -90
202 #expect  102
203 #expect  -26
204 #expect  22
205 #expect  -106
206 #expect  86
207 #expect  -42
208 #expect  54
209 #expect  -74
210 #expect  118
211 #expect  -10
212 #expect  14
213 #expect  -114
214 #expect  78
215 #expect  -50
216 #expect  46
217 #expect  -82
218 #expect  110
219 #expect  -18
220 #expect  30
221 #expect  -98
222 #expect  94
223 #expect  -34
224 #expect  62
225 #expect  -66
226 #expect  126
227 #expect  -2
228 #expect  1
229 #expect  -127
230 #expect  65
231 #expect  -63
232 #expect  33
233 #expect  -95
234 #expect  97
235 #expect  -31
236 #expect  17
237 #expect  -111
238 #expect  81
239 #expect  -47
240 #expect  49
241 #expect  -79
242 #expect  113
243 #expect  -15
244 #expect  9
245 #expect  -119
246 #expect  73
247 #expect  -55
248 #expect  41
249 #expect  -87
250 #expect  105
251 #expect  -23
252 #expect  25
253 #expect  -103
254 #expect  89
255 #expect  -39
256 #expect  57
257 #expect  -71
258 #expect  121
259 #expect  -7
260 #expect  5
261 #expect  -123
262 #expect  69
263 #expect  -59
264 #expect  37
265 #expect  -91
266 #expect  101
267 #expect  -27
268 #expect  21
269 #expect  -107
270 #expect  85
271 #expect  -43
272 #expect  53
273 #expect  -75
274 #expect  117
275 #expect  -11
276 #expect  13
277 #expect  -115
278 #expect  77
279 #expect  -51
280 #expect  45
281 #expect  -83
282 #expect  109
283 #expect  -19
284 #expect  29
285 #expect  -99
286 #expect  93
287 #expect  -35
288 #expect  61
289 #expect  -67
290 #expect  125
291 #expect  -3
292 #expect  3
293 #expect  -125
294 #expect  67
295 #expect  -61
296 #expect  35
297 #expect  -93
298 #expect  99
299 #expect  -29
300 #expect  19
301 #expect  -109
302 #expect  83
303 #expect  -45
304 #expect  51
305 #expect  -77
306 #expect  115
307 #expect  -13
308 #expect  11
309 #expect  -117
310 #expect  75
311 #expect  -53
312 #expect  43
313 #expect  -85
314 #expect  107
315 #expect  -21
316 #expect  27
317 #expect  -101
318 #expect  91
319 #expect  -37
320 #expect  59
321 #expect  -69
322 #expect  123
323 #expect  -5
324 #expect  7
325 #expect  -121
326 #expect  71
327 #expect  -57
328 #expect  39
329 #expect  -89
330 #expect  103
331 #expect  -25
332 #expect  23
333 #expect  -105
334 #expect  87
335 #expect  -41
336 #expect  55
337 #expect  -73
338 #expect  119
339 #expect  -9
340 #expect  15
341 #expect  -113
342 #expect  79
343 #expect  -49
344 #expect  47
345 #expect  -81
346 #expect  111
347 #expect  -17
348 #expect  31
349 #expect  -97
350 #expect  95
351 #expect  -33
352 #expect  63
353 #expect  -65
354 #expect  127
355 #expect  -1
356
357 #ship debug        : Debug
358 #ship lut          : Lut3
359 #ship alu          : Alu
360
361 lut.in1:   set word= 85; set ilc=*;  deliver;
362 lut.in2:   set word= 51; set ilc=*;  deliver;
363 lut.in3:   set word= 15; set ilc=*;  deliver;
364 lut.out:   set ilc=*;  collect, send to debug.in;
365
366 // cycle through truth tables using alu as INC
367 alu.in2:
368    set word= 1;
369    set ilc=*;  deliver;
370 alu.inOp:
371    set word= Alu.inOp[ADD];
372    set ilc=*;  deliver;
373 alu.in1:
374    set word= 0;
375    deliver;
376    set ilc=*;  recv, deliver;
377 alu.out:
378   set olc=2;
379   [Rq] recv token, collect, send to lut.inLut;
380   [Rq] 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>