- if (!have_a) begin
- `onread(in1_r, in1_a) have_a = 1; reg_a = in1_d; end
- end
- if (!have_b) begin
- `onread(in2_r, in2_a) have_b = 1; reg_b = in2_d; end
- end
- if (!have_op) begin
- `onread(inOp_r, inOp_a) have_op = 1; reg_op = inOp_d; end
- end
-
- if (have_a && have_b && have_op) begin
- case (reg_op)
- 0: out_d = reg_a + reg_b;
- 1: out_d = reg_a - reg_b;
- 2: out_d = reg_a > reg_b ? reg_a : reg_b;
- 3: out_d = reg_a > reg_b ? reg_b : reg_a;
- default: out_d = 0;
- endcase
- `onwrite(out_r, out_a)
- have_a = 0;
- have_b = 0;
- have_op = 0;
+ if (out_r && out_a) out_r <= 0;
+ if (!in1_r && in1_a) in1_a <= 0;
+ if (!in2_r && in2_a) in2_a <= 0;
+ if (!inOp_r && inOp_a) inOp_a <= 0;
+ if (!out_r && !out_a && in1_r && !in1_a && in2_r && !in2_a && inOp_r && !inOp_a) begin
+ out_r <= 1;
+ in1_a <= 1;
+ in2_a <= 1;
+ inOp_a <= 1;
+ case (inOp_d)
+ 0: out_d <= in1_d + in2_d;
+ 1: out_d <= in1_d - in2_d;
+ 2: out_d <= in1_d > in2_d ? in1_d : in2_d;
+ 3: out_d <= in1_d > in2_d ? in2_d : in1_d;
+ default: out_d <= 0;
+ endcase