A conditional branch prediction method, device, terminal and storage medium

In conditional branch prediction, based on the combination of the target branch predictor and the TAGE predictor, prediction is made for the conditional judgment rules of different modes, which solves the problem of low prediction accuracy of the TAGE predictor in the conditional judgment rule change mode, and achieves higher prediction accuracy.

CN119536821BActive Publication Date: 2025-04-11SHENZHEN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510089828.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2025-04-11
Estimated Expiration
2045-01-21

AI Technical Summary

Technical Problem

In the prior art, TAGE predictors lack adaptability in processing dynamic change information in the condition judgment rule change mode, resulting in low accuracy of prediction results.

Method used

A conditional branch prediction method is adopted, based on the target branch predictor and the TAGE predictor, mode judgment is performed on the conditional judgment rules in the conditional branch. If it is a fixed mode, a first predictor secondary development based on the TAGE predictor is used for prediction; if it is a change mode, a TAGE predictor and a local history predictor are used for prediction.

Benefits of technology

By using different predictors for the conditional judgment rules for different modes, different predictors are used to predict, and when the conditional judgment rules are in a changing mode, the prediction results are generated, which effectively improves the accuracy of the prediction results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536821B_ABST
    Figure CN119536821B_ABST
Patent Text Reader

Abstract

The present invention provides a conditional branch prediction method, device, terminal and storage medium, which belong to the field of data processing technology. The method includes: receiving a conditional branch to be processed; performing mode judgment on a conditional judgment rule in the conditional branch; if the conditional judgment rule is a fixed mode, using a first predictor to predict the conditional branch to obtain a first prediction result, the first predictor is a conditional predictor secondary developed based on a TAGE predictor; if the conditional judgment rule is a variable mode, using a TAGE predictor and a second predictor to predict the conditional branch to obtain a second prediction result, the second predictor is a local history predictor with a variable matching pattern length. The present invention uses different predictors for prediction for conditional judgment rules of different modes, and combines the two predictors to generate prediction results when the conditional judgment rule is a variable mode, which can effectively improve the accuracy of the prediction results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a conditional branch prediction method, device, terminal and storage medium. Background Art

[0002] In the existing technology, using TAGE (Tagged Geometric History Length) predictor for branch prediction has become the mainstream prediction method. TAGE predictor is based on the principle of saturated counter for prediction. When the conditional judgment rules are fixed, it can maintain a certain prediction accuracy. However, when the conditional judgment rules change, it lacks adaptability in processing dynamically changing information, resulting in low prediction accuracy.

[0003] Therefore, the prior art has defects and needs to be improved and developed. Summary of the invention

[0004] The technical problem to be solved by the present invention is that, in view of the above-mentioned defects of the prior art, a conditional branch prediction method, device, terminal and storage medium are provided, aiming to solve the problem in the prior art that when the conditional judgment rules in the conditional branch are in a changing mode, the prediction result given by the predictor has a low accuracy.

[0005] The technical solution adopted by the present invention to solve the technical problem is as follows:

[0006] In a first aspect, an embodiment of the present invention provides a conditional branch prediction method. The conditional branch prediction method is implemented based on a target branch predictor and a TAGE predictor. The target branch predictor includes a first predictor and a second predictor. The method includes:

[0007] Receive conditional branches to be processed;

[0008] Performing pattern judgment on the conditional judgment rules in the conditional branch;

[0009] If the conditional judgment rule is a fixed mode, the conditional branch is predicted by using the first predictor to obtain a first prediction result, wherein the first predictor is a conditional predictor secondary developed based on the TAGE predictor;

[0010] If the conditional judgment rule is a changing mode, the conditional branch is predicted using the TAGE predictor and the second predictor to obtain a second prediction result, wherein the second predictor is a local history predictor having a variable matching pattern length.

[0011] In one implementation, performing mode judgment on the conditional judgment rule in the conditional branch includes:

[0012] Identifying a conditional judgment rule in the conditional branch;

[0013] Determining whether a condition in the condition determination rule is based on a fixed value;

[0014] If the condition is based on a fixed value, determining the conditional judgment rule of the conditional branch to be a fixed mode;

[0015] If the condition is based on a changing value, the conditional judgment rule of the conditional branch is determined to be a changing mode.

[0016] In one implementation, the using the first predictor to predict the conditional branch to obtain a first prediction result includes:

[0017] Using the first predictor to obtain branch information corresponding to the conditional branch, the branch information includes a start address, a target address, and a jump direction;

[0018] Using the first predictor to process based on the start address, the target address and the jump direction to obtain target history information, and storing the target history information in a target address history register and a global history register of the first predictor;

[0019] Determine an index by combining the jump direction and the target history information through the global history register;

[0020] Searching for entries in the multiple prediction tables corresponding to the first predictor in sequence by using the index, and if a corresponding entry is found in the current prediction table, performing validity judgment and confidence evaluation on the corresponding entry, and if the corresponding entry is valid and the confidence meets a first preset threshold, generating a first prediction result based on the data of the corresponding entry and stopping the search;

