Multi-cycle instruction fetch branch prediction mechanism and branch aliasing and jitter optimization solutions
Through the multi-cycle branch prediction mechanism and branch aliasing and jitter optimization solutions, multi-level predictors and feature extraction operators are used to solve the branch aliasing and jitter problems of the branch predictor and improve the accuracy of branch prediction and processor performance. Instruction set parallelism.
Patent Information
- Application Number
- CN202111301148.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-04
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-11-04
AI Technical Summary
Existing branch predictors have branch aliasing and branch jitter problems, which limit the improvement of their performance and instruction set parallelism.
Adopts a multi-cycle fetch branch prediction mechanism, including the first-level micro branch target buffer, the second-level large branch target buffer and the third-level TAGE predictor, and uses Sobel feature extraction operator to optimize branch aliases, dynamic monitoring and prediction Direction flip circuitry optimizes branch jitter.
It improves the accuracy of branch prediction, reduces branch aliasing and jitter effects, and improves the instruction set parallelism of the processor.
Smart Images

Figure CN114020334B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer architecture, and in particular to a multi-cycle instruction fetch branch prediction mechanism and a branch alias and jitter optimization solution. Background Art
[0002] The branch predictor is a basic component of the CPU core of a general-purpose processor. It can solve control hazards in the processor pipeline by predicting instruction fetch. By predicting the instruction fetch of the next cycle, the pipeline can work in a speculative manner, thereby improving the efficiency of the pipeline and increasing the parallelism of the instruction set.
[0003] At present, branch predictors are divided into two categories: static prediction and dynamic prediction. Dynamic prediction can be roughly divided into one-level dynamic prediction and two-level dynamic prediction structures. The two-level dynamic prediction structure can achieve a higher prediction accuracy by introducing branch history, so it is widely used. However, for different processor microarchitectures, the specific implementation of the branch predictor needs to be adapted in combination with the characteristics of the processor microarchitecture. Only by adapting the branch predictor that meets the characteristics of the current processor microarchitecture can the instruction set parallelism of the adapted processor be maximized. In addition, the branch predictor itself also has some common defects, such as branch aliasing and branch jitter, which limit the performance of the branch predictor to a certain extent. Summary of the invention
[0004] The purpose of the present invention is to provide a multi-cycle instruction fetch branch prediction mechanism and a branch alias and jitter optimization solution to solve the problems in the background technology.
[0005] To solve the above technical problems, the present invention provides a multi-cycle instruction fetch branch prediction mechanism, including a first-level predictor, a second-level predictor and a third-level predictor;
[0006] The first-level predictor includes a micro-branch target cache, which uses a register array as a storage unit and can predict both the branch direction and the branch target;
[0007] The second-level predictor includes a large branch target cache and a bimodal table, which uses SRAM as a storage unit and supports a wide range of target jumps, and the bimodal table predicts the branch direction;
[0008] The third-level predictor is a TAGE predictor and a loop predictor, which uses SRAM as a storage unit and uses global history for prediction;
[0009] For the third-level predictor, the return address stack RAS and the branch decoding unit are also used for prediction.
[0010] Optionally, the storage table entry of the first-level predictor includes a tag field, a saturation counter, an offset, and a flag indicating whether it is a conditional branch instruction; during prediction, whether it is a conditional branch instruction flag will determine whether the branch direction prediction is provided by the saturation counter or a direct jump.
[0011] Optionally, the storage table entries of the second-level predictor include a tag field, an offset, an extended target address, a flag indicating whether an extension is required, and a flag indicating whether it is a conditional branch instruction; when predicting, whether it is a conditional branch instruction flag will determine whether the branch direction prediction is provided by the saturation counter of the bimodal table or a direct jump; whether an extension flag is required will determine whether the branch target prediction is provided directly by the extended target address cache or obtained by signed operation of the offset.
[0012] Optionally, the TAGE predictor includes a reference predictor and several tag prediction tables, each entry of the tag prediction table consists of a saturation counter, a tag field and a usage counter, and the bit widths of the saturation counter, the tag field and the usage counter are flexibly set.
[0013] Optionally, the third-level predictor uses the bimodal table of the second-level predictor as a reference predictor, and uses the loop predictor to perform auxiliary correction on the loop body predicted by the TAGE predictor.
[0014] Optionally, the final prediction result of the third-level predictor is jointly determined by a branch decoding unit and a return address stack RAS.
[0015] The present invention also provides a branch alias optimization solution, which completes the feature extraction of the virtual PC by using the Sobel feature extraction operator, and indexes the bimodal table and the TAGE predictor with the value after the feature extraction as the index.
[0016] Optionally, the pixel matrix of the virtual PC is constructed with 4 bits of binary as one pixel, and the feature extraction of the virtual PC is completed by using a feature operator in a convolution operation manner.
[0017] The present invention also provides a branch jitter optimization solution, which monitors the branch prediction error peak period through dynamic monitoring and prediction direction flipping circuit. When the prediction error rate exceeds a set threshold, the prediction direction of the predictor is flipped to reduce the number of branch prediction error peak areas, or reduce the height of the branch prediction error peak area.
[0018] Optionally, the dynamic monitoring and prediction direction flipping circuit is implemented in a state machine manner, and the state machine is more sensitive to correct predictions than incorrect predictions; when a correct prediction occurs, the state jump interval is one state to achieve a flexibly configurable flipping threshold of the dynamic monitoring and prediction direction flipping circuit.
[0019] In the multi-cycle instruction fetch branch prediction mechanism and branch alias and jitter optimization scheme provided by the present invention, the first-level predictor includes a micro-branch target cache, which uses a register array as a storage unit and can predict both the branch direction and the branch target; the second-level predictor includes a large branch target cache and a bimodal table, which uses SRAM as a storage unit and supports a wide range of target jumps, and the bimodal table predicts the branch direction; the third-level predictor is a TAGE predictor and a loop predictor, which uses SRAM as a storage unit and uses global history for prediction; for the third-level predictor, it is also assisted by a return address stack RAS and a branch decoding unit for prediction. The multi-cycle instruction fetch branch prediction mechanism is suitable for the instruction fetch unit of a multi-stage pipeline, can provide fast and accurate branch prediction, and is a branch prediction mechanism with practical application value. The present invention also optimizes the common problems of branch alias and branch jitter in branch prediction, and proposes a feature extraction method based on history independence and a dynamic monitoring and flipping circuit based on branch prediction errors, which reduces the branch alias and branch jitter effects to a certain extent and improves the branch prediction accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a schematic diagram of the prediction structure of the first-level predictor;
[0021] Figure 2 is a schematic diagram of the prediction structure of the second-level predictor;
[0022] Figure 3 is a schematic diagram of the TAGE predictor structure;
[0023] Figure 4 This is a schematic diagram of the return address stack RAS structure;
[0024] Figure 5 is a schematic diagram of the global structure of the prediction mechanism of the present invention;
[0025] Figure 6 This is a schematic diagram of the branch alias optimization solution based on history independence;
[0026] Figure 7 This is a schematic diagram of a branch jitter optimization solution based on the local characteristics of branch prediction error time. DETAILED DESCRIPTION
[0027] The following is a further detailed description of a multi-cycle instruction fetch branch prediction mechanism and branch aliasing and jitter optimization scheme proposed by the present invention in combination with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become clearer according to the following description and claims. It should be noted that the drawings are all in a very simplified form and are not in precise proportions, and are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention.
[0028] Embodiment 1
[0029] like Figure 1 The circuit structure of a micro branch target buffer that uses a register array as a storage unit and can predict both the branch direction and the target is shown. First, it should be explained that the implementation scenario of the present invention is an embedded processor, and the processor is a RISC-V instruction set. Figure 1 The virtual address bit width in is 40. When making predictions, the virtual PC matches the Meta register array in a fully associative manner. When multiple matches are hit, they are selected based on the principle of low order priority, and the BTB register array is read with the corresponding hit path as the index. In the signal read out by the low order priority hit path of the Meta register array, if the is_br field is high, it indicates that the branch instruction is a conditional branch instruction. At this time, the branch direction prediction is provided by the highest bit of the read 2-bit saturation counter (1 means jump, 0 means no jump); if the is_br field is low, it indicates that the branch instruction is a direct or indirect jump instruction. At this time, the branch direction prediction is a must jump. The above ideas about branch direction prediction come from the Fliter branch predictor, but the implementation of the present invention is a simple implementation, which can reduce the impact of different branch instructions on the state of the 2-bit saturation counter in the same table entry to a certain extent, thereby improving the accuracy of branch prediction. For branch target prediction, the 13-bit signed offset read out of the BTB register array is signed with the current PC, and the calculated value is the predicted target address. The above prediction is only valid when there is a hit in the tag field, otherwise it is invalid; invalid means that the current prediction is a sequential instruction fetch. For the update of the branch prediction, the hit way is used as the index for update. If it does not hit, the hash value after the folded XOR operation of the current PC and the tag field is used for update without index. In fact, it can be understood as a random update.
[0030] like Figure 2 The following is the prediction structure of the second-level predictor of the present invention. When predicting, the virtual PC indexes and matches the Meta register in a two-way group-associative manner. If there are multiple hits, the low-order priority principle is also adopted. The direction prediction mechanism for branch instructions is consistent with the first-level predictor. For branch target prediction, the main difference of the second-level predictor is reflected in Figure 2 The eBTB branch predictor in the eBTB branch predictor has a table entry of 40 bits wide, which stores the virtual PC address. When the extended field in the entry result read from the BTB register array is high, the branch prediction target address is directly provided by the eBTB branch predictor. In this way, the second-level predictor will be able to support branch instruction target prediction with a larger jump range.
[0031] Figure 3 The figure shows the prediction circuit structure of the TAGE predictor. T0 is the reference predictor. In order to save hardware resources, the bimodal table in the second-level predictor can be directly reused. T1 to T4 are tag prediction tables. Each tag prediction table entry consists of a saturation counter, a tag domain, and a usage counter, and their bit widths can be flexibly set. The global history length used by each tag prediction table is also different, and the relationship between the global history lengths they use satisfies the following relationship:
[0032] L(i)=(int)(α i-1 *L(1)+0.5),(i>1)
[0033] Where α is the history length coefficient, and the value that can be taken is generally between 1.0 and 1.5. (int) means that the subsequent calculation result is rounded to an integer. i is the prediction level, and L(i) is actually the number of bits of the address used when making the i-th level prediction. When i=1, the specific initial value L(1) is not important. The TAGE predictor only cares about the relationship between the global history lengths used in different tag prediction tables. When predicting, the global history is XORed with the low bit of the virtual PC and the remaining high bit after folding XOR. The hash operation obtains the index and tag domain of the tag prediction table respectively. Each tag predictor that hits is a valid predictor. For the tag prediction table that hits, the tag prediction table that uses the longest history length is the provider component, and the one that uses the second longest history is the altpred. In particular, if there is only one tag prediction table hit, the baseline predictor is called altpred. When predicting, the TAGE predictor usually takes the saturated counter value of the tag prediction table with the longest history length as the prediction result of the branch instruction direction. In particular, if the saturation counter of the provider component is "weak", altpred will be selected as the prediction result. This is mainly related to its update mechanism. For the case where the saturation counter value is weak, the branch prediction usually considers that the table entry is newly allocated. In order to make the prediction result stable, the TAGE predictor will select altpred as the prediction result instead of the newly allocated table entry. If the untagged prediction table hits, the TAGE predictor will use the prediction result of the baseline predictor as the basis.
[0034] For the update of the TAGE predictor, whether the prediction is correct or not, the tag prediction table providing the prediction must be updated. The usage counter is incremented by 1 each time it is used until the maximum value. In particular, when the prediction is wrong, the branch prediction will consider that the branch instruction is difficult to predict, so a new table entry will be allocated to the tag prediction table with a longer history length. The specific allocation basis is mainly based on whether the usage counter of the corresponding table entry is 0. For the table entries with a usage of 0, these table entries are all objects to be allocated. When there are multiple allocable table entries, the TAGE predictor can allocate multiple table entries or one table entry according to the amount of hardware resources. The present invention is mainly used in embedded scenarios, so only one table entry is allocated, and which table entry is specifically allocated can be determined by the random number generated by the Fibonacci-style linear feedback shift register. The tag field in the allocated table entry content will be written through a data path similar to that during prediction, and the saturation counter will be allocated to the corresponding "weak state" according to the actual jump situation, and the usage counter will be allocated to 0. The above is the update process of the TAGE predictor. In particular, the update process will cause the usage counter to be filled as the application is continuously executed, which may result in no idle tag predictor table entries being available for allocation, thereby affecting the prediction accuracy. Therefore, the present invention implements a periodic reset mechanism for the usage counter, that is, the usage counter in each tag predictor table entry is reset regularly and sequentially every 2048 cycles to maintain the allocation process of the TAGE predictor when the prediction is wrong.
[0035] As for the loop predictor, it exists as a small predictor to assist in correcting the TAGE predictor. The counter counts the number of loop executions. When a loop is executed 7 or more times with the same number of iterations, the loop predictor will consider the branch instruction as a loop and flip the prediction result of the TAGE predictor to indicate the exit of the loop body.
[0036] The return address stack in the third level predictor is as follows Figure 4 As shown in the figure, it is responsible for the call type push and return type pop of the JALR instruction in the RISC-V instruction set. It has a high prediction accuracy for the function body in the high-level programming language. Through the RAS and branch decoding unit as well as the TAGE predictor and loop predictor, the third-level predictor will be able to complete the absolutely correct prediction of the JAL instruction, the absolutely correct prediction of the JALR instruction direction, and the absolutely correct prediction of the conditional branch instruction BR target.
[0037] The final branch prediction structure of the present invention is as follows Figure 5 During the prediction process, as long as the prediction or prediction update history of the subsequent stage is inconsistent with that of the previous stage, the subsequent stage shall prevail and flush the pipeline of the previous stage to support its fast and accurate prediction characteristics.
[0038] For the branch aliasing scheme based on history-independent in the optimization scheme proposed by the present invention, one implementation scheme of the implementation process is as follows: Figure 6 As shown. That is, by reconstructing the virtual PC according to 4 bits as 1 pixel, and convolving with the edge detection feature operator Sobel in different directions, the convolution results are spliced, and the missing bits are supplemented by the low bits of the original virtual PC to obtain the index after feature extraction. This optimization scheme can be applied to the bimodal table and TAGE predictor of the present invention to improve the prediction accuracy to a certain extent.
[0039] For the branch jitter optimization scheme in the optimization scheme proposed by the present invention, one implementation scheme of its implementation process is as follows: Figure 7 As shown in the figure, the C state is the correct state and the M state is the error state. By setting the difficulty of switching between different states, the threshold of the prediction direction flip can be expressed. According to the temporal local characteristics of branch prediction errors, branch prediction errors will occur frequently in a certain hot program. Figure 7 Circuit detection, when Figure 7 After the circuit detects that the prediction error exceeds the flip threshold (i.e. Figure 7 The left side of the dotted line), that is, the branch prediction direction is flipped, and the branch prediction accuracy will be improved. For example, the threshold is set to 70%. When the branch prediction error rate reaches 70% or more within a certain period of time, the state machine flips the prediction direction. The prediction error rate will become 30% under ideal conditions, thereby improving the prediction accuracy. However, due to the update delay between the actual back-end ALU and the instruction fetch unit, the optimization range will not be as high as the ideal value. However, for shallower pipelines, this solution will provide better optimization performance. Specifically, the prediction flip circuit can be used flexibly and can be applied to the bimodal table in the present invention to directly improve the accuracy of the second-level predictor, and indirectly affect the accuracy of the third-level predictor by affecting the accuracy of the benchmark predictor.
[0040] The above description is only a description of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any changes or modifications made by a person skilled in the art in the field of the present invention based on the above disclosure shall fall within the scope of protection of the claims.
Claims
1. A multi-cycle instruction fetch branch prediction system, characterized in that: including a first-level predictor, a second-level predictor, and a third-level predictor; The first-level predictor includes a micro-branch target cache, which uses a register array as a storage unit and can predict both the branch direction and the branch target; The second-level predictor includes a large branch target cache and a bimodal table, wherein the large branch target cache uses SRAM as a storage unit and supports a wide range of target jumps, and the bimodal table predicts the branch direction; The third-level predictor is a TAGE predictor and a loop predictor, which uses SRAM as a storage unit and uses global history for prediction; For the third-level predictor, the return address stack RAS and the branch decoding unit are also used for prediction; The storage table entry of the first-level predictor includes a tag field, a saturation counter, an offset, and a flag indicating whether it is a conditional branch instruction; when predicting, whether it is a conditional branch instruction flag will determine whether the branch direction prediction is provided by the saturation counter or a direct jump; The storage table entry of the second-level predictor includes a tag field, an offset, an extended target address, a flag whether an extension is required, and a flag whether it is a conditional branch instruction; when predicting, whether it is a conditional branch instruction flag will determine whether the branch direction prediction is provided by the saturation counter of the bimodal table or a direct jump; Whether the extension flag is needed will determine whether the branch target prediction is provided directly by the extended target address cache or obtained by signed operation from the offset; The TAGE predictor includes a reference predictor and a plurality of tag prediction tables, each entry of which is composed of a saturation counter, a tag field and a usage counter, and the bit widths of the saturation counter, the tag field and the usage counter are flexibly set; The third-level predictor uses the bimodal table of the second-level predictor as a reference predictor and uses the cycle predictor to perform auxiliary correction on the cycle predicted by the TAGE predictor; The final prediction result of the third-level predictor is jointly determined by the branch decoding unit and the return address stack RAS.
