2019-02-10 18:46:26 +01:00
|
|
|
/*
|
|
|
|
* Alu module
|
|
|
|
* calculations are in here
|
|
|
|
*/
|
|
|
|
|
|
|
|
`include "fields.v"
|
|
|
|
|
|
|
|
`DEC_ALU_INIT, `DEC_ALU_CONT: begin
|
|
|
|
`ifdef SIM
|
|
|
|
if (alu_debug) begin
|
|
|
|
$display("------------------------------- z_alu_phase_3 ---------------------------------");
|
|
|
|
$display("alu_src1 %h | alu_src2 %h | alu_tmp %h | alu_carry %b",
|
|
|
|
alu_src1, alu_src2, alu_tmp, alu_carry);
|
|
|
|
end
|
|
|
|
`endif
|
|
|
|
|
|
|
|
case (alu_op)
|
|
|
|
`ALU_OP_ZERO: begin
|
|
|
|
$display("ALU_OP_ZERO");
|
|
|
|
case (alu_reg_dest)
|
|
|
|
`ALU_REG_A: A[alu_first*4+:4] <= 0;
|
|
|
|
`ALU_REG_B: B[alu_first*4+:4] <= 0;
|
|
|
|
`ALU_REG_C: C[alu_first*4+:4] <= 0;
|
|
|
|
`ALU_REG_D: D[alu_first*4+:4] <= 0;
|
2019-02-10 23:00:06 +01:00
|
|
|
default: begin
|
|
|
|
$display("ALU_OP_ZERO register not handled");
|
|
|
|
alu_requested_halt <= 1;
|
|
|
|
end
|
2019-02-10 18:46:26 +01:00
|
|
|
endcase
|
|
|
|
alu_first <= (alu_first + 1) & 4'hF;
|
|
|
|
end
|
2019-02-10 22:02:39 +01:00
|
|
|
`ALU_OP_2CMPL: begin
|
|
|
|
case (alu_reg_dest)
|
|
|
|
`ALU_REG_A: {Carry, A[alu_first*4+:4]} <= !alu_src1 + alu_carry;
|
2019-02-10 23:00:06 +01:00
|
|
|
default: begin
|
|
|
|
$display("ALU_OP_2CMPL register not handled");
|
|
|
|
alu_requested_halt <= 1;
|
|
|
|
end
|
2019-02-10 22:02:39 +01:00
|
|
|
endcase
|
|
|
|
alu_first <= (alu_first + 1) & 4'hF;
|
|
|
|
end
|
|
|
|
`ALU_OP_1CMPL: begin
|
|
|
|
case (alu_reg_dest)
|
|
|
|
`ALU_REG_A: A[alu_first*4+:4] <= ~alu_src1;
|
2019-02-10 23:00:06 +01:00
|
|
|
`ALU_REG_C: C[alu_first*4+:4] <= ~alu_src1;
|
|
|
|
default: begin
|
|
|
|
$display("ALU_OP_1CMPL register not handled");
|
|
|
|
alu_requested_halt <= 1;
|
|
|
|
end
|
2019-02-10 22:02:39 +01:00
|
|
|
endcase
|
|
|
|
alu_first <= (alu_first + 1) & 4'hF;
|
2019-02-10 18:46:26 +01:00
|
|
|
end
|
|
|
|
`ALU_OP_INC: begin
|
|
|
|
case (alu_reg_dest)
|
|
|
|
`ALU_REG_D: {Carry, D[alu_first*4+:4]} <= alu_src1 + alu_carry;
|
2019-02-10 23:00:06 +01:00
|
|
|
default: begin
|
|
|
|
$display("ALU_OP_INC register not handled");
|
|
|
|
alu_requested_halt <= 1;
|
|
|
|
end
|
2019-02-10 18:46:26 +01:00
|
|
|
endcase
|
|
|
|
alu_first <= (alu_first + 1) & 4'hF;
|
|
|
|
end
|
2019-02-10 22:02:39 +01:00
|
|
|
`ALU_OP_TEST_EQ: begin
|
|
|
|
Carry <= (alu_src1 == alu_src2) & alu_carry;
|
|
|
|
alu_first <= (alu_first + 1) & 4'hF;
|
|
|
|
end
|
|
|
|
`ALU_OP_TEST_NEQ: begin
|
|
|
|
Carry <= (alu_src1 != alu_src2) & alu_carry;
|
|
|
|
alu_first <= (alu_first + 1) & 4'hF;
|
|
|
|
end
|
2019-02-10 18:46:26 +01:00
|
|
|
default: begin
|
|
|
|
`ifdef SIM
|
2019-02-10 22:02:39 +01:00
|
|
|
$display("ALU: operation not implemented");
|
|
|
|
decode_error <= 1;
|
2019-02-10 18:46:26 +01:00
|
|
|
`endif
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
|
|
|
|
|
|
|
|
if (alu_last == alu_first) begin
|
|
|
|
// the alu is done
|
2019-02-10 22:02:39 +01:00
|
|
|
next_cycle <= alu_next_cycle;
|
|
|
|
decstate <= alu_return;
|
2019-02-10 18:46:26 +01:00
|
|
|
alu_requested_halt <= alu_halt;
|
|
|
|
end else decstate <= `DEC_ALU_CONT;
|
|
|
|
|
|
|
|
end
|