[0021] If the corresponding entry is invalid or the confidence does not meet the first preset threshold, the above-mentioned search, validity judgment and confidence evaluation operations are repeated in the current prediction table and / or the next prediction table until the first prediction result is generated.

[0022] In one implementation, the processing based on the start address, the target address and the jump direction to obtain the target history information includes:

[0023] Shift the target address left by one bit and perform XOR with the start address to generate a first intermediate address;

[0024] Shift the first intermediate address left by one bit to generate a second intermediate address;

[0025] XOR the jump direction with the lower bit of the second intermediate address to generate a third intermediate address;

[0026] The third intermediate address is subjected to a folding XOR process to compress it into target history information of a preset length.

[0027] In one implementation, the data of the corresponding entry includes a flag bit, a counter, and a useful bit; and the performing validity judgment on the corresponding entry includes:

[0028] If the useful bit in the corresponding entry indicates usefulness, determining that the corresponding entry is valid;

[0029] If the useful bit in the corresponding entry indicates useless, determining the state of the counter, and if the counter is in a saturated state, determining that the corresponding entry is valid;

[0030] If the counter is in an unsaturated state, the corresponding entry is determined to be invalid.

[0031] In one embodiment, the using the TAGE predictor and the second predictor to predict the conditional branch to obtain a second prediction result includes:

[0032] Using the TAGE predictor to predict the conditional branch, obtaining a first intermediate prediction result;

[0033] Using the second predictor to predict the conditional branch, to obtain a second intermediate prediction result;

[0034] determining whether the confidence of the second intermediate prediction result is saturated, and if the confidence of the second intermediate prediction result is saturated, using the second intermediate prediction result as the second prediction result;

[0035] If the confidence of the second prediction result is not saturated, the first intermediate prediction result is used as the second prediction result.

[0036] In one implementation, the using the second predictor to predict the conditional branch to obtain a second intermediate prediction result includes:

[0037] Using the second predictor to obtain a starting address corresponding to the conditional branch;

[0038] According to the starting address, searching a preset matching table of the second predictor for an associated entry associated with the conditional branch, the associated entry including a local history pattern, a match length field, and a confidence field;

[0039] Based on the start address, extracting a corresponding local history pattern from the associated entry, the local history pattern being used to store local execution history information of the conditional branch;

[0040] intercepting a pattern field corresponding to the match length field from the lower bits of the local history pattern, and matching it with the actual execution history of the conditional branch;

[0041] If the pattern field successfully matches the actual execution history, a second prediction result is generated according to the next bit of data adjacent to the matching field in the local history pattern.

[0042] In a second aspect, an embodiment of the present invention further provides a conditional branch prediction device, wherein the conditional branch prediction device is constructed based on a target branch predictor and a TAGE predictor, wherein the target branch predictor includes a first predictor and a second predictor; the device includes:

[0043] A branch receiving module, used for receiving conditional branches to be processed;

[0044] A mode judgment module, used for performing mode judgment on the condition judgment rules in the conditional branch;

[0045] A first prediction module, configured to predict the conditional branch using the first predictor to obtain a first prediction result if the conditional judgment rule is a fixed mode, wherein the first predictor is a conditional predictor improved based on a TAGE predictor;

[0046] The second prediction module is used to predict the conditional branch using the TAGE predictor and the second predictor to obtain a second prediction result if the conditional judgment rule is a change mode. The second predictor is a local history predictor with a variable matching pattern length.

[0047] In a third aspect, an embodiment of the present invention further provides a terminal, comprising: a memory, a processor, and a conditional branch prediction program stored in the memory and executable on the processor, wherein the conditional branch prediction program implements the steps of the conditional branch prediction method as described above when executed by the processor.

[0048] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a conditional branch prediction program, and the conditional branch prediction program can be executed to implement the steps of the conditional branch prediction method as described above.

[0049] Beneficial effects of the present invention: The present invention receives a conditional branch to be processed; performs pattern judgment on the conditional judgment rule in the conditional branch; if the conditional judgment rule is a fixed pattern, the conditional branch is predicted by a first predictor to obtain a first prediction result, and the first predictor is a conditional predictor secondary developed based on a TAGE predictor; if the conditional judgment rule is a variable pattern, the conditional branch is predicted by a TAGE predictor and a second predictor to obtain a second prediction result, and the second predictor is a local history predictor with a variable matching pattern length. The present invention uses different predictors for prediction for conditional judgment rules of different patterns, and combines the two predictors to generate prediction results when the conditional judgment rule is a variable pattern, which can effectively improve the accuracy of the prediction results. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a flow chart of a preferred embodiment of the conditional branch prediction method in the present invention.

[0051] Figure 2 It is a schematic diagram of code in which the conditional judgment rule in the present invention is a changing mode.

[0052] Figure 3 It is a schematic diagram of generating target historical information in the present invention.

[0053] Figure 4 It is a schematic diagram of generating the second prediction result in the present invention.

