added comments to ship files
[fleet.git] / ships / Lut.ship
1 ship: Lut
2
3 == Ports ===========================================================
4 data  in:   in1
5 data  in:   in2
6 data  in:   inLut
7
8 data  out:  out
9
10 == Constants ========================================================
11
12 == TeX ==============================================================
13
14 This ship implements a {\bf L}ook {\bf U}p {\bf T}able.  The least
15 significant eight bits of the {\tt inLut} value form a truth table
16 with two inputs and one output (FIXME: specify the layout).
17
18 When values are available at all three inputs they are consumed and a
19 value is produced at {\tt out}.  Each bit of {\tt out} is produced by
20 looking up the corresponding bits of {\tt in1} and {\tt in2} in the
21 {\tt inLut} truth table.
22
23 == Fleeterpreter ====================================================
24     public void service() {
25         if (box_in1.dataReadyForShip() &&
26             box_in2.dataReadyForShip() &&
27             box_inLut.dataReadyForShip()) {
28             int a      = box_in1.removeDataForShip();
29             int b      = box_in2.removeDataForShip();
30             int lut    = box_inLut.removeDataForShip();
31             int ret = 0;
32             if ((lut & 1) != 0) ret |= (~a) & (~b);
33             if ((lut & 2) != 0) ret |= (a)  & (~b);
34             if ((lut & 4) != 0) ret |= (~a) &  (b);
35             if ((lut & 8) != 0) ret |=   a  &    b;
36             box_out.addDataFromShip(ret);
37         }
38     }
39
40 == FleetSim ==============================================================
41 == FPGA ==============================================================
42 // not implemented FIXME
43
44 == Contributors =========================================================
45 Adam Megacz <megacz@cs.berkeley.edu>