run all tests (including ships directory), add #skip tests where missing
[fleet.git] / ships / Alu1.ship
1 ship: Alu1
2
3 == Ports ===========================================================
4 data  in:   in
5 data  in:   inOp
6 data  in:   inOp.x
7 data  in:   inOp.y
8 data  in:   inOp.z
9
10 data  out:  out
11
12 == Constants ========================================================
13 NEG:
14 INC:
15 DEC:
16 ABS:
17
18 == TeX ==============================================================
19 == Fleeterpreter ====================================================
20     public void service() {
21         if (box_in.dataReadyForShip() && box_inOp.dataReadyForShip() && box_out.readyForDataFromShip()) {
22             long data   = box_in.removeDataForShip();
23             long opcode = box_inOp.removeDataForShip();
24             switch((int)opcode) {
25                 case 0: box_out.addDataFromShip(-1 * data);      // NEG
26                     break;
27                 case 1: box_out.addDataFromShip(data+1);         // INC
28                     break;
29                 case 2: box_out.addDataFromShip(data-1);         // DEC
30                     break;
31                 case 3: box_out.addDataFromShip(Math.abs(data)); // ABS
32                     break;
33                 default: box_out.addDataFromShip(0);
34                     break;
35             }
36         }
37     }
38
39 == FleetSim ==============================================================
40 == FPGA ==============================================================
41   reg                       have_a;
42   reg [(`PACKET_WIDTH-1):0] reg_a;
43   reg                       have_op;
44   reg [(`PACKET_WIDTH-1):0] reg_op;
45   reg [(`PACKET_WIDTH-1):0] extrabits;
46
47   always @(posedge clk) begin
48     if (!have_a) begin
49       `onread(in_r, in_a) have_a = 1; reg_a = in_d; end
50       end
51     if (!have_op) begin
52       `onread(inOp_r, inOp_a)
53          have_op   = 1;
54          reg_op    = inOp_d[(`DATAWIDTH-1):0];
55          extrabits = inOp_d[(`PACKET_WIDTH-1):`DATAWIDTH];
56       end
57     end
58   
59     if (have_a && have_op) begin
60       case (reg_op)
61         0: out_d = -reg_a;
62         1: out_d = reg_a+1;
63         2: out_d = reg_a-1;
64         3: out_d = (reg_a<0) ? (-reg_a) : reg_a;
65         4: out_d = 37'b1111111111111111111111111111111111111;
66         5: out_d = extrabits;
67         default: out_d = 0;
68       endcase        
69       `onwrite(out_r, out_a)
70         have_a  = 0;
71         have_op = 0;
72       end
73     end
74   end
75
76 == Test ==============================================================================
77 #skip
78
79
80 == Contributors =========================================================
81 Adam Megacz <megacz@cs.berkeley.edu>