[0054] Figure 5 It is a structural diagram of a preferred embodiment of the conditional branch prediction device in the present invention.

[0055] Figure 6 It is a terminal principle block diagram of the present invention. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solution and advantages of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. 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.

[0057] In the instruction fetching stage of the processor, instructions are traditionally fetched from memory in sequence. However, if a branch instruction is encountered, the situation becomes complicated. At this time, if the processor needs to determine whether to jump and where to jump before fetching the next instruction, a delay will occur. Since this judgment process takes time, it will slow down the entire instruction fetching process, thereby reducing the execution efficiency of the processor.

[0058] The emergence of branch predictors provides a solution to this situation. They can determine whether the instruction fetched in this cycle is a branch instruction during the instruction fetch stage, and predict its direction and target address. Based on the predicted result, the instruction fetch of the next cycle is completed in advance, thereby improving the execution efficiency of the processor. However, if the prediction result of the branch predictor is wrong, the instructions originally loaded based on the wrong prediction path in the pipeline will be discarded, and then the instructions will be re-fetched from the correct address based on the information provided by the back-end feedback, which greatly affects the instruction execution efficiency of the processor. Therefore, improving the accuracy of the branch predictor is crucial to improving processor performance and reducing the power consumption overhead caused by the execution of invalid instructions.

[0059] In the prior art, using TAGE (Tagged Geometric History Length) predictor for branch prediction has become the mainstream prediction method. TAGE predictor makes predictions based on the principle of saturated counters. When the conditional judgment rules are fixed, it can maintain a certain prediction accuracy. However, when the conditional judgment rules change, it lacks adaptability in processing dynamically changing information, resulting in low prediction accuracy. In addition, there are also predictors based on neural networks, which rely on training data and can combine different types of input information, but cannot guarantee the accuracy of the prediction results.

[0060] In view of the above-mentioned defects of the prior art, the present invention provides a conditional branch prediction method, device and storage medium, the method comprising: receiving a conditional branch to be processed; performing mode judgment on a conditional judgment rule in the conditional branch; if the conditional judgment rule is a fixed mode, using a first predictor to predict the conditional branch to obtain a first prediction result, the first predictor is a conditional predictor secondary developed based on a TAGE predictor; if the conditional judgment rule is a variable mode, using a TAGE predictor and a second predictor to predict the conditional branch to obtain a second prediction result, the second predictor is a local history predictor with a variable matching pattern length. The present invention can effectively improve the accuracy of the prediction result by using different predictors for prediction of conditional judgment rules of different modes, and combining the two predictors to generate a prediction result when the conditional judgment rule is a variable mode.

[0061] See also Figure 1 The conditional branch prediction method described in the embodiment of the present invention is implemented based on a target branch predictor and a TAGE predictor, wherein the target branch predictor includes a first predictor and a second predictor, and includes the following steps:

[0062] Step S100: receiving a conditional branch to be processed.

[0063] Specifically, a conditional branch is an instruction fragment encountered by a processor during the execution of an instruction sequence, which has a conditional judgment rule and determines the subsequent execution path based on the judgment result. For example, during program execution, the instruction set corresponding to the common "if - else" structure belongs to a typical conditional branch. When the processor reads such an instruction, it needs to select whether to branch to the "else" branch instruction block or sequentially execute the subsequent instructions based on the evaluation result of the conditional expression.

[0064] Please refer to Figure 1 , the conditional branch prediction method described in the embodiments of the present invention further includes the following steps:

[0065] Step S200: Perform a pattern judgment on the conditional judgment rule in the conditional branch.

[0066] Specifically, when a conditional branch is received, it is necessary to identify the conditional judgment rule in the conditional branch and determine whether the condition in the conditional judgment rule is based on a fixed value. If the condition is based on a fixed value, it is determined that the conditional judgment rule of the conditional branch is a fixed pattern; if the condition is based on a changing value, it is determined that the conditional judgment rule of the conditional branch is a changing pattern. For example, if a conditional branch like if x>5 is encountered, since 5 is a fixed value, it is determined that the conditional judgment rule of this conditional branch is a fixed pattern. If code as shown in Figure 2 is encountered, where the j<cond part is based on a changing value, at this time, it is determined that the conditional judgment rule of the for(int j = 0; j<cond; j++) branch is a changing pattern. By performing a pattern judgment on the conditional judgment rule of the conditional branch, the present invention can provide a data basis for subsequent processing using different predictors.

[0067] Please refer to Figure 1 , the conditional branch prediction method described in the embodiments of the present invention further includes the following steps:

[0068] Step S300: If the conditional judgment rule is a fixed pattern, use the first predictor to predict the conditional branch to obtain a first prediction result, where the first predictor is a conditional predictor developed based on the TAGE predictor through secondary development.

