New Table Entry Allocation Method, Device, Equipment and Medium in Branch Instruction Predictor

By generating random numbers in the TAGE branch predictor and forcibly setting table items with the usefulness counter to 0, the problem of failure in allocation of new table items is solved, the accuracy of branch prediction is improved, and the operation efficiency of the processor is improved.

CN120010927BActive Publication Date: 2025-07-18SHANDONG BOSUAN ZHIXIN INFORMATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510502888.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-22
Publication Date
2025-07-18
Estimated Expiration
2045-04-22

AI Technical Summary

Technical Problem

The existing TAGE branch predictor fails when allocating new table entries, resulting in a decrease in branch prediction accuracy and cannot guarantee the successful implementation of new table entries allocation.

Method used

By generating a random number, search the sub-predictor number in the branch instruction predictor with a number not lower than the random number, and determine whether there is a table entry with a value of 0 for the usefulness counter. If it does not exist, set the table entry of the sub-predictor corresponding to the random number to 0 to ensure that the table entry with the shortest branch history length and the value of 0 for the usefulness counter in the table entry is allocated until the preset threshold is reached.

Benefits of technology

Improve the branch prediction accuracy of the branch predictor, ensure that the new table entries are successfully allocated in the branch instruction predictor, and improve the processor's operating efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120010927B_ABST
    Figure CN120010927B_ABST
Patent Text Reader

Abstract

The present invention discloses a new entry allocation method, device, equipment and medium in a branch instruction predictor, which relates to the field of computers and is used to solve the problem of low branch prediction accuracy caused by the inability of the existing branch instruction predictor to ensure the successful implementation of new entry allocation. The method includes: obtaining the predicted jump result of the target branch instruction by the branch instruction predictor and its corresponding target sub-predictor; generating a random number according to the number of the target sub-predictor in the branch instruction predictor; retrieving the sub-predictors with numbers not lower than the random number, and determining whether there is an entry with the value of the usefulness counter being 0 in each sub-predictor; if not, setting the value of the usefulness counter in the entry corresponding to the sub-predictor with the number being the random number to 0, so as to sequentially allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches the preset threshold; if so, the above-mentioned operation of allocating new entries can be directly executed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a new entry allocation method in a branch instruction predictor, and also relates to a new entry allocation device, an electronic device, a computer-readable storage medium, and a computer program product in a branch instruction predictor. Background Art

[0002] To improve the operating speed of a processor, modern processors use pipelines for parallel operations. However, branch instructions need to wait until the execution stage to determine whether this instruction jumps, which will affect the operating efficiency of the processor. To solve this problem, branch prediction technology can be used to predict branch instructions and determine whether they should jump.

[0003] Branch prediction technology means that when the processor encounters a branch instruction, it no longer waits for the branch result, but can directly predict in advance whether the branch instruction "jumps" or "does not jump" and the jump target address at an earlier stage. The purpose is to achieve an uninterrupted instruction stream based on the prediction result, thereby ensuring the operating speed of the processor. The existing branch predictor algorithm is mainly the TAGE (TAgged GEometric history length) predictor, which can improve the accuracy of the prediction result by allocating new entries to each internal sub-predictor during the branch prediction process. However, there are some defects in the method of allocating new entries in the current TAGE predictor. In some cases, new entries may not be successfully allocated, resulting in the performance of the TAGE algorithm not reaching the best, that is, the branch prediction accuracy of the TAGE predictor may be reduced.

[0004] Therefore, how to ensure the successful allocation of new entries in the branch instruction predictor and thus effectively improve the branch prediction accuracy of the TAGE predictor is an urgent problem to be solved by those skilled in the art. Summary of the Invention

[0005] The object of the present invention is to provide a new entry allocation method in a branch instruction predictor. This new entry allocation method in the branch instruction predictor can ensure the successful allocation of new entries in the branch instruction predictor, and thus effectively improve the branch prediction accuracy of the TAGE predictor; another object of the present invention is to provide a new entry allocation device, an electronic device, a computer-readable storage medium, and a computer program product in a branch instruction predictor, all of which have the above beneficial effects.

[0006] In a first aspect, the present invention provides a new entry allocation method in a branch instruction predictor, including:

[0007] Obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the target sub-predictor corresponding to the predicted jump result;

[0008] Generate a random number based on the number of the target sub-predictor in the branch instruction predictor;

[0009] In the branch instruction predictor, retrieve the sub-predictors with numbers not lower than the random number to determine whether there is an entry in each sub-predictor with the value of the usefulness counter being 0;

[0010] If there is such an entry, allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches the preset threshold;

[0011] If there is no such entry, set the value of the usefulness counter in the entry corresponding to the sub-predictor with the number being the random number to 0, so as to allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches the preset threshold.

[0012] Among them, obtaining the predicted jump result of the branch instruction predictor for the target branch instruction includes:

[0013] Determine the prediction results of each sub-predictor in the branch instruction predictor for the target branch instruction;

[0014] Determine the predicted jump result of the branch instruction predictor for the target branch instruction according to each prediction result.

[0015] Among them, the branch instruction predictor includes 1 basic sub-predictor and multiple label sub-predictors;

[0016] Determining the predicted jump result of the branch instruction predictor for the target branch instruction according to each prediction result includes:

[0017] Determine the index information of the target branch instruction;

[0018] Judge whether the target branch instruction hits the label sub-predictor according to the index information;

[0019] When the target branch instruction hits the label sub-predictor and the number of hits is not unique, use the prediction result of the first label sub-predictor with the longest history length among the hits as the first prediction result, and use the prediction result of the second label sub-predictor with the secondary history length among the hits as the second prediction result;

[0020] When the target branch instruction hits the label sub-predictor and the number of hits is unique, use the prediction result of the first label sub-predictor with the longest history length among the hits as the first prediction result, and use the prediction result of the basic sub-predictor as the second prediction result;

[0021] When the entry corresponding to the first tag sub - predictor is a pseudo - entry and the alternative flag is not 0, use the second prediction result as the predicted jump result of the target branch instruction;

[0022] When the entry corresponding to the first tag sub - predictor is not a pseudo - entry and / or the alternative flag is 0, use the first prediction result as the predicted jump result of the target branch instruction;

[0023] When the target branch instruction misses the tag sub - predictor, use the prediction result of the base sub - predictor as the predicted jump result of the target branch instruction.

[0024] Among them, determining whether the target branch instruction hits the tag sub - predictor according to the index information includes:

[0025] For each tag sub - predictor in the branch instruction predictor, determine the index value of the tag sub - predictor according to the program counter value, folded history, and historical path of the tag sub - predictor;

[0026] According to the index information of the target branch instruction and the index values of each tag sub - predictor, determine whether the target branch instruction hits the tag sub - predictor in the branch instruction predictor.

[0027] Among them, determining the index value of the tag sub - predictor according to the program counter value, folded history, and historical path of the tag sub - predictor includes:

[0028] Perform a hash calculation on the program counter value, folded history, and historical path of the tag sub - predictor to obtain a hash value;

[0029] Use the hash value as the index value of the tag sub - predictor.

[0030] Among them, obtaining the predicted jump result of the branch instruction predictor for the target branch instruction and determining the target sub - predictor corresponding to the predicted jump result includes:

[0031] Obtain the predicted jump result of the branch instruction predictor for the target branch instruction and determine the actual jump result of the target branch instruction;

[0032] When the actual jump result and the predicted jump result are inconsistent, and the predicted jump result is not the prediction result of the first tag sub - predictor, determine the target sub - predictor corresponding to the predicted jump result;

[0033] When the actual jump result is the same as the predicted jump result, and / or the predicted jump result is the prediction result of the first tag predictor, wait for the predicted jump result of the next branch instruction.

