anchor.diff:        rg_index     <= 0;
         rg_resetting <= True;
      endmethod
  +
  +   // ----------------
  +   // Request prediction for given pc; available on 'predict_rsp' on next cycle
   
      method Action  predict_req (WordXL pc) if (! rg_resetting);
         if (verbosity > 1)
  
positive.code: // ================================================================
  // Branch Predictor for RISC-V CPU
  //
  // This is implemented as a simple direct-mapped cache.
  
  // The 'insert' method overwrites the previous entry in the cache
  //     (there is no 'writeback' of the victim)
  
  // The 'predict' method requests a prediction.
  // The 'prediction' method returns (and consumes) the response
  // and is available from the next cycle onwards.
  //    On a 'hit', returns 'predicted_pc'
  //    On a 'miss', returns 'pc+4' (there is no 'cache refill')
  
  // If there was no previous 'predict' request, then 'prediction'
  // returns an invalid PC ('1') (no prediction).
  
  // ================================================================
  // Exports
  
negative.code:       // BTB training using cf_info which is feedback from downpipe
        // exec stage (several instructions earlier)
  
        WordXL    pred_PC = bogus_PC;
        BTB_Index index_b = fn_pc_to_index (cf_info.from_PC);
        Bit #(2)  fsm_val = rf_btb_fsms.sub (index_b);
  
        if (cf_info.cf_op == CF_BR) begin
  	 if (cf_info.taken)
  	    case (fsm_val)
  	       2'b00: begin fsm_val = 2'b01; pred_PC  = cf_info.fallthru_PC; end
  	       2'b01: begin fsm_val = 2'b10; pred_PC  = cf_info.taken_PC;    end
  	       2'b10: begin fsm_val = 2'b11; pred_PC  = cf_info.taken_PC;    end
  	       2'b11: begin fsm_val = 2'b11; pred_PC  = cf_info.taken_PC;    end
  	    endcase
  	 else
  	    case (fsm_val)
  	       2'b00: begin fsm_val = 2'b00; pred_PC  = cf_info.fallthru_PC; end
  	       2'b01: begin fsm_val = 2'b00; pred_PC  = cf_info.fallthru_PC; end
  	       2'b10: begin fsm_val = 2'b01; pred_PC  = cf_info.fallthru_PC; end
  	       2'b11: begin fsm_val = 2'b10; pred_PC  = cf_info.taken_PC;    end
  	    endcase
        end
        else if ((cf_info.cf_op == CF_JAL) || (cf_info.cf_op == CF_JALR)) begin
  	 fsm_val = 2'b11;    // strong taken
  	 pred_PC = cf_info.taken_PC;
        end
        if (pred_PC != bogus_PC) begin
  	 rf_btb_fsms.upd (index_b, fsm_val);
  	 let btb_entry = BTB_Entry {valid:        True,
  				    pc_tag:       fn_pc_to_tag (cf_info.from_PC),
  				    predicted_pc: fn_pc_to_word_addr (pred_PC) };
  	 Bool op_write_not_read = True;
  	 btb_bramcore2.b.put (op_write_not_read, index_b, btb_entry);
  	 if (verbosity > 2)
  	    $display ("    insert prediction [0x%0h] <= (%0h -> %0h)",
  		      index_b, cf_info.from_PC, pred_PC);
  