== Fleeterpreter ====================================================
+int state = 0;
+long temp;
+long out;
+public void reset() {
+ super.reset();
+ state = 0;
+ temp = 0;
+ out = 0;
+}
+private long maj(long a, long b, long c) {
+ long ret = 0;
+ for(int i=0; i<64; i++) {
+ boolean a_ = (a&(1L<<i))!=0L;
+ boolean b_ = (b&(1L<<i))!=0L;
+ boolean c_ = (c&(1L<<i))!=0L;
+ if ( (a_ && b_) || (b_ && c_) || (a_ && c_) )
+ ret |= (1L << i);
+ }
+ return ret;
+}
public void service() {
- if (box_in.dataReadyForShip() && box_out.readyForDataFromShip()) {
+ if (!box_out.readyForDataFromShip()) return;
+ if (state!=3 && !box_in.dataReadyForShip()) return;
+ switch(state) {
+ case 0: out = box_in.removeDataForShip(); break;
+ case 1: temp = box_in.removeDataForShip(); break;
+ case 2:
+ long in = box_in.removeDataForShip();
+ long mm = maj(temp, out, in);
+ box_out.addDataFromShip(mm << 1, ((mm >> (getFleet().getWordWidth()-1)) & 1L)!=0);
+ temp = (temp ^ out) ^ in;
+ break;
+ case 3: box_out.addDataFromShip(temp, false); break;
}
+ state = (state+1) % 4;
}
endgenerate
always @(posedge clk) begin
- if (!rst) begin
+ if (rst) begin
`reset
state <= 0;
end else begin
- `flush
`cleanup
if (`out_empty && state==3) begin
out_d <= { 1'b0, temp };