Method to improve the accuracy of loop branch prediction algorithm through bypass circuit

By introducing the bypass feedback mechanism of bypass circuits and register circuits into the processor, the problem of poor branch prediction accuracy and slow speed in loop nesting scenarios is solved, and the prediction accuracy of loop instructions and processor performance are improved.

CN114895966BActive Publication Date: 2024-10-22JIANGSU HUACHUANG MICROSYSTEM CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210657136.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-10
Publication Date
2024-10-22
Estimated Expiration
2042-06-10

AI Technical Summary

Technical Problem

In modern superscalar processor designs, the direction of the last branch instruction of a loop instruction is different from the previous direction, resulting in poor branch prediction accuracy and slow speed in loop nesting scenarios.

Method used

By introducing a bypass circuit into the loop branch prediction algorithm, register circuits and comparison circuits are used for bypass feedback at different stages of the pipeline, and the prediction results of the previous PC are reused to improve branch prediction accuracy and speed.

Benefits of technology

It improves the prediction accuracy of loop instructions, reduces table lookup operations, reduces power consumption, and monitors subsequent PCs through a bypass feedback mechanism, improving the accuracy and speed of branch prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114895966B_ABST
    Figure CN114895966B_ABST
Patent Text Reader

Abstract

The invention discloses a method for improving the accuracy of a loop branch prediction algorithm through a bypass circuit. Three PCs enter a pipeline respectively. PC1 obtained in the if0 stage enters a hybrid branch predictor. When PC1 hits in the loop, PC1 is stored in a register. Branch prediction information is obtained in the if1 stage. A prediction result is obtained in the if2 stage through comparison in the hybrid branch predictor. The prediction result of the if2 stage is stored. Similarly, PC2 and PC1. After PC3 enters the if1 stage, it is compared with the PC values ​​stored in PC1 and PC2. If it is equal to PC1, the prediction result of PC1 is bypassed to if1 for use through a bypass circuit. If it is equal to PC2, the prediction result of PC2 is bypassed to if1 for use through a bypass circuit. If they are not equal and hit in the loop, the prediction result of PC2 covers the prediction result of PC1, the prediction result of PC3 covers the prediction result of PC2, and PC2 covers PC1 and PC3 covers PC2.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for improving the accuracy of the loop branch prediction algorithm through a bypass circuit, belonging to the technical field of processor design. Background Art

[0002] In modern superscalar processor design, branch prediction greatly affects the performance of the processor, and the two main factors affecting branch prediction performance are accuracy and speed. In the research and development of a certain model of processor, it is found that the direction of the last branch instruction of the loop instruction is different from the previous one, and it is difficult for other prediction algorithms to predict the last branch instruction of the loop. Therefore, the loop prediction algorithm is usually used to predict whether the loop instruction jumps. However, although this prediction algorithm can achieve high-precision prediction of the jump direction of the loop instruction, this branch predictor is mostly used as a secondary branch predictor, and there are problems of poor prediction accuracy and slow speed for the scenario of multi-loop nesting. In order to improve the prediction accuracy and speed of the loop algorithm, it is improved, and the prediction accuracy and speed of this branch prediction algorithm are improved by adding a bypass feedback circuit technical solution, thereby improving the processor performance.

[0003] The original basic principle of the loop algorithm is as follows:

[0004] Count Limit DIR

[0005] The predictor includes a counter, a loop threshold, and a prediction direction. The calculator (count) represents the state of the current loop control branch instruction, the threshold (limit) field is the number of loop iterations of the previous loop, and the prediction direction (DIR) identifies the opposite direction of the branch exit. When a loop exit is detected, the count field overwrites the limit field, and at the same time, the count is initialized to 1. When count < limit, DIR is the branch prediction direction. When count = limit, the loop exits at this time, and the opposite direction of DIR is used as the prediction result. Summary of the Invention

[0006] The present invention proposes a technical implementation solution for increasing the bypass feedback circuit to improve the prediction accuracy and speed of the loop branch prediction algorithm for the loop nesting scenario; for the method of improving the accuracy of the loop branch prediction algorithm through the bypass circuit, the technical solution adopted is:

[0007] A method for improving the accuracy of a loop branch prediction algorithm through a bypass circuit includes adding a bypass circuit to the loop branch prediction algorithm. The specific method is as follows: for three PCs entering a pipeline, namely, pc1, pc2, and pc3, pc1, pc2, and the results of their corresponding branch predictions are respectively stored in registers at the back end of the pipeline, and then bypassed to the if1 stage of the pipeline through the bypass circuit; in circuit design, register circuits of pc1 and pc2 need to be added to if3 and if4 of the pipeline respectively, and pc1 and pc2 meet the loo When the p predictor hits, the values ​​of pc1 and pc2 are respectively stored in the registers of the subsequent pipeline stages and bypassed to the if1 stage of the pipeline through the bypass circuit and compared with the newly entered pc through the comparison circuit; for the prediction results of pc1 and pc2, a register circuit is also added to store the prediction results in the registers of the subsequent pipeline stages, if4 and if3 stages, and bypassed to the if1 stage of the pipeline through the bypass circuit. When pc3 is judged to be equal to pc1 or pc2 through the comparison circuit, the pc1 and pc2 bypass prediction results corresponding to the if1 stage can be used;

[0008] The specific method of improving the accuracy of the loop branch prediction algorithm through the bypass circuit is as follows:

[0009] The first PC obtained in the if0 stage enters the hybrid branch predictor, and the loop predictor of the hybrid branch predictor directly uses PC addressing;

[0010] When pc1 hits in the loop predictor, the register will be used to store pc1; at the same time, after the hit, the branch prediction information will be obtained in the if1 stage, and the prediction result will be obtained after comparison in the hybrid branch predictor in the if2 stage, and the prediction result of the if2 stage of the pipeline will be stored through the register pc1_loop_bypass_reg;

[0011] When pc2 is obtained in the next if0 stage, the if1 stage is entered. At this time, pc2 will be compared with the pc1 value. When the second pc2 is equal to pc1, the prediction result and hit information of the first PC (the value in pc1_loop_bypass_reg) are reused through the bypass circuit. Otherwise, if the loop predictor is hit, pc2 and the corresponding prediction result are stored in pc2_loop_bypass_reg.

[0012] Similarly, after pc3 enters the if1 stage, it will be compared with the PC values ​​stored in pc1_bypass_reg and pc2_bypass_reg. If it is equal to pc1, the prediction result will bypass pc1_loop_bypass_reg to if1 through the bypass circuit; if it is equal to pc2, the prediction result will bypass pc2_loop_bypass_reg to if1 through the bypass circuit; if they are not equal and the hit loop predictor is satisfied, the pc2_bypass_reg prediction result will overwrite pc1_bypass_reg, and the prediction result obtained by the third PC will be stored in pc2_bypass_reg.

[0013] For the preferred technical solution of the present invention, for the fourth PC, if the loop predictor is hit, the above process is repeated. In this case, pc4, pc3, and pc2 replace the previous pc3, pc2, and pc1 to form a new three-item group; pc2, pc3, and the prediction results pc2_bypass_reg and pc3_bypass_reg are stored cyclically for use in the subsequent pc4 prediction.

[0014] In the method of the present invention, the loopP prediction algorithm mentioned is a known technology, known to those skilled in the art. In the method of the present invention, the bypass circuit mentioned is a known technology, known to those skilled in the art.

[0015] Compared with the prior art, the present invention has the following beneficial effects:

[0016] The method of the present invention improves the accuracy of the loop algorithm for loop instructions, and reduces operations such as table lookup, thereby reducing the power consumption of the algorithm implementation, because the loop predictor has a high probability of repeating the PC of loop instructions.

[0017] In the method of the present invention, the bypass feedback mechanism realizes monitoring of subsequent PCs. Once the same value as the two stored PCs appears, the prediction result of the previous PC will be reused immediately to improve the accuracy and speed of branch prediction. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 It is a flowchart of the method of the present invention.

[0019] Figure 2 It is a flowchart of the loop prediction algorithm in this embodiment. DETAILED DESCRIPTION

[0020] The technical solution of the present invention is described in detail below, but the protection scope of the present invention is not limited to the embodiments.

[0021] To make the content of the present invention more clearly understood, the following Figure 1 -Attached Figure 2 The specific implementation manner is further described.

[0022] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0023] like Figure 1 As shown, for three adjacent PCs (i.e., pc1, pc2, and pc3) entering the pipeline, the figure shows that pc1 and pc2 have entered the pipeline, and pc3 is entering the pipeline.

[0024] The present invention proposes a method for improving the accuracy of a loop branch prediction algorithm through a bypass circuit. For three PCs entering a pipeline, namely, pc1, pc2 and pc3, pc1, pc2 and the results of the corresponding branch predictions are respectively stored in registers at the back end of the pipeline, and then bypassed to the if1 stage of the pipeline through the bypass circuit; in circuit design, register circuits of pc1 and pc2 need to be added to if3 and if4 of the pipeline respectively. When pc1 and pc2 meet the hit of the loop predictor, the values ​​of pc1 and pc2 are respectively stored in registers of subsequent pipeline stages, bypassed to the if1 stage of the pipeline through the bypass circuit, and compared with the newly entered pc through a comparison circuit; for the prediction results of pc1 and pc2, a register circuit is also added to store the prediction results in registers of subsequent pipeline stages, if4 and if3 stages, and bypassed to the if1 stage of the pipeline through the bypass circuit. When pc3 is judged to be equal to pc1 or pc2 through the comparison circuit, the bypass prediction results of pc1 and pc2 corresponding to the if1 stage can be used;

