move fifo and lut3 tests into ship files
[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 3-input {\bf L}ook {\bf U}p {\bf T}able.  The
22 least significant eight bits of the {\tt inLut} value form a truth
23 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 The ship-specific constants refer to commonly-used truth tables for
38 {\it two-input} functions; these constant truth tables are invariant
39 under input {\tt in3}.
40
41 == Fleeterpreter ====================================================
42   public void service() {
43       if (box_in1.dataReadyForShip() &&
44           box_in2.dataReadyForShip() &&
45           box_in3.dataReadyForShip() &&
46           box_inLut.dataReadyForShip()) {
47           long a      = box_in1.removeDataForShip();
48           long b      = box_in2.removeDataForShip();
49           long c      = box_in3.removeDataForShip();
50           long lut    = box_inLut.removeDataForShip();
51           long ret = 0;
52           ret |= ((lut & (1<<0))==0) ? 0 : (~a) & (~b) & (~c);
53           ret |= ((lut & (1<<1))==0) ? 0 : ( a) & (~b) & (~c);
54           ret |= ((lut & (1<<2))==0) ? 0 : (~a) & ( b) & (~c);
55           ret |= ((lut & (1<<3))==0) ? 0 : ( a) & ( b) & (~c);
56           ret |= ((lut & (1<<4))==0) ? 0 : (~a) & (~b) & ( c);
57           ret |= ((lut & (1<<5))==0) ? 0 : ( a) & (~b) & ( c);
58           ret |= ((lut & (1<<6))==0) ? 0 : (~a) & ( b) & ( c);
59           ret |= ((lut & (1<<7))==0) ? 0 : ( a) & ( b) & ( c);
60           box_out.addDataFromShip(ret);
61       }
62   }
63
64 == FleetSim ==============================================================
65 == FPGA ==============================================================
66
67   reg                    have_in1;
68   reg [(`DATAWIDTH-1):0] reg_in1;
69   reg                    have_in2;
70   reg [(`DATAWIDTH-1):0] reg_in2;
71   reg                    have_in3;
72   reg [(`DATAWIDTH-1):0] reg_in3;
73   reg                    have_inLut;
74   reg [(`DATAWIDTH-1):0] reg_inLut;
75
76   wire [(`DATAWIDTH-1):0] out;
77   genvar i;
78   generate
79     for(i=0; i<`DATAWIDTH; i=i+1) begin : OUT
80       assign out[i] = inLut_d[{in3_d[i], in2_d[i], in1_d[i]}];
81     end
82   endgenerate
83
84   always @(posedge clk) begin
85     if (!have_in1) begin
86       `onread(in1_r, in1_a) have_in1 = 1; reg_in1 = in1_d; end
87       end
88     if (!have_in2) begin
89       `onread(in2_r, in2_a) have_in2 = 1; reg_in2 = in2_d; end
90       end
91     if (!have_in3) begin
92       `onread(in3_r, in3_a) have_in3 = 1; reg_in3 = in3_d; end
93       end
94     if (!have_inLut) begin
95       `onread(inLut_r, inLut_a) have_inLut = 1; reg_inLut = inLut_d; end
96       end
97   
98     if (have_in1 && have_in2 && have_in3 && have_inLut) begin
99       out_d = out;
100       `onwrite(out_r, out_a)
101         have_in1  = 0;
102         have_in2  = 0;
103         have_in3  = 0;
104         have_inLut = 0;
105       end
106     end
107   end
108
109
110 == Test =================================================================
111 #expect  0
112 #expect  -128
113 #expect  64
114 #expect  -64
115 #expect  32
116 #expect  -96
117 #expect  96
118 #expect  -32
119 #expect  16
120 #expect  -112
121 #expect  80
122 #expect  -48
123 #expect  48
124 #expect  -80
125 #expect  112
126 #expect  -16
127 #expect  8
128 #expect  -120
129 #expect  72
130 #expect  -56
131 #expect  40
132 #expect  -88
133 #expect  104
134 #expect  -24
135 #expect  24
136 #expect  -104
137 #expect  88
138 #expect  -40
139 #expect  56
140 #expect  -72
141 #expect  120
142 #expect  -8
143 #expect  4
144 #expect  -124
145 #expect  68
146 #expect  -60
147 #expect  36
148 #expect  -92
149 #expect  100
150 #expect  -28
151 #expect  20
152 #expect  -108
153 #expect  84
154 #expect  -44
155 #expect  52
156 #expect  -76
157 #expect  116
158 #expect  -12
159 #expect  12
160 #expect  -116
161 #expect  76
162 #expect  -52
163 #expect  44
164 #expect  -84
165 #expect  108
166 #expect  -20
167 #expect  28
168 #expect  -100
169 #expect  92
170 #expect  -36
171 #expect  60
172 #expect  -68
173 #expect  124
174 #expect  -4
175 #expect  2
176 #expect  -126
177 #expect  66
178 #expect  -62
179 #expect  34
180 #expect  -94
181 #expect  98
182 #expect  -30
183 #expect  18
184 #expect  -110
185 #expect  82
186 #expect  -46
187 #expect  50
188 #expect  -78
189 #expect  114
190 #expect  -14
191 #expect  10
192 #expect  -118
193 #expect  74
194 #expect  -54
195 #expect  42
196 #expect  -86
197 #expect  106
198 #expect  -22
199 #expect  26
200 #expect  -102
201 #expect  90
202 #expect  -38
203 #expect  58
204 #expect  -70
205 #expect  122
206 #expect  -6
207 #expect  6
208 #expect  -122
209 #expect  70
210 #expect  -58
211 #expect  38
212 #expect  -90
213 #expect  102
214 #expect  -26
215 #expect  22
216 #expect  -106
217 #expect  86
218 #expect  -42
219 #expect  54
220 #expect  -74
221 #expect  118
222 #expect  -10
223 #expect  14
224 #expect  -114
225 #expect  78
226 #expect  -50
227 #expect  46
228 #expect  -82
229 #expect  110
230 #expect  -18
231 #expect  30
232 #expect  -98
233 #expect  94
234 #expect  -34
235 #expect  62
236 #expect  -66
237 #expect  126
238 #expect  -2
239 #expect  1
240 #expect  -127
241 #expect  65
242 #expect  -63
243 #expect  33
244 #expect  -95
245 #expect  97
246 #expect  -31
247 #expect  17
248 #expect  -111
249 #expect  81
250 #expect  -47
251 #expect  49
252 #expect  -79
253 #expect  113
254 #expect  -15
255 #expect  9
256 #expect  -119
257 #expect  73
258 #expect  -55
259 #expect  41
260 #expect  -87
261 #expect  105
262 #expect  -23
263 #expect  25
264 #expect  -103
265 #expect  89
266 #expect  -39
267 #expect  57
268 #expect  -71
269 #expect  121
270 #expect  -7
271 #expect  5
272 #expect  -123
273 #expect  69
274 #expect  -59
275 #expect  37
276 #expect  -91
277 #expect  101
278 #expect  -27
279 #expect  21
280 #expect  -107
281 #expect  85
282 #expect  -43
283 #expect  53
284 #expect  -75
285 #expect  117
286 #expect  -11
287 #expect  13
288 #expect  -115
289 #expect  77
290 #expect  -51
291 #expect  45
292 #expect  -83
293 #expect  109
294 #expect  -19
295 #expect  29
296 #expect  -99
297 #expect  93
298 #expect  -35
299 #expect  61
300 #expect  -67
301 #expect  125
302 #expect  -3
303 #expect  3
304 #expect  -125
305 #expect  67
306 #expect  -61
307 #expect  35
308 #expect  -93
309 #expect  99
310 #expect  -29
311 #expect  19
312 #expect  -109
313 #expect  83
314 #expect  -45
315 #expect  51
316 #expect  -77
317 #expect  115
318 #expect  -13
319 #expect  11
320 #expect  -117
321 #expect  75
322 #expect  -53
323 #expect  43
324 #expect  -85
325 #expect  107
326 #expect  -21
327 #expect  27
328 #expect  -101
329 #expect  91
330 #expect  -37
331 #expect  59
332 #expect  -69
333 #expect  123
334 #expect  -5
335 #expect  7
336 #expect  -121
337 #expect  71
338 #expect  -57
339 #expect  39
340 #expect  -89
341 #expect  103
342 #expect  -25
343 #expect  23
344 #expect  -105
345 #expect  87
346 #expect  -41
347 #expect  55
348 #expect  -73
349 #expect  119
350 #expect  -9
351 #expect  15
352 #expect  -113
353 #expect  79
354 #expect  -49
355 #expect  47
356 #expect  -81
357 #expect  111
358 #expect  -17
359 #expect  31
360 #expect  -97
361 #expect  95
362 #expect  -33
363 #expect  63
364 #expect  -65
365 #expect  127
366 #expect  -1
367
368 #ship debug        : Debug
369 #ship lut          : Lut3
370 #ship alu          : Alu1
371
372 // constant inputs
373 85:          sendto lut.in1;
374 51:          sendto lut.in2;
375 15:          sendto lut.in3;
376
377 lut.in1:   take; [*] deliver;
378 lut.in2:   take; [*] deliver;
379 lut.in3:   take; [*] deliver;
380 lut.inLut: [*] take, deliver;
381 lut.out:   [*] take, sendto debug.in;
382
383 // cycle through truth tables using alu as INC
384 1: sendto alu.inOp;
385 alu.inOp:
386    take;
387    [120] deliver;
388    [120] deliver;
389    [15] deliver;
390 alu.in: [*] take, deliver;
391 0: sendto alu.in;
392 alu.out:
393   [*]  nop;
394   (*) wait, take, sendto lut.inLut;
395   (*) sendto alu.in;
396   kill;
397
398 // acks from debug ship trigger new truth tables
399 debug.in:   [*] take, deliver, notify alu.out;
400
401 // kickoff
402 0:           sendto lut.inLut;
403
404
405
406
407 == Contributors =========================================================
408 Adam Megacz <megacz@cs.berkeley.edu>