FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

自作CPUの検証環境改変 (Gshareの検証環境)

自作CPUの分岐予測器(Gshare)をちゃんとデバッグしたいため、モデルとの比較環境を構築している。

まずはGHR(Global History Table)の比較をしたいため、RTLとの比較環境を構築した。

C++側の実装を構成して、RTLとの値を比較するようにしている:

void step_gshare (long long rtl_time,
                  long long rtl_gshare_bhr)
{
  processor_t *p = spike_core->get_core(0);
  auto iss_next_pc = p->get_state()->pc;
  auto iss_pc      = p->get_state()->prev_pc;
  auto iss_insn    = p->get_state()->insn;

  if (is_cond_branch_inst(iss_insn.bits())) {
    bool is_branch_taken = iss_next_pc != iss_pc + 4;
    iss_bhr = iss_bhr << 1 | is_branch_taken;

    if ((iss_bhr & (1 << iss_bhr) - 1) != rtl_gshare_bhr) {
      fprintf(compare_log_fp, "Warning : BHR different: RTL = %s, ISS = %s\n",
                              to_binString(iss_bhr & ((1 << iss_bhr_length)-1)).c_str(), 
                              to_binString(rtl_gshare_bhr).c_str());
    } else {
      fprintf(compare_log_fp, "BHR RTL = %s\n",
                              to_binString(iss_bhr & ((1 << iss_bhr_length)-1)).c_str());
    }
  }
}

RTLとの比較結果、かなり合っていない。これは地味にデバッグだな...

Warning : BHR different: RTL = 10, ISS = 11
Warning : BHR different: RTL = 101, ISS = 10
Warning : BHR different: RTL = 1010, ISS = 1011111111
Warning : BHR different: RTL = 10100, ISS = 1011111111
Warning : BHR different: RTL = 101000, ISS = 1011111111
Warning : BHR different: RTL = 1010000, ISS = 1011111111
Warning : BHR different: RTL = 10100001, ISS = 1011111111
Warning : BHR different: RTL = 101000011, ISS = 1111111111
Warning : BHR different: RTL = 1010000111, ISS = 1111111111
Warning : BHR different: RTL = 100001111, ISS = 1111111111
Warning : BHR different: RTL = 1000011111, ISS = 1111111111
Warning : BHR different: RTL = 111111, ISS = 1111111111
Warning : BHR different: RTL = 1111111, ISS = 1111111111
Warning : BHR different: RTL = 11111111, ISS = 1111111111
Warning : BHR different: RTL = 111111111, ISS = 1111111111
Warning : BHR different: RTL = 1111111111, ISS = 1111111111
Warning : BHR different: RTL = 1111111111, ISS = 1111111111
Warning : BHR different: RTL = 1111111111, ISS = 1111111111
Warning : BHR different: RTL = 1111111110, ISS = 1111111111
Warning : BHR different: RTL = 1111111100, ISS = 1111100111
Warning : BHR different: RTL = 1111111000, ISS = 1111100111
Warning : BHR different: RTL = 1111110000, ISS = 1111111111
Warning : BHR different: RTL = 1111100001, ISS = 1111111111
Warning : BHR different: RTL = 1111000010, ISS = 1111111111
Warning : BHR different: RTL = 1110000100, ISS = 1111111111