[0025] The specific method of improving the accuracy of the loop branch prediction algorithm through the bypass circuit is as follows:

[0026] The first PC obtained in the if0 stage enters the hybrid branch predictor, and the loop predictor of the hybrid branch predictor directly uses PC addressing;

[0027] When pc1 hits in the loop predictor, the register will be used to store pc1; at the same time, after the hit, the branch prediction information will be obtained in the if1 stage, and the prediction result will be obtained after comparison in the hybrid branch predictor in the if2 stage, and the prediction result of the if2 stage of the pipeline will be stored through the register pc1_loop_bypass_reg;

[0028] When pc2 is obtained in the next if0 stage, the if1 stage is entered. At this time, pc2 will be compared with the pc1 value. When the second pc2 is equal to pc1, the prediction result and hit information of the first PC (the value in pc1_loop_bypass_reg) are reused through the bypass circuit. Otherwise, if the loop predictor is hit, pc2 and the corresponding prediction result are stored in pc2_loop_bypass_reg.

[0029] Similarly, after pc3 enters the if1 stage, it will be compared with the PC values ​​stored in pc1_bypass_reg and pc2_bypass_reg. If it is equal to pc1, the prediction result will bypass pc1_loop_bypass_reg to if1 through the bypass circuit; if it is equal to pc2, the prediction result will bypass pc2_loop_bypass_reg to if1 through the bypass circuit; if they are not equal and the hit loop predictor is satisfied, the pc2_bypass_reg prediction result will overwrite pc1_bypass_reg, and the prediction result obtained by the third PC will be stored in pc2_bypass_reg.

[0030] For the fourth PC, if the loop predictor is hit, the above process is repeated. In this case, pc4, pc3, and pc2 replace pc3, pc2, and pc1 to form a new three-item group; pc2, pc3, and the prediction results pc2_bypass_reg and pc3_bypass_reg are stored in a loop for the subsequent pc4 prediction.

[0031] The method of the present invention improves the accuracy of loop algorithms for loop instructions because the probability of repeated PCs of loop predictors for loop instructions is relatively high, and reduces operations such as table lookup, thereby reducing the power consumption of algorithm implementation. The bypass feedback mechanism monitors subsequent PCs, and once a value identical to the two stored PCs appears, the prediction result of the previous PC is reused immediately to improve the accuracy and speed of branch prediction.

[0032] like Figure 2 As shown, the loop branch prediction algorithm with bypass circuit in this embodiment includes the following steps:

[0033] S1, obtain PC, generate the index field and part of the identification field of the loop history table LHT, in this step, compare PC with pc1 and pc2 bypassed by the bypass circuit, if they are not equal, go to S2, if they are equal to one of pc1 and pc2, go to S4;

[0034] S2, when it is not equal to pc1 and pc2, on the next level pipeline for obtaining PC, the prediction item and prediction information of the loop branch history table are found through the index field, and then enter S3;

[0035] S3. Determine whether the loop history table hits by partial identification and the read prediction items. If it hits, the final prediction result is obtained based on the hit information and the final mixed predictor arbitration, and the PC and the final prediction result are stored in the register; if it does not hit, the relevant information is not stored.

[0036] S4. If PC and pc1 are equal in step S1, the prediction result of pc1 bypassed to if1 is used as the final result. If PC and pc2 are equal in step S1, the prediction result of pc2 bypassed to if1 is used as the final result.

[0037] In this embodiment, a loop history table LHT is generated, and each item in the table contains a 10-bit counter count, a 10-bit loop upper limit, a 10-bit tag, a 3-bit confidence, a 3-bit age, and a 1-bit dir. The count field is used to record the number of loops in this loop, the limit is the total number of loops in the previous loop, the tag is used to identify whether the LHT hits, the confidence is used to determine whether the loop predictor has learned stably, the age is used to replace the LHT, and the dir is the opposite direction of the loop exit. Since the loop predictor mainly predicts regular loop conditional branches, its historical information is in the count and limit fields, and no history is needed, so its INDEX and TAG generation directly uses the PC part field for XOR operation.