[0069] Specifically, the first predictor in the present invention is obtained by secondary development based on the TAGE predictor. Although the existing TAGE predictor has a good accuracy rate in the conditional branch judgment of the fixed mode, it only uses the jump direction of the branch as historical information to generate the index. In a complex program execution process, many different conditional branches may have the same jump direction. The index generated only based on this unique jump direction information is very easy to repeat, resulting in the prediction table entries corresponding to different conditional branches being incorrectly associated, that is, index aliasing occurs. Based on this situation, the present invention improves the TAGE predictor. The present invention generates the target historical information by combining the starting address, the target address and the jump direction, and then determines the index, which effectively enriches the characteristic information of the index and can reduce the situation of index aliasing.

[0070] In one implementation, the using the first predictor to predict the conditional branch to obtain a first prediction result includes:

[0071] Using the first predictor to obtain branch information corresponding to the conditional branch, the branch information includes a start address, a target address, and a jump direction;

[0072] Using the first predictor to process based on the start address, the target address and the jump direction to obtain target history information, and storing the target history information in a target address history register and a global history register of the first predictor;

[0073] Determine an index by combining the jump direction and the target history information through the global history register;

[0074] Searching for entries in the multiple prediction tables corresponding to the first predictor in sequence by using the index, and if a corresponding entry is found in the current prediction table, performing validity judgment and confidence evaluation on the corresponding entry, and if the corresponding entry is valid and the confidence meets a first preset threshold, generating a first prediction result based on the data of the corresponding entry and stopping the search;

[0075] If the corresponding entry is invalid or the confidence does not meet the first preset threshold, the above-mentioned search, validity judgment and confidence evaluation operations are repeated in the current prediction table and / or the next prediction table until the first prediction result is generated.

[0076] Specifically, the start address is the memory address of the conditional branch instruction, which identifies the specific location where the conditional branch occurs. The target address is the target memory address that the conditional branch may jump to, and is used when the branch decides to jump. The jump direction indicates whether the conditional branch takes a jump or continues to execute sequentially when executed. The present invention generates target history information by combining the start address, the target address and the jump direction, and then determines the index, which can reduce the situation of index aliasing. The first predictor corresponds to prediction tables with different history lengths. When using the index to search for entries in multiple prediction tables corresponding to the first predictor, first search from the prediction table with a short history length. If the corresponding entry is found, stop searching and determine its validity. If the entry is valid, perform a confidence evaluation. When the confidence meets the first preset threshold, generate a first prediction result based on the data of the entry. If the entry is invalid or the confidence does not reach the first preset threshold, continue to search in the prediction table. If it is not found, search in the next prediction table in turn until an entry is found that is valid and the confidence meets the preset threshold, and generate a first prediction result based on the data of the entry.

[0077] In one implementation, the processing based on the start address, the target address and the jump direction to obtain the target history information includes:

[0078] Shift the target address left by one bit and perform XOR with the start address to generate a first intermediate address;

[0079] Shift the first intermediate address left by one bit to generate a second intermediate address;

[0080] XOR the jump direction with the lower bit of the second intermediate address to generate a third intermediate address;

[0081] The third intermediate address is subjected to a folding XOR process to compress it into target history information of a preset length.

[0082] Specifically, since the jump address is longer than the index address, it is necessary to compress the jump address to make it shorter in history length, so as to ensure that more branch information can be stored in a limited history register. Figure 3 As shown, the target address is first shifted left by one bit, XORed with the starting address, and then shifted left by one bit as a whole, and XORed in the jump direction of its low bit, thereby forming a longer hash information. Then, according to the preset fixed length, the XOR is folded in this longer hash information, that is, the third intermediate address, to obtain the target historical information. In the present invention, in order to avoid the occurrence of aliasing caused by overlapping insertion of historical information, that is, when two branches calculate the same historical information, the later generated historical information needs to be inverted or self-incremented.

[0083] In one implementation, the preset fixed length is 3 bits. In this case, a better indexing effect can be achieved under the condition that the maximum length of the register is about 200 bits (including about 66 branch information).

[0084] In one implementation, the data of the corresponding entry includes a flag bit, a counter, and a useful bit; and determining the validity of the entry based on the data in the corresponding entry includes:

[0085] If the useful bit in the corresponding entry indicates usefulness, determining that the corresponding entry is valid;

[0086] If the useful bit in the corresponding entry indicates useless, determining the state of the counter, and if the counter is in a saturated state, determining that the corresponding entry is valid;

[0087] If the counter is in an unsaturated state, the corresponding entry is determined to be invalid.

[0088] Specifically, due to the limited number of flag bits, it is easy to consider the table entry with saturated training as useless, and there is a high probability of wrong prediction after replacing the item. Therefore, when evaluating the validity of the entry, the training status of the counter is taken into account. If the useful bit in the corresponding entry indicates useless, but the counter is in a saturated state, the corresponding entry is determined to be valid, and the item will not be replaced even if the prediction is wrong within the preset time, thereby ensuring that the subsequent prediction of the item is highly confident.