[0034] Among them, in the order of increasing numbers, new table entries are sequentially allocated to the predictors with numbers not lower than the random number until the allocation quantity reaches the preset threshold, and then it further includes:

[0035] Determine the hit result of the target branch instruction in the branch instruction predictor;

[0036] Update the table entries corresponding to the basic predictor and / or each of the tag predictors according to the hit result.

[0037] Among them, updating the table entries corresponding to the basic predictor and / or each of the tag predictors according to the hit result includes:

[0038] When the hit result is that the target branch instruction misses the tag predictor, update the table entry corresponding to the basic predictor;

[0039] When the hit result is that the target branch instruction hits the tag predictor, update the table entry corresponding to the hit tag predictor.

[0040] Among them, updating the table entry corresponding to the hit tag predictor includes:

[0041] Update the usefulness counter and the saturation counter in the table entry corresponding to the first tag predictor;

[0042] Update the saturation counter in the table entry corresponding to the second tag predictor.

[0043] Among them, in the order of increasing numbers, new table entries are sequentially allocated to the predictors with numbers not lower than the random number until the allocation quantity reaches the preset threshold, and then it further includes:

[0044] Count the number of new table entry allocations, and determine whether the number of new table entry allocations reaches the preset number;

[0045] When the number of new table entry allocations does not reach the preset number, wait for the next branch instruction as the target branch instruction, and return to the step of obtaining the predicted jump result of the target branch instruction by the branch instruction predictor;

[0046] When the number of new table entry allocations reaches the preset number, reset the table entries corresponding to all the tag predictors in the branch instruction predictor.

[0047] Among them, resetting the entries corresponding to all the tag sub-predictors in the branch instruction predictor includes:

[0048] For each tag sub-predictor in the branch instruction predictor, determine the current value of the usefulness counter in the entry corresponding to the tag sub-predictor;

[0049] Shift the current value one bit to the right to reset the entry corresponding to the tag sub-predictor.

[0050] In a second aspect, the present invention also discloses a new entry allocation device in a branch instruction predictor, including:

[0051] An acquisition module, configured to acquire the predicted jump result of the branch instruction predictor for a target branch instruction, and determine the target sub-predictor corresponding to the predicted jump result;

[0052] A generation module, configured to generate a random number according to the number of the target sub-predictor in the branch instruction predictor;

[0053] A retrieval module, configured to retrieve, in the branch instruction predictor, sub-predictors with numbers not lower than the random number to determine whether there is an entry with a usefulness counter value of 0 in each of the sub-predictors;

[0054] A first allocation module, configured to, if there is such an entry, sequentially allocate new entries to sub-predictors with numbers not lower than the random number in ascending order of numbers until the allocation quantity reaches a preset threshold;

[0055] A second allocation module, configured to, if there is no such entry, set the value of the usefulness counter in the entry corresponding to the sub-predictor with the random number to 0, so as to sequentially allocate new entries to sub-predictors with numbers not lower than the random number in ascending order of numbers until the allocation quantity reaches the preset threshold.

[0056] In a third aspect, the present invention also discloses an electronic device, including:

[0057] A memory, configured to store a computer program;

[0058] A processor, configured to implement the steps of any of the above-mentioned new entry allocation methods in a branch instruction predictor when executing the computer program.

[0059] In a fourth aspect, the present invention also discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above-mentioned new entry allocation methods in a branch instruction predictor are implemented.

[0060] Fifth aspect, the present invention also discloses a computer program product, including computer programs / instructions, which when executed by a processor, implement the steps of the method for allocating new entries in any of the above branch instruction predictors.

[0061] The present invention provides a method for allocating new entries in a branch instruction predictor, including: obtaining a predicted jump result of the branch instruction predictor for a target branch instruction, and determining a target sub-predictor corresponding to the predicted jump result; generating a random number according to the number of the target sub-predictor in the branch instruction predictor; in the branch instruction predictor, retrieving sub-predictors with numbers not lower than the random number to determine whether there is an entry with a usefulness counter value of 0 in each of the sub-predictors; if there is such an entry, allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches a preset threshold; if there is no such entry, set the value of the usefulness counter in the entry corresponding to the sub-predictor with the random number to 0, so as to allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches the preset threshold.

[0062] Applying the technical solution provided by the present invention, since the principle followed by the branch instruction predictor when allocating new entries is: perform the new entry allocation operation when finding an entry with the shortest branch history length and a usefulness counter value of 0 in a sub-predictor with a longer branch history length than the target sub-predictor (i.e., the sub-predictor hit by the branch instruction to be measured), and the reason for the failure of the branch instruction predictor to allocate new entries is that it fails to find an entry with the shortest branch history length and a usefulness counter value of 0 in the table entry, therefore, in the technical solution provided by the present invention, to ensure successful allocation of new entries in the branch predictor, for the scenario where an entry with the shortest branch history length and a usefulness counter value of 0 in the table entry cannot be found, that is, the scenario where no entry with a usefulness counter value of 0 is retrieved in the sub-predictors with numbers not lower than the random number as described above, the value of the usefulness counter in the entry corresponding to the sub-predictor with the random number can be directly forced to 0 to ensure that an entry with the shortest branch history length and a usefulness counter value of 0 can be found, thereby ensuring successful allocation of new entries in the branch instruction predictor and further improving the branch prediction accuracy of the branch instruction predictor.

[0063] The new entry allocation device, electronic device, computer-readable storage medium, and computer program product in the branch instruction predictor provided by the present invention also have the above technical effects, and the present invention will not repeat them here. Description of the Drawings

[0064] To more clearly illustrate the technical solutions in the prior art and the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the prior art and the embodiments of the present invention. Of course, the following description of the drawings of the embodiments of the present invention only covers a part of the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained according to the provided drawings, and the other obtained drawings also fall within the protection scope of the present invention.

[0065] Figure 1 Schematic flowchart of a method for allocating new table entries in a branch instruction predictor provided by an embodiment of the present invention;

[0066] Figure 2 Schematic flowchart of a branch instruction prediction method based on a branch instruction predictor provided by an embodiment of the present invention;

[0067] Figure 3 Schematic flowchart of a method for updating table entries in a branch instruction predictor provided by an embodiment of the present invention;

[0068] Figure 4 Schematic flowchart of another method for allocating new table entries in a branch instruction predictor provided by an embodiment of the present invention;

[0069] Figure 5 Schematic structural diagram of a device for allocating new table entries in a branch instruction predictor provided by an embodiment of the present invention;

[0070] Figure 6 Schematic structural diagram of an electronic device provided by an embodiment of the present invention. Detailed implementation manners

[0071] The core of the present invention is to provide a method for allocating new table entries in a branch instruction predictor. This method for allocating new table entries in the branch instruction predictor can ensure the successful allocation of new table entries in the branch instruction predictor, thereby effectively improving the branch prediction accuracy of the TAGE predictor. Another core of the present invention is to provide a device for allocating new table entries in a branch instruction predictor, an electronic device, a computer-readable storage medium, and a computer program product, all of which have the above beneficial effects.

[0072] To more clearly and completely describe the technical solutions in the embodiments of the present invention, the following will introduce the technical solutions in the embodiments of the present invention in combination with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.

[0073] An embodiment of the present invention provides a new entry allocation method in a branch instruction predictor.

[0074] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of a new entry allocation method in a branch instruction predictor provided by an embodiment of the present invention. The new entry allocation method in the branch instruction predictor may include the following S101 to S105.

[0075] S101: Obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the target sub-predictor corresponding to the predicted jump result.