[0038] LHT RESULT_SEL: Compare the generated index and tag with the LHT readout item to determine whether it is a hit, and output the entire content of the hit item. At the same time, determine whether to replace the prediction result of the main predictor with the result of the loop predictor based on whether the confidence is the maximum value.

[0039] like Figure 2 As shown in the figure, the loop prediction result and the hit related conditions during prediction are added to the flowchart of the loop algorithm, and stored in the subsequent pipeline through the register. When the same PC value is encountered again, the previous prediction result can be used. This solution can not only reduce the power consumption of the prediction algorithm again, but also because the stored prediction result selects a relatively correct result, avoiding the occurrence of prediction errors, thereby improving the accuracy of the prediction result.

[0040] The method of this embodiment is based on the fact that the loop predictor mainly predicts loop instructions and the probability of repeated PCs is high; by storing the index of the hit loop predictor and the final prediction result, and running to the if1 stage of the pipeline through the bypass circuit, the probability of prediction errors when encountering the same PC is reduced, and the accuracy of processor branch prediction for instruction prediction is improved. The problem of processor performance degradation caused by a high branch prediction error rate is solved.

[0041] The parts not involved in the present invention are the same as the prior art or can be implemented by using the prior art.

[0042] As described above, although the present invention has been shown and described with reference to specific preferred embodiments, it should not be construed as limiting the present invention itself. Various changes in form and details may be made without departing from the spirit and scope of the present invention as defined in the appended claims.

Claims

1. A method for improving the accuracy of a loop branch prediction algorithm by using a bypass circuit, characterized in that: The method includes adding a bypass circuit to the loop branch prediction algorithm. The specific method is as follows: for three PCs entering the pipeline, namely pc1, pc2 and pc3, pc1, pc2 and the corresponding branch prediction results are respectively stored in registers at the back end of the pipeline, and then bypassed to the if1 stage of the pipeline through the bypass circuit; in the circuit design, the register circuits of pc1 and pc2 need to be added to if3 and if4 of the pipeline respectively. When pc1 and pc2 meet the hit of the loop predictor, the values ​​of pc1 and pc2 are respectively stored in the registers of the subsequent pipeline stages, bypassed to the if1 stage of the pipeline through the bypass circuit, and compared with the newly entered pc through the comparison circuit; for the prediction results of pc1 and pc2, a register circuit is also added to store the prediction results in the registers of the subsequent pipeline stages, if4 and if3 stages, and bypassed to the if1 stage of the pipeline through the bypass circuit. When pc3 is judged to be equal to pc1 or pc2 through the comparison circuit, the bypass prediction results of pc1 and pc2 corresponding to the if1 stage can be used; The specific method of improving the accuracy of the loop branch prediction algorithm through the bypass circuit is as follows: The first PC obtained in the if0 stage enters the hybrid branch predictor, and the loop predictor of the hybrid branch predictor directly uses PC addressing; When pc1 hits in the loop predictor, the register will be used to store pc1; at the same time, after the hit, the branch prediction information will be obtained in the if1 stage, and the prediction result will be obtained after comparison in the hybrid branch predictor in the if2 stage, and the prediction result of the if2 stage of the pipeline will be stored through the register pc1_loop_bypass_reg; When pc2 is obtained in the next if0 stage, the if1 stage is entered. At this time, pc2 will be compared with the pc1 value. When the second pc2 is equal to pc1, the prediction result and hit information of the first PC (the value in pc1_loop_bypass_reg) are reused through the bypass circuit. Otherwise, if the loop predictor is hit, pc2 and the corresponding prediction result are stored in pc2_loop_bypass_reg. Similarly, after pc3 enters the if1 stage, it will be compared with the PC values ​​stored in pc1_bypass_reg and pc2_bypass_reg. If it is equal to pc1, the prediction result will bypass pc1_loop_bypass_reg to if1 through the bypass circuit; if it is equal to pc2, the prediction result will bypass pc2_loop_bypass_reg to if1 through the bypass circuit; if they are not equal and the hit loop predictor is satisfied, the pc2_bypass_reg prediction result will overwrite pc1_bypass_reg, and the prediction result obtained by the third PC will be stored in pc2_bypass_reg.

2. The method of improving the accuracy of a loop branch prediction algorithm by using a bypass circuit according to claim 1, characterized in that: For the fourth PC, if the loop predictor is hit, the above process is repeated. In this case, pc4, pc3, and pc2 replace pc3, pc2, and pc1 to form a new three-item group; pc2, pc3, and the prediction results pc2_bypass_reg and pc3_bypass_reg are stored in a loop for the subsequent pc4 prediction.