[0089] In addition, in the prior art, when the number of prediction errors is large, the predictor will decay the useful bits of all table entries, which will affect other irrelevant branches. The present invention restricts this useful bit reset mechanism, and determines whether to trigger the useful bit reset mechanism by a random number, or increases the length of the counter, requiring a larger threshold to trigger. The present invention eliminates unnecessary table entry initialization in the above manner, and can effectively solve the problem of cold counters.

[0090] See also Figure 1 The conditional branch prediction method described in the embodiment of the present invention further includes the following steps:

[0091] Step S400: If the conditional judgment rule is a changing mode, the conditional branch is predicted using the TAGE predictor and the second predictor to obtain a second prediction result, wherein the second predictor is a local history predictor having a variable matching pattern length.

[0092] Specifically, when the conditional judgment rule is a change mode, it is necessary to combine two predictors to jointly determine the second prediction result. The second predictor is a local history predictor, which uses the recent execution history of the branch and tries to find a match in a longer history, and can capture all patterns with a specified length. In the conditional branch prediction process, 12 bits of information are used to capture 6 bits of key data as an example. First, the 12 bits of local history information involved in the current branch will be recorded in order in the shift register. At the same time, the most recent 6 bits of the 12 bits of local history are selected and used as the current pattern for matching. For example, when processing the branch flow of a program code, assuming that the 12 bits of local history information are "101100111001", then the most recent 6 bits "111001" are selected as the current pattern, and a matching search is performed in the existing historical data or the preset pattern library. Once the pattern is successfully matched in the 12-bit local history, the next bit of the matched pattern is immediately used as the prediction result of the current branch.

[0093] In one implementation, the using the TAGE predictor and the second predictor to predict the conditional branch to obtain a second prediction result includes:

[0094] Using the TAGE predictor to predict the conditional branch, obtaining a first intermediate prediction result;

[0095] Using the second predictor to predict the conditional branch, to obtain a second intermediate prediction result;

[0096] determining whether the confidence of the second intermediate prediction result is saturated, and if the confidence of the second intermediate prediction result is saturated, taking the second intermediate prediction result as the second prediction result;

[0097] If the confidence of the second prediction result is not saturated, the first intermediate prediction result is used as the second prediction result.

[0098] Specifically, due to the change of the conditional judgment rule, the accuracy of TAGE prediction is low. Therefore, the present invention combines two predictors to make predictions. When the confidence of the prediction result generated by the second predictor is saturated, it is used as the second prediction result, which can effectively improve the accuracy of branch prediction. The flow chart of this process is shown in Figure 4 As shown. The starting address is input into the TAGE predictor and the second predictor, the TAGE predictor generates the first intermediate prediction result, and the matching table of the second predictor calculates whether the pattern matches. When it matches and the confidence is saturated, the second intermediate prediction result generated by the second predictor is used as the second prediction result. The prediction result is used to update the global history register and the target address register, and the matching table is updated according to the prediction result.

[0099] In one implementation, the using the second predictor to predict the conditional branch to obtain a second intermediate prediction result includes:

[0100] Using the second predictor to obtain a starting address corresponding to the conditional branch;

[0101] According to the starting address, searching a preset matching table of the second predictor for an associated entry associated with the conditional branch, the associated entry including a local history pattern, a match length field, and a confidence field;

[0102] Based on the start address, extracting a corresponding local history pattern from the associated entry, the local history pattern being used to store local execution history information of the conditional branch;

[0103] intercepting a pattern field corresponding to the match length field from the lower bits of the local history pattern, and matching it with the actual execution history of the conditional branch;

[0104] If the pattern field successfully matches the actual execution history, a second prediction result is generated according to the next bit of data adjacent to the matching field in the local history pattern.

[0105] Specifically, the local history mode is 12 bits, and the confidence field is 2 bits, which can change according to the prediction results. The match length field is initially 3 bits, and the length can change according to the prediction results. In the early stages of training, it is difficult for the predictor to know the optimal match length for each branch, and empty items need to be trained from a default initial value. During the training process, it is necessary to update the result of each jump to the local history, and determine whether the match length and confidence change based on whether the prediction result of the hit is correct. When the prediction is wrong at full confidence, the match length needs to be increased. When the same branch is predicted incorrectly for a preset number of consecutive times, the match length needs to be initialized. The confidence field increments when TAGE predicts incorrectly and the second predictor predicts correctly.

[0106] In summary, the present invention receives a conditional branch to be processed; performs pattern judgment on the conditional judgment rule in the conditional branch; if the conditional judgment rule is a fixed pattern, the conditional branch is predicted by a first predictor to obtain a first prediction result, and the first predictor is a conditional predictor secondary developed based on a TAGE predictor; if the conditional judgment rule is a variable pattern, the conditional branch is predicted by a TAGE predictor and a second predictor to obtain a second prediction result, and the second predictor is a local history predictor with a variable matching pattern length. The present invention uses different predictors for prediction for conditional judgment rules of different patterns, and combines the two predictors to generate prediction results when the conditional judgment rule is a variable pattern, which can effectively improve the accuracy of the prediction results.

