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