[0076] This step aims to determine the predicted jump result of the target branch instruction and its corresponding target sub-predictor. It can be understood that the target branch instruction is the branch instruction for which the jump result needs to be predicted, and its jump result is divided into "jump" and "no jump". By predicting it in advance through the branch instruction predictor, the corresponding predicted jump result can be obtained, thereby ensuring the processor operation rate. Among them, the branch instruction predictor generally includes multiple sub-predictors. Taking the TAGE predictor as an example, it internally includes a basic sub-predictor and multiple tag sub-predictors. The final predicted jump result can be determined through the prediction results of each internal sub-predictor for the target branch instruction. That is to say, by comprehensively considering the prediction results of each sub-predictor in the branch instruction predictor for the target branch instruction, to determine which sub-predictor's prediction result is the most accurate, and use this most accurate prediction result as the final predicted jump result. Therefore, the target sub-predictor corresponding to the predicted jump result is the sub-predictor in the branch instruction predictor that can give the most accurate prediction result, that is, the final predicted jump result.

[0077] Based on this, in an embodiment of the present invention, obtaining the predicted jump result of the branch instruction predictor for the target branch instruction may include:

[0078] Determine the prediction results of each sub-predictor in the branch instruction predictor for the target branch instruction;

[0079] Determine the predicted jump result of the branch instruction predictor for the target branch instruction according to each prediction result.

[0080] Furthermore, taking the TAGE predictor that internally includes 1 basic sub-predictor and multiple tag sub-predictors as an example, the above determining the predicted jump result of the branch instruction predictor for the target branch instruction according to each prediction result may include:

[0081] Determine the index information of the target branch instruction;

[0082] Judge whether the target branch instruction hits the tag sub-predictor according to the index information;

[0083] When the target branch instruction hits the label sub-predictor and the number of hits is not unique, the prediction result of the first label sub-predictor with the longest history length among the hits is used as the first prediction result, and the prediction result of the second label sub-predictor with the secondary history length among the hits is used as the second prediction result;

[0084] When the target branch instruction hits the label sub-predictor and the number of hits is unique, the prediction result of the first label sub-predictor with the longest history length among the hits is used as the first prediction result, and the prediction result of the base sub-predictor is used as the second prediction result;

[0085] When the entry corresponding to the first label sub-predictor is a pseudo-entry and the alternative flag is not 0, the second prediction result is used as the predicted jump result of the target branch instruction;

[0086] When the entry corresponding to the first label sub-predictor is not a pseudo-entry and / or the alternative flag is 0, the first prediction result is used as the predicted jump result of the target branch instruction;

[0087] When the target branch instruction misses the label sub-predictor, the prediction result of the base sub-predictor is used as the predicted jump result of the target branch instruction.

[0088] An embodiment of the present invention provides a branch instruction prediction method taking the TAGE predictor as an example. It can be understood that implementing branch instruction prediction based on the TAGE predictor, that is, implementing branch instruction prediction based on the base sub-predictor and each tag sub-predictor in the TAGE predictor to obtain the predicted jump result of the target branch instruction. First, respectively determine the index information of the target branch instruction and the index information of each sub-predictor in the TAGE predictor (including one base sub-predictor and all tag sub-predictors), and the sub-predictor hit by the target branch instruction can be determined by matching the index information, which can be called the hit sub-predictor for convenience of description. It should be noted that the number of the hit sub-predictors is not unique, and there may be only one or more tag sub-predictors, or only one base sub-predictor, or may also include the base sub-predictor and one or more tag sub-predictors at the same time. Further, when the hit sub-predictor is only the base sub-predictor, its prediction result for the target branch instruction can be directly used as the final predicted jump result; when the hit sub-predictor includes tag sub-predictors, it is necessary to comprehensively analyze the historical length, corresponding table entries, and the value of the current alternative flag of each tag sub-predictor, where the historical length is the branch history length of the tag sub-predictor. In the implementation process, two most accurate prediction results, that is, the above-mentioned first prediction result (essentially belonging to the primary selection result) and the second prediction result (essentially belonging to the alternative result), can be filtered out according to the number of the hit tag sub-predictors and their respective historical lengths; then the final predicted jump result is determined from the two alternative results according to the table entries corresponding to the hit tag sub-predictors and the current alternative representation. It should be noted that the alternative flag is used to determine whether to use the alternative result (that is, the second prediction result) as the final predicted jump result when the table entry corresponding to the hit tag sub-predictor is a pseudo-newly allocated table entry. When its value is 1, the alternative result is used, and when its value is 0, the primary selection result is selected.

[0089] Among them, determining whether the target branch instruction hits the tag sub-predictor according to the index information may include: for each tag sub-predictor in the branch instruction predictor, determining the index value of the tag sub-predictor according to the program counter value, folded history, and historical path of the tag sub-predictor; judging whether the target branch instruction hits the tag sub-predictor in the branch instruction predictor according to the index information of the target branch instruction and the index values of each tag sub-predictor.

[0090] In a possible implementation manner, determining the index value of the tag sub-predictor according to the program counter value, folded history, and historical path of the tag sub-predictor may include: performing a hash calculation on the program counter value, folded history, and historical path of the tag sub-predictor to obtain a hash value; using the hash value as the index value of the tag sub-predictor.

[0091] This embodiment provides a method for determining the index information of a tag sub-predictor. For each tag sub-predictor in the TAGE predictor, its program counter value pc (program counter), folded history (compressed branch history length for easy calculation), historical path, etc. can be respectively subjected to hash calculation to obtain the index value of each tag sub-predictor.

[0092] Among them, determining whether the target branch instruction hits the basic sub-predictor according to the index information may include: determining the index value of the basic sub-predictor according to the program counter value of the basic sub-predictor; judging whether the target branch instruction hits the basic sub-predictor in the branch instruction predictor according to the index information of the target branch instruction and the index value of the basic sub-predictor.

[0093] In a possible implementation manner, determining the index value of the basic sub-predictor according to the program counter value of the basic sub-predictor may include: performing a shift calculation on the program counter value of the basic sub-predictor to obtain a shift result; using the shift result as the index value of the basic sub-predictor.

[0094] This embodiment provides a method for determining the index information of a basic sub-predictor. For the basic sub-predictor in the TAGE predictor, a shift calculation can be directly performed on its program counter value to obtain the index value of the basic sub-predictor.

[0095] S102: Generate a random number according to the number of the target sub-predictor in the branch instruction predictor.

[0096] This step aims to realize the generation of a random number, which is used as the sub-predictor number in the subsequent steps to realize the retrieval of the sub-predictor. Among them, the sub-predictor number is the number of the sub-predictor in the branch instruction predictor. As described above, the TAGE predictor includes a basic sub-predictor and multiple tag sub-predictors, and the numbering method is: the basic sub-predictor number is 0, and the remaining tag sub-predictors are numbered 1, 2, 3,...., N (N is the total number of tag sub-predictors) according to their deployment order in the TAGE predictor. Then, generating a random number according to the number of the target sub-predictor in the branch instruction can be specifically: assuming that the number of the target sub-predictor in the branch instruction is M, M belongs to [1, N], then the generated random number X belongs to [M + 1, M + 3], that is, generating a random number X according to the number M of the target sub-predictor in the branch instruction predictor, X belongs to [M + 1, M + 3], and the values of N, M, and X are all positive integers.

[0097] S103: In the branch instruction predictor, retrieve the sub-predictors with numbers not lower than the random number to determine whether there is an entry with a usefulness counter value of 0 in each sub-predictor; if not, execute S104, if so, execute S105.

[0098] S104: Set the value of the usefulness counter in the entry corresponding to the sub-predictor with a random number as its number to 0.

[0099] S105: Allocate new entries to the sub-predictors whose numbers are not less than the random number in ascending order of the numbers until the allocated quantity reaches a preset threshold.