[0107] In one embodiment, if Figure 5 As shown, based on the above conditional branch prediction method, the present invention also provides a conditional branch prediction device, the conditional branch prediction device is constructed based on a target branch predictor and a TAGE predictor, the target branch predictor includes a first predictor and a second predictor; the device includes:

[0108] A branch receiving module 100, used for receiving a conditional branch to be processed;

[0109] A mode judgment module 200, used for performing mode judgment on the condition judgment rules in the conditional branch;

[0110] A first prediction module 300, configured to predict the conditional branch using the first predictor to obtain a first prediction result if the conditional judgment rule is a fixed mode, wherein the first predictor is a conditional predictor improved based on a TAGE predictor;

[0111] The second prediction module 400 is used to predict the conditional branch using the TAGE predictor and the second predictor to obtain a second prediction result if the conditional judgment rule is a change mode. The second predictor is a local history predictor with a variable matching pattern length.

[0112] In one embodiment, the device further comprises:

[0113] A rule identification unit, used to identify the conditional judgment rule in the conditional branch;

[0114] A condition judgment unit, used to judge whether the condition in the condition judgment rule is based on a fixed value;

[0115] a first determining unit, configured to determine that the condition judgment rule of the conditional branch is a fixed mode if the condition is based on a fixed value;

[0116] The second determining unit is configured to determine that the condition judgment rule of the conditional branch is a change mode if the condition is based on a changed value.

[0117] In one embodiment, the device further comprises:

[0118] A first information acquisition unit, configured to acquire branch information corresponding to the conditional branch using the first predictor, the branch information including a start address, a target address, and a jump direction;

[0119] a history information generating unit, configured to use the first predictor to perform processing based on the start address, the target address and the jump direction to obtain target history information, and store the target history information in a target address history register and a global history register of the first predictor;

[0120] An index determination unit, configured to determine an index by combining the global history register with the jump direction and the target history information;

[0121] A first result generating unit, configured to sequentially search for entries in a plurality of prediction tables corresponding to the first predictor using an index, and if a corresponding entry is found in a current prediction table, perform validity judgment and confidence evaluation on the corresponding entry, and if the corresponding entry is valid and the confidence meets a first preset threshold, generate a first prediction result based on the data of the corresponding entry and stop searching;

[0122] The second result generating unit is used to continue to repeat the above-mentioned search, validity judgment and confidence evaluation operations in the current prediction table and / or the next prediction table if the corresponding entry is invalid or the confidence does not meet the first preset threshold until the first prediction result is generated.

[0123] In one embodiment, the device further comprises:

[0124] A first address generating unit, configured to perform an XOR operation on the target address after shifting the target address left by one bit and the target address and the start address to generate a first intermediate address;

[0125] A second address generating unit, used for shifting the first intermediate address left by one bit to generate a second intermediate address;

[0126] A third address generating unit, configured to perform an XOR operation on the jump direction and a lower bit of the second intermediate address to generate a third intermediate address;

[0127] The folding XOR unit is used to perform folding XOR processing on the third intermediate address to compress it into target historical information of a preset length.

[0128] In one embodiment, the data of the corresponding entry includes a flag bit, a counter, and a useful bit; and the device further includes:

[0129] a first state determination unit, configured to determine that the corresponding entry is valid if the useful bit in the corresponding entry indicates usefulness;

[0130] A second state determination unit, configured to determine the state of the counter if the useful bit in the corresponding entry indicates useless, and determine that the corresponding entry is valid if the counter is in a saturated state;

[0131] The third state determination unit is configured to determine that the corresponding entry is invalid if the counter is in an unsaturated state.

[0132] In one embodiment, the device further comprises:

[0133] A first intermediate prediction result generating unit, configured to predict the conditional branch using the TAGE predictor to obtain a first intermediate prediction result;

[0134] A second intermediate prediction result generating unit, configured to predict the conditional branch using the second predictor to obtain a second intermediate prediction result;

[0135] a first confidence comparison unit, configured to determine whether the confidence of the second intermediate prediction result is saturated, and if the confidence of the second intermediate prediction result is saturated, use the second intermediate prediction result as the second prediction result;

[0136] The second confidence comparison unit is configured to use the first intermediate prediction result as the second prediction result if the confidence of the second intermediate prediction result is not saturated.

[0137] In one embodiment, the device further comprises:

[0138] An address acquisition unit, configured to acquire a start address corresponding to the conditional branch using the second predictor;

[0139] an entry search unit, configured to search, according to the start address, a preset matching table of the second predictor for an associated entry associated with the conditional branch, the associated entry comprising a local history pattern, a match length field, and a confidence field;

[0140] an information extraction unit, configured to extract a corresponding local history pattern from the associated entry based on the start address, wherein the local history pattern is used to store local execution history information of the conditional branch;

[0141] an information matching unit, configured to intercept a pattern field corresponding to the matching length field from a low bit of the local history pattern, and match it with an actual execution history of the conditional branch;

