Branch prediction method and device based on covering branch predictor
By adding a pre-stage auxiliary predictor and a post-stage predictor to the traditional covered branch predictor, and combining the branch address and the hash result of the global branch history for arbitration and coverage, the problems of high latency and pipeline bubbles of the traditional TAGE branch predictor are solved. High-accuracy and low-latency branch prediction is achieved.
Patent Information
- Application Number
- CN202411096646.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-08-12
AI Technical Summary
The traditional TAGE branch predictor has a complex structure in the design of modern high-performance processors, resulting in high branch prediction delays, and the pre-predictor in the coverage branch predictor cannot accurately predict branches related to the branch history, which is prone to pipeline bubbles. Leading to higher branch prediction latency.
A branch prediction method based on covering branch predictors is proposed, which includes parallel front-level predictors, front-level auxiliary predictors and rear-level predictors. By inputting the branch address into the front-level predictor and front-level auxiliary predictor, it combines the global The hash result of the branch history is arbitrated to obtain the prediction result of the previous stage, and the hash result is input into the predictor of the subsequent stage to determine the prediction result of the subsequent stage. When the prediction results of the previous stage and the subsequent stage are different, the prediction result of the subsequent stage overwrites the previous stage. Predict the results.
It achieves branch prediction with short delay and high prediction accuracy, reduces the generation of pipeline bubbles, and improves the accuracy and efficiency of branch prediction.
Smart Images

Figure CN118626150B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a branch prediction method and device based on a covering branch predictor. Background Art
[0002] The traditional TAGE (TAgged GEometric History Length) branch predictor can track a long branch history with high prediction accuracy, but due to its complex structure and long combinational logic path, it often takes at least 2-3 clock cycles to complete branch prediction in modern high-performance processor designs.
[0003] Using only one TAGE branch predictor for branch prediction will cause pipeline delays. In order to reduce the delay of branch prediction, multiple different branch predictors are often used to form an overlay branch predictor.
[0004] Since the front-stage predictor in the coverage branch predictor often cannot accurately predict branches related to branch history in order to reduce latency, when encountering these branches, pipeline bubbles caused by the coverage prediction of the back-stage predictor are easily generated, resulting in higher branch prediction delays. Summary of the invention
[0005] The present application aims to solve one of the technical problems in the related art at least to some extent.
[0006] To this end, the first objective of the present application is to propose a branch prediction method based on a covering branch predictor to achieve branch prediction with shorter delay and higher prediction accuracy.
[0007] The second objective of the present application is to provide a branch prediction device based on a covering branch predictor.
[0008] The third objective of the present application is to provide an electronic device.
[0009] A fourth objective of the present application is to provide a computer-readable storage medium.
[0010] A fifth object of the present application is to provide a computer program product.
[0011] To achieve the above-mentioned purpose, the first embodiment of the present application proposes a branch prediction method based on a covering branch predictor, wherein the covering branch predictor includes a parallel front-stage predictor, a front-stage auxiliary predictor, and a back-stage predictor, including:
[0012] Inputting the branch address into the previous stage predictor to obtain a first prediction result;
[0013] inputting a hash result of the branch address and the global branch history into the previous auxiliary predictor to determine a second prediction result based on a first label prediction table included in the previous auxiliary predictor;
[0014] arbitrating the first prediction result and the second prediction result to obtain a previous prediction result;
[0015] Inputting the hash result into the subsequent predictor to determine a subsequent prediction result based on a second label prediction table included in the subsequent predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table;
[0016] When the previous stage prediction result and the next stage prediction result are different, the next stage prediction result is used to overwrite the previous stage prediction result as the branch prediction result.
[0017] To achieve the above-mentioned purpose, the second embodiment of the present application proposes a branch prediction device based on an overlay branch predictor, wherein the overlay branch predictor includes a parallel front-stage predictor, a front-stage auxiliary predictor, and a back-stage predictor, including:
[0018] A first prediction module, used for inputting a branch address into the previous stage predictor to obtain a first prediction result;
[0019] a second prediction module, configured to input a hash result of the branch address and the global branch history into the previous auxiliary predictor to determine a second prediction result based on a first label prediction table included in the previous auxiliary predictor;
[0020] An arbitration module, used for arbitrating the first prediction result and the second prediction result to obtain a previous prediction result;
[0021] a third prediction module, configured to input the hash result into the subsequent predictor to determine a subsequent prediction result based on a second label prediction table included in the subsequent predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table;
[0022] The branch prediction module is used to overwrite the previous stage prediction result with the next stage prediction result as the branch prediction result when the previous stage prediction result and the next stage prediction result are different.
[0023] To achieve the above-mentioned purpose, the third aspect of the present application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0024] The memory stores computer-executable instructions;
[0025] The processor executes the computer-executable instructions stored in the memory to implement a branch prediction method based on a covering branch predictor proposed in the embodiment of the first aspect of the present application.
[0026] To achieve the above-mentioned purpose, the fourth aspect embodiment of the present application proposes a computer-readable storage medium, in which computer execution instructions are stored. When the computer execution instructions are executed by the processor, they are used to implement a branch prediction method based on a covering branch predictor proposed in the first aspect embodiment of the present application.
[0027] To achieve the above-mentioned purpose, the fifth aspect embodiment of the present application proposes a computer program product, including a computer program, which, when executed by a processor, implements a branch prediction method based on a covering branch predictor proposed in the first aspect embodiment of the present application.
[0028] The branch prediction method and device based on the covering branch predictor provided by the present application obtain the first prediction result by inputting the branch address into the front-stage predictor; inputting the hash result of the branch address and the global branch history into the front-stage auxiliary predictor to determine the second prediction result based on the first label prediction table included in the front-stage auxiliary predictor; arbitrating the first prediction result and the second prediction result to obtain the front-stage prediction result; inputting the hash result into the back-stage predictor to determine the back-stage prediction result based on the second label prediction table included in the back-stage predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table; when the front-stage prediction result and the back-stage prediction result are different, the back-stage prediction result covers the front-stage prediction result as the branch prediction result. The problem of high delay of branch prediction is solved. By adding a front-stage auxiliary predictor to the traditional covering predictor, the front-stage predictor can be assisted to predict some branches related to the branch history. At the same time, it has fewer pipeline bubbles than the traditional covering branch predictor, reduces the delay of branch prediction, and realizes branch prediction with fewer bubbles and higher accuracy.
[0029] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0031] Figure 1 A schematic diagram of a flow chart of a branch prediction method based on a covering branch predictor provided in an embodiment of the present application;
[0032] Figure 2 A schematic diagram of a flow chart of a branch prediction method based on a covering branch predictor provided in an embodiment of the present application;
[0033] Figure 3 A structural flow chart of a branch prediction method based on a covering branch predictor provided in an embodiment of the present application;
[0034] Figure 4 A schematic diagram of the structure of a branch prediction device based on an overlay branch predictor provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0036] The following describes a branch prediction method and device based on a covering branch predictor according to an embodiment of the present application with reference to the accompanying drawings.
[0037] Figure 1 A schematic flow chart of a branch prediction method based on a covering branch predictor provided in an embodiment of the present application.
[0038] If only one TAGE branch predictor is used for branch prediction, the branch prediction result will be obtained after at least 2-3 clock cycles before instructions can be submitted based on the prediction result. This will cause the pipeline to stall, that is, generate an ineffective bubble in the pipeline.
[0039] In order to avoid the delay of branch prediction, a branch predictor is currently composed of multiple predictors with different delays. Generally, a branch predictor with a simple structure that is independent of the branch history is used as the front-stage predictor to provide bubble-free branch prediction. The predictor with large delay and relatively more accuracy is placed in the later pipeline stage as the post-stage predictor. The prediction result it produces will be compared with the previous predictor. If they are different, the pipeline will be flushed. The overall prediction result is based on the most accurate predictor.
[0040] However, since the front-end predictor cannot predict branches related to branch history, the prediction accuracy is often low, and it may make multiple prediction errors, resulting in multiple pipeline flushes. Pipeline bubbles caused by the back-end predictor overwriting the prediction pipeline flush will still occur.
[0041] To solve this problem, an embodiment of the present application provides a branch prediction method based on a covering branch predictor to achieve branch prediction with short delay and high prediction accuracy. The covering branch predictor includes a parallel front-stage predictor, a front-stage auxiliary predictor and a back-stage predictor, such as Figure 1 As shown, the branch prediction method based on the covering branch predictor includes the following steps:
[0042] Step 101: input the branch address into a previous stage predictor to obtain a first prediction result.
[0043] Optionally, the front-stage predictor is a branch predictor that is independent of branch history, has a simple structure, and is used for front-stage bubble-free prediction.
[0044] For example, the previous predictor may be a PHT (Pattern History Table) branch predictor, and the branch address is input into the PHT predictor for table lookup prediction to obtain a prediction result of the previous predictor as the first prediction result.
[0045] Step 102: Input the hash result of the branch address and the global branch history into a previous auxiliary predictor to determine a second prediction result based on a first label prediction table included in the previous auxiliary predictor.
[0046] Optionally, the front-stage auxiliary predictor is a predictor that is related to the branch history but has a shorter delay than the back-stage predictor, and includes multiple first label prediction tables, wherein the number of the first label prediction tables is a power of 2.
[0047] For example, the front-stage auxiliary predictor can be a small variant of the back-stage predictor.
[0048] It can be understood that the front-stage auxiliary predictor is a new part compared to the traditional coverage predictor. Compared with the front-stage predictor, the front-stage auxiliary predictor has a higher accuracy, and compared with the back-stage predictor, the front-stage auxiliary predictor has a shorter delay. By combining multiple predictors with different delays, a branch predictor with fewer bubbles and higher accuracy is obtained.
[0049] Optionally, a hash calculation is performed on the branch address and the global branch history to obtain a hash result, and the hash result is used to look up the first label prediction table. The hash result includes a label (tag hash) and an index (index hash) of each first label prediction table.
[0050] There may be multiple global branch histories, and the historical record sizes of each global branch history are different. Any global branch history corresponds to a first label prediction table.
[0051] It should be noted that the hash calculation process is a prior art and will not be described in detail in this specification.
[0052] Optionally, the hash result is input into a previous auxiliary predictor to obtain a prediction result of each first label prediction table as a second prediction result.
[0053] Step 103: arbitrate the first prediction result and the second prediction result to obtain the previous prediction result.
[0054] In the embodiment of the present application, arbitration is performed by the longest match principle, that is, the first label prediction table with the longest global history hit is used to provide a prediction, and the second prediction result predicted by the first label prediction table is used as the previous prediction result.
[0055] Optionally, when all first label prediction tables do not hit, the first prediction result predicted by the previous-level prediction table is used as the previous-level prediction result.
[0056] Step 104, inputting the hash result into the post-stage predictor to determine the post-stage prediction result based on the second label prediction table included in the post-stage predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table.
[0057] Optionally, the later-stage predictor is the branch predictor with the highest accuracy among the coverage predictors, and relatively, more bubbles are generated and the delay is greater.
[0058] For example, the latter stage predictor may be a complete TAGE predictor, including a plurality of second tag prediction tables, for the latter stage prediction with high accuracy.
[0059] It can be understood that the front-stage auxiliary predictor is a small variant of the back-stage predictor, that is, the number and size of the first label prediction tables included in the front-stage auxiliary predictor do not exceed the second label prediction tables.
[0060] In the embodiment of the present application, the number of the first label prediction tables does not exceed the number of the second label prediction tables; in terms of size, the first label prediction table is a subtable of the second label prediction table. This ensures that the delay generated by the previous auxiliary predictor is small, the bubbles are small, and the global branch history is referenced, and the accuracy is higher than that of the previous predictor.
[0061] The hash result is input into the subsequent predictor to obtain the prediction result of each second label prediction table as the subsequent prediction result.
[0062] Step 105 , when the previous stage prediction result and the next stage prediction result are different, the next stage prediction result overwrites the previous stage prediction result as the branch prediction result.
[0063] Optionally, the previous-stage prediction result is obtained by arbitrating the first prediction result and the second prediction result, which is a more accurate result obtained by initially comparing the previous-stage predictor and the previous-stage auxiliary predictor. Since the subsequent-stage predictor is more complete, the obtained prediction result is more accurate. The previous-stage prediction result is compared with the subsequent-stage prediction result, and the subsequent-stage prediction result is used as a standard to correct the previous-stage prediction result.
[0064] It is understandable that when the previous stage prediction result and the next stage prediction result are different, it means that the previous stage prediction result is wrong and needs to be corrected and the wrong prediction result is flushed. Therefore, the previous stage prediction result is overwritten by the next stage prediction result to obtain the branch prediction result.
[0065] In this embodiment, the branch address is input into the front-stage predictor to obtain the first prediction result; the hash result of the branch address and the global branch history is input into the front-stage auxiliary predictor to determine the second prediction result based on the first label prediction table included in the front-stage auxiliary predictor; the first prediction result and the second prediction result are arbitrated to obtain the front-stage prediction result; the hash result is input into the back-stage predictor to determine the back-stage prediction result based on the second label prediction table included in the back-stage predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table; when the front-stage prediction result and the back-stage prediction result are different, the back-stage prediction result covers the front-stage prediction result as the branch prediction result. The problem of high delay of branch prediction is solved. By adding a front-stage auxiliary predictor to the traditional coverage predictor, the front-stage predictor can be assisted to predict some branches related to the branch history. At the same time, it has fewer pipeline bubbles than the traditional coverage branch predictor, reduces the delay of branch prediction, and realizes branch prediction with fewer bubbles and higher accuracy.
[0066] This embodiment provides another branch prediction method based on an overlay branch predictor, wherein the overlay branch predictor includes a parallel front-stage predictor, a front-stage auxiliary predictor, and a back-stage predictor. Figure 2 A schematic flow chart of another branch prediction method based on a covering branch predictor provided in an embodiment of the present application.
[0067] like Figure 2 As shown, the branch prediction method based on the covering branch predictor may include the following steps:
[0068] Step 201, input the branch address into the previous stage predictor to obtain a first prediction result.
[0069] For step 201, reference may be made to the relevant description of the corresponding step in the aforementioned embodiment, which will not be described in detail in this embodiment.
[0070] Step 202, obtaining a hash result of the branch address and the global branch history, wherein the hash result includes a label.
[0071] Optionally, the branch address and global branch history are input into a hash function to obtain a hash result containing a tag (tag hash) and an index (index hash).
[0072] The hash function is used to calculate a hash result based on the branch address and the global branch history, and the hash result includes the tag and index of each first prediction table.
[0073] In the embodiment of the present application, the branch address and the global branch history are used as inputs of the hash function, which are XORed and output to obtain a hash result.
[0074] Step 203, input the label into the previous auxiliary predictor for full associative matching; when the label is equal to any label field in the first label prediction table, the previous auxiliary predictor hits and outputs the highest bit of the counter field of the hit label prediction table entry as the second prediction result.
[0075] Optionally, the front-stage auxiliary predictor is a predictor that is related to the branch history but has a shorter delay than the back-stage predictor, and includes multiple first label prediction tables, wherein the number of the first label prediction tables is a power of 2.
[0076] In an embodiment of the present application, the front-stage auxiliary predictor is a small TAGE predictor variant with only a small number of first label prediction tables. Each first label prediction table is configured with only a small number of table entries, and a fully associative register stack is used as a storage medium to store high-confidence prediction information when the subsequent-stage TAGE is updated.
[0077] Optionally, each entry of the first tag prediction table includes two fields: tag and ctr, wherein the tag field is used for full associative matching table lookup during prediction, and the ctr field is used to predict the jump direction of the branch.
[0078] Among them, the fully associative matching process is that when the tag field of an item in the first label prediction table is equal to the input tag, it is considered a hit, and the highest bit of the ctr field of this table item is output as the second prediction result of the first label prediction table; otherwise it is considered a miss, and the second prediction result is no jump.
[0079] Step 204: arbitrate the first prediction result and the second prediction result to obtain a previous prediction result.
[0080] Optionally, when the previous auxiliary predictor hits, the second prediction result corresponding to the longest global branch history is used as the previous prediction result; when the previous auxiliary predictor misses, the first prediction result is used as the previous prediction result.
[0081] In an embodiment of the present application, when the previous-stage auxiliary predictor hits, arbitration is performed using the longest match principle, that is, the first label prediction table with the longest global history hit is used to provide a prediction, and the second prediction result predicted by the first label prediction table is used as the previous-stage prediction result; when the previous-stage auxiliary predictor misses, the second prediction result of the previous-stage auxiliary predictor is not credible, and the first prediction result is used as the previous-stage prediction result.
[0082] Among them, the previous stage prediction results can be obtained within 1 cycle to provide bubble-free prediction.
[0083] Step 205, inputting the hash result into the post-stage predictor to determine the post-stage prediction result based on the second label prediction table included in the post-stage predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table.
[0084] Optionally, the later-stage predictor is the branch predictor with the highest accuracy among the coverage predictors, and relatively, more bubbles are generated and the delay is greater.
[0085] For example, the latter stage predictor may be a complete TAGE predictor, including a plurality of second tag prediction tables, for the latter stage prediction with high accuracy.
[0086] It can be understood that the front-stage auxiliary predictor is a small variant of the back-stage predictor, that is, the number and size of the first label prediction tables included in the front-stage auxiliary predictor do not exceed the second label prediction tables.
[0087] In an embodiment of the present application, the first label prediction table in the front-stage auxiliary predictor is called a sub-table, and the second label prediction table in the back-stage TAGE predictor is called a parent table. Each sub-table has a corresponding parent table, and the prediction information stored in the sub-table is a subset of the parent table.
[0088] Among them, any first label prediction table corresponds to a second label prediction table that tracks the same global branch history; the bit widths of labels and counters in the first label prediction table and the corresponding second label prediction table are consistent.
[0089] In an embodiment of the present application, any sub-table and the corresponding parent table track the same global branch history, that is, the same global branch history is input into the previous auxiliary predictor and the next predictor respectively, and tracked through the corresponding first label prediction table and the second label prediction table respectively.
[0090] Optionally, the hash result is input to the post-stage TAGE predictor, and the post-stage prediction result is obtained after table lookup and arbitration. This process is consistent with the prediction process of TAGE, and the longest match principle is still used. It takes at least 2 cycles to get the prediction result. The prediction result of the post-stage predictor has a higher accuracy, but correspondingly, the delay generated is larger.
[0091] Step 206: When the previous prediction result and the next prediction result are different, the next prediction result overwrites the previous prediction result as the branch prediction result.
[0092] Optionally, the previous-stage prediction result is obtained by arbitrating the first prediction result and the second prediction result, which is a more accurate result obtained by initially comparing the previous-stage predictor and the previous-stage auxiliary predictor. Since the subsequent-stage predictor is more complete, the obtained prediction result is more accurate. The previous-stage prediction result is compared with the subsequent-stage prediction result, and the subsequent-stage prediction result is used as a standard to correct the previous-stage prediction result.
[0093] It is understandable that when the previous stage prediction result and the next stage prediction result are different, it means that the previous stage prediction result is wrong and needs to be corrected and the wrong prediction result is flushed. Therefore, the previous stage prediction result is overwritten by the next stage prediction result to obtain the branch prediction result.
[0094] Optionally, when the previous-stage prediction result and the next-stage prediction result are the same, the previous-stage prediction result is used as the branch prediction result.
[0095] When the prediction results of the previous and next stages are the same, the coverage predictor pulls down the coverage prediction flag and outputs the previous stage prediction result to fetch instructions without pipeline bubbles. When the prediction results are different, the coverage predictor outputs the next stage prediction result to fetch instructions and pulls up the coverage prediction flag to instruct the pipeline to flush the fetch request generated by the previous stage predictor in the previous cycle.
[0096] In the embodiment of the present application, the coverage predictor outputs the subsequent prediction result to perform instruction fetch, and pulls up the coverage prediction flag to flush the previous prediction result.
[0097] By overlaying arbitration to determine the final prediction result, it is possible to perform bubble-free branch prediction when the previous-stage predictor predicts accurately. When the previous-stage predictor predicts incorrectly, the previous-stage prediction result is flushed by the prediction result of the subsequent-stage predictor and corrected to the correct prediction result. Under the premise of ensuring prediction accuracy, it reduces pipeline bubbles and improves prediction speed.
[0098] Furthermore, after the instruction is submitted based on the branch prediction result, the previous auxiliary predictor is updated.
[0099] Among them, the update algorithms of PHT predictor and TAGE predictor are consistent with the original algorithms.
[0100] For the front-end auxiliary predictor, update it through the following steps:
[0101] As an example, in case of a hit in the previous auxiliary predictor, the counter field of the hit table entry in the previous auxiliary predictor is updated.
[0102] In the embodiment of the present application, the counter field of the hit table entry in the previous auxiliary predictor is updated as follows: when a branch jumps, the counter (ctr) is incremented, otherwise it is decremented.
[0103] As another example, when the previous-level auxiliary predictor misses and predicts incorrectly, determine whether the target table entry in the subsequent-level predictor is predicted correctly, where the target table entry is an entry whose counter is within a preset range; when the target table entry is predicted correctly and the second label prediction table of the subsequent-level predictor is a parent table of any first label prediction table, allocate a new table entry to the previous-level auxiliary predictor based on the second label prediction table.
[0104] In the embodiment of the present application, the preset range is ctr≥5 or ctr≤2, that is, when the counter of the second label prediction table is ctr≥5 or ctr≤2, the table entry corresponding to the second label prediction table is the target table entry. When the target table entry is correctly predicted and the second label prediction table of the subsequent predictor is the parent table of any first label prediction table, a new table entry is allocated to the previous auxiliary predictor based on the second label prediction table.
[0105] The table entry to be replaced is selected through a replacement algorithm, and the prediction information of the TAGE table entry is written to achieve allocation of a new table entry.
[0106] The replacement algorithm can be a random algorithm, a first-in-first-out algorithm, a least recently used algorithm, etc.
[0107] like Figure 3 As shown, the branch address is input into the front-level predictor to obtain a first prediction result; the branch address and multiple global branch histories are hashed respectively and the labels included in the hash results are input into the front-level auxiliary predictor, and prediction is performed through the first label prediction table to obtain a second prediction result; the hash result is input into the back-level predictor, and prediction is performed through the second label prediction table to obtain a back-level prediction result; the first prediction result and the second prediction result are arbitrated to obtain the front-level prediction result, the front-level prediction result and the back-level prediction result are compared, and the branch prediction result is obtained through coverage arbitration, and the prediction result and the coverage prediction flag are output.
[0108] In this embodiment, the branch address is input into the front-level predictor to obtain a first prediction result; a hash result of the branch address and the global branch history is obtained, wherein the hash result includes a label; the label is input into the front-level auxiliary predictor to perform a fully associative match; when the label is equal to any label field in the first label prediction table, the front-level auxiliary predictor hits and outputs the highest bit of the counter field of the hit label prediction table item as the second prediction result; the first prediction result and the second prediction result are arbitrated to obtain the front-level prediction result; the hash result is input into the back-level predictor to determine the back-level prediction result based on the second label prediction table included in the back-level predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table; when the front-level prediction result and the back-level prediction result are different, the back-level prediction result overwrites the front-level prediction result as the branch prediction result. The problem of high delay in branch prediction is solved by adding a front-stage auxiliary predictor to the traditional coverage predictor, which can assist the front-stage predictor in predicting some branches related to branch history. At the same time, it has fewer pipeline bubbles than the traditional coverage branch predictor, reduces the delay of branch prediction, and realizes branch prediction with fewer bubbles and higher accuracy.
[0109] In order to implement the above embodiments, the present application also proposes a branch prediction device based on a covering branch predictor.
[0110] Figure 4 A schematic diagram of the structure of a branch prediction device based on an overlay branch predictor provided in an embodiment of the present application.
[0111] like Figure 4 As shown, the branch prediction device 400 based on the covering branch predictor includes: a first prediction module 401 , a second prediction module 402 , an arbitration module 403 , a third prediction module 404 and a branch prediction module 405 .
[0112] A first prediction module 401, configured to input a branch address into a previous stage predictor to obtain a first prediction result;
[0113] A second prediction module 402, configured to input a hash result of a branch address and a global branch history into a previous auxiliary predictor to determine a second prediction result based on a first label prediction table included in the previous auxiliary predictor;
[0114] An arbitration module 403 is used to arbitrate the first prediction result and the second prediction result to obtain a previous prediction result;
[0115] a third prediction module 404, configured to input the hash result into a subsequent predictor to determine a subsequent prediction result based on a second label prediction table included in the subsequent predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table;
[0116] The branch prediction module 405 is used to overwrite the previous stage prediction result with the next stage prediction result as the branch prediction result when the previous stage prediction result and the next stage prediction result are different.
[0117] Further, in a possible implementation of the embodiment of the present application, the hash result includes a label, and the second prediction module 402 is specifically configured to:
[0118] Input the label into the previous auxiliary predictor for full associative matching;
[0119] When the tag is equal to any tag field in the first tag prediction table, the previous auxiliary predictor hits and outputs the highest bit of the counter field of the hit tag prediction table entry as the second prediction result.
[0120] In the case of a hit in the previous auxiliary predictor, the second prediction result corresponding to the longest global branch history is used as the previous prediction result;
[0121] In the event of a miss in the previous auxiliary predictor, the first prediction result is used as the previous prediction result.
[0122] Furthermore, in a possible implementation of the embodiment of the present application, the branch prediction module 405 is specifically used for:
[0123] The coverage predictor outputs the subsequent prediction result to perform instruction fetching, and pulls up the coverage prediction flag to flush the previous prediction result.
[0124] Furthermore, in a possible implementation of the embodiment of the present application, the third prediction module 404 is specifically configured to:
[0125] Any first label prediction table corresponds to a second label prediction table that tracks the same global branch history;
[0126] The bit widths of the tags and counters in the first tag prediction table and the corresponding second tag prediction table are consistent.
[0127] Furthermore, in a possible implementation of the embodiment of the present application, the device is also used for:
[0128] After the instruction is submitted based on the branch prediction result, the previous auxiliary predictor is updated.
[0129] In case of a hit in the previous auxiliary predictor, the counter field of the hit table entry in the previous auxiliary predictor is updated.
[0130] In the case where the previous stage auxiliary predictor misses and makes an incorrect prediction, determining whether a target table entry in a subsequent stage predictor is predicted correctly, wherein the target table entry is an entry whose counter is within a preset range;
[0131] When the target table entry is predicted correctly and the second label prediction table of the subsequent predictor is a parent table of any first label prediction table, a new table entry is allocated to the previous auxiliary predictor based on the second label prediction table.
[0132] When the previous prediction result and the next prediction result are the same, the previous prediction result is used as the branch prediction result.
[0133] It should be noted that the above explanation of the branch prediction method embodiment based on the covering branch predictor is also applicable to the branch prediction device based on the covering branch predictor of this embodiment, which will not be repeated here.
[0134] In the embodiment of the present application, a branch address is input into a front-stage predictor to obtain a first prediction result; a hash result of the branch address and the global branch history is input into a front-stage auxiliary predictor to determine a second prediction result based on a first label prediction table included in the front-stage auxiliary predictor; the first prediction result and the second prediction result are arbitrated to obtain a front-stage prediction result; the hash result is input into a back-stage predictor to determine a back-stage prediction result based on a second label prediction table included in the back-stage predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table; when the front-stage prediction result and the back-stage prediction result are different, the back-stage prediction result covers the front-stage prediction result as the branch prediction result. The problem of high delay in branch prediction is solved. By adding a front-stage auxiliary predictor to a traditional coverage predictor, the front-stage predictor can be assisted to predict some branches related to the branch history. At the same time, it has fewer pipeline bubbles than a traditional coverage branch predictor, reduces the delay of branch prediction, and realizes branch prediction with fewer bubbles and higher accuracy.
[0135] In order to implement the above embodiments, the present application also proposes an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to implement the branch prediction method based on the covering branch predictor provided in the above embodiments.
[0136] In order to implement the above embodiments, the present application also proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the branch prediction method based on the covering branch predictor provided in the above embodiments.
[0137] In order to implement the above embodiments, the present application also proposes a computer program product, including a computer program, which, when executed by a processor, implements the branch prediction method based on the covering branch predictor provided by the above embodiments.
[0138] The collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this application are in compliance with relevant laws and regulations and do not violate public order and good morals.
[0139] It should be noted that personal information from users should be collected for legitimate and reasonable purposes and should not be shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign the agreement / authorization including authorization of relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data and ensure that others who have access to personal information data comply with its privacy policy and procedures.
[0140] This application is expected to provide an implementation scheme for users to selectively block the use or access of personal information data. That is, this application is expected to provide hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, risks can be minimized by limiting data collection and deleting data. In addition, when applicable, personal identifiers are removed from such personal information to protect the privacy of users.
[0141] In the description of the aforementioned embodiments, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0142] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0143] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0144] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples (non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0145] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0146] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0147] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0148] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A branch prediction method based on covering branch predictor, It is characterized in that The covering branch predictor includes a parallel front-stage predictor, a front-stage auxiliary predictor and a back-stage predictor, and the method includes the following steps: Inputting the branch address into the previous stage predictor to obtain a first prediction result; inputting a hash result of the branch address and the global branch history into the previous auxiliary predictor to determine a second prediction result based on a first label prediction table included in the previous auxiliary predictor; arbitrating the first prediction result and the second prediction result to obtain a previous prediction result, wherein, in the case where the previous auxiliary predictor hits, the second prediction result corresponding to the longest global branch history is used as the previous prediction result, and in the case where the previous auxiliary predictor does not hit, the first prediction result is used as the previous prediction result; Inputting the hash result into the subsequent predictor to determine a subsequent prediction result based on a second label prediction table included in the subsequent predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table; In the case where the previous stage prediction result and the next stage prediction result are different, overwriting the previous stage prediction result with the next stage prediction result as the branch prediction result; The hash result includes a tag; The hash result of the branch address and the global branch history is input into the front-stage auxiliary predictor to determine the second prediction result based on the first label prediction table included in the front-stage auxiliary predictor, including: inputting the label into the front-stage auxiliary predictor to perform a fully associative match; when the label is equal to any label field in the first label prediction table, the front-stage auxiliary predictor hits and outputs the highest bit of the counter field of the hit label prediction table entry as the second prediction result.
2. The branch prediction method based on the covering branch predictor according to claim 1, It is characterized in that The step of overwriting the previous stage prediction result with the subsequent stage prediction result includes: The latter prediction result is outputted by the coverage predictor to perform instruction fetching, and the coverage prediction flag is pulled high to flush out the former prediction result.
3. The branch prediction method based on the covering branch predictor according to claim 1, It is characterized in that The first label prediction table is a subtable of the second label prediction table, including: Any of the first label prediction tables corresponds to the second label prediction table that tracks the same global branch history; The bit widths of the tags and counters in the first tag prediction table and the corresponding second tag prediction table are consistent.
4. The branch prediction method based on the covering branch predictor according to claim 1, It is characterized in that The method further comprises: After the instruction is submitted based on the branch prediction result, the previous auxiliary predictor is updated.
5. The branch prediction method based on the covering branch predictor according to claim 4, It is characterized in that The updating of the previous auxiliary predictor comprises: In case of a hit in the previous auxiliary predictor, a counter field of the hit table entry in the previous auxiliary predictor is updated.
6. The branch prediction method based on covering branch predictor according to claim 4, It is characterized in that The updating of the previous auxiliary predictor comprises: In the case that the front-stage auxiliary predictor misses and makes an incorrect prediction, determining whether a target entry in the back-stage predictor is predicted correctly, wherein the target entry is an entry whose counter is within a preset range; When the target table entry is predicted correctly and the second label prediction table of the subsequent predictor is a parent table of any of the first label prediction tables, a new table entry is allocated to the previous auxiliary predictor based on the second label prediction table.
7. The branch prediction method based on the covering branch predictor according to claim 1, It is characterized in that The method further comprises: When the previous stage prediction result and the next stage prediction result are the same, the previous stage prediction result is used as the branch prediction result.
8. A branch prediction device based on a covering branch predictor, It is characterized in that The covering branch predictor includes a parallel pre-stage predictor, a pre-stage auxiliary predictor, and a post-stage predictor, including: A first prediction module, used for inputting a branch address into the previous stage predictor to obtain a first prediction result; a second prediction module, configured to input a hash result of the branch address and the global branch history into the previous auxiliary predictor to determine a second prediction result based on a first label prediction table included in the previous auxiliary predictor; an arbitration module, configured to arbitrate the first prediction result and the second prediction result to obtain a previous prediction result, wherein, in the case where the previous auxiliary predictor hits, the second prediction result corresponding to the longest global branch history is used as the previous prediction result, and in the case where the previous auxiliary predictor does not hit, the first prediction result is used as the previous prediction result; a third prediction module, configured to input the hash result into the subsequent predictor to determine a subsequent prediction result based on a second label prediction table included in the subsequent predictor, wherein the number of the first label prediction tables does not exceed the number of the second label prediction tables, and the first label prediction table is a subtable of the second label prediction table; A branch prediction module, configured to, when the previous stage prediction result and the next stage prediction result are different, overwrite the previous stage prediction result with the next stage prediction result as the branch prediction result; The hash result includes a tag; The hash result of the branch address and the global branch history is input into the front-stage auxiliary predictor to determine the second prediction result based on the first label prediction table included in the front-stage auxiliary predictor, including: inputting the label into the front-stage auxiliary predictor to perform a fully associative match; when the label is equal to any label field in the first label prediction table, the front-stage auxiliary predictor hits and outputs the highest bit of the counter field of the hit label prediction table entry as the second prediction result.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
Citation Information
Patent Citations
Branch prediction method and device and storage medium
CN117909254A
Re-order buffer managing method and processor
US20020091913A1
