ship: Alu == Ports =========================================================== data in: in1 data in: in2 data in: inOp constant IN1: 0 constant IN2: 1 constant ADD: 2 constant SUB: 3 constant MAX: 4 constant MIN: 5 constant CMP: 6 constant DROP1: 7 constant DROP2: 8 constant MAXMERGE: 9 constant AND: 10 constant OR: 11 constant XOR: 12 data out: out == TeX ============================================================== {\tt Alu} is a ``two-input'' arithmetic logic unit. It includes logic for performing arithmetic operations on a pair of arguments. Currently this includes addition ({\sc add}), subtraction ({\sc sub}), maximum ({\sc max}), and minimum ({\sc min}). \subsection*{Semantics} When a value is present at each of {\tt in1}, {\tt in2} and {\tt inOp}, these three values are consumed. Based on the value consumed at {\tt inOp}, the requested operation is performed on the values consumed from {\tt in1} and {\tt in2}. The result of this operation is then made available at {\tt out}. \subsection*{C-Flag} \begin{verbatim} IN1 - undefined; drain in1 only IN2 - undefined; drain in2 only ADD - carry-out SUB - undefined MAX - if in1>in2 cflag=0 and drain in1, else cflag=1 and drain in2 MIN - if in1>in2 cflag=1 and drain in2, else cflag=0 and drain in1 CMP - if in1==in2 cflag=1, else cflag=0 DROP1 - consume in1, produce no output DROP2 - consume in2, produce no output MAXMERGE - if (in1<0 && in2<0) consume both, emit either, cflag=undef else act as MAX \end{verbatim} \subsection*{To Do} The {\it link bit} and other features of \cite{ies31} are not yet implemented. The carry-in, carry-out, zero-test, negative-test, and overflow-test flags typically present in a conventional processor ALU are also not yet implemented. == Fleeterpreter ==================================================== public void service() { if (box_inOp.dataReadyForShip() && box_in1.dataReadyForShip() && box_in2.dataReadyForShip() && box_out.readyForDataFromShip()) { long a; long b; long op = box_inOp.removeDataForShip(); switch((int)op) { case 0: a = box_in1.removeDataForShip(); box_out.addDataFromShip(a); // IN1 break; case 1: b = box_in2.removeDataForShip(); box_out.addDataFromShip(b); // IN2 break; case 2: a = box_in1.removeDataForShip(); b = box_in2.removeDataForShip(); box_out.addDataFromShip(a+b); // ADD break; case 3: a = box_in1.removeDataForShip(); b = box_in2.removeDataForShip(); box_out.addDataFromShip(a-b); // SUB break; case 9: // MAXMERGE if (box_in1.peekDataForShip()<0 && box_in2.peekDataForShip()<0) { a = box_in1.removeDataForShip(); b = box_in2.removeDataForShip(); box_out.addDataFromShip(a, false); break; } // fall through to MAX case 4: a = box_in1.peekDataForShip(); b = box_in2.peekDataForShip(); box_out.addDataFromShip(Math.max(a,b), !(a>b)); // MAX if (a>b) box_in1.removeDataForShip(); else box_in2.removeDataForShip(); break; case 5: a = box_in1.peekDataForShip(); b = box_in2.peekDataForShip(); box_out.addDataFromShip(Math.min(a,b), a>b); // MIN if (a