New table item distribution method and device in branch instruction predictor, equipment and medium

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

CN120010927AActive Publication Date: 2025-05-16SHANDONG BOSUAN ZHIXIN INFORMATION TECHNOLOGY CO LTD
View PDF 11 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing TAGE branch predictor fails when allocating new table entries, resulting in low branch prediction accuracy.

Method used

By obtaining the prediction jump result of the branch instruction predictor, the target subpredictor is determined, and a random number is generated for retrieving the subpredictor. If there is a table entry with the value of 0 for the usefulness counter, the new table entry will be allocated in the order of the number from small to large; if it does not exist, the usefulness counter of the corresponding table entry will be set to 0 for allocation.

Benefits of technology

Ensure that new table entries are successfully allocated in the branch instruction predictor, and improve the branch prediction accuracy of the TAGE predictor.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120010927A_ABST
    Figure CN120010927A_ABST
Patent Text Reader

Abstract

The invention discloses a new table item distribution method and device in a branch instruction predictor, equipment and a medium, relates to the field of computers, and is used for solving the problem that the branch prediction accuracy is low due to the fact that an existing branch instruction predictor cannot guarantee successful implementation of new table item distribution. The method comprises the steps of obtaining a prediction jump result of a branch instruction predictor to a target branch instruction and a corresponding target sub-predictor; generating a random number according to the number of the target sub-predictor in the branch instruction predictor; the sub-predictors with the serial numbers not lower than the random numbers are retrieved, and whether table items with the value of the usefulness counter being 0 exist in all the sub-predictors or not is judged; if not, setting the value of the usefulness counter in the table item corresponding to the sub-predictor with the serial number as the random number to be 0, so as to sequentially allocate new table items to the sub-predictors with the serial numbers not lower than the random number according to the sequence of the serial numbers from small to large until the allocation quantity reaches a preset threshold value; and if yes, the new table item distribution operation 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 method for allocating new table entries in a branch instruction predictor, and also to 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. Background Art

[0002] To increase the processor's operating speed, modern processors use pipelines for parallel computing, but branch instructions need to wait until the execution stage to determine whether the instruction should jump, which will affect the processor's operating efficiency. 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 a processor encounters a branch instruction, it no longer waits for the branch result, but can directly predict whether the branch instruction will "jump" or "not jump" and the jump target address in the early stage. The purpose is to achieve an uninterrupted instruction flow based on the prediction result, thereby ensuring the operating speed of the processor. The existing branch predictor algorithm is mainly the TAGE (TAggedGEometric history length, tagged geometric series increasing history length) predictor, which can improve the accuracy of the prediction result by allocating new table entries to each internal sub-predictor during the branch prediction process. However, the current method of allocating new table entries in the TAGE predictor has some defects. In some cases, the new table 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 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 method for allocating new table entries in a branch instruction predictor, which 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 object of the present invention is to provide a new table entry allocation device, electronic device, computer-readable storage medium and computer program product in a branch instruction predictor, all of which have the above-mentioned beneficial effects.

[0006] In a first aspect, the present invention provides a method for allocating new table entries in a branch instruction predictor, comprising:

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

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

[0009] In the branch instruction predictor, searching sub-predictors whose numbers are not less than the random number to determine whether there is an entry in each of the sub-predictors whose usefulness counter has a value of 0;

[0010] If the table entry exists, new table entries are allocated to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold;

[0011] If the table entry does not exist, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as the random number is set to 0, so that new table entries are allocated to the sub-predictors with numbers not less than the random number in order from small to large until the allocated number reaches the preset threshold.

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

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

[0014] The predicted jump result of the branch instruction predictor for the target branch instruction is determined according to each of the prediction results.

[0015] Wherein, the branch instruction predictor includes a basic sub-predictor and a plurality of label sub-predictors;

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

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

[0018] Determining 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 hit number is not unique, the prediction result of the hit first label sub-predictor with the longest history length is used as the first prediction result, and the prediction result of the hit second label sub-predictor with the secondary history length is used as the second prediction result;

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

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

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

[0023] When the target branch instruction does not hit the tag sub-predictor, the prediction result of the basic sub-predictor is used as the predicted jump result of the target branch instruction.

[0024] Wherein, judging whether the target branch instruction hits the label sub-predictor according to the index information includes:

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

[0026] According to the index information of the target branch instruction and the index values ​​of each of the label sub-predictors, it is determined whether the target branch instruction hits the label sub-predictor in the branch instruction predictor.

[0027] The step of determining the index value of the label sub-predictor according to the program counter value, the folding history, and the historical path of the label sub-predictor includes:

[0028] Performing hash calculation on the program counter value of the label sub-predictor, the folding history, and the historical path to obtain a hash value;

[0029] The hash value is used as the index value of the label sub-predictor.

[0030] Wherein, obtaining a predicted jump result of a branch instruction predictor for a target branch instruction, and determining a target sub-predictor corresponding to the predicted jump result, comprises:

[0031] Obtaining a predicted jump result of the target branch instruction by the branch instruction predictor, and determining an actual jump result of the target branch instruction;

[0032] When the actual jump result is inconsistent with the predicted jump result, and the predicted jump result is not a predicted result of the first label sub-predictor, determining a target sub-predictor corresponding to the predicted jump result;

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

[0034] The method further comprises: allocating new table entries to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold.

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

[0036] The table entries corresponding to the basic sub-predictor and / or each of the label sub-predictors are updated according to the hit result.

[0037] Wherein, updating the table entries corresponding to the basic sub-predictor and / or each of the label sub-predictors according to the hit result includes:

[0038] When the hit result is that the target branch instruction does not hit the label sub-predictor, updating the table entry corresponding to the basic sub-predictor;

[0039] When the hit result is that the target branch instruction hits the label sub-predictor, the table entry corresponding to the hit label sub-predictor is updated.

[0040] Wherein, updating the table entry corresponding to the hit label sub-predictor includes:

[0041] Updating a usefulness counter and a saturation counter in a table entry corresponding to the first tag sub-predictor;

[0042] The saturation counter in the table entry corresponding to the second label sub-predictor is updated.

[0043] The method further comprises: allocating new table entries to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold.

[0044] Counting the number of new entry allocations, and determining whether the number of new entry allocations reaches a preset number;

[0045] When the number of times the new table entry is allocated does not reach the preset number, waiting for the next branch instruction to be used as the target branch instruction, and returning to the step of obtaining the predicted jump result of the branch instruction predictor for the target branch instruction;

[0046] When the number of times the new table entry is allocated reaches a preset number, the table entries corresponding to all the label sub-predictors in the branch instruction predictor are reset.

[0047] Wherein, resetting the table entries corresponding to all the label sub-predictors in the branch instruction predictor includes:

[0048] For each label sub-predictor in the branch instruction predictor, determining a current value of a usefulness counter in a table entry corresponding to the label sub-predictor;

[0049] The current value is shifted right by one position to reset the table entry corresponding to the label sub-predictor.

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

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

[0052] A generating module, used for generating a random number according to the serial number of the target sub-predictor in the branch instruction predictor;

[0053] A search module, used for searching the sub-predictors with numbers not less than the random number in the branch instruction predictor to determine whether there is a table entry with a usefulness counter value of 0 in each of the sub-predictors;

[0054] A first allocation module, configured to allocate new table entries to the sub-predictors whose numbers are not less than the random number in ascending order if the table entries exist, until the number of allocated entries reaches a preset threshold;

[0055] The second allocation module is used to set the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as the random number to 0 if the table entry does not exist, so as to allocate new table entries to the sub-predictors with numbers not less than the random number in order from small to large until the allocated number reaches the preset threshold.

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

[0057] Memory for storing computer programs;

[0058] A processor is used to implement the steps of any one of the above-mentioned new table entry allocation methods in the branch instruction predictor when executing the computer program.

[0059] In a fourth aspect, the present invention further discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the new table entry allocation method in any branch instruction predictor as described above are implemented.

[0060] In a fifth aspect, the present invention further discloses a computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the new table entry allocation method in any branch instruction predictor as described above.

[0061] The present invention provides a method for allocating new table entries in a branch instruction predictor, comprising: obtaining a predicted jump result of a 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, searching for 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; if the table entry exists, allocating new table entries to the sub-predictors with numbers not less than the random number in order from small to large, until the allocated number reaches a preset threshold; if the table entry does not exist, setting the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as the random number to 0, so that new table entries are allocated to the sub-predictors with numbers not less than the random number in order from small to large, until the allocated number reaches the preset threshold.

[0062] In applying the technical solution provided by the present invention, since the principle followed by the branch instruction predictor when allocating a new table entry is: when a table entry with the shortest branch history length and a usefulness counter value of 0 is found in a sub-predictor with a longer branch history length than the target sub-predictor (i.e., the sub-predictor hit by the tested branch instruction), a new table entry allocation operation is performed, and the reason why the branch instruction predictor fails to allocate a new table entry is that the table entry with the shortest branch history length and a usefulness counter value of 0 is not found. Therefore, in the technical solution provided by the present invention, in order to ensure that the branch instruction predictor can be successfully allocated in the branch predictor, For the scenario where the table entry with the shortest branch history and a usefulness counter value of 0 cannot be found, that is, the scenario where the table entry with a usefulness counter value of 0 is not retrieved in the sub-predictor numbered not less than the random number, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as a random number can be directly forced to be set to 0, ensuring that the table entry with the shortest branch history and a usefulness counter value of 0 can be found, thereby ensuring the successful allocation of new table entries in the branch instruction predictor, further improving the branch prediction accuracy of the branch instruction predictor.

[0063] The new table 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-mentioned technical effects, and the present invention will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] In order to more clearly illustrate the technical solutions in the prior art and the embodiments of the present invention, the drawings required for describing the prior art and the embodiments of the present invention are briefly introduced below. Of course, the drawings related to the embodiments of the present invention below only describe some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without creative work, and the obtained other drawings also belong to the protection scope of the present invention.

[0065] Figure 1 A schematic flow chart of a new table entry allocation method in a branch instruction predictor provided by an embodiment of the present invention;

[0066] Figure 2 A schematic flow chart of a branch instruction prediction method based on a branch instruction predictor provided by an embodiment of the present invention;

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

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

[0069] Figure 5 A schematic diagram of the structure of a new entry allocation device in a branch instruction predictor provided by an embodiment of the present invention;

[0070] Figure 6 The present invention is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0071] The core of the present invention is to provide a method for allocating new table entries in a branch instruction predictor, which 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 new table entry allocation device, electronic device, computer-readable storage medium and computer program product in a branch instruction predictor, all of which have the above-mentioned beneficial effects.

[0072] In order to describe the technical solutions in the embodiments of the present invention more clearly and completely, the technical solutions in the embodiments of the present invention will be introduced below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0073] An embodiment of the present invention provides a method for allocating new table entries in a branch instruction predictor.

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

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