[0100] The above steps are aimed at realizing the allocation of new entries through the retrieval of target entries, where the target entry is the entry with the value of the usefulness counter being 0. It can be understood that in the branch instruction predictor, the number of the sub-predictor corresponds to the branch history length, and the larger the number of the sub-predictor, the larger its branch history length. Based on this, in the branch instruction predictor, retrieve each sub-predictor whose number is not less than the random number to determine whether there is a target entry in the entry corresponding to this part of the sub-predictors. If there is, the operation of allocating new entries can be directly executed; if not, to ensure the successful execution of the operation of allocating new entries, the value of the usefulness counter in the entry corresponding to the sub-predictor with a random number as its number can be directly forced to 0, that is, directly regard the entry corresponding to the sub-predictor with a random number as its number as the target entry, ensuring that the target entry can be found in the branch instruction predictor to facilitate the execution of the operation of allocating new entries.

[0101] Among them, the operation of allocating new entries can specifically be: in the branch instruction predictor, allocate new entries to the sub-predictors whose numbers are not less than the random number in ascending order of the numbers until the allocated quantity reaches a preset threshold. It should be noted that the allocated quantity is the quantity of allocating new entries. Starting from the sub-predictor with a random number as its number, for each successfully allocated new entry of a sub-predictor, this allocated quantity is incremented by one. In addition, the value of the preset threshold does not affect the implementation of this technical solution, which is determined by the performance of the branch instruction predictor itself and its actual processing situation, and the present invention does not limit it; in a possible implementation manner, new entries are directly allocated to all sub-predictors whose numbers are not less than the random number.

[0102] In an embodiment of the present invention, after allocating new entries to the sub-predictors whose numbers are not less than the random number in ascending order of the numbers until the allocated quantity reaches a preset threshold, it may further include:

[0103] Count the number of times of allocating new entries, and judge whether the number of times of allocating new entries reaches a preset number of times;

[0104] When the number of times of allocating new entries does not reach the preset number of times, wait for the next branch instruction as the target branch instruction, and return to the step of obtaining the predicted jump result of the branch instruction predictor for the target branch instruction;

[0105] When the number of new entry allocations reaches a preset number of times, reset the entries corresponding to all tag sub-predictors in the branch instruction predictor.

[0106] This embodiment provides an implementation method for resetting the entry content. Specifically, each time a complete new entry allocation operation (S101~S105) is executed, the number of new entry allocations will be recorded once; at the same time, there is a preset upper limit for the number of times of allocating new entries in the branch instruction predictor, that is, the above-mentioned preset number of times. Therefore, after each complete new entry allocation operation is completed, it can be judged whether the current number of new entry allocations reaches the preset number of times. If it does not reach the preset number of times, it can continue to wait for the arrival of the next branch instruction for further processing; if it has reached the preset number of times, it is necessary to perform a reset operation on the entries corresponding to all tag sub-predictors in the branch instruction predictor. It should be noted that the specific value of the above-mentioned preset number of times does not affect the implementation of this technical solution and can be set according to actual needs. The present invention does not make any limitations in this regard.

[0107] It can be understood that performing a reset operation on the entries in the branch instruction predictor helps to provide a "clean" initial state and avoid historical data (residual data of old entries) from interfering with the context and affecting the branch prediction accuracy of the branch instruction predictor.

[0108] Among them, resetting the entries corresponding to all tag sub-predictors in the branch instruction predictor may include: for each tag sub-predictor in the branch instruction predictor, determining the current value of the usefulness counter in the entry corresponding to the tag sub-predictor; shifting the current value one bit to the right to achieve resetting the entry corresponding to the tag sub-predictor. That is to say, the reset operation on the entries corresponding to each tag sub-predictor in the branch instruction predictor essentially refers to resetting the value of the usefulness counter in the entry, and this process can be achieved by shifting its current value to the right.

[0109] It can be seen that in the method for allocating new entries in the branch instruction predictor provided by the embodiments of the present invention, the principle followed by the branch instruction predictor when allocating new entries is as follows: when a new entry allocation operation is performed by finding an entry with the shortest branch history length and a useful counter value of 0 in a sub-predictor whose branch history length is longer than that of the target sub-predictor (i.e., the sub-predictor hit by the branch instruction under test), and the reason for the failure of the branch instruction predictor to allocate a new entry is that an entry with the shortest branch history length and a useful counter value of 0 cannot be found. Therefore, in the technical solution provided by the present invention, to ensure that a new entry can be successfully allocated in the branch predictor, for the scenario where an entry with the shortest branch history length and a useful counter value of 0 cannot be found, that is, the scenario where an entry with a useful counter value of 0 cannot be retrieved in a sub-predictor with a number not less than the random number, the value of the useful counter in the entry corresponding to the sub-predictor with the number of the random number can be directly forced to be 0, ensuring that an entry with the shortest branch history length and a useful counter value of 0 can be found, so as to ensure the successful allocation of a new entry in the branch instruction predictor and further improve the branch prediction accuracy of the branch instruction predictor.

[0110] Based on the above embodiments:

[0111] In an embodiment of the present invention, obtaining the predicted jump result of the branch instruction predictor for the target branch instruction and determining the target sub-predictor corresponding to the predicted jump result may include:

[0112] Obtain the predicted jump result of the branch instruction predictor for the target branch instruction and determine the actual jump result of the target branch instruction;

[0113] When the actual jump result and the predicted jump result are inconsistent and the predicted jump result is not the prediction result of the first label sub-predictor, determine the target sub-predictor corresponding to the predicted jump result;

[0114] When the actual jump result and the predicted jump result are consistent and / or the predicted jump result is the prediction result of the first label sub-predictor, wait for the predicted jump result of the next branch instruction.

[0115] An embodiment of the present invention provides a judgment condition for determining whether to perform a new entry allocation operation. It can be understood that the new entry allocation operation in the branch instruction predictor aims to achieve accurate branch instruction prediction by allocating new entries. Therefore, when the predicted jump result of the branch instruction predictor for the target branch instruction is correct, there is no need to perform the operation of reallocating new entries; when the predicted jump result of the branch instruction predictor for the target branch instruction is incorrect, the operation of reallocating new entries can be performed to improve the branch prediction accuracy of the branch instruction predictor. In addition, the predicted jump result of the branch instruction predictor corresponding to the target branch instruction is more dependent on the tag sub-predictor with the longest history length in the branch instruction predictor, that is, the above-mentioned first tag sub-predictor. Therefore, the prediction result of this first tag sub-predictor may also be one of the judgment conditions. Among them, to determine whether the predicted jump result of the branch instruction predictor corresponding to the target branch instruction is correct, it can be achieved by comparing the predicted jump result with the actual jump result.

[0116] Furthermore, in the specific implementation process, the branch instruction predictor can be informed whether a new entry allocation operation is required by setting an allocation flag, that is: obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the actual jump result of the target branch instruction; when the actual jump result and the predicted jump result are inconsistent, and the predicted jump result is not the prediction result of the first tag sub-predictor, set the allocation flag to 1; when the actual jump result and the predicted jump result are consistent, and / or the predicted jump result is the prediction result of the first tag sub-predictor, set the allocation flag to 0. Thus, the branch instruction predictor can determine whether to continue to perform the new entry allocation operation according to the value of the allocation flag. Obviously, when the allocation flag is 1, the new entry allocation operation needs to be performed; when the allocation flag is 0, the new entry allocation operation does not need to be performed.

[0117] To further ensure the branch prediction accuracy of the branch instruction predictor, before determining that the allocation flag is 1 and the new entry allocation operation needs to be performed, and before actually performing the new entry allocation operation, it can be first determined whether the allocation flag needs to be updated to ensure that the branch instruction predictor can obtain an accurate allocation flag, so as to determine whether to perform the subsequent new entry allocation operation to further improve the accuracy.

