3 == Ports ===========================================================
15 == TeX ==============================================================
16 This ship is a two-input arithmetic unit. It features several
17 opcodes, such as {\tt ADD} and {\tt SUB}. In my opinion, it is
20 FIXME: implement all the link bit stuff
22 Use carry-in bit to create a selector? Perhaps a waste of an ALU.
24 Flags: zero, negative, overflow, ?
33 == Fleeterpreter ====================================================
34 public long resolveLiteral(String literal) {
35 if (literal.equals("ADD")) return 0;
36 if (literal.equals("SUB")) return 1;
37 if (literal.equals("MAX")) return 2;
38 if (literal.equals("MIN")) return 3;
39 return super.resolveLiteral(literal);
41 public void service() {
42 if (box_in1.dataReadyForShip() &&
43 box_in2.dataReadyForShip() &&
44 box_inOp.dataReadyForShip() &&
45 box_out.readyForDataFromShip()) {
46 long a = box_in1.removeDataForShip();
47 long b = box_in2.removeDataForShip();
48 long op = box_inOp.removeDataForShip();
50 case 0: box_out.addDataFromShip(a+b); // ADD
52 case 1: box_out.addDataFromShip(a-b); // SUB
54 case 2: box_out.addDataFromShip(Math.max(a,b)); // MAX
56 case 3: box_out.addDataFromShip(Math.min(a,b)); // MIN
58 default: box_out.addDataFromShip(0);
64 == FleetSim ==============================================================
66 == FPGA ==============================================================
69 reg [(`DATAWIDTH-1):0] reg_a;
71 reg [(`DATAWIDTH-1):0] reg_b;
73 reg [(`DATAWIDTH-1):0] reg_op;
75 always @(posedge clk) begin
77 `onread(in1_r, in1_a) have_a = 1; reg_a = in1_d; end
80 `onread(in2_r, in2_a) have_b = 1; reg_b = in2_d; end
83 `onread(inOp_r, inOp_a) have_op = 1; reg_op = inOp_d; end
86 if (have_a && have_b && have_op) begin
88 0: out_d = reg_a + reg_b;
89 1: out_d = reg_a - reg_b;
90 2: out_d = reg_a > reg_b ? reg_a : reg_b;
91 3: out_d = reg_a > reg_b ? reg_b : reg_a;
94 `onwrite(out_r, out_a)
102 == Test ==============================================================================
112 debug.in: [*] take, deliver;
114 literal 9; [4] deliver;
117 literal 8; [4] deliver;
119 alu.in1: [*] take, deliver;
120 alu.in2: [*] take, deliver;
121 alu.out: [*] take, sendto debug.in;
124 literal Alu2.inOp[ADD]; deliver;
125 literal Alu2.inOp[SUB]; deliver;
126 literal Alu2.inOp[MIN]; deliver;
127 literal Alu2.inOp[MAX]; deliver;
131 == Contributors =========================================================
132 Adam Megacz <megacz@cs.berkeley.edu>