[0076] This step is intended to achieve the prediction jump result of the target branch instruction and the determination of its corresponding target sub-predictor. It can be understood that the target branch instruction is the branch instruction that needs to predict the jump result, 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 contains a basic sub-predictor and multiple tag sub-predictors. The final predicted jump result can be determined by the prediction results of each internal sub-predictor for the target branch instruction. In other words, by synthesizing the prediction results of each sub-predictor in the molecular branch instruction predictor for the target branch instruction, it is determined which sub-predictor has the most accurate prediction result, and the most accurate prediction result is used as the final predicted jump result. Therefore, the target sub-predictor corresponding to the predicted jump result is the branch instruction predictor that can give the most accurate prediction result, that is, the sub-predictor of the final predicted jump result.

[0077] Based on this, in one 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] The predicted jump result of the branch instruction predictor for the target branch instruction is determined according to each prediction result.

[0080] Furthermore, taking a TAGE predictor including one basic sub-predictor and multiple tag sub-predictors as an example, the above-mentioned determination of the predicted jump result of the branch instruction predictor for the target branch instruction according to each prediction result may include:

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

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

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

[0084] When the target branch instruction hits the label sub-predictor and the hit number is unique, the prediction result of the first label sub-predictor with the longest history length 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 table entry corresponding to the first label sub-predictor is a pseudo table entry and the candidate flag is not 0, the second prediction result is used as the predicted jump result of the target branch instruction;

[0086] When the table entry corresponding to the first label sub-predictor is not a pseudo table entry and / or the candidate 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 tag sub-predictor, the prediction result of the base sub-predictor is used as the predicted jump result of the target branch instruction.

[0088] The embodiment of the present invention provides a branch instruction prediction method by taking the TAGE predictor as an example. It can be understood that the branch instruction prediction is implemented based on the TAGE predictor, that is, the branch instruction prediction is implemented based on the basic sub-predictor and each label sub-predictor in the TAGE predictor to obtain the predicted jump result of the target branch instruction. First, the index information of the target branch instruction and the index information of each sub-predictor (including a basic sub-predictor and all label sub-predictors) in the TAGE predictor are determined respectively, and the sub-predictor hit by the target branch instruction can be determined by matching the index information. For the convenience of description, it can be called a hit sub-predictor. It should be pointed out that the number of the hit sub-predictors is not unique, there may be only one or more label sub-predictors, there may be only one basic sub-predictor, and it may also include both the basic sub-predictor and one or more label sub-predictors. Furthermore, when the hit sub-predictor is only a basic 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 a label sub-predictor, it is necessary to combine the history length of each label sub-predictor, the corresponding table entry, and the value of the current alternative flag for comprehensive analysis, wherein the history length is the branch history length of the label sub-predictor. In the implementation process, two prediction results with the highest accuracy can be first selected according to the number of hit label sub-predictors and their respective history lengths, namely the first prediction result (essentially the main selection result) and the second prediction result (essentially the alternative result); then, the final predicted jump result is determined from the two alternative results according to the table entry corresponding to the hit label sub-predictor and the current alternative representation. It should be pointed out that the alternative flag is used to determine whether to use the alternative result (i.e., the second prediction result) as the final predicted jump result when the table entry corresponding to the hit label sub-predictor is a pseudo-new allocation table entry. When its value is 1, the alternative result is used, and when its value is 0, the main selection result is selected.

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

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

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

[0092] Among them, judging 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, determining the index value of the base sub-predictor according to the program counter value of the base sub-predictor may include: performing a shift calculation on the program counter value of the base sub-predictor to obtain a shift result; and using the shift result as the index value of the base sub-predictor.

[0094] This embodiment provides a method for determining index information of a basic sub-predictor. For a basic sub-predictor in a TAGE predictor, a shift calculation can be performed directly on the value of its program counter 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 is intended to realize the generation of random numbers, which are used as sub-predictor numbers in subsequent steps to realize the retrieval of sub-predictors, wherein 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 label sub-predictors, and the numbering method is: the basic sub-predictor is numbered 0, and the remaining label sub-predictors are numbered 1, 2, 3, ..., N according to their respective deployment order in the TAGE predictor (N is the total number of label sub-predictors). Then, the random number generated 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, the random number X is generated 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, search the sub-predictors whose numbers are not less than the random number to determine whether there is an entry in each sub-predictor whose usefulness counter has a value of 0; if not, execute S104; if yes, execute S105.

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

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

[0100] The above steps are intended to achieve new table item allocation through target table item retrieval, wherein the target table item is a table item with a usefulness counter value of 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 the branch history length. Based on this, in the branch instruction predictor, each sub-predictor with a number not less than the random number can be retrieved to determine whether there is a target table item in the table item corresponding to this part of the sub-predictors. If it exists, the new table item allocation operation can be directly executed; if it does not exist, in order to ensure the successful execution of the new table item allocation operation, the value of the usefulness counter in the table item corresponding to the sub-predictor numbered as a random number can be directly forced to be set to 0, that is, the table item corresponding to the sub-predictor numbered as a random number is directly identified as the target table item, ensuring that the target table item can be found in the branch instruction predictor, so as to facilitate the execution of the new table item allocation operation.

[0101] Specifically, the operation of allocating new table entries may be performed as follows: in the branch instruction predictor, in order of numbers from small to large, new table entries are allocated to the sub-predictors whose numbers are not less than the random number, until the number of allocations reaches a preset threshold. It should be noted that the number of allocations is the number of new table entries allocated, starting from the sub-predictor numbered as a random number, and the number of allocations increases by one each time a new table entry of a sub-predictor is successfully allocated. In addition, the value of the preset threshold does not affect the implementation of the present technical solution, and is determined by the performance of the branch instruction predictor itself and its actual processing conditions, and the present invention does not limit this; in one possible implementation, new table 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, allocating new table entries to sub-predictors whose numbers are not less than the random number in order from small to large until the number of allocated entries reaches a preset threshold may also include:

[0103] Count the number of new table item allocations to determine whether the number of new table item allocations reaches a preset number;

[0104] 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;

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

[0106] The present embodiment provides an implementation method for resetting the content of a table entry. Specifically, each time a complete new table entry allocation operation (S101~S105) is performed, the number of new table entry allocations will be recorded; at the same time, the branch instruction predictor is preset with a maximum upper limit on the number of new table entry allocations, that is, the above-mentioned preset number. Therefore, after each complete new table entry allocation operation is completed, it can be determined whether the current number of new table entry allocations has reached the preset number. If it has not reached the preset number, it can continue to wait for the arrival of the next branch instruction to continue processing; if it has reached the preset number, it is necessary to reset the table entries corresponding to all label sub-predictors in the branch instruction predictor. It should be pointed out that the specific value of the above-mentioned preset number does not affect the implementation of the present technical solution, and it can be set according to actual needs, and the present invention does not limit this.

[0107] It is understandable that resetting the table entries in the branch instruction predictor helps provide a "clean" initial state and prevents historical data (residual data of old table entries) from interfering with the context and affecting the branch prediction accuracy of the branch instruction predictor.

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

[0109] It can be seen that the method for allocating new table entries in the branch instruction predictor provided in the embodiment of the present invention is that the principle followed by the branch instruction predictor when allocating new table entries is: when a table entry with the shortest branch history length and a usefulness counter value of 0 is found in a sub-predictor with a longer branch history length than the target sub-predictor (i.e., the sub-predictor hit by the tested branch instruction), a new table entry allocation operation is performed, and the reason why the branch instruction predictor fails to allocate a new table entry is that the table entry with the shortest branch history length and a usefulness counter value of 0 is not found. Therefore, in the technical solution provided by the present invention, in order to ensure that the branch instruction predictor can be used in the branch instruction predictor, the branch instruction predictor can allocate new table entries in the branch instruction predictor. A new table entry is successfully allocated in the branch predictor. For the scenario in which the table entry with the shortest branch history length and a usefulness counter value of 0 cannot be found, that is, the scenario in which the table entry with a usefulness counter value of 0 is not retrieved in the sub-predictor numbered not less than the random number, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as a random number can be directly forced to be set to 0, ensuring that the table entry with the shortest branch history length and a usefulness counter value of 0 can be found, thereby ensuring the successful allocation of new table entries in the branch instruction predictor, and further improving the branch prediction accuracy of the branch instruction predictor.

[0110] Based on the above embodiments:

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

[0112] Obtaining the predicted jump result of the target branch instruction by the branch instruction predictor, and determining 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 predicted result of the first label sub-predictor, determining a target sub-predictor corresponding to the predicted jump result;

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

[0115] The embodiment of the present invention provides a judgment condition for determining whether to perform a new table entry allocation operation. It can be understood that the new table entry allocation operation in the branch instruction predictor is intended to achieve accurate branch instruction prediction by allocating new table 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 reallocation of new table entry operation; and when the predicted jump result of the branch instruction predictor for the target branch instruction is incorrect, the reallocation of new table entry operation 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 label sub-predictor with the longest history length in the branch instruction predictor, that is, the above-mentioned first label sub-predictor. Therefore, the prediction result of the first label sub-predictor may also become one of the judgment conditions. Among them, judging whether the predicted jump result of the branch instruction predictor corresponding to the target branch instruction is correct can be achieved by comparing the predicted jump result with the actual jump result.

[0116] Furthermore, in the specific implementation process, the allocation flag can be set to inform the branch instruction predictor whether a new table entry allocation operation is required, that is: obtain the predicted jump result of the target branch instruction by the branch instruction predictor, 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 predicted result of the first label sub-predictor, the allocation flag is set to 1; when the actual jump result is consistent with the predicted jump result, and / or the predicted jump result is the predicted result of the first label sub-predictor, the allocation flag is set to 0. Thus, the branch instruction predictor can determine whether to continue to perform the new table entry allocation operation according to the value of the allocation flag. Obviously, when the allocation flag is 1, the new table entry allocation operation needs to be performed; when the allocation flag is 0, the new table 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 a new table entry allocation operation needs to be performed, and before actually performing the new table entry allocation operation, it is possible to first determine whether the allocation flag needs to be updated, to ensure that the branch instruction predictor can obtain an accurate allocation flag, thereby determining whether to perform subsequent new table entry allocation operations, to further improve 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 predicted result of the first label sub-predictor, before the above-mentioned determination of the target sub-predictor corresponding to the predicted jump result, it can also include: when the target branch instruction hits the label sub-predictor in the branch instruction predictor, and the table entry corresponding to the hit label sub-predictor is a pseudo-table entry, the allocation flag is updated; when the target branch instruction does not hit the label sub-predictor in the branch instruction predictor, or the table entry corresponding to the hit label sub-predictor is not a pseudo-table entry, the allocation flag is not updated. Among them, the update process of the allocation flag includes: when the prediction result of the first label sub-predictor is inconsistent with the actual jump result, the allocation flag value remains unchanged; when the prediction result of the first label sub-predictor is consistent with the actual jump result, the allocation flag is set to 0.

[0119] In an embodiment of the present invention, allocating new table entries to sub-predictors whose numbers are not less than the random number in order from small to large until the number of allocated entries reaches a preset threshold may also include:

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

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

[0122] The new table entry allocation method provided in the embodiment of the present invention can also realize the table entry update function after the new table entry is allocated, that is, the table 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 in the target branch instruction and the branch instruction predictor. Among them, the hit result of the target branch instruction in the branch instruction predictor, that is, the sub-predictor hit by the target branch instruction in the branch instruction predictor, may be the basic sub-predictor and / or one or more label sub-predictors.

[0123] Wherein, updating the table 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 the label sub-predictor, updating the table entry corresponding to the basic sub-predictor; when the hit result is that the target branch instruction hits the label sub-predictor, updating the table entry corresponding to the hit label sub-predictor. In other words, the table entry that needs to be updated is the table entry corresponding to the sub-predictor hit by the target branch instruction in the branch instruction predictor.

[0124] Furthermore, updating the table entry corresponding to the hit label sub-predictor may include: updating the usefulness counter and the saturation counter in the table entry corresponding to the first label sub-predictor; updating the saturation counter in the table entry corresponding to the second label sub-predictor. It should be noted that the table entry corresponding to each sub-predictor in the branch instruction predictor mainly includes a saturation counter, a usefulness counter and a label. The table entry update mainly refers to updating the values ​​of the saturation counter and the usefulness counter in the table entry. The update method is to add or subtract one to the value of each counter according to the actual situation until it exceeds the preset threshold interval. Generally speaking, when the prediction result of the hit sub-predictor is consistent with the actual jump result of the target branch instruction, the addition operation is performed; when the prediction result of the hit sub-predictor is inconsistent with the actual jump result of the target branch instruction, the subtraction operation is performed. In addition, the preset threshold interval does not affect the implementation of the present technical solution, and it can be set according to the actual situation, and the present invention does not limit this.

[0125] The embodiment of the present invention takes the TAGE predictor as an example and provides another method for allocating new table entries in a branch instruction predictor.

[0126] First, please refer to Figure 2 , Figure 2 A schematic flow chart of a branch instruction prediction method based on a branch instruction predictor provided by an embodiment of the present invention, the implementation process of which 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 sub-predictor indexes in the TAGE predictor.

[0128] 2. When the branch instruction misses the tag sub-predictor in the TAGE predictor, the prediction result of the base sub-predictor is directly used as the final predicted jump result of the branch instruction.

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

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

[0131] (2) Determine whether the branch instruction hits the label 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, i.e., the second prediction result; if not, use the prediction result of the base sub-predictor as the alternative result altTaken, i.e., the second prediction result;

[0132] (3) When the entry corresponding to the hit label sub-predictor with the longest history length 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 hit label sub-predictor with the longest history length 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] For further information, please refer to Figure 3 , Figure 3 A schematic flow chart of a method for updating table entries in a branch instruction predictor provided by an embodiment of the present invention, the implementation process of which is as follows:

[0135] 1. Get the actual jump result of the branch instruction.

[0136] 2. Initialization of the allocation flag alloc: If the predicted jump result of the TAGE predictor for the branch instruction is inconsistent with the actual jump result, and the hit sub-predictor of the branch instruction in the TAGE predictor is not the label sub-predictor with the longest history length, then set the allocation flag alloc to 1, and a new table entry needs to be allocated; otherwise, set the allocation flag alloc to 0, and no new table 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 the label sub-predictor, and the table entry corresponding to the hit label sub-predictor is a pseudo-new allocation table entry, the allocation flag alloc and the alternative flag useAltPredForNewlyAllocated are updated, otherwise they are not updated. 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 actual 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 hit result 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 consistent with the actual jump result, the alternative flag is increased by 1 until saturation; if the alternative result altTaken is inconsistent with the actual jump result, the alternative flag is decreased by 1 until saturation.

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

[0142] 5. Update table items:

[0143] (1) When a branch instruction does not hit the tag sub-predictor in the TAGE predictor, the saturation counter ctr in the table entry corresponding to the base sub-predictor is updated. When the base sub-predictor predicts correctly, the counter value increases by one until it is saturated; when the base sub-predictor predicts incorrectly, the counter value decreases by one until it is saturated.

[0144] (2) When a branch instruction hits a label sub-predictor in the TAGE predictor, the saturation counter ctr in the table entry corresponding to the label sub-predictor with the longest history length (the first label sub-predictor) is updated. When the first label sub-predictor predicts correctly, the counter value is increased by one until it is saturated; when the first label sub-predictor predicts incorrectly, the counter value is decreased by one until it is saturated.

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

[0146] A. If the candidate sub-predictor that hits is a label sub-predictor (the label sub-predictor is a label sub-predictor with a secondary history length, i.e., a second label sub-predictor), then update the saturation counter ctr in the corresponding table entry of the second label sub-predictor. When the second label sub-predictor predicts correctly, the counter value increases by one until it is saturated; when the second label sub-predictor predicts incorrectly, the counter value decreases by one until it is saturated.

[0147] B. If the hit candidate sub-predictor is not the label sub-predictor (the label sub-predictor is the basic sub-predictor), the saturation counter ctr in the corresponding table entry of the basic sub-predictor is updated. When the basic sub-predictor predicts correctly, the counter value is increased by one until it is saturated; when the basic sub-predictor predicts incorrectly, the counter value is decreased by one until it is saturated.

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

[0149] A. When the candidate result is consistent with the predicted jump result, the usefulness counter u in the corresponding table entry of the first label sub-predictor is not updated;

[0150] B. When the alternative result is inconsistent with the predicted jump result, update the usefulness counter u in the corresponding table entry of the first label sub-predictor: if the longest hit result is correct, the counter value is increased by one until saturation; if the longest hit result is incorrect, the counter value is reduced by one until saturation.

[0151] For more information about the new table entry allocation operation in step 4 above, please refer to Figure 4 , Figure 4 A schematic flow chart of another method for allocating new table entries in a branch instruction predictor provided by an embodiment of the present invention, the implementation process of which is as follows:

[0152] 1. Determine the relevant parameters input to the TAGE predictor, including the allocation flag alloc, the actual jump result of the branch instruction, the usefulness counter value in each table 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, the Xth sub-predictor and all subsequent sub-predictors are searched to determine whether a table entry with a usefulness counter value of 0 is retrieved.

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

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

[0157] 6. Periodic reset: count the number of new table item allocations until the number of new table item allocations reaches the upper limit, and then reset the table item. The table item reset specifically resets the usefulness counter u in the pseudo-reset table item, shifts its current value right by one position, and divides its current value by 2 to achieve the table item reset.

[0158] It can be seen that the method for allocating new table entries in the branch instruction predictor provided in the embodiment of the present invention is that the principle followed by the branch instruction predictor when allocating new table entries is: when a table entry with the shortest branch history length and a usefulness counter value of 0 is found in a sub-predictor with a longer branch history length than the target sub-predictor (i.e., the sub-predictor hit by the tested branch instruction), a new table entry allocation operation is performed, and the reason why the branch instruction predictor fails to allocate a new table entry is that the table entry with the shortest branch history length and a usefulness counter value of 0 is not found. Therefore, in the technical solution provided by the present invention, in order to ensure that the new table entry can be allocated in the branch instruction predictor, the branch instruction predictor can allocate a new table entry in the branch instruction predictor. A new table entry is successfully allocated in the branch predictor. For the scenario in which the table entry with the shortest branch history length and a usefulness counter value of 0 cannot be found, that is, the scenario in which the table entry with a usefulness counter value of 0 is not retrieved in the sub-predictor numbered not less than the random number, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as a random number can be directly forced to be set to 0, ensuring that the table entry with the shortest branch history length and a usefulness counter value of 0 can be found, thereby ensuring the successful allocation of the new table entry in the branch instruction predictor, and further improving the branch prediction accuracy of the branch instruction predictor.

[0159] An embodiment of the present invention provides a new table entry allocation device in a branch instruction predictor.

[0160] Please refer to Figure 5 , Figure 5 This is a schematic diagram of the structure 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 is used to acquire a predicted jump result of a branch instruction predictor for a target branch instruction, and determine a target sub-predictor corresponding to the predicted jump result;

[0162] A generating module 2, used for generating a random number according to the number of the target sub-predictor in the branch instruction predictor;

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

[0164] A first allocation module 4 is used to allocate new table entries to the sub-predictors whose numbers are not less than the random number in order from small to large if the table entries exist, until the number of allocated entries reaches a preset threshold;

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

[0166] It can be seen that the new table entry allocation device in the branch instruction predictor provided by the embodiment of the present invention, because the principle followed by the branch instruction predictor when allocating new table entries is: when a table entry with the shortest branch history length and a usefulness counter value of 0 is found in a sub-predictor with a longer branch history length than the target sub-predictor (i.e., the sub-predictor hit by the tested branch instruction), a new table entry allocation operation is performed, and the reason why the branch instruction predictor fails to allocate a new table entry is that the table entry with the shortest branch history length and a usefulness counter value of 0 is not found. Therefore, in the technical solution provided by the present invention, in order to ensure that the branch instruction predictor can be used in the branch instruction predictor, the branch instruction predictor can allocate new table entries. A new table entry is successfully allocated in the branch predictor. For the scenario in which the table entry with the shortest branch history length and a usefulness counter value of 0 cannot be found, that is, the scenario in which the table entry with a usefulness counter value of 0 is not retrieved in the sub-predictor numbered not less than the random number, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as a random number can be directly forced to be set to 0, ensuring that the table entry with the shortest branch history length and a usefulness counter value of 0 can be found, thereby ensuring the successful allocation of new table entries in the branch instruction predictor, and further improving the branch prediction accuracy of the branch instruction predictor.

[0167] In one embodiment of the present invention, the acquisition module 1 may include:

[0168] A first determining unit, used to determine the prediction results of each sub-predictor in the branch instruction predictor for the target branch instruction;

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

[0170] In one embodiment of the present invention, the branch instruction predictor includes one basic sub-predictor and multiple label sub-predictors; the second determination unit may include:

[0171] A determination subunit, used to determine index information of a target branch instruction;

[0172] A judgment subunit, used for judging whether the target branch instruction hits the label sub-predictor according to the index information;

[0173] A first setting subunit is used for, when the target branch instruction hits the label sub-predictor and the hit number is not unique, using the prediction result of the hit first label sub-predictor with the longest history length as the first prediction result, and using the prediction result of the hit second label sub-predictor with the secondary history length as the second prediction result;

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

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

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

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

[0178] In one embodiment of the present invention, the above-mentioned judgment sub-unit can be specifically used to determine the index value of each label sub-predictor in the branch instruction predictor according to the program counter value, folding history, and historical path of the label sub-predictor; and judge whether the target branch instruction hits the label sub-predictor in the branch instruction predictor according to the index information of the target branch instruction and the index values ​​of each label sub-predictor.

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

[0180] In one embodiment of the present invention, the above-mentioned acquisition module 1 can be specifically used 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 is inconsistent with the predicted jump result, and the predicted jump result is not the predicted result of the first label 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 predicted result of the first label sub-predictor, wait for the predicted jump result of the next branch instruction.

[0181] In one embodiment of the present invention, the new table entry allocation device in the branch instruction predictor may also include an update module, which is used to allocate new table entries to the sub-predictors with numbers not less than the random number in the order from small to large, until the allocated number reaches a preset threshold, and then determine the hit result of the target branch instruction in the branch instruction predictor; and update the table entries corresponding to the basic sub-predictor and / or each label sub-predictor according to the hit result.

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

[0183] A first updating subunit, configured to update a table entry corresponding to a basic sub-predictor when a hit result indicates that the target branch instruction does not hit the label sub-predictor;

[0184] The second updating subunit is used to update the table entry corresponding to the hit label sub-predictor when the hit result is that the target branch instruction hits the label sub-predictor.

[0185] In one embodiment of the present invention, the second updating subunit may be specifically used to update the usefulness counter and the saturation counter in the table entry corresponding to the first label sub-predictor; and update the saturation counter in the table entry corresponding to the second label sub-predictor.

[0186] In one embodiment of the present invention, the new table entry allocation device in the branch instruction predictor may also include a reset module, which is used to allocate new table entries to the sub-predictors with numbers not less than the random number in the order from small to large, until the allocation number reaches a preset threshold, count the number of new table entry allocations, and determine whether the number of new table entry allocations reaches the 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 label sub-predictors in the branch instruction predictor.

[0187] In one embodiment of the present invention, the above-mentioned reset module can be specifically used to determine, for each label sub-predictor in the branch instruction predictor, the current value of the usefulness counter in the table entry corresponding to the label sub-predictor; and shift the current value right by one position to reset the table entry corresponding to the label sub-predictor.

[0188] For an introduction to 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 here.

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

[0190] Please refer to Figure 6 , Figure 6This is a schematic diagram of the structure of an electronic device provided by the present invention, and the electronic device may include:

[0191] A memory 11, used for storing computer programs;

[0192] The processor 10 can implement the steps of any of the above-mentioned new table entry allocation methods in the branch instruction predictor when executing a computer program.

[0193] like Figure 6 , which 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 communicate with each other through the communication bus 13.

[0194] In the 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.

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

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

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

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

[0199] In the branch instruction predictor, searching the sub-predictors whose numbers are not less than the random number to determine whether there is an entry in each sub-predictor whose usefulness counter has a value of 0;

[0200] If there are entries, new entries are allocated to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold;

[0201] If there is no table entry, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as a random number is set to 0, so that new table entries are allocated to the sub-predictors with numbers not less than the random number in order from small to large until the allocated number reaches a preset threshold.

[0202] In a possible implementation, the memory 11 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application 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 device.

[0204] The communication interface 12 may be an interface of a communication module, and is used to connect to other devices or systems.

[0205] Of course, it should be noted that Figure 6 The structure shown does not constitute a limitation on the electronic device in the embodiment of the present invention. In actual applications, the electronic device may include Figure 6 More or fewer components than shown, or combinations of certain components.

[0206] An embodiment of the present invention provides a computer-readable storage medium.

[0207] The computer-readable storage medium provided in the embodiment of the present invention stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned methods for allocating new table entries in a branch instruction predictor can be implemented.

[0208] Among them, the computer-readable storage medium can be any available medium that can be stored in a computer or a data storage device such as a server or data center that includes one or more available media integrated. For example, it can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape, etc.), an optical medium (such as a DVD) or a semiconductor medium (such as a solid-state hard disk) and other media that can store computer program codes.

[0209] For an introduction to the computer-readable storage medium provided in an embodiment of the present invention, please refer to the above method embodiment, and the present invention will not elaborate on it here.

[0210] An embodiment of the present invention provides a computer program product.

[0211] The computer program product provided by the embodiment of the present invention includes a computer program / instruction. When the computer program / instruction is executed by a processor, the steps of any of the above-mentioned new table entry allocation methods in a branch instruction predictor can be implemented.

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

[0213] Among them, the computer program product may include one or more computer programs / instructions, and when the computer program / instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention may be generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions may be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line, etc.) or wireless (e.g., infrared, wireless, microwave, etc.) means.

[0214] For an introduction to the computer program product provided by the embodiment of the present invention, please refer to the above method embodiment, and the present invention will not be elaborated here.

[0215] The technical solution provided by the present invention is described in detail above. Specific examples are used herein to illustrate the principle and implementation of the present invention, and the description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A method for allocating new table entries in a branch instruction predictor, characterized in that: include: Obtaining a predicted jump result of a branch instruction predictor for a target branch instruction, and determining a 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, searching sub-predictors whose numbers are not less than the random number to determine whether there is an entry in each of the sub-predictors whose usefulness counter has a value of 0; If the table entry exists, new table entries are allocated to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold; If the table entry does not exist, the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as the random number is set to 0, so that new table entries are allocated to the sub-predictors with numbers not less than the random number in order from small to large until the allocated number reaches the preset threshold.

2. The method for allocating new table entries in a branch instruction predictor according to claim 1, characterized in that: Get the predicted jump result of the branch instruction predictor for the target branch instruction, including: Determine the prediction result of each sub-predictor in the branch instruction predictor for the target branch instruction; The predicted jump result of the branch instruction predictor for the target branch instruction is determined according to each of the prediction results.

3. The method for allocating new table entries in a branch instruction predictor according to claim 2, characterized in that: The branch instruction predictor includes a basic sub-predictor and a plurality of label sub-predictors; Determining the predicted jump result of the branch instruction predictor for the target branch instruction according to each of the prediction results includes: Determining index information of the target branch instruction; Determining whether the target branch instruction hits the label sub-predictor according to the index information; When the target branch instruction hits the label sub-predictor and the hit number is not unique, the prediction result of the hit first label sub-predictor with the longest history length is used as the first prediction result, and the prediction result of the hit second label sub-predictor with the secondary history length is used as the second prediction result; When the target branch instruction hits the label sub-predictor and the hit number is unique, the prediction result of the first label sub-predictor with the longest history length is used as the first prediction result, and the prediction result of the basic sub-predictor is used as the second prediction result; When the table entry corresponding to the first label sub-predictor is a pseudo table entry and the candidate flag is not 0, using the second prediction result as the predicted jump result of the target branch instruction; When the table entry corresponding to the first label sub-predictor is not a pseudo table entry and / or the alternative flag is 0, using the first prediction result as the predicted jump result of the target branch instruction; When the target branch instruction does not hit the tag sub-predictor, the prediction result of the basic sub-predictor is used as the predicted jump result of the target branch instruction.

4. The method for allocating new table entries in a branch instruction predictor according to claim 3, characterized in that: Determining whether the target branch instruction hits the label sub-predictor according to the index information includes: For each label sub-predictor in the branch instruction predictor, determine an index value of the label sub-predictor according to a program counter value, a folding history, and a historical path of the label sub-predictor; According to the index information of the target branch instruction and the index values ​​of each of the label sub-predictors, it is determined whether the target branch instruction hits the label sub-predictor in the branch instruction predictor.

5. The method for allocating new table entries in a branch instruction predictor according to claim 4, characterized in that: Determining the index value of the label sub-predictor according to the program counter value, the folding history, and the historical path of the label sub-predictor includes: Performing hash calculation on the program counter value of the label sub-predictor, the folding history, and the historical path to obtain a hash value; The hash value is used as the index value of the label sub-predictor.

6. The method for allocating new table entries in a branch instruction predictor according to claim 3, characterized in that: Obtaining a predicted jump result of a branch instruction predictor for a target branch instruction, and determining a target sub-predictor corresponding to the predicted jump result, including: Obtaining a predicted jump result of the target branch instruction by the branch instruction predictor, and determining an 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 a predicted result of the first label sub-predictor, determining a 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 predicted result of the first label sub-predictor, wait for the predicted jump result of the next branch instruction.

7. The method for allocating new table entries in a branch instruction predictor according to claim 3, characterized in that: Allocating new table entries to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold, further comprising: Determine a hit result of the target branch instruction in the branch instruction predictor; The table entries corresponding to the basic sub-predictor and / or each of the label sub-predictors are updated according to the hit result.

8. The method for allocating new table entries in a branch instruction predictor according to claim 7, characterized in that: Updating the table entries corresponding to the basic sub-predictor and / or each of the label sub-predictors according to the hit result includes: When the hit result is that the target branch instruction does not hit the label sub-predictor, updating the table entry corresponding to the basic sub-predictor; When the hit result is that the target branch instruction hits the label sub-predictor, the table entry corresponding to the hit label sub-predictor is updated.

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

10. The method for allocating new table entries in a branch instruction predictor according to claim 3, characterized in that: Allocating new table entries to the sub-predictors whose numbers are not less than the random number in order from small to large, until the number of allocated entries reaches a preset threshold, further comprising: Counting the number of new entry allocations, and determining whether the number of new entry allocations reaches a preset number; When the number of times the new table entry is allocated does not reach the preset number, waiting for the next branch instruction to be used as the target branch instruction, and returning to the step of obtaining the predicted jump result of the branch instruction predictor for the target branch instruction; When the number of times the new table entry is allocated reaches a preset number, the table entries corresponding to all the label sub-predictors in the branch instruction predictor are reset.

11. The method for allocating new table entries in a branch instruction predictor according to claim 10, characterized in that: Resetting the table entries corresponding to all the label sub-predictors in the branch instruction predictor includes: For each label sub-predictor in the branch instruction predictor, determining a current value of a usefulness counter in a table entry corresponding to the label sub-predictor; The current value is shifted right by one position to reset the table entry corresponding to the label sub-predictor.

12. A new table entry allocation device in a branch instruction predictor, characterized in that: include: An acquisition module, used to acquire a predicted jump result of a branch instruction predictor for a target branch instruction, and determine a target sub-predictor corresponding to the predicted jump result; A generating module, used for generating a random number according to the serial number of the target sub-predictor in the branch instruction predictor; A search module, used for searching the sub-predictors with numbers not less than the random number in the branch instruction predictor to determine whether there is a table entry with a usefulness counter value of 0 in each of the sub-predictors; A first allocation module, configured to allocate new table entries to the sub-predictors whose numbers are not less than the random number in ascending order if the table entries exist, until the number of allocated entries reaches a preset threshold; The second allocation module is used to set the value of the usefulness counter in the table entry corresponding to the sub-predictor numbered as the random number to 0 if the table entry does not exist, so as to allocate new table entries to the sub-predictors with numbers not less than the random number in order from small to large until the allocated number reaches the preset threshold.

13. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for allocating new table entries in a branch instruction predictor as claimed in any one of claims 1 to 11 when executing the computer program.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the new table entry allocation method 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 new table entry allocation method 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

  • Security enhancement method for randomized index-based processor chip branch predictor and electronic device

    CN111638913A

  • Branch instruction prediction-oriented deviation corrector and method

    CN112988233A

  • New table item distribution method for TAGE branch predictor

    CN113703846A

  • Indirect branch predictor and prediction method based on global historical classification

    CN114296803A