+ wire waiting_cpsr_1a = use_cpsr & (cpsr_inflight_2a | cpsr_inflight_3a);
+ wire waiting_regs_1a = |(use_regs & (regs_inflight_2a | regs_inflight_3a));
+ wire waiting_1a = waiting_cpsr_1a | waiting_regs_1a;
+ assign stall_0a = (waiting_1a && !bubble_1a && !flush_1a) || stall_1a;
+
+ reg delayedflush_1a = 0;
+ always @(posedge clk/* or negedge Nrst*/)
+ if (!Nrst)
+ delayedflush_1a <= 0;
+ else if (flush_1a && stall_0a /* halp! I can't do it now, maybe later? */)
+ delayedflush_1a <= 1;
+ else if (!stall_0a /* anything has been handled this time around */)
+ delayedflush_1a <= 0;
+
+ /* Actually do the issue. */
+ always @(posedge clk or negedge Nrst)
+ begin
+ if (waiting_1a)
+ $display("ISSUE: Stalling instruction %08x because %d/%d", insn_1a, waiting_cpsr_1a, waiting_regs_1a);
+
+ if (!Nrst) begin
+ bubble_2a <= 1;
+ /*AUTORESET*/
+ // Beginning of autoreset for uninitialized flops
+ cpsr_inflight_2a <= 1'h0;
+ cpsr_inflight_3a <= 1'h0;
+ insn_2a <= 32'h0;
+ pc_2a <= 32'h0;
+ regs_inflight_2a <= 16'h0;
+ regs_inflight_3a <= 16'h0;
+ // End of automatics
+ end else if (!stall_1a)
+ begin
+ cpsr_inflight_3a <= cpsr_inflight_2a; /* I'm not sure how well selects work with arrays, and that seems like a dumb thing to get anusulated by. */
+ cpsr_inflight_2a <= (waiting_1a || bubble_1a || !condition_met_1a) ? 0 : def_cpsr;
+ regs_inflight_3a <= regs_inflight_2a;
+ regs_inflight_2a <= (waiting_1a || bubble_1a || !condition_met_1a) ? 0 : def_regs;
+
+ bubble_2a <= bubble_1a | waiting_1a | !condition_met_1a | flush_1a | delayedflush_1a;
+ pc_2a <= pc_1a;
+ insn_2a <= insn_1a;
+ end
+ end