Summarizing the Current Front-End Configuration of My Own CPU

When I tried to implement GShare for the first time in a while, I found I had forgotten a lot of things, so this is a memo to help me remember.

By the way, I think the current front-end configuration summarized below is not good at all. I think it is an old-fashioned configuration that you should not use in a real design, so please do not copy it. If possible, I would be glad if someone who knows better could tell me a proper configuration.

Basically, the front end finishes fetch and branch prediction in three stages, s0 to s2. For instruction fetch:

  • s0 stage: Issue the instruction fetch request. Access the TLB. Access the instruction cache
  • s1 stage: Instruction fetch in progress
  • s2 stage: The instructions are returned. They are stored in the instruction buffer at the same time

The problem is on the branch prediction side, which has the following stage configuration:

  • s0 stage: Access the BTB and BIM
  • s1 stage: Return the BTB result. Determine hit or miss
  • s2 stage: Store the result in the instruction buffer

The RAS has to determine CALL/RET, so currently it looks at all the instructions available from the instruction cache in the s2 stage and operates the RAS from there. However, as you can see from the figure, the s2 stage has too much work to do, and I think it will be hard to meet timing. So this approach is probably wrong.

One option is to obtain the CALL/RET information from the BTB in the s0 stage and use it, but that means predicting the actual instruction fetch information of the s2 stage, doesn't it? Having written this far, I realized that as long as the instructions themselves are not rewritten (in which case the whole instruction cache has to be flushed anyway), it should be fine in the normal case to store the CALL/RET information in the BTB and use it.

In that case, the question is whether to also detect CALL/RET in the s2 stage using the instruction cache data:

  • If we do: The stage is still overloaded. Should we add one more stage?
  • If we don't: The RAS cannot be updated for CALL/RET instructions that cannot be detected in s0. The strategy needs to be reconsidered.

Currently I am going with "if we do", so I can fully check the RAS state updates with assertions. With "if we don't", the circuit load is reduced, but verifying that the RAS works correctly becomes a hassle.

Having thought this far, let me go back to GShare. GShare first XORs the PC virtual address with the BHR and uses the result as the BIM index to read out the predictor. Then we have to store the conditional branch information in the BTB along with the actual BIM value and check that they really match. The branch prediction is done after that (writing this, I am starting to feel optimistic that it might be doable after all).


This is an English translation of the original Japanese post: 自作CPUの現状のフロントエンド構成をまとめる