[0142] The second prediction result generating unit is used to generate a second prediction result according to the next bit of data adjacent to the matching field in the local history pattern if the pattern field matches the actual execution history successfully.

[0143] Based on the above embodiment, the present invention further provides a terminal, whose structural diagram can be as follows: Figure 6As shown. The terminal includes a processor, a memory, a network interface and a display screen connected via a device bus. The processor of the terminal is used to provide computing and control capabilities. The memory of the terminal includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating device and a conditional branch prediction program. The internal memory provides an environment for the operation of the operating device and the conditional branch prediction program in the non-volatile storage medium. The network interface of the terminal is used to communicate with an external terminal via a network connection. When the conditional branch prediction program is executed by the processor, the steps of any one of the above-mentioned conditional branch prediction methods are implemented. The display screen of the terminal can be a liquid crystal display screen or an electronic ink display screen.

[0144] Those skilled in the art will understand that Figure 6 The structural schematic diagram shown in the figure is only a schematic diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the terminal to which the scheme of the present invention is applied. The specific terminal may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0145] In one embodiment, a terminal is provided, comprising a memory, a processor, and a conditional branch prediction program stored in the memory and executable on the processor. When the conditional branch prediction program is executed by the processor, the steps of any one of the conditional branch prediction methods provided in the embodiments of the present invention are implemented.

[0146] An embodiment of the present invention further provides a computer-readable storage medium, on which a conditional branch prediction program is stored. When the conditional branch prediction program is executed by a processor, the steps of any one of the conditional branch prediction methods provided by the embodiments of the present invention are implemented.

[0147] It should be understood that the serial numbers of the steps in the above embodiments do not imply a sequence of execution, and the execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0148] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the above-mentioned device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned device can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0149] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0150] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0151] In the embodiments provided by the present invention, it should be understood that the disclosed apparatus / terminal equipment and method can be implemented in other ways. For example, the apparatus / terminal equipment embodiments described above are only illustrative, for example, the division of the above modules or units is only a logical function division, and in actual implementation, other division methods can be used, for example, multiple units or components can be combined or integrated into another apparatus, or some features can be ignored or not executed.

[0152] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features therein may be replaced by equivalents. However, these modifications or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. A conditional branch prediction method, the conditional branch prediction method is implemented based on a target branch predictor and a TAGE predictor, the target branch predictor includes a first predictor and a second predictor, characterized in that: The method comprises: Receive conditional branches to be processed; Performing pattern judgment on the conditional judgment rules in the conditional branch; If the conditional judgment rule is a fixed mode, the conditional branch is predicted by using the first predictor to obtain a first prediction result, wherein the first predictor is a conditional predictor secondary developed based on the TAGE predictor; If the conditional judgment rule is a change mode, the conditional branch is predicted using the TAGE predictor and the second predictor to obtain a second prediction result, wherein the second predictor is a local history predictor having a variable matching pattern length; The using the first predictor to predict the conditional branch to obtain a first prediction result includes: Using the first predictor to obtain branch information corresponding to the conditional branch, the branch information includes a start address, a target address, and a jump direction; Using the first predictor to process based on the start address, the target address and the jump direction to obtain target history information, and storing the target history information in a target address history register and a global history register of the first predictor; Determine an index by combining the jump direction and the target history information through the global history register; Searching for entries in the multiple prediction tables corresponding to the first predictor in sequence by using the index, and if a corresponding entry is found in the current prediction table, performing validity judgment and confidence evaluation on the corresponding entry, and if the corresponding entry is valid and the confidence meets a first preset threshold, generating a first prediction result based on the data of the corresponding entry and stopping the search; If the corresponding entry is invalid or the confidence does not meet the first preset threshold, continue to repeat the above search, validity judgment and confidence evaluation operations in the current prediction table and / or the next prediction table until a first prediction result is generated; The using the TAGE predictor and the second predictor to predict the conditional branch to obtain a second prediction result includes: Using the TAGE predictor to predict the conditional branch, obtaining a first intermediate prediction result; Using the second predictor to predict the conditional branch, to obtain a second intermediate prediction result; determining whether the confidence of the second intermediate prediction result is saturated, and if the confidence of the second intermediate prediction result is saturated, using the second intermediate prediction result as the second prediction result; If the confidence of the second intermediate prediction result is not saturated, taking the first intermediate prediction result as the second prediction result; The using the second predictor to predict the conditional branch to obtain a second intermediate prediction result includes: Using the second predictor to obtain a starting address corresponding to the conditional branch; According to the starting address, searching a preset matching table of the second predictor for an associated entry associated with the conditional branch, the associated entry including a local history pattern, a match length field, and a confidence field; Based on the start address, extracting a corresponding local history pattern from the associated entry, the local history pattern being used to store local execution history information of the conditional branch; intercepting a pattern field corresponding to the match length field from the lower bits of the local history pattern, and matching it with the actual execution history of the conditional branch; If the pattern field successfully matches the actual execution history, a second intermediate prediction result is generated according to the next bit of data adjacent to the matching field in the local history pattern.

2. The conditional branch prediction method according to claim 1, characterized in that: The performing pattern judgment on the condition judgment rule in the conditional branch includes: Identifying a conditional judgment rule in the conditional branch; Determining whether a condition in the condition determination rule is based on a fixed value; If the condition is based on a fixed value, determining the conditional judgment rule of the conditional branch to be a fixed mode; If the condition is based on a changing value, the conditional judgment rule of the conditional branch is determined to be a changing mode.

3. The conditional branch prediction method according to claim 1, characterized in that: The processing based on the start address, the target address and the jump direction to obtain the target history information includes: Shift the target address left by one bit and perform XOR with the start address to generate a first intermediate address; Shift the first intermediate address left by one bit to generate a second intermediate address; XOR the jump direction with the lower bit of the second intermediate address to generate a third intermediate address; The third intermediate address is subjected to a folding XOR process to compress it into target history information of a preset length.

4. The conditional branch prediction method according to claim 1, characterized in that: The data of the corresponding entry includes a flag bit, a counter and a useful bit; and the validity judgment of the corresponding entry includes: If the useful bit in the corresponding entry indicates usefulness, determining that the corresponding entry is valid; If the useful bit in the corresponding entry indicates useless, determining the state of the counter, and if the counter is in a saturated state, determining that the corresponding entry is valid; If the counter is in an unsaturated state, the corresponding entry is determined to be invalid.

5. A conditional branch prediction device, the conditional branch prediction device is constructed based on a target branch predictor and a TAGE predictor, the target branch predictor includes a first predictor and a second predictor; characterized in that: include: A branch receiving module, used for receiving conditional branches to be processed; A mode judgment module, used for performing mode judgment on the condition judgment rules in the conditional branch; A first prediction module, configured to predict the conditional branch using the first predictor to obtain a first prediction result if the conditional judgment rule is a fixed mode, wherein the first predictor is a conditional predictor improved based on a TAGE predictor; The using the first predictor to predict the conditional branch to obtain a first prediction result includes: Using the first predictor to obtain branch information corresponding to the conditional branch, the branch information includes a start address, a target address, and a jump direction; Using the first predictor to process based on the start address, the target address and the jump direction to obtain target history information, and storing the target history information in a target address history register and a global history register of the first predictor; Determine an index by combining the jump direction and the target history information through the global history register; Searching for entries in the multiple prediction tables corresponding to the first predictor in sequence by using the index, and if a corresponding entry is found in the current prediction table, performing validity judgment and confidence evaluation on the corresponding entry, and if the corresponding entry is valid and the confidence meets a first preset threshold, generating a first prediction result based on the data of the corresponding entry and stopping the search; If the corresponding entry is invalid or the confidence does not meet the first preset threshold, continue to repeat the above search, validity judgment and confidence evaluation operations in the current prediction table and / or the next prediction table until a first prediction result is generated; A second prediction module, used for predicting the conditional branch using the TAGE predictor and the second predictor to obtain a second prediction result if the conditional judgment rule is a change mode, wherein the second predictor is a local history predictor having a variable matching pattern length; The using the TAGE predictor and the second predictor to predict the conditional branch to obtain a second prediction result includes: Using the TAGE predictor to predict the conditional branch, obtaining a first intermediate prediction result; Using the second predictor to predict the conditional branch, to obtain a second intermediate prediction result; determining whether the confidence of the second intermediate prediction result is saturated, and if the confidence of the second intermediate prediction result is saturated, using the second intermediate prediction result as the second prediction result; If the confidence of the second intermediate prediction result is not saturated, taking the first intermediate prediction result as the second prediction result; The using the second predictor to predict the conditional branch to obtain a second intermediate prediction result includes: Using the second predictor to obtain a starting address corresponding to the conditional branch; According to the starting address, searching a preset matching table of the second predictor for an associated entry associated with the conditional branch, the associated entry including a local history pattern, a match length field, and a confidence field; Based on the start address, extracting a corresponding local history pattern from the associated entry, the local history pattern being used to store local execution history information of the conditional branch; intercepting a pattern field corresponding to the match length field from the lower bits of the local history pattern, and matching it with the actual execution history of the conditional branch; If the pattern field successfully matches the actual execution history, a second intermediate prediction result is generated according to the next bit of data adjacent to the matching field in the local history pattern.

6. A terminal, characterized in that: The terminal includes: a memory, a processor, and a conditional branch prediction program stored in the memory and executable on the processor. When the conditional branch prediction program is executed by the processor, the steps of the conditional branch prediction method according to any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a conditional branch prediction program, and when the conditional branch prediction program is executed by a processor, the steps of the conditional branch prediction method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Branch predictor with serially connected predictor stages for improving branch prediction accuracy

    US20010056531A1

  • Multi-level pattern history branch predictor using branch prediction accuracy history to mediate the predicted outcome

    US6918033B1