[0118] Based on this, in a possible implementation, when the actual jump result is inconsistent with the predicted jump result, and the predicted jump result is not the prediction result of the first label sub-predictor, before determining the target sub-predictor corresponding to the predicted jump result as described above, it may further include: when the target branch instruction hits a label sub-predictor in the branch instruction predictor and the entry corresponding to the hit label sub-predictor is a pseudo-entry, updating the allocation flag; when the target branch instruction does not hit a label sub-predictor in the branch instruction predictor, or the entry corresponding to the hit label sub-predictor is not a pseudo-entry, not updating the allocation flag. Among them, the process of updating the allocation flag includes: when the prediction result of the first label sub-predictor is inconsistent with the actual jump result, the value of the allocation flag remains unchanged; when the prediction result of the first label sub-predictor is consistent with the actual jump result, setting the allocation flag to 0.

[0119] In an embodiment of the present invention, in the order of increasing numbers, new entries are sequentially allocated to sub-predictors with numbers not lower than the random number until the allocation quantity reaches a preset threshold, and it may further include:

[0120] Determining the hit result of the target branch instruction in the branch instruction predictor;

[0121] Updating the entries corresponding to the basic sub-predictor and / or each label sub-predictor according to the hit result.

[0122] The new entry allocation method provided by the embodiments of the present invention can also implement the function of updating the entries after new entry allocation, that is, the entries corresponding to the basic sub-predictor and / or each label sub-predictor in the branch instruction predictor can be updated according to the hit result of the target branch instruction and the branch instruction predictor. Among them, the hit result of the target branch instruction in the branch instruction predictor is the sub-predictor hit by the target branch instruction in the branch instruction predictor, and may be the basic sub-predictor and / or one or more label sub-predictors.

[0123] Among them, updating the entries corresponding to the basic sub-predictor and / or each label sub-predictor according to the hit result may include: when the hit result is that the target branch instruction does not hit a label sub-predictor, updating the entry corresponding to the basic sub-predictor; when the hit result is that the target branch instruction hits a label sub-predictor, updating the entry corresponding to the hit label sub-predictor. In other words, the entry to be updated is the entry corresponding to the sub-predictor hit by the target branch instruction in the branch instruction predictor.

[0124] Further, updating the entry corresponding to the hit tag sub-predictor may include: updating the usefulness counter and the saturation counter in the entry corresponding to the first tag sub-predictor; updating the saturation counter in the entry corresponding to the second tag sub-predictor. It should be noted that the main content of the entry corresponding to each sub-predictor in the branch instruction predictor includes a saturation counter, a usefulness counter, and a tag. The update of the entry mainly refers to updating the values of the saturation counter and the usefulness counter in the entry. The update method is to increment or decrement the values of each counter according to the actual situation until the values exceed the pre-set threshold range. Generally, when the prediction result of the hit sub-predictor is consistent with the true jump result of the target branch instruction, an increment operation is performed; when the prediction result of the hit sub-predictor is inconsistent with the true jump result of the target branch instruction, a decrement operation is performed. In addition, the pre-set threshold range does not affect the implementation of the technical solution of the present invention and can be set according to the actual situation. The present invention does not limit this.

[0125] In an embodiment of the present invention, taking the TAGE predictor as an example, another method for allocating new entries in a branch instruction predictor is provided.

[0126] First, please refer to Figure 2 , Figure 2 which is a schematic flow chart of a branch instruction prediction method based on a branch instruction predictor provided by an embodiment of the present invention, and its implementation process is as follows:

[0127] 1. When a branch instruction is received, determine whether the branch instruction hits the tag sub-predictor in the TAGE predictor by calculating the branch instruction index and the indices of each sub-predictor in the TAGE predictor.

[0128] 2. When the branch instruction does not hit the tag sub-predictor in the TAGE predictor, directly use the prediction result of the base sub-predictor as the final predicted jump result of the branch instruction.

[0129] 3. When the branch instruction hits the tag sub-predictor in the TAGE predictor:

[0130] (1) Determine the tag sub-predictor with the longest history length (i.e., the first tag sub-predictor) among all the hit tag sub-predictors, and use its prediction result as the longest hit result longestMatchPred, that is, the first prediction result;

[0131] (2) Determine whether the branch instruction hits the tag sub-predictor with the second-longest history length (i.e., the second sub-predictor). If so, use its prediction result as the alternative result altTaken, that is, the second prediction result; if not, use the prediction result of the base sub-predictor as the alternative result altTaken, that is, the second prediction result;

[0132] (3) When the entry corresponding to the tag sub-predictor with the longest history length that is hit is a pseudo-newly allocated entry and the alternative flag useAltPredForNewlyAllocated is greater than zero, the alternative result altTaken is used as the final predicted jump result of the branch instruction;

[0133] (4) When the entry corresponding to the tag sub-predictor with the longest history length that is hit is not a pseudo-newly allocated entry, and / or the alternative flag useAltPredForNewlyAllocated is not greater than zero, the longest hit result longestMatchPred is used as the final predicted jump result of the branch instruction.

[0134] Further, please refer to Figure 3 , Figure 3 which is a schematic flowchart of a method for updating entries in a branch instruction predictor provided by an embodiment of the present invention, and its implementation process is as follows:

[0135] 1. Obtain the true jump result of the branch instruction.

[0136] 2. Initialize the allocation flag alloc: If the predicted jump result of the branch instruction by the TAGE predictor is inconsistent with the true jump result, and the hit sub-predictor of the branch instruction in the TAGE predictor is not the tag sub-predictor with the longest history length, then set the allocation flag alloc to 1, and a new entry needs to be allocated; otherwise, set the allocation flag alloc to 0, and no new entry needs to be allocated.

[0137] 3. Update the allocation flag alloc and the alternative flag useAltPredForNewlyAllocated:

[0138] When the hit sub-predictor of the branch instruction in the TAGE predictor is a tag sub-predictor and the entry corresponding to the hit tag sub-predictor is a pseudo-newly allocated entry, update the allocation flag alloc and the alternative flag useAltPredForNewlyAllocated, otherwise do not update. Among them, the implementation process of updating the allocation flag alloc and the alternative flag useAltPredForNewlyAllocated may include:

[0139] (1) Update the allocation flag alloc: When the longest hit result longestMatchPred is consistent with the true jump result, set the allocation flag alloc to 0, otherwise the allocation flag alloc remains unchanged.

[0140] (2)Update the alternative flag useAltPredForNewlyAllocated: When the longest match prediction longestMatchPred is different from the alternative result altTaken, the alternative flag remains unchanged; otherwise, update the alternative flag useAltPredForNewlyAllocated: If the alternative result altTaken is the same as the actual jump result, the alternative flag is incremented until saturation; if the alternative result altTaken is different from the actual jump result, the alternative flag is decremented until saturation.

[0141] 4. Allocate a new table entry: When the allocation flag alloc is 1, allocate a new table entry; when the allocation flag alloc is 0, do not allocate a new table entry.

[0142] 5. Update the table entry:

[0143] (1)When the branch instruction misses the tag sub - predictor in the TAGE predictor, update the saturation counter ctr in the corresponding table entry of the base sub - predictor. When the base sub - predictor predicts correctly, the counter value is incremented until saturation; when the base sub - predictor predicts incorrectly, the counter value is decremented until saturation.

[0144] (2)When the branch instruction hits a tag sub - predictor in the TAGE predictor, update the saturation counter ctr in the corresponding table entry of the tag sub - predictor with the longest history length (the first tag sub - predictor) that is hit. When the first tag sub - predictor predicts correctly, the counter value is incremented until saturation; when the first tag sub - predictor predicts incorrectly, the counter value is decremented until saturation.

[0145] (3)Update the saturation counter ctr in the corresponding table entry of the hit alternative sub - predictor:

[0146] A. If the hit alternative sub - predictor is a tag sub - predictor (this tag sub - predictor is the tag sub - predictor with the secondary history length, i.e., the second tag sub - predictor), then update the saturation counter ctr in the corresponding table entry of this second tag sub - predictor. When the second tag sub - predictor predicts correctly, the counter value is incremented until saturation; when the second tag sub - predictor predicts incorrectly, the counter value is decremented until saturation;

[0147] B. If the hit alternative sub - predictor is not a tag sub - predictor (this tag sub - predictor is the base sub - predictor), then update the saturation counter ctr in the corresponding table entry of this base sub - predictor. When the base sub - predictor predicts correctly, the counter value is incremented until saturation; when the base sub - predictor predicts incorrectly, the counter value is decremented until saturation.

[0148] (4) Update the usefulness counter u in the entry corresponding to the tag sub-predictor (the first tag sub-predictor) with the longest history length that is hit:

[0149] A. When the alternative result is consistent with the predicted jump result, do not update the usefulness counter u in the entry corresponding to the first tag sub-predictor;

[0150] B. When the alternative result is inconsistent with the predicted jump result, update the usefulness counter u in the entry corresponding to the first tag sub-predictor: If the longest hit result is correct, increment the counter value until saturation; if the longest hit result is incorrect, decrement the counter value until saturation.

[0151] Furthermore, regarding the operation of allocating new entries in step 4 above, please refer to Figure 4 , Figure 4 which is a flowchart showing the method for allocating new entries in another branch instruction predictor provided by an embodiment of the present invention, and its implementation process is as follows:

[0152] 1. Determine the relevant parameters input to the TAGE predictor, including the allocation flag alloc, the true jump result of the branch instruction, the values of the usefulness counters in each entry, etc.

[0153] 2. Generate a random number X, where X belongs to [M + 1, M + 3], and M is the number of the target sub-predictor corresponding to the predicted jump result in the TAGE predictor.

[0154] 3. When the allocation flag alloc is 1, search the Xth sub-predictor and all subsequent sub-predictors to determine whether an entry with a usefulness counter value of 0 is found.

[0155] 4. If an entry with a usefulness counter value of 0 is not found, set the usefulness counter in the entry corresponding to the Xth sub-predictor to zero, and allocate new entries one by one to the Xth sub-predictor and subsequent sub-predictors until the total number of sub-predictors to which new entries are allocated reaches the upper limit.

[0156] 5. If an entry with a usefulness counter value of 0 is found, allocate new entries one by one to the Xth sub-predictor and subsequent sub-predictors until the total number of sub-predictors to which new entries are allocated reaches the upper limit.

[0157] 6. Periodic reset: Count the number of times new entries are allocated until the number of times new entries are allocated reaches the upper limit, and then perform a table entry reset. Specifically, the table entry reset pseudo-resets the usefulness counter u in the entry, and shifts its current value one bit to the right, that is, dividing its current value by 2 can achieve the table entry reset.

[0158] It can be seen that in the new entry allocation method in the branch instruction predictor provided by the embodiments of the present invention, the principle followed by the branch instruction predictor when allocating new entries is as follows: when a new entry allocation operation is performed by finding an entry with the shortest branch history length and a useful counter value of 0 in a sub-predictor whose branch history length is longer than that of the target sub-predictor (i.e., the sub-predictor hit by the branch instruction to be measured), and the reason for the failure of the branch instruction predictor to allocate a new entry is that an entry with the shortest branch history length and a useful counter value of 0 cannot be found. Therefore, in the technical solution provided by the present invention, to ensure that a new entry can be successfully allocated in the branch predictor, for the scenario where an entry with the shortest branch history length and a useful counter value of 0 cannot be found, that is, the scenario where an entry with a useful counter value of 0 cannot be retrieved in the sub-predictor with a number not less than the random number, the value of the useful counter in the entry corresponding to the sub-predictor with the number of the random number can be directly forced to 0, ensuring that an entry with the shortest branch history length and a useful counter value of 0 can be found, thereby ensuring the successful allocation of new entries in the branch instruction predictor and further improving the branch prediction accuracy of the branch instruction predictor.

[0159] The embodiments of the present invention provide a new entry allocation device in a branch instruction predictor.

[0160] Please refer to Figure 5 , Figure 5 which is a structural schematic diagram of a new entry allocation device in a branch instruction predictor provided by the present invention. The new entry allocation device in the branch instruction predictor may include:

[0161] An acquisition module 1, configured to acquire a predicted jump result of the branch instruction predictor for a target branch instruction, and determine a target sub-predictor corresponding to the predicted jump result;

[0162] A generation module 2, configured to generate a random number according to the number of the target sub-predictor in the branch instruction predictor;

[0163] A retrieval module 3, configured to retrieve sub-predictors with numbers not less than the random number in the branch instruction predictor to determine whether there is an entry with a useful counter value of 0 in each sub-predictor;

[0164] A first allocation module 4, configured to, if there is an entry, allocate new entries to sub-predictors with numbers not less than the random number in ascending order of numbers until the allocation quantity reaches a preset threshold;

[0165] The second allocation module 5 is configured to, if there is no entry, set the value of the usefulness counter in the entry corresponding to the sub-predictor with the random number as the number to 0, so as to sequentially allocate new entries to the sub-predictors with numbers not less than the random number in ascending order of the numbers until the allocation quantity reaches a preset threshold.

[0166] It can be seen that for the new entry allocation device in the branch instruction predictor provided by the embodiment of the present invention, since the principle followed by the branch instruction predictor when allocating new entries is: perform the new entry allocation operation when finding the entry with the shortest branch history length and the value of the usefulness counter in the entry being 0 among the sub-predictors with a branch history length longer than the target sub-predictor (i.e., the sub-predictor hit by the branch instruction to be measured), and the reason for the failure of the branch instruction predictor to allocate new entries is that it fails to find the entry with the shortest branch history length and the value of the usefulness counter in the entry being 0. Therefore, in the technical solution provided by the present invention, to ensure successful allocation of new entries in the branch predictor, for the scenario where the entry with the shortest branch history length and the value of the usefulness counter in the entry being 0 cannot be found, that is, the scenario where no entry with the value of the usefulness counter being 0 is retrieved in the sub-predictors with numbers not less than the random number, the value of the usefulness counter in the entry corresponding to the sub-predictor with the random number as the number can be directly forced to be 0 to ensure that the entry with the shortest branch history length and the value of the usefulness counter in the entry being 0 can be found, thereby ensuring successful allocation of new entries in the branch instruction predictor and further improving the branch prediction accuracy of the branch instruction predictor.

[0167] In an embodiment of the present invention, the above-mentioned acquisition module 1 may include:

[0168] The first determination unit is configured to determine the prediction results of each sub-predictor in the branch instruction predictor for the target branch instruction;

[0169] The second determination unit is configured to determine the predicted jump result of the branch instruction predictor for the target branch instruction according to each prediction result.

[0170] In an embodiment of the present invention, the branch instruction predictor includes 1 basic sub-predictor and multiple tag sub-predictors; the above-mentioned second determination unit may include:

[0171] The determination subunit is configured to determine the index information of the target branch instruction;

[0172] The judgment subunit is configured to judge whether the target branch instruction hits the tag sub-predictor according to the index information.

[0173] The first setting subunit is configured to, when the target branch instruction hits the label sub-predictor and the number of hits is not unique, use the prediction result of the first label sub-predictor with the longest history length among the hits as the first prediction result, and use the prediction result of the second label sub-predictor with the secondary history length among the hits as the second prediction result;

[0174] The second setting subunit is configured to, when the target branch instruction hits the label sub-predictor and the number of hits is unique, use the prediction result of the first label sub-predictor with the longest history length among the hits as the first prediction result, and use the prediction result of the base sub-predictor as the second prediction result;

[0175] The third setting subunit is configured to, when the entry corresponding to the first label sub-predictor is a pseudo-entry and the alternative flag is not 0, use the second prediction result as the predicted jump result of the target branch instruction;

[0176] The fourth setting subunit is configured to, when the entry corresponding to the first label sub-predictor is not a pseudo-entry and / or the alternative flag is 0, use the first prediction result as the predicted jump result of the target branch instruction;

[0177] The fifth setting subunit is configured to, when the target branch instruction does not hit the label sub-predictor, use the prediction result of the base sub-predictor as the predicted jump result of the target branch instruction.

[0178] In an embodiment of the present invention, the above-mentioned judgment subunit may specifically be configured to, for each label sub-predictor in the branch instruction predictor, determine the index value of the label sub-predictor according to the program counter value, folded history, and history path of the label sub-predictor; according to the index information of the target branch instruction and the index values of each label sub-predictor, determine whether the target branch instruction hits the label sub-predictor in the branch instruction predictor.

[0179] In an embodiment of the present invention, the above-mentioned judgment subunit may specifically be configured to perform a hash calculation on the program counter value, folded history, and history path of the label sub-predictor to obtain a hash value; use the hash value as the index value of the label sub-predictor.

[0180] In an embodiment of the present invention, the above-mentioned obtaining module 1 may specifically be configured to obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the actual jump result of the target branch instruction; when the actual jump result and the predicted jump result are inconsistent, and the predicted jump result is not the prediction result of the first label sub-predictor, determine the target sub-predictor corresponding to the predicted jump result; when the actual jump result and the predicted jump result are consistent, and / or the predicted jump result is the prediction result of the first label sub-predictor, wait for the predicted jump result of the next branch instruction.

[0181] In an embodiment of the present invention, the new entry allocation device in the branch instruction predictor may further include an update module, which is configured to sequentially allocate new entries to sub-predictors with numbers not lower than a random number in ascending order of the numbers until the allocation quantity reaches a preset threshold, and then determine the hit result of the target branch instruction in the branch instruction predictor; and update the entries corresponding to the basic sub-predictor and / or each tag sub-predictor according to the hit result.

[0182] In an embodiment of the present invention, the above update module may include:

[0183] A first update subunit, which is configured to update the entry corresponding to the basic sub-predictor when the hit result is that the target branch instruction misses the tag sub-predictor;

[0184] A second update subunit, which is configured to update the entry corresponding to the hit tag sub-predictor when the hit result is that the target branch instruction hits the tag sub-predictor.

[0185] In an embodiment of the present invention, the above second update subunit may specifically be configured to update the usefulness counter and the saturation counter in the entry corresponding to the first tag sub-predictor; and update the saturation counter in the entry corresponding to the second tag sub-predictor.

[0186] In an embodiment of the present invention, the new entry allocation device in the branch instruction predictor may further include a reset module, which is configured to sequentially allocate new entries to sub-predictors with numbers not lower than a random number in ascending order of the numbers until the allocation quantity reaches a preset threshold, and then count the number of new entry allocations, and determine whether the number of new entry allocations reaches a preset number; when the number of new entry allocations does not reach the preset number, wait for the next branch instruction as the target branch instruction, and return to the step of obtaining the predicted jump result of the branch instruction predictor for the target branch instruction; when the number of new entry allocations reaches the preset number, reset the entries corresponding to all tag sub-predictors in the branch instruction predictor.

[0187] In an embodiment of the present invention, the above reset module may specifically be configured to, for each tag sub-predictor in the branch instruction predictor, determine the current value of the usefulness counter in the entry corresponding to the tag sub-predictor; shift the current value one bit to the right to implement resetting the entry corresponding to the tag sub-predictor.

[0188] For the introduction of the device provided in the embodiment of the present invention, please refer to the above method embodiment, and the present invention will not be elaborated herein.

[0189] The embodiment of the present invention provides an electronic device.

[0190] Please refer to Figure 6 , Figure 6Schematic diagram of the structure of an electronic device provided by the present invention. The electronic device may include:

[0191] A memory 11 for storing computer programs;

[0192] A processor 10, which can implement the steps of the new entry allocation method in any of the above branch instruction predictors when executing a computer program.

[0193] As Figure 6 shown, it is a schematic diagram of the composition structure of an electronic device. The electronic device may include: a processor 10, a memory 11, a communication interface 12, and a communication bus 13. The processor 10, the memory 11, and the communication interface 12 all complete communication with each other through the communication bus 13.

[0194] In an embodiment of the present invention, the processor 10 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array, or other programmable logic devices, etc.

[0195] The processor 10 can call the program stored in the memory 11. Specifically, the processor 10 can execute the operations in the embodiment of the new entry allocation method in the branch instruction predictor.

[0196] The memory 11 is used to store one or more programs. The program may include program code, and the program code includes computer operation instructions. In an embodiment of the present invention, the memory 11 stores at least a program for implementing the following functions:

[0197] Obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the target sub-predictor corresponding to the predicted jump result;

[0198] Generate a random number according to the number of the target sub-predictor in the branch instruction predictor;

[0199] In the branch instruction predictor, retrieve the sub-predictors with numbers not lower than the random number to determine whether there is an entry with a usage counter value of 0 in each sub-predictor;

[0200] If there is an entry, allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches a preset threshold;

[0201] If there is no entry, set the value of the usage counter in the entry corresponding to the sub-predictor with the random number to 0, so as to allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of the numbers until the allocation quantity reaches a preset threshold.

[0202] In a possible implementation, the memory 11 may include a program storage area and a data storage area. The program storage area may store an operating system and application programs required for at least one function, etc.; the data storage area may store data created during use.

[0203] In addition, the memory 11 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device or other volatile solid-state storage devices.

[0204] The communication interface 12 may be an interface of a communication module for connecting to other devices or systems.

[0205] Of course, it should be noted that Figure 6 the structure shown does not limit the electronic device in the embodiments of the present invention. In actual applications, the electronic device may include more or fewer components than Figure 6 those shown, or combine certain components.

[0206] The embodiments of the present invention provide a computer-readable storage medium.

[0207] The computer program stored on the computer-readable storage medium provided by the embodiments of the present invention, when executed by a processor, can implement the steps of the new entry allocation method in any of the above branch instruction predictors.

[0208] Among them, the computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or a data center that integrates one or more available media. For example, it may be various media that can store computer program codes, such as magnetic media (such as floppy disks, hard disks, magnetic tapes, etc.), optical media (such as DVDs), or semiconductor media (such as solid-state drives).

[0209] For the introduction of the computer-readable storage medium provided by the embodiments of the present invention, please refer to the above method embodiments, and the present invention will not be elaborated here.

[0210] The embodiments of the present invention provide a computer program product.

[0211] The computer program product provided by the embodiments of the present invention includes computer programs / instructions, and when the computer programs / instructions are executed by a processor, they can implement the steps of the new entry allocation method in any of the above branch instruction predictors.

[0212] Specifically, in the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product.

[0213] Among them, the computer program product may include one or more computer programs / instructions. When the computer program / instructions are loaded and executed on a computer, they can wholly or partly generate the processes or functions described in the embodiments of the present invention. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line, etc.) or wirelessly (such as infrared, wireless, microwave, etc.).

[0214] For the introduction of the computer program product provided in the embodiments of the present invention, please refer to the above method embodiments, and the present invention will not be elaborated herein.

[0215] The technical solutions provided by the present invention have been introduced in detail above. Specific examples are used herein to illustrate the principles and implementation manners of the present invention. The description of the above embodiments is only for helping to understand the method and its core idea of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can still be made to the present invention, and these improvements and modifications also fall within the protection scope of the present invention.

Claims

1. A new table entry allocation method in a branch instruction predictor, characterized in that, Including: Obtain the predicted jump result of the target branch instruction by the branch instruction predictor, and determine the target sub-predictor corresponding to the predicted jump result; Generate a random number according to the number of the target sub-predictor in the branch instruction predictor; In the branch instruction predictor, retrieve the sub-predictors with numbers not lower than the random number to determine whether there is an entry in each sub-predictor with the value of the utility counter being 0; the utility counter is the u-bit in the entry; If there is such an entry, allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of numbers until the allocation quantity reaches a preset threshold; If there is no such entry, set the value of the utility counter in the entry corresponding to the sub-predictor with the number being the random number to 0, so as to allocate new entries to the sub-predictors with numbers not lower than the random number in ascending order of numbers until the allocation quantity reaches the preset threshold.

2. The method for allocating new table entries in the branch instruction predictor according to claim 1, wherein, Obtain the predicted jump result of the target branch instruction by the branch instruction predictor, including: Determine the predicted results of each sub-predictor in the branch instruction predictor for the target branch instruction; Determine the predicted jump result of the branch instruction predictor for the target branch instruction according to each predicted result.

3. The method for allocating new table entries in the branch instruction predictor according to claim 2, wherein The branch instruction predictor includes 1 basic sub-predictor and multiple tag sub-predictors; Determine the predicted jump result of the branch instruction predictor for the target branch instruction according to each predicted result, including: Determine the index information of the target branch instruction; Judge whether the target branch instruction hits the tag sub-predictor according to the index information; When the target branch instruction hits the tag sub-predictor and the number of hits is not unique, use the predicted result of the first tag sub-predictor with the longest history length among the hits as the first predicted result, and use the predicted result of the second tag sub-predictor with the secondary history length among the hits as the second predicted result; When the target branch instruction hits the tag sub-predictor and the number of hits is unique, use the predicted result of the first tag sub-predictor with the longest history length among the hits as the first predicted result, and use the predicted result of the basic sub-predictor as the second predicted result; When the entry corresponding to the first tag sub-predictor is a pseudo-entry and the alternative flag is not 0, use the second predicted result as the predicted jump result of the target branch instruction; When the entry corresponding to the first tag sub-predictor is not a pseudo-entry and / or the alternative flag is 0, use the first predicted result as the predicted jump result of the target branch instruction; When the target branch instruction does not hit the tag sub-predictor, use the predicted result of the basic sub-predictor as the predicted jump result of the target branch instruction.

4. The method for allocating new table entries in the branch instruction predictor according to claim 3, characterized in that, Judge whether the target branch instruction hits the tag sub-predictor according to the index information, including: For each tag sub-predictor in the branch instruction predictor, determine the index value of the tag sub-predictor according to the program counter value, folded history, and history path of the tag sub-predictor; Based on the index information of the target branch instruction and the index values of each of the tag sub - predictors, determine whether the target branch instruction hits the tag sub - predictor in the branch instruction predictor.

5. The method for allocating a new table entry in the branch instruction predictor according to claim 4, characterized in that, Determine the index value of the tag sub - predictor according to the program counter value, folded history, and historical path of the tag sub - predictor, including: Perform a hash calculation on the program counter value, the folded history, and the historical path of the tag sub - predictor to obtain a hash value; Use the hash value as the index value of the tag sub - predictor.

6. The method for allocating a new table entry in the branch instruction predictor according to claim 3, wherein Obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the target sub - predictor corresponding to the predicted jump result, including: Obtain the predicted jump result of the branch instruction predictor for the target branch instruction, and determine the actual jump result of the target branch instruction; When the actual jump result is inconsistent with the predicted jump result, and the predicted jump result is not the prediction result of the first tag sub - predictor, determine the target sub - predictor corresponding to the predicted jump result; When the actual jump result is consistent with the predicted jump result, and / or the predicted jump result is the prediction result of the first tag sub - predictor, wait for the predicted jump result of the next branch instruction.

7. The method for allocating new table entries in the branch instruction predictor according to claim 3, wherein In the order of increasing numbers, sequentially allocate new table entries to the sub - predictors with numbers not less than the random number until the allocation quantity reaches a preset threshold. After that, it also includes: Determine the hit result of the target branch instruction in the branch instruction predictor; Update the table entries corresponding to the base sub - predictor and / or each of the tag sub - predictors according to the hit result.

8. The method for allocating a new table entry in the branch instruction predictor according to claim 7, wherein Update the table entries corresponding to the base sub - predictor and / or each of the tag sub - predictors according to the hit result, including: When the hit result is that the target branch instruction does not hit the tag sub - predictor, update the table entry corresponding to the base sub - predictor; When the hit result is that the target branch instruction hits the tag sub - predictor, update the table entry corresponding to the hit tag sub - predictor.

9. The method for allocating new table entries in the branch instruction predictor according to claim 8, characterized in that, Update the table entry corresponding to the hit tag sub - predictor, including: Update the usefulness counter and the saturation counter in the table entry corresponding to the first tag sub - predictor; Update the saturation counter in the table entry corresponding to the second tag sub - predictor.

10. The method for allocating new table entries in the branch instruction predictor according to claim 3, wherein In the order of increasing numbers, sequentially allocate new table entries to the sub - predictors with numbers not less than the random number until the allocation quantity reaches a preset threshold. After that, it also includes: Count the number of new table entry allocations, and determine whether the number of new table entry allocations reaches a preset number; When the number of new table entry allocations does not reach the preset number, wait for the next branch instruction as the target branch instruction, and return to the step of obtaining the predicted jump result of the branch instruction predictor for the target branch instruction; When the number of new table entry allocations reaches the preset number, reset the table entries corresponding to all the tag sub - predictors in the branch instruction predictor.

11. The method for allocating a new table entry in the branch instruction predictor according to claim 10, characterized in that, Reset the table entries corresponding to all the tag sub - predictors in the branch instruction predictor, including: For each tag sub - predictor in the branch instruction predictor, determine the current value of the usefulness counter in the table entry corresponding to the tag sub - predictor; Shift the current value one bit to the right to reset the table entry corresponding to the tag sub - predictor.

12. A new table entry allocation device in a branch instruction predictor, characterized in that, Comprising: An acquisition module, configured to acquire the predicted jump result of the branch instruction predictor for a target branch instruction and determine the target sub - predictor corresponding to the predicted jump result; A generation module, configured to generate a random number according to the number of the target sub - predictor in the branch instruction predictor; A retrieval module, configured to retrieve, in the branch instruction predictor, sub - predictors with numbers not less than the random number to determine whether there is a table entry with a usefulness counter value of 0 in each of the sub - predictors; the usefulness counter is the u - bit in the table entry; A first allocation module, configured to, if there is such a table entry, sequentially allocate new table entries to sub - predictors with numbers not less than the random number in ascending order of numbers until the allocation quantity reaches a preset threshold; A second allocation module, configured to, if there is no such table entry, set the value of the usefulness counter in the table entry corresponding to the sub - predictor with the number of the random number to 0, so as to sequentially allocate new table entries to sub - predictors with numbers not less than the random number in ascending order of numbers until the allocation quantity reaches the preset threshold.

13. An electronic device, characterized in that, Comprising: A memory, configured to store a computer program; A processor, configured to implement the steps of the method for allocating new table entries in the branch instruction predictor according to any one of claims 1 to 11 when executing the computer program.

14. A computer-readable storage medium, characterized in that, A computer program is stored on the computer - readable storage medium, and when the computer program is executed by a processor, the steps of the method for allocating new table entries in the branch instruction predictor according to any one of claims 1 to 11 are implemented.

15. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by a processor, the steps of the method for allocating new table entries in the branch instruction predictor according to any one of claims 1 to 11 are implemented.

Citation Information

Patent Citations

  • Hybrid branch prediction device and method for out-of-order high-performance cores

    CN111078295A

  • New table item distribution method for TAGE branch predictor

    CN113703846A