FPGA開発日記

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

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

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

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

もう少し進めて、モデル側にも同様なgshareの予測器を追加して、予測が一致するかを検証するようにした。

  if (is_cond_branch_inst(iss_insn.bits())) {
    const size_t iss_bhr_mask = (1 << iss_bhr_length) - 1;

    size_t bim_array_index = (iss_pc >> 1) / iss_cache_block_byte_size;
    size_t bim_block_internal_index = (iss_pc & (iss_cache_block_byte_size -1)) >> 1;
    bim_array_index = (bim_array_index ^ iss_bhr) & iss_bhr_mask;

    // fprintf (gshare_log_fp, "bim_array_index = %d, bim_block_internal_index = %d\n",                                                                                                                                                                                                                                                                    //          bim_array_index,                                                                                                                                                                                                                                                                                                                           //          bim_block_internal_index);                                                                                                                                                                                                                                                                                                             

    uint8_t bim_counter = bim_array.at(bim_array_index)->bim[bim_block_internal_index];
    bool iss_predict_taken = (bim_counter >> 1) & 1;

    bool is_branch_taken = iss_next_pc != iss_pc + cond_inst_size(iss_insn.bits());

    fprintf (gshare_log_fp, "GSHARE MODEL : PC = %08lx (%02d,%02d), index = (%4x, %2x), MODEL_BHR = %s, predict = %s, result = %s, %s          ",
             iss_pc,
             rtl_cmt_id, rtl_grp_id,
             static_cast<unsigned int>(bim_array_index), static_cast<unsigned int>(bim_block_internal_index),
             to_binString(iss_bhr & ((1 << iss_bhr_length)-1), iss_bhr_length).c_str(),
             iss_predict_taken ? "    TAKEN" : "NOT TAKEN",
             is_branch_taken   ? "    TAKEN" : "NOT TAKEN",
             iss_predict_taken == is_branch_taken ? "MATCH" : "FAIL ");

いろんな情報を比較できるようにした。これで、デバッグがもうちょっとやりやすくなるかな? モデル側の分岐予測のヒット率を確認すると、マイクロベンチマークであったとしてもかなり高くなっている(90%以上)。 ちゃんとデバッグできるかな?

GSHARE MODEL : PC = 80002578 (48,04), index = ( 3b5, 1c), MODEL_BHR = 1111111111, predict =     TAKEN, result =     TAKEN, MATCH          // BHR RTL = 1111111111
GSHARE MODEL : PC = 80002578 (49,04), index = ( 3b5, 1c), MODEL_BHR = 1111111111, predict =     TAKEN, result =     TAKEN, MATCH          // BHR RTL = 1111111111
GSHARE MODEL : PC = 80002578 (50,04), index = ( 3b5, 1c), MODEL_BHR = 1111111111, predict =     TAKEN, result =     TAKEN, MATCH          // BHR RTL = 1111111111
GSHARE MODEL : PC = 80002578 (51,04), index = ( 3b5, 1c), MODEL_BHR = 1111111111, predict =     TAKEN, result =     TAKEN, MATCH          // BHR RTL = 1111111111
GSHARE MODEL : PC = 80002578 (52,04), index = ( 3b5, 1c), MODEL_BHR = 1111111111, predict =     TAKEN, result = NOT TAKEN, FAIL           // BHR RTL = 1111111110
GSHARE MODEL : PC = 8000241e (58,01), index = ( 3b6,  f), MODEL_BHR = 1111111110, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111111110, ISS = 1111111100
GSHARE MODEL : PC = 80002002 (01,02), index = ( 3bc,  1), MODEL_BHR = 1111111100, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1111111111, ISS = 1111111001
GSHARE MODEL : PC = 8000200c (07,04), index = ( 3b9,  6), MODEL_BHR = 1111111001, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1111111111, ISS = 1111110011
GSHARE MODEL : PC = 80002014 (11,02), index = ( 3b3,  a), MODEL_BHR = 1111110011, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111111111, ISS = 1111100110
GSHARE MODEL : PC = 80002760 (13,02), index = ( 3a8, 10), MODEL_BHR = 1111100110, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111111111, ISS = 1111001100
GSHARE MODEL : PC = 8000276c (14,08), index = ( 382, 16), MODEL_BHR = 1111001100, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1111111111, ISS = 1110011001
GSHARE MODEL : PC = 80002002 (19,02), index = ( 3d9,  1), MODEL_BHR = 1110011001, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1111111111, ISS = 1100110011
GSHARE MODEL : PC = 8000200c (20,04), index = ( 373,  6), MODEL_BHR = 1100110011, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111111110, ISS = 1001100110
GSHARE MODEL : PC = 80002014 (27,01), index = ( 226,  a), MODEL_BHR = 1001100110, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1111101111, ISS = 0011001101
GSHARE MODEL : PC = 80002760 (31,02), index = (  83, 10), MODEL_BHR = 0011001101, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111011110, ISS = 0110011010
GSHARE MODEL : PC = 8000276c (34,08), index = ( 1d4, 16), MODEL_BHR = 0110011010, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1111011111, ISS = 1100110101
GSHARE MODEL : PC = 80002002 (36,02), index = ( 375,  1), MODEL_BHR = 1100110101, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1110111111, ISS = 1001101011
GSHARE MODEL : PC = 8000200c (37,04), index = ( 22b,  6), MODEL_BHR = 1001101011, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 0111101111, ISS = 0011010111
GSHARE MODEL : PC = 80002014 (40,02), index = (  97,  a), MODEL_BHR = 0011010111, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111011110, ISS = 0110101110
GSHARE MODEL : PC = 80002760 (44,02), index = ( 1e0, 10), MODEL_BHR = 0110101110, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1110111100, ISS = 1101011100
GSHARE MODEL : PC = 8000276c (47,08), index = ( 312, 16), MODEL_BHR = 1101011100, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1110011111, ISS = 1010111001
GSHARE MODEL : PC = 80002002 (49,02), index = ( 2f9,  1), MODEL_BHR = 1010111001, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1100111111, ISS = 0101110011
GSHARE MODEL : PC = 8000200c (50,04), index = ( 133,  6), MODEL_BHR = 0101110011, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1111001110, ISS = 1011100110
GSHARE MODEL : PC = 80002014 (54,01), index = ( 2a6,  a), MODEL_BHR = 1011100110, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1100111011, ISS = 0111001101
GSHARE MODEL : PC = 80002760 (58,02), index = ( 183, 10), MODEL_BHR = 0111001101, predict =     TAKEN, result = NOT TAKEN, FAIL           // Warning : BHR different: RTL = 1001110110, ISS = 1110011010
GSHARE MODEL : PC = 8000276c (61,08), index = ( 3d4, 16), MODEL_BHR = 1110011010, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 1011011111, ISS = 1100110101
GSHARE MODEL : PC = 80002002 (63,02), index = ( 375,  1), MODEL_BHR = 1100110101, predict =     TAKEN, result =     TAKEN, MATCH          // Warning : BHR different: RTL = 0110111111, ISS = 1001101011