Control method of multi-branch jump chain prediction information and related device
Patent Information
- Application Number
- CN202611088497.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-22
- Publication Date
- 2026-10-20
AI Technical Summary
[0005]鉴于此,本申请的目的在于提供一种多分支跳转链预测信息的控制方法、分支预测器、处理器及电子设备,以改善现有分支预测器的预取准确率不高的问题
[0034]其中,第二方面至第五方面中任一种实现方式所带来的技术效果可参见第一方面中相同或者类似实现方式所带来的技术效果,此处不再赘述。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer science, and specifically relates to a control method and related equipment for predicting multi-branch jump chain information, wherein the related equipment includes a branch predictor, a processor, and electronic equipment. Background Technology
[0002] At the processor's instruction fetch front end, the branch predictor predicts the direction of control flow and the target address of the branch instruction in memory before its actual execution. To improve fetch throughput, the branch predictor can predict subsequent multi-branch jumps based on multi-branch jump chain prediction information, thereby generating multiple jump branch prediction results in a single prediction process. This multi-branch jump chain prediction information is used to represent the continuity of control flow between multiple jump branch prediction results at the prediction level, without requiring these branch instructions to be consecutive in static address space or located in adjacent instruction blocks or fetch blocks.
[0003] The branch whose jump result is directly predicted and output by the multi-branch jump chain prediction information is called an intra-chain jump branch. For two adjacent intra-chain jump branches, the target region (instruction region) pointed to by the predicted target of the preceding intra-chain jump branch is the continuous instruction fetch range of the instruction region where the subsequent intra-chain jump branch is located. The branch predictor also predicts the target address of the subsequent intra-chain jump branch within this target region. In other words, the multi-branch jump chain prediction information implicitly assumes that the target region of the preceding intra-chain jump branch should be able to reach the subsequent intra-chain jump branch.
[0004] Based on this implicit relationship, existing multi-branch jump chain prediction mechanisms typically train and maintain only branches that can serve as intra-chain jump branches. In these mechanisms, the branch predictor determines whether multi-branch jump chain prediction information is trained, participates in prediction, or remains valid based on the target relationship, type relationship, historical training results, or the historical success rate of the entire prediction chain among the intra-chain jump branches. Here, the target relationship refers to the constraints associated with the branch target address, such as whether the number of target addresses is unique or within a certain range; the type relationship refers to the type of branch instruction, including conditional branches, unconditional branches, direct branches, indirect branches, subroutine calls, subroutine returns, and combinations of these types; historical training results refer to the historical behavior information associated with the branch chain or the branches themselves, such as recent jump frequency or recent chain formation frequency; and the historical success rate of the entire prediction chain refers to the overall prediction accuracy frequency of the prediction chain. Some mechanisms also maintain an overall confidence level for the entire multi-branch jump chain to determine the reliability of the multi-branch jump chain prediction information. However, these mechanisms are prone to low prefetch accuracy in practical applications. Summary of the Invention
[0005] Therefore, the purpose of this application is to provide a control method, branch predictor, processor and electronic device for multi-branch jump chain prediction information, so as to improve the problem of low prefetch accuracy of existing branch predictors.
[0006] The embodiments of this application are implemented as follows: In a first aspect, embodiments of this application provide a method for controlling multi-branch jump chain prediction information, comprising: acquiring jump branch prediction results, wherein the jump branch prediction results are generated based on multi-branch jump chain prediction information and the jump branch prediction results include multiple intra-chain jump branches; determining target regions corresponding to adjacent intra-chain jump branches in the jump branch prediction results; identifying inter-chain dynamic branches within the target regions, wherein the inter-chain dynamic branches are not directly predicted as intra-chain jump branches by the multi-branch jump chain prediction information; acquiring the local prediction state of the inter-chain dynamic branches themselves; and performing at least one of training control, prediction control, or failure control on the multi-branch jump chain prediction information based on the local prediction state.
[0007] In the above implementation scheme, when the branch predictor trains, predicts, or controls the failure of multi-branch jump chain prediction information, this application not only considers the intra-chain jump branches directly predicted by the prediction information, but also further identifies the inter-chain dynamic branches within the target region between adjacent intra-chain jump branches. Utilizing the local prediction state of the inter-chain dynamic branches themselves, it determines whether the multi-branch jump chain prediction information is suitable for training, participation in prediction, or continued validity. In this way, the stability of using multi-branch jump chain prediction information can be improved without increasing or simplifying the implementation of complete dynamic prediction support for inter-chain branches, thereby reducing the probability of mismatch between prediction layer mapping and actual control, and ultimately improving the prefetch accuracy of the branch predictor.
[0008] In one possible implementation of the first aspect embodiment, the local prediction state includes at least one of the following: prediction confidence, directional bias, prediction source, and behavioral stability information.
[0009] In the above implementation scheme, the suitability of inter-chain dynamic branches for implicit path mapping can be evaluated from different dimensions. For example, prediction confidence can be used to avoid using prediction information when the prediction is unreliable; directional bias can be used to identify the risk of control flow deviating from subsequent branches; prediction source can be used to ensure that the judgment basis comes from a reliable prediction structure; and behavioral stability can be used to avoid continuing to rely on the prediction information when the branch behavior is unstable. This allows the application to not only flexibly adapt to the judgment needs of different types of inter-chain dynamic branches, but also to more accurately identify local control flow points that cause instability in prediction layer mapping from multiple dimensions. Compared with existing technologies that rely solely on the overall confidence of the entire prediction chain, this application can effectively reduce the probability of mismatch between prediction layer mapping and actual control flow, while retaining the throughput benefits of indexing in stable scenarios.
[0010] In one possible implementation of the first aspect embodiment, based on the local prediction state, at least one of training control, prediction control, or failure control is applied to the multi-branch jump chain prediction information, including: determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state, and obtaining a determination result; wherein, the implicit traversal condition is used to determine whether the current inter-chain dynamic branch is suitable for implicit traversal by the prediction layer mapping represented by the multi-branch jump chain prediction information; and applying at least one of training control, prediction control, or failure control to the multi-branch jump chain prediction information based on the determination result.
[0011] In the above implementation scheme, by further introducing implicit traversal conditions as the basis for control decisions and executing corresponding control actions based on the judgment results, the local predicted state of dynamic branches between chains is linked to specific control actions (training control, predictive control, or failure control). This makes control decisions based on evidence and avoids control blind spots caused by a lack of clear judgment criteria. Simultaneously, the introduction of implicit traversal conditions further refines the control granularity, enabling differentiated judgment results based on the specific circumstances of different dynamic branches between chains (e.g., whether the prediction confidence level meets the standard, whether the direction bias deviates, whether the prediction source is reliable, whether the behavior is stable, etc.). This achieves precise control over different branches, improving prediction accuracy while also considering throughput benefits. Furthermore, the implicit traversal conditions can be set flexibly and diversely, allowing for individual or combined settings for different types of local predicted states to adapt to different processor microarchitecture design requirements.
[0012] In one possible implementation of the first aspect embodiment, the local prediction state includes the prediction confidence of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: if the prediction confidence is lower than a preset confidence threshold, then determining that the inter-chain dynamic branch does not satisfy the implicit traversal condition; if the prediction confidence reaches or exceeds the preset confidence threshold, then determining that the inter-chain dynamic branch satisfies the implicit traversal condition.
[0013] In the above implementation scheme, when the local prediction state includes the prediction confidence of inter-chain dynamic branches, the implicit traversal condition can be set as follows: the prediction confidence of any inter-chain dynamic branch is not lower than a preset confidence threshold. After obtaining the prediction confidence of the inter-chain dynamic branch, the predictor compares it with the preset confidence threshold: if the prediction confidence is lower than the preset confidence threshold, it is determined that the inter-chain dynamic branch does not meet the implicit traversal condition; if the prediction confidence reaches or exceeds the preset confidence threshold, it is determined that the inter-chain dynamic branch meets the implicit traversal condition. In this way, the predictor only needs to perform a simple numerical comparison to quickly determine whether the inter-chain dynamic branch meets the implicit traversal condition, without performing complex calculations or multi-dimensional state analysis, reducing the hardware overhead and latency of the judgment logic; at the same time, the preset confidence threshold can be flexibly configured according to different implementation requirements. For example, high-performance processors can set a higher confidence threshold to ensure prediction accuracy, while low-power processors can set a lower confidence threshold to reduce the performance loss caused by restricting the use of prediction information.
[0014] In one possible implementation of the first aspect embodiment, the local prediction state includes the directional bias of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: if the directional bias indicates that the inter-chain dynamic branch tends to jump to a direction deviating from the subsequent intra-chain jump branch, then the inter-chain dynamic branch is determined not to satisfy the implicit traversal condition; if the directional bias indicates that the inter-chain dynamic branch tends to be implicitly traversed to reach the direction of the subsequent intra-chain jump branch, then the inter-chain dynamic branch satisfies the implicit traversal condition.
[0015] In the above implementation scheme, when the local prediction state includes the directional bias of inter-chain dynamic branches, the implicit traversal condition can be set as follows: any inter-chain dynamic branch must be biased without jumping; after the branch predictor obtains the directional bias of the inter-chain dynamic branch, if the directional bias indicates that the inter-chain dynamic branch tends to jump to a direction deviating from the subsequent intra-chain jump branch, then the inter-chain dynamic branch is determined not to meet the implicit traversal condition; if the directional bias indicates that the inter-chain dynamic branch tends to be implicitly traversed to reach the direction of the subsequent intra-chain jump branch, then the inter-chain dynamic branch is determined to meet the implicit traversal condition. In this way, the branch predictor can quickly determine whether the control flow may deviate from the subsequent intra-chain jump branch using the directional bias of the inter-chain dynamic branch, thereby achieving early control and avoiding the continued use of prediction information when the control flow may deviate.
[0016] In one possible implementation of the first aspect embodiment, the local prediction state includes the prediction source of the inter-chain dynamic branch, the prediction source representing the reliability of the prediction source of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: if the prediction source represents that the inter-chain dynamic branch is not confirmed by a preset reliable prediction structure, or is predicted by a non-preset reliable prediction structure, then the inter-chain dynamic branch is determined not to satisfy the implicit traversal condition; if the prediction source represents that the inter-chain dynamic branch is confirmed by a preset reliable prediction structure, then the inter-chain dynamic branch is determined to satisfy the implicit traversal condition.
[0017] In the above implementation scheme, when the local prediction state includes the prediction source of inter-chain dynamic branches, the implicit traversal condition can be that the prediction source information of any inter-chain dynamic branch must originate from a reliable prediction structure. After the branch predictor obtains the prediction source of the inter-chain dynamic branch, it determines whether the prediction source indicates confirmation by a preset reliable prediction structure, thus quickly determining whether the implicit traversal condition is met. In this way, the predictor can use the prediction source state to determine whether the prediction result of the inter-chain dynamic branch originates from a reliable prediction structure, thereby ensuring that the prediction state on which the control decision depends has sufficient reliability.
[0018] In one possible implementation of the first aspect embodiment, the local prediction state includes behavioral stability information of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: if the behavioral stability information indicates that the behavior of the inter-chain dynamic branch is unstable, then it is determined that the inter-chain dynamic branch does not satisfy the implicit traversal condition; if the behavioral stability information indicates that the behavior of the inter-chain dynamic branch is stable, then it is determined that the inter-chain dynamic branch satisfies the implicit traversal condition.
[0019] In the above implementation scheme, when the local prediction state includes the behavioral stability information of inter-chain dynamic branches, the implicit traversal condition can be set as follows: the target address prediction result of the inter-chain dynamic branch is stable, and / or the recent behavior of all inter-chain dynamic branches is stable. The branch predictor obtains the behavioral stability information of the inter-chain dynamic branches and determines whether the above implicit traversal condition is met based on this information. If the behavioral stability information indicates that the target address prediction result of the inter-chain dynamic branch is unstable, or the recent behavior is unstable, then the inter-chain dynamic branch is determined not to meet the implicit traversal condition; conversely, if the behavioral stability information indicates that the target address prediction result of the inter-chain dynamic branch is stable and the recent behavior is stable, then the implicit traversal condition is met. In this way, the branch predictor can use the behavioral stability information to accurately identify whether the behavior pattern of the inter-chain dynamic branches is stable, avoid continuing to use the prediction information when the branch behavior is unstable, thereby reducing the mismatch between the prediction layer mapping and the actual control caused by changes in the behavior of inter-chain dynamic branches, and improving the stability of the use of multi-branch jump chain prediction information.
[0020] In one possible implementation of the first aspect embodiment, the multi-branch jump chain prediction information is subjected to at least one of training control, prediction control, or failure control based on the judgment result, including: when the judgment result indicates that the inter-chain dynamic branch satisfies the implicit traversal condition, the multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain valid; when the judgment result indicates that the inter-chain dynamic branch does not satisfy the implicit traversal condition, the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid.
[0021] In the above implementation scheme, multi-branch jump chain prediction information is only allowed to be trained, participate in prediction, or remain valid when the dynamic branches between chains meet the implicit traversal conditions. Otherwise, the training of multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is made invalid. Through the selective control mechanism (allow if the condition is met, restrict if the condition is not met), it is possible to improve prediction accuracy while taking performance into account.
[0022] In one possible implementation of the first aspect embodiment, the local prediction state includes the type of the inter-chain dynamic branch or the position of the inter-chain dynamic branch in the target region; based on the local prediction state, at least one of training control, prediction control, or failure control is applied to the multi-branch jump chain prediction information, including: if the type of the inter-chain dynamic branch is a preset type, or the position of the inter-chain dynamic branch in the target region is a preset position, then the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid.
[0023] In the above implementation scheme, the type or location of inter-chain dynamic branches can be used for rapid determination, enabling training control, prediction control, or failure control of multi-branch jump chain prediction information. This achieves low-cost, low-latency, and rapid control. Simultaneously, this method can serve as a pre-filter, prioritizing the exclusion of inter-chain dynamic branches that are clearly unsuitable for the predicted layer's implicit mapping, allowing subsequent fine-grained judgments to focus on branches that require more evaluation, reducing unnecessary state reading and judgment overhead. Furthermore, type or location information can usually be obtained during instruction pre-decoding or instruction fetching, eliminating the need for additional maintenance of dynamic prediction states, making it suitable for implementation scenarios with limited hardware resources or power sensitivity.
[0024] In one possible implementation of the first aspect embodiment, the training control includes at least one of the following: prohibiting the creation of new multi-branch jump chain prediction information; prohibiting the updating of the multi-branch jump chain prediction information; prohibiting the updating of candidate prediction information to multi-branch jump chain prediction information; reducing the training priority of the multi-branch jump chain prediction information; and suppressing repeated training of the multi-branch jump chain prediction information under the same or similar local prediction states.
[0025] In the above implementation scheme, one or more of the above control measures are used to limit the training control of branch jump chain prediction information. This can intervene in the formation of prediction information at multiple levels during the training phase, avoid solidifying unstable control flow relationships into subsequent reusable prediction information, and reduce the probability of erroneous predictions from the source.
[0026] In one possible implementation of the first aspect embodiment, the prediction control includes at least one of the following: restricting the multi-branch jump chain prediction information from participating in prediction; restricting the multi-branch jump chain prediction information from outputting prediction results for multiple in-chain jump branches; masking the prediction results for subsequent in-chain jump branches; downgrading the multi-branch jump chain prediction information to only output the prediction results for the preceding in-chain jump branches; and ignoring the multi-branch jump chain prediction information in the current prediction period.
[0027] In the above implementation scheme, one or more of the above control measures are used to restrict the participation of branch jump chain prediction information in prediction. This allows for intervention in the output of prediction information at different levels during the prediction phase, preventing the continued output of inaccurate subsequent branch prediction results when dynamic branches between chains do not meet the implicit traversal conditions. This reduces the error in instruction fetching caused by mismatch between prediction layer mapping and actual control.
[0028] In one possible implementation of the first aspect embodiment, the failure control includes at least one of the following: disabling the multi-branch jump chain prediction information; deleting the multi-branch jump chain prediction information; downgrading the multi-branch jump chain prediction information to non-multi-branch jump chain prediction information; clearing the valid states in the multi-branch jump chain prediction information used to generate subsequent intra-chain jump branch prediction results; adjusting the state of the multi-branch jump chain prediction information so that it no longer participates in multi-branch jump chain prediction; and suppressing the multi-branch jump chain prediction information from re-participating in training or prediction under the same or similar local prediction states.
[0029] In the above implementation scheme, one or more of the above control measures are used to control the failure of multi-branch jump chain prediction information. This can terminate the continued use of erroneous prediction information in a timely manner and avoid repeated erroneous predictions caused by the continuous mismatch between the prediction layer mapping and the actual control flow.
[0030] Secondly, embodiments of this application also provide a branch predictor, including: a prediction unit, a target region determination unit, an identification unit, an acquisition unit, and a control unit; the prediction unit is used to generate a branch prediction result based on multi-branch jump chain prediction information, wherein the branch prediction result includes multiple intra-chain jump branches; the target region determination unit is used to determine the target region corresponding to adjacent intra-chain jump branches in the branch prediction result; the identification unit is used to identify inter-chain dynamic branches within the target region, wherein the inter-chain dynamic branches are not directly predicted as intra-chain jump branches by the multi-branch jump chain prediction information; the acquisition unit is used to acquire the local prediction state of the inter-chain dynamic branches themselves; the control unit is used to perform at least one of training control, prediction control, or failure control on the multi-branch jump chain prediction information according to the local prediction state.
[0031] Thirdly, embodiments of this application also provide a processor, including the branch predictor provided in the second aspect embodiment.
[0032] Fourthly, embodiments of this application also provide an electronic device, including the processor provided in the third aspect embodiment.
[0033] Fifthly, embodiments of this application also provide an electronic device, including: a memory and a processor, the processor being connected to the memory; the memory being used to store a program; the processor being used to invoke the program stored in the memory to perform a method provided as described in the first aspect embodiments and / or in combination with any possible implementation of the first aspect embodiments.
[0034] The technical effects of any of the implementation methods in the second to fifth aspects can be referred to the technical effects of the same or similar implementation methods in the first aspect, and will not be repeated here.
[0035] Other features and advantages of this application will be set forth in the following description. The objectives and other advantages of this application can be realized and obtained through the structures specifically pointed out in the written description and the accompanying drawings. Attached Figure Description
[0036] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings used in the embodiments will be briefly described below. Obviously, the drawings described below are only some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings. The above and other objects, features, and advantages of this application will become clearer through the accompanying drawings.
[0037] Figure 1 This illustration shows a schematic diagram of the relationship between an intra-chain jump branch and an inter-chain dynamic branch provided in this application.
[0038] Figure 2 The diagram illustrates the flow of a control method for predicting multi-branch jump chain information provided in this application.
[0039] Figure 3 A flowchart illustrating another method for controlling multi-branch jump chain prediction information provided in this application is shown.
[0040] Figure 4 This illustration shows a schematic diagram of the principle of controlling dynamic branches between chains based on the type or position provided in this application.
[0041] Figure 5 This illustration shows a schematic diagram of a control principle based on implicit pass conditions provided in this application.
[0042] Figure 6 A schematic diagram of a control method provided in this application is shown.
[0043] Figure 7 A schematic diagram of the structure of a branch predictor provided in this application is shown.
[0044] Figure 8 A schematic diagram of another branch predictor provided in this application is shown.
[0045] Figure 9 A schematic diagram of the structure of an electronic device provided in this application is shown. Detailed Implementation
[0046] The technical solutions of the embodiments of this application will now be described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. The following embodiments are provided as examples to more clearly illustrate the technical solutions of this application, and should not be used to limit the scope of protection of this application. Those skilled in the art will understand that, without conflict, the following embodiments and features can be combined with each other.
[0047] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, relational terms such as "first," "second," etc., in the description of this application are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus.
[0048] Furthermore, the term "and / or" in this application is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0049] In the description of the embodiments of this application, unless otherwise expressly specified and limited, the technical term "connection" can be a direct connection or an indirect connection through an intermediate medium.
[0050] To facilitate understanding of the solutions in the embodiments of this application, some related technical terms that may be used will be explained below: Branch predictor: A prediction structure in the processor's instruction fetch front end used to predict the direction of program execution control flow and the target address of the branch instruction in memory before the branch instruction is actually executed.
[0051] Multi-branch jump chain: refers to the continuous control flow relationship formed between multiple jump branches in the control flow of executed instructions. This continuous control flow relationship belongs to the control flow facts that have already occurred and can serve as an objective basis for the branch predictor to learn and maintain the corresponding prediction information. In the subsequent prediction process, the branch predictor can generate corresponding prediction results based on this prediction information, but the prediction results do not indicate that the actual execution control flow of the program will necessarily be like this in the future.
[0052] Multi-branch jump chain prediction information: Based on the prediction layer mapping formed by the branch predictor through multi-branch jump chain learning or training, it is used to characterize the control flow continuity relationship between multiple jump branches and generate the corresponding multi-branch jump chain prediction results in the subsequent instruction control flow prediction process.
[0053] In-chain jump branch: In the prediction layer mapping of a multi-branch jump chain, the branch that is selected as the explicit prediction object by the multi-branch jump chain prediction information and whose jump branch prediction result is directly generated by the prediction information. The in-chain jump branch is defined by the prediction layer and is not required to be reached in actual execution.
[0054] Adjacent intra-chain jump branches: In the prediction layer mapping formed by the prediction information of multi-branch jump chains, there are two intra-chain jump branches with a continuous relationship of control flow before and after.
[0055] Target region: Located between adjacent intra-chain jump branches, it is a prediction region starting from the address pointed to by the predicted target of the previous intra-chain jump branch. It is used to determine whether the prediction result of the subsequent intra-chain jump branch can be formed.
[0056] Inter-chain dynamic branches: These are dynamic branches located within the target area between adjacent intra-chain jump branches. They are not directly predicted as intra-chain jump branches by the multi-branch jump chain prediction information, but changes in their direction or target address may affect whether the actual control flow continues to reach subsequent intra-chain jump branches. This branch is not an arbitrary branch in the actual control flow, nor is it a branch that is guaranteed not to jump.
[0057] Local prediction state: Prediction state information formed by the dynamic branches between chains themselves, which is different from the overall confidence information formed for the entire multi-branch jump chain. The local prediction state includes at least one of the following: prediction confidence, directional bias, prediction source, and behavioral stability information. It may also include the type of the dynamic branches between chains or their location in the target region.
[0058] Implicit traversal condition: Used to determine whether the current dynamic branch between chains is suitable for implicit traversal of the prediction layer mapping represented by the multi-branch jump chain prediction information. In other words, the implicit traversal condition is the condition used to determine whether the current dynamic branch between chains is suitable for implicit traversal of the prediction layer mapping of the multi-branch jump chain.
[0059] To illustrate that the "multi-branch jump chain" in this application is a prediction layer mapping rather than an actual control flow fact, an abstract example is given below.
[0060] like Figure 1As shown, assuming there is a multi-branch jump chain prediction information in the branch predictor, this prediction information directly outputs the prediction results of two jump branches in one prediction process: <Jump branch A> jumps to <the region where jump branch B is located> jumps to <the target region of jump branch B>. The two jump branches are intra-chain jump branches, and the "region where jump branch B is located" is the "target region of jump branch A".
[0061] The prediction layer mapping corresponding to this prediction information can be represented as: <jump branch A> jumps to <the region where jump branch B is located> jumps to <the target region of jump branch B>; where "the region where jump branch B is located" is "the target region of jump branch A".
[0062] It should be noted that the above prediction layer mapping means that the branch predictor believes that after the jump result of A is true, it can continue to form the jump prediction result of B. However, this mapping does not mean that the actual execution control flow will necessarily reach B from A. In actual execution, the control flow enters a target region from the predicted target of A. There may be a dynamic branch X in this target region, and its execution path can be represented as: <Jump to branch A> jumps to <target area of jump branch A>; ↓ Execute the ordinary instruction within the target area of branch A; ↓ Execute <Jump to dynamic branch X within the target area of branch A>; ↓ Execute the ordinary instruction within the target area of branch A; ↓ <Jump to branch B> Jump to <Target area of branch B>.
[0063] In the example above, A and B are intra-chain jump branches because they are branches directly predicted and output by the multi-branch jump chain prediction information. X is an inter-chain dynamic branch because X is located within the target region between A and B, but was not directly predicted as an intra-chain jump branch by the multi-branch jump chain prediction information. X is not an irrelevant branch, nor is it a branch that will not necessarily jump in the actual control flow; changes in the direction or target address of X may affect whether the actual control flow continues to reach B.
[0064] Based on the above analysis, if the change in the current actual direction or target address of X does not prevent the control flow from reaching B, the prediction layer mapping may be consistent with the actual control flow, allowing the corresponding prediction information to participate in prediction, training, or maintain effectiveness. If the change in the current direction or target address of X causes the control flow to deviate from B, the prediction layer mapping may be inconsistent with the actual control flow, potentially limiting prediction or triggering failure. If the prediction confidence of X is low, or its prediction source is insufficient to reliably determine whether X will affect reaching B, training, prediction, or failure can be limited even if no actual error has occurred.
[0065] Therefore, although inter-chain dynamic branches are not directly predicted as intra-chain jump branches, changes in their direction or target can significantly affect the consistency between the prediction layer mapping and the actual control flow. However, given the current problem of low prefetch accuracy, the inventors of this application discovered during their research that existing multi-branch jump chain prediction mechanisms typically only focus on branches that can serve as intra-chain jump branches. Their training and maintenance revolve solely around intra-chain jump branches, while other branches or control flow changes that may occur during actual program execution are not taken into account. This can lead to deviations between the control flow continuity on which the predictor relies and the actual situation. When such deviations occur, the prediction information may still be used, resulting in jump prediction results that do not match the actual control flow, thus reducing the prefetch accuracy of the instruction fetching front end.
[0066] For example, within the target region corresponding to adjacent intra-chain jump branches, there may be dynamic branches that were not directly predicted as intra-chain jump branches (i.e., inter-chain dynamic branches X in the example above). The direction or target address of these inter-chain dynamic branches changes with the runtime context, which may alter whether the control flow can actually reach subsequent intra-chain jump branches. However, existing mechanisms do not include inter-chain dynamic branches located within the target region in training, prediction, or failure control. Since these inter-chain dynamic branches are not explicitly predicted by the prediction information, changes in their direction or target address may cause inconsistencies between the prediction layer mapping and the actual control flow, thus affecting whether subsequent intra-chain jump branches are actually reachable. Existing mechanisms fail to address this issue, therefore prediction information may still be used, leading to erroneous predictions.
[0067] The purpose of this invention is to solve a control blind spot in multi-branch jump chain prediction: although the inter-chain dynamic branch is not directly predicted as the intra-chain jump branch, the inter-chain dynamic branch is located between adjacent intra-chain jump branches, and its direction or target address change will affect whether the subsequent intra-chain jump branch is suitable to be predicted.
[0068] This approach does not transform inter-chain dynamic branches into intra-chain jump branches, nor does it simply maintain the overall confidence level for the entire multi-branch jump chain. Instead, it utilizes the local prediction state of the inter-chain dynamic branches themselves to determine whether the prediction information of the multi-branch jump chain is suitable for training, participation in prediction, or continued validity. In this way, without increasing or simplifying the implementation of full dynamic prediction support for inter-chain branches, the stability of the use of multi-branch jump chain prediction information can be improved, thereby reducing the probability of mismatch between prediction layer mapping and actual control, and ultimately improving the prefetch accuracy of the branch predictor.
[0069] To achieve the above objectives, this scheme, when training or using the multi-branch jump chain prediction information, not only considers the intra-chain jump branches directly predicted by the prediction information, but also further identifies the inter-chain dynamic branches within the target region between adjacent intra-chain jump branches, and further obtains the local prediction state of the inter-chain dynamic branches themselves. Based on the local prediction state, at least one of the following controls is applied to the multi-branch jump chain prediction information: training control, prediction control, or failure control. For example, based on the local prediction state, it is determined whether the inter-chain dynamic branches meet the implicit traversal condition. When the inter-chain dynamic branches meet the implicit traversal condition, the corresponding multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain valid; when the inter-chain dynamic branches do not meet the implicit traversal condition, the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid.
[0070] Therefore, this scheme can precisely control the training, prediction, or failure of multi-branch jump chain prediction information by utilizing the local prediction state of the inter-chain dynamic branches themselves, without directly predicting the inter-chain dynamic branches as intra-chain jump branches.
[0071] To achieve the above objectives, this application provides a control method and related equipment for predicting multi-branch jump chain information, wherein the related equipment includes a branch predictor, a processor, and electronic equipment. The following describes the method in conjunction with... Figure 2 The control method for multi-branch jump chain prediction information provided in this application is described. This control method can be executed by a processor, for example, by a branch predictor in the processor.
[0072] S1: Obtain the jump branch prediction result.
[0073] In one possible implementation, the jump branch prediction results can be obtained from external sources or memory, wherein the jump branch prediction results are generated based on multi-branch jump chain prediction information and contain multiple in-chain jump branches.
[0074] In one possible implementation, multi-branch jump chain prediction information can be obtained from external storage or memory, and then jump branch prediction results can be generated based on the multi-branch jump chain prediction information.
[0075] Among these, multi-branch jump chain prediction information can be formed based on multi-branch jump chain information. This information reflects the objectively existing multi-branch jump chain behavior during program execution; this behavior is an inherent characteristic of the program execution sequence and will not change due to the presence or absence of a branch predictor. The branch predictor learns and trains on this multi-branch jump chain information to form multi-branch jump chain prediction information. This prediction information is used to characterize the control flow continuity relationship between multiple intra-chain jump branches at the prediction level.
[0076] The carriers for implementing multi-branch jump chain prediction information include, but are not limited to, prediction table entries, prediction cache entries, chained prediction records, training records, state fields, BTB (Branch Target Buffer) type prediction structures, front-end control flow records, or other information structures that can support prediction results of multiple intra-chain jump branches in a single prediction process. As long as the prediction information is used to form a prediction layer mapping between multiple intra-chain jump branches and can be used for training, prediction, or failure control based on the local prediction state of dynamic branches between chains, it can be considered an alternative implementation under the same inventive concept.
[0077] S2: Determine the target region between adjacent chain jump branches in the jump branch prediction results.
[0078] After obtaining the jump branch prediction result, the target region corresponding to the jump branches in adjacent chains within the prediction result can be determined. This target region can be directly or indirectly indicated by the multi-branch jump chain prediction information recorded in the branch predictor. For example, one entry in this prediction information records "Branch A jumps to target region B, target region B contains branch B, and branch B jumps to target region C". When the instruction fetch unit fetches branch A, the branch predictor instructs the instruction fetch unit to continue fetching instructions for target regions B and C based on this prediction information. The prediction information can record the jump target addresses of each branch in the branch jump chain; the target region is the instruction fetch space pointed to by these target addresses.
[0079] The determination of the target region is not limited to fixed-size fetch blocks or prediction blocks. It can be a prediction block, multiple prediction blocks, a fetch block, multiple fetch blocks, or a region determined by the branch predictor based on the prediction target, prediction window, fetch boundary, prediction structure granularity, or other front-end related information of the preceding in-chain jump branch. As long as the region is located between adjacent in-chain jump branches and is used to identify inter-chain dynamic branches that are not directly predicted as in-chain jump branches, it can belong to the target region of this application.
[0080] S3: Identify dynamic inter-chain branches within the target region.
[0081] Once the target region is determined, the inter-chain dynamic branches within the target region can be identified. These inter-chain dynamic branches are not directly predicted by the multi-branch jump chain prediction information as intra-chain jump branches.
[0082] The branch predictor can identify branch instructions within the target region, excluding intra-chain jump branches, as inter-chain dynamic branches. For example, a prediction entry records "Branch A jumps to target region B, target region B contains branch B, and branch B jumps to target region C." Instructed by this prediction information, the predictor first determines that the intra-chain jump branches are A and B, and then determines the target region B to which the prediction target of A points, and the target region C to which the prediction target of B points. Besides A and B, which are intra-chain jump branches, other branch instructions within the target region located in the fetch block containing branch A, as well as other branch instructions within target region B excluding branch B, can all be identified as inter-chain dynamic branches.
[0083] S4: Obtain the local predicted state of the dynamic branch between chains.
[0084] After identifying a dynamic branch between chains, the local prediction state of that branch can be obtained. This local prediction state includes at least one of the following: prediction confidence, direction bias, prediction source, and behavioral stability information (including target stability and / or recent behavioral stability). This information in the local prediction state can be obtained by the branch predictor or performance monitoring unit in the processor by statistically analyzing the branch's historical behavior for later use. For example, the prediction confidence can be obtained from a confidence counter maintained by the branch predictor for that branch; the direction bias can be obtained from a direction counter maintained by the branch predictor for that branch; and the behavioral stability information can be obtained by the performance monitoring unit by statistically analyzing the branch's historical jump behavior.
[0085] In some implementations, the local predicted state may also include the type of dynamic inter-chain branch or its location within the target region.
[0086] If there are multiple inter-chain dynamic branches, there will be multiple local prediction states; that is, each inter-chain dynamic branch corresponds to a local prediction state. Local prediction states can be obtained through at least one of the following methods: branch type detection results (used to obtain the type of the inter-chain dynamic branch), branch position detection results (used to obtain the position of the inter-chain dynamic branch in the target region), direction counter (used to obtain directional bias), target prediction results (used to obtain target stability information or recent behavior stability information), prediction confidence counter (used to obtain prediction confidence, target stability information, or recent behavior stability information), prediction source marker (used to obtain the prediction source state), target stability statistics (used to obtain target stability information), recent behavior statistics (used to obtain recent behavior stability information), or historical behavior records related to the inter-chain dynamic branch (used to obtain target stability information or recent behavior stability information). The above methods can be used individually or in combination, and the specific implementation can be flexibly configured according to the processor design requirements.
[0087] At the representation level, the aforementioned local predicted state can be represented by a counter, flag bits, state vector, table entry extension fields, prediction source identifier, historical statistical information, or a combination of the above methods. It is understood that the acquisition and representation methods described above can be flexibly selected and combined according to processor design requirements, and the specific implementation method does not constitute a limitation on this solution.
[0088] In one possible implementation, the local prediction state can be stored in a branch prediction table, a prediction cache, a BTB-type prediction structure, an instruction fetch queue, a training information cache, prediction block metadata, a control flow state record structure, table entry extended fields, a state vector, or a state flag. The local prediction state can be provided by a single prediction structure or by a combination of multiple prediction structures. For example, a direction prediction structure can provide direction bias; a target prediction structure can provide target stability information; a prediction source marker can provide the prediction source; and a historical statistics structure can provide recent behavior stability information. This information can be used individually or in combination to determine whether dynamic branches between chains satisfy implicit traversal conditions.
[0089] It is understood that the specific storage location and acquisition method of the local prediction state can be flexibly configured according to design requirements, and the above examples do not constitute a limitation on this solution. The specific bit width, encoding format, update cycle and storage location of the local prediction state do not constitute a limitation on this solution. As long as the state is formed for the inter-chain dynamic branch itself and is used to determine whether the inter-chain dynamic branch is suitable for the implicit mapping of the predicted layer, it can be used as the local prediction state of this application.
[0090] S5: Based on the local predicted state, perform at least one of the following controls on the multi-branch jump chain prediction information: training control, predictive control, or failure control.
[0091] After obtaining the aforementioned local prediction state, at least one of the following controls—training control, predictive control, or failure control—can be applied to the multi-branch jump chain prediction information based on the local prediction state.
[0092] In some possible implementations, the method for controlling multi-branch jump chain prediction information provided in this application can also be as follows: Figure 3 As shown. Figure 3 The process shown is the same as Figure 2 The processes shown are largely the same, the difference being that... Figure 3 Instead of directly obtaining the jump branch prediction results, it first obtains multi-branch jump chain information, and then forms multi-branch jump chain prediction information based on the multi-branch jump chain information. Finally, it generates jump branch prediction results based on the multi-branch jump chain prediction information. Figure 3 Steps one through six are numbered in the method flow, and do not mean that each step must be executed by a physically independent module, nor does it exclude that different steps are completed by the same control logic or the same prediction update path within the same prediction cycle.
[0093] The following describes, with reference to different embodiments, how to perform training control, predictive control, or failure control on the prediction information of multi-branch jump chains based on the local prediction state.
[0094] Example 1 If the local prediction state includes the type of inter-chain dynamic branches or the position of inter-chain dynamic branches in the target region, then the process of training control, prediction control, or failure control of the multi-branch jump chain prediction information based on the local prediction state may include: if the type of inter-chain dynamic branches is a preset type (e.g., inter-chain dynamic branches cannot be indirect branch types, conditional branch types, etc.), or the position of inter-chain dynamic branches in the target region is a preset position (e.g., inter-chain dynamic branches cannot appear in a specific position in the target region, such as the first position, the middle position, etc.), then the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid. Conversely, if the type of inter-chain dynamic branches is not a preset type, or the position of inter-chain dynamic branches in the target region is not a preset position, then the multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain valid.
[0095] The types of dynamic branches between chains can be conditional branches, unconditional branches, direct branches, indirect branches, subroutine calls, subroutine returns, etc. In some implementations, they can also be composite types formed by combining the above types, such as direct conditional branches, indirect conditional branches, indirect subroutine calls, and indirect subroutine returns.
[0096] In this implementation, the local prediction state of each inter-chain dynamic branch within the target area can be obtained; then, based on the local prediction state of each inter-chain dynamic branch, training control, prediction control, or failure control can be performed on the multi-branch jump chain prediction information. If the type of any inter-chain dynamic branch within the target area is a preset type, or if the position of any inter-chain dynamic branch within the target area is a preset position, then the training of the multi-branch jump chain prediction information can be restricted, its participation in prediction can be restricted, or it can be rendered invalid.
[0097] To improve efficiency, such as Figure 4 As shown, when identifying inter-chain dynamic branches within a target area, the branch predictor may detect whether there is a preset type of inter-chain dynamic branch within the target area, or detect whether there is a preset position of inter-chain dynamic branch within the target area. If such an inter-chain dynamic branch exists, the training of multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid. If such an inter-chain dynamic branch does not exist, the multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain valid.
[0098] Example 2 If the local prediction state includes at least one of the following: prediction confidence, direction bias, prediction source, and behavioral stability information, then the process of training control, prediction control, or failure control of the multi-branch jump chain prediction information based on the local prediction state may include: determining whether the dynamic branches between chains meet the implicit traversal conditions based on the local prediction state, and obtaining the determination result; and performing training control, prediction control, or failure control on the multi-branch jump chain prediction information based on the determination result, wherein the implicit traversal conditions are used to determine whether the dynamic branches between chains are currently suitable for implicit traversal by the prediction layer mapping represented by the multi-branch jump chain prediction information.
[0099] When performing training control, prediction control, or failure control on multi-branch jump chain prediction information based on the judgment result, if the judgment result indicates that the dynamic branches between chains meet the implicit traversal conditions, the multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain effective; if the judgment result indicates that the dynamic branches between chains do not meet the implicit traversal conditions, the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid. The above process can be described as follows: Figure 5 As shown, after obtaining the local prediction state of the dynamic branch between the chains, it is possible to determine whether the dynamic branch between the chains meets the implicit traversal condition based on the local prediction state. If not, the multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain valid. If yes, the training of multi-branch jump chain prediction information is restricted, the participation of multi-branch jump chain prediction information in prediction is restricted, and the multi-branch jump chain prediction information is made invalid.
[0100] Understandably, if there are multiple inter-chain dynamic branches, and any one of them fails to meet the implicit traversal condition, then the training, participation in prediction, or invalidation of multi-branch jump chain prediction information is restricted. In this case, multi-branch jump chain prediction information is only allowed to be trained, participate in prediction, or remain valid if all inter-chain dynamic branches meet the implicit traversal condition. Alternatively, multi-branch jump chain prediction information is only allowed to be trained, participate in prediction, or remain valid if more than half of the inter-chain dynamic branches meet the implicit traversal condition.
[0101] In one possible implementation, the local prediction state includes the prediction confidence of inter-chain dynamic branches (which can be a measure of the branch predictor's confidence in or reliability of the prediction results). Determining whether an inter-chain dynamic branch meets the implicit traversal condition based on the local prediction state can include: if the prediction confidence is lower than a preset confidence threshold (configurable, e.g., the prediction confidence threshold for inter-chain dynamic branches can be set to 80%, meaning at least 10 predictions must be made, and at least 8 of the most recent 10 predictions must be correct), then the inter-chain dynamic branch does not meet the implicit traversal condition; if the prediction confidence reaches or exceeds the preset confidence threshold, then the inter-chain dynamic branch meets the implicit traversal condition. In this implementation, the implicit traversal condition can include: the prediction confidence of any inter-chain dynamic branch cannot be lower than a certain threshold, or the combined confidence of all inter-chain dynamic branches must be higher than a certain threshold, etc.
[0102] For example, after identifying dynamic branches between chains, the branch predictor obtains the prediction confidence of that dynamic branch. Based on the prediction confidence, it determines whether the dynamic branch between chains meets the implicit traversal condition. If the prediction confidence is lower than a preset confidence threshold, it restricts the training of the multi-branch jump chain prediction information, restricts its participation in prediction, or disables it. For example, the branch predictor can prohibit the training of new multi-branch jump chain prediction information based on the current intra-chain jump branch relationship (training control), restrict the participation of existing multi-branch jump chain prediction information in prediction (prediction control), or disable existing multi-branch jump chain prediction information (disabling control). If the prediction confidence reaches or exceeds the preset confidence threshold, it allows the multi-branch jump chain prediction information to be trained, participate in prediction, or remain valid.
[0103] In one possible implementation, the local prediction state includes the directional bias of the inter-chain dynamic branches. Determining whether an inter-chain dynamic branch meets the implicit traversal condition based on the local prediction state can include: if the directional bias indicates that the inter-chain dynamic branch tends to jump to a direction deviating from the subsequent intra-chain jump branch, then the inter-chain dynamic branch does not meet the implicit traversal condition; if the directional bias indicates that the inter-chain dynamic branch tends to be implicitly traversed to reach the subsequent intra-chain jump branch, then the inter-chain dynamic branch meets the implicit traversal condition. In this implementation, the implicit traversal condition can include: any inter-chain dynamic branch must be biased towards not jumping, or the proportion of inter-chain dynamic branches biased towards not jumping must be greater than a certain threshold (e.g., 70%).
[0104] For example, after identifying dynamic branches between chains, the branch predictor obtains the directional bias of the dynamic branches. Based on this directional bias, it determines whether the dynamic branches between chains meet the implicit traversal condition: if the directional bias indicates that the dynamic branches between chains tend to jump to a direction that deviates from the subsequent intra-chain jump branch, then the output of the multi-branch jump chain prediction information for the subsequent intra-chain jump branch prediction result is restricted, or it is made invalid. For example, the output of the multi-branch jump chain prediction information for the subsequent intra-chain jump branch prediction result can be restricted, or invalidation control can be triggered; if the directional bias indicates that the dynamic branches between chains tend to be implicitly traversed to reach the subsequent intra-chain jump branch, then the multi-branch jump chain prediction information is allowed to continue to participate in the prediction or remain valid.
[0105] In some examples, the directional bias can be the value of a directional counter. The branch predictor maintains a directional counter to record the jump / non-jump history of dynamic branches X between chains. If a jump occurs during the actual execution of X, the directional counter is incremented; if X does not jump, the directional counter is decremented. When the accumulated directional counter exceeds a certain threshold, X is considered to have a bias towards jumping; when the accumulated directional counter falls below a certain threshold, X is considered to have a bias towards not jumping. The branch predictor reads the current value of this directional counter as the basis for determining the directional bias. If the directional bias indicates that X tends to jump to a direction deviating from the direction of the subsequent chain's jump branch B, for example, if the jump target address of X points to an address outside the target region of branch B, then the branch predictor determines that X does not meet the implicit traversal condition and restricts the prediction result of the multi-branch jump chain prediction information output B, or invalidates the prediction information.
[0106] In one possible implementation, if the local prediction state includes the prediction source of inter-chain dynamic branches, where the prediction source characterizes the reliability of the prediction source of the inter-chain dynamic branches; determining whether the inter-chain dynamic branches meet the implicit traversal condition based on the local prediction state may include: if the prediction source characterizes that the inter-chain dynamic branches are not confirmed by a preset reliable prediction structure, or are predicted by a non-preset reliable prediction structure, then the inter-chain dynamic branches are determined not to meet the implicit traversal condition; if the prediction source characterizes that the inter-chain dynamic branches are confirmed by a preset reliable prediction structure, then the inter-chain dynamic branches are determined to meet the implicit traversal condition. In this implementation, the implicit traversal condition may include: the prediction source information of any inter-chain dynamic branch must originate from a reliable prediction structure (such as a predictor using a specific algorithm or structure, a BTB-type prediction structure, a Bimodal predictor, a TAGE (Tagged Geometric) predictor, etc.).
[0107] For example, after identifying dynamic inter-chain branches, the branch predictor obtains the prediction source of that dynamic branch. The prediction source can characterize whether the dynamic inter-chain branch is confirmed by a preset reliable prediction structure, such as whether the prediction is given by the dynamic prediction structure or only by the basic prediction structure. If the dynamic inter-chain branch is not confirmed by the preset reliable prediction structure, such as only by the basic prediction structure or lacking a reliable prediction source, it is determined that the dynamic inter-chain branch does not meet the implicit traversal condition, and the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid.
[0108] In one possible implementation, if the local prediction state includes behavioral stability information of the inter-chain dynamic branches, then determining whether the inter-chain dynamic branches meet the implicit traversal conditions based on the local prediction state may include: if the behavioral stability information indicates that the behavior of the inter-chain dynamic branches is unstable, then the inter-chain dynamic branches are determined not to meet the implicit traversal conditions; if the behavioral stability information indicates that the behavior of the inter-chain dynamic branches is stable, then the inter-chain dynamic branches are determined to meet the implicit traversal conditions.
[0109] Among them, behavioral stability information includes target stability information and / or recent behavioral stability information; target stability information is used to characterize whether the target address of the inter-chain dynamic branch is stable, and recent behavioral stability information is used to characterize the changes in the direction or target address of the inter-chain dynamic branch in recent predictions or executions.
[0110] If the behavioral stability information includes target stability information, which can be various predicted state information used to characterize whether the target address of the inter-chain dynamic branch is stable, such as target address change frequency information, target address distribution information, and target address prediction result stability information; then judging whether the inter-chain dynamic branch meets the implicit traversal condition based on the local prediction state can include: if the target stability information indicates that the recent change of the target address of the inter-chain dynamic branch meets the first preset frequent change condition, then it is determined that the inter-chain dynamic branch does not meet the implicit traversal condition; if the target stability information indicates that the target address of the inter-chain dynamic branch is stable, then it is determined that the inter-chain dynamic branch meets the implicit traversal condition.
[0111] In this approach, the implicit conditions may include: the number of target addresses in the dynamic inter-chain branches is within a preset range (e.g., unique or falling within a limited number), and / or, the target address prediction results are stable (e.g., the prediction results are consistent in recent predictions). Accordingly, the first preset frequent change condition can be set to the number of target addresses exceeding a preset range, or the target address prediction results being inconsistent in recent predictions.
[0112] For example, if the dynamic branch between chains is an indirect branch, the predictor can count the number of times the target address changes in its most recent 8 executions. If more than 3 different target addresses appear in 8 executions, it indicates that the number of target addresses exceeds the preset range, and it can be determined that the preset frequent change condition is met; if the target address repeatedly alternates between address X and address Y in recent executions and lacks a clear bias, it indicates that the target address prediction result is unstable, and it can be determined that the preset frequent change condition is met; if the predictor's prediction result for the target address is inconsistent in recent predictions, it can also be determined that the preset frequent change condition is met.
[0113] If the behavioral stability information includes recent behavioral stability information, which characterizes the changes in the direction or target address of the inter-chain dynamic branch in recent predictions or executions, then determining whether the inter-chain dynamic branch meets the implicit traversal condition based on the local prediction state can include: if the recent behavioral stability information indicates that the behavioral change of the inter-chain dynamic branch meets a second preset frequent change condition, then the inter-chain dynamic branch is determined not to meet the implicit traversal condition; if the recent behavioral stability information indicates that the behavior of the inter-chain dynamic branch is stable, then the inter-chain dynamic branch is determined to meet the implicit traversal condition. In this implementation, the implicit traversal condition can include: all inter-chain dynamic branches have stable recent behavior, for example, the prediction accuracy is not lower than a certain preset threshold (configurable), etc.
[0114] The recent behavior stability information can include recent prediction accuracy information, that is, the proportion of prediction results that match the actual execution results of the inter-chain dynamic branch in the most recent N predictions. Accordingly, the preset frequent change condition can be set to a prediction accuracy rate that is lower than a preset threshold. For example, when the preset threshold is set to 70%, if the recent prediction accuracy rate of the inter-chain dynamic branch is lower than 70%, its behavior can be determined to be unstable and does not meet the implicit traversal condition.
[0115] If the behavioral stability information includes both target stability information and recent behavioral stability information, then judging whether the inter-chain dynamic branch meets the implicit traversal condition based on the local predicted state can include: if the target stability information indicates that the recent change of the target address of the inter-chain dynamic branch meets the preset frequent change condition, or the recent behavioral stability information indicates that the behavioral change of the inter-chain dynamic branch meets the preset frequent change condition, then the inter-chain dynamic branch is determined not to meet the implicit traversal condition; if the target stability information indicates that the target address of the inter-chain dynamic branch is stable, and the recent behavioral stability information indicates that the behavior of the inter-chain dynamic branch is stable, then the inter-chain dynamic branch is determined to meet the implicit traversal condition.
[0116] It is understandable that the aforementioned prediction confidence, direction bias, prediction source, and behavioral stability information can be used in combination, and correspondingly, their respective implicit traversal conditions can also be combined for judgment. For example, it can be determined that the inter-chain dynamic branch satisfies the implicit traversal condition only if the prediction confidence of the inter-chain dynamic branch reaches a preset confidence threshold, the direction bias indicates that it tends to jump to a direction that can reach the subsequent intra-chain jump branch, and its behavioral stability information represents its stable behavior; conversely, if any of the local prediction states does not satisfy the corresponding implicit traversal condition, it can be determined that the inter-chain dynamic branch does not satisfy the implicit traversal condition.
[0117] Furthermore, the types of inter-chain dynamic branches are not limited to conditional branches; they can also be indirect branches or other dynamic control flow instructions whose direction, target, or control flow influence may change with the runtime context. Different local prediction states can be used as control criteria for different types of inter-chain dynamic branches. For example, for conditional branches, prediction confidence and / or directional bias can be emphasized for judgment; for indirect branches, target stability information and / or prediction source state can be emphasized for judgment.
[0118] Different processor implementations can choose different implicit traversal condition judgment rules based on performance, power consumption, area, or misprediction cost. For example, low-power implementations can use simpler prediction source or direction bias judgments, while high-performance implementations can combine prediction confidence, target stability information, and recent behavior stability information for judgment. It should be noted that the specific settings and judgment rules of the above implicit traversal conditions do not constitute a limitation on this solution, and can be flexibly configured according to processor design requirements in actual implementation.
[0119] In one example, the local prediction state can simultaneously include prediction confidence and directional bias. The branch predictor directly predicts intra-chain jump branches A and B based on existing multi-branch jump chain prediction information. The branch predictor determines the target region pointed to by the prediction target of A and identifies the inter-chain dynamic branch X within that target region. X is not directly predicted as an intra-chain jump branch by the multi-branch jump chain prediction information. The branch predictor obtains the prediction confidence and directional bias of X. If the prediction confidence of X is lower than a preset confidence threshold, or if the directional bias of X indicates that it tends to jump to a direction deviating from B, the branch predictor determines that X does not meet the implicit traversal condition. At this time, the branch predictor restricts the multi-branch jump chain prediction information from outputting the prediction result of B in the current prediction and restricts its training or disables it. If the prediction confidence of X reaches or exceeds the preset confidence threshold, and the directional bias of X indicates that it tends to jump to a direction that can reach B, the branch predictor allows the multi-branch jump chain prediction information to continue participating in the prediction or remain valid.
[0120] The above-described Embodiments 1 and 2 can be implemented individually or in combination. In some scenarios, Embodiment 1 can serve as a prerequisite for Embodiment 2. By filtering out inter-chain dynamic branches at preset types and preset positions through Embodiment 1, those inter-chain dynamic branches that are obviously unsuitable for being implicitly mapped by the prediction layer in terms of type or position are preferentially excluded. Then, based on the remaining inter-chain dynamic branches, the local prediction state in Embodiment 2 is applied for further evaluation.
[0121] For example, after determining the target region between adjacent chain jump branches, first filter out the inter-chain dynamic branches of preset type or preset position in the target region, obtain the local prediction state of the remaining inter-chain dynamic branches (including prediction confidence, direction bias, prediction source, and behavior stability information), determine whether the inter-chain dynamic branches meet the implicit traversal conditions based on the local prediction state, obtain the judgment result, and perform training control, prediction control, or failure control on the multi-branch jump chain prediction information based on the judgment result.
[0122] The training control, predictive control, and failure control methods in this application, such as... Figure 6As shown, the branch predictor obtains the local prediction state of the dynamic branch between chains as the basis for control, and performs at least one of the following controls on the multi-branch jump chain prediction information: training control, prediction control, or failure control. Training control includes, but is not limited to, restricting training, allowing training, or updating control; prediction control includes, but is not limited to, allowing participation in prediction or blocking subsequent intra-chain jump branch prediction results; failure control includes, but is not limited to, invalidating prediction information, deleting it, or downgrading it to non-multi-branch jump chain prediction information.
[0123] Training control determines whether to allow training or updating of multi-branch jump chain prediction information based on current predictions or execution feedback. If the local prediction state of a dynamic branch between chains does not satisfy the implicit traversal condition, it indicates that the prediction layer mapping between jump branches within adjacent chains may be unstable. In this case, training or updating of the multi-branch jump chain prediction information can be restricted to avoid solidifying unstable control flow relationships into subsequently reusable prediction information. The training control includes at least one of the following: 1) Creating new multi-branch jump chain prediction information is prohibited; 2) Updates to multi-branch jump chain prediction information are prohibited; 3) It is prohibited to update candidate prediction information with multi-branch jump chain prediction information; 4) Reduce the training priority of multi-branch jump chain prediction information; 5) Suppress repeated training of multi-branch jump chain prediction information under the same or similar local prediction states.
[0124] Predictive control determines whether existing multi-branch jump chain prediction information can participate in the current prediction cycle, specifically whether it is allowed to output prediction results for subsequent intra-chain jump branches. If the inter-chain dynamic branches do not currently meet the implicit traversal conditions, outputting prediction results for subsequent intra-chain jump branches may lead to a mismatch between the prediction layer mapping and the actual control. Predictive control includes at least one of the following: 1) Restrict the participation of multi-branch jump chain prediction information in prediction; 2) Limit the output of prediction results for multiple intra-chain jump branches in the multi-branch jump chain prediction information; 3) Hides the prediction results of subsequent in-chain jump branches; 4) Downgrade the prediction information of multi-branch jump chains to only output the prediction results of jump branches within the preceding chain; 5) Ignore multi-branch jump chain prediction information in the current prediction period.
[0125] Failure control is used to adjust the validity of existing multi-branch jump chain prediction information. Unlike invalidating prediction information only after an actual misprediction occurs, this scheme can determine whether the prediction information should remain valid based on the local prediction state of the dynamic branches between chains, without waiting for an actual misprediction to occur. Failure control includes at least one of the following: 1) Makes the prediction information of multi-branch jump chains invalid; 2) Delete multi-branch jump chain prediction information; 3) Downgrade multi-branch jump chain prediction information to non-multi-branch jump chain prediction information; 4) Clear the valid states used to generate subsequent intra-chain jump branch prediction results in the multi-branch jump chain prediction information; 5) Adjust the state of the multi-branch jump chain prediction information so that it no longer participates in the multi-branch jump chain prediction; 6) Suppress the re-involvement of multi-branch jump chain prediction information in training or prediction under the same or similar local prediction states.
[0126] Control over multi-branch jump chain prediction information can occur during the training phase, prediction phase, failure control phase, or any combination thereof. During the training phase, the creation, updating, or modification of multi-branch jump chain prediction information can be restricted. During the prediction phase, its participation in prediction can be restricted, or subsequent intra-chain jump branch prediction results can be masked. During the failure control phase, it can be disabled, downgraded, its valid state cleared, or its re-participation in training or prediction under the same or similar local prediction states can be inhibited. It is understood that the division of the above phases and the corresponding control actions can be flexibly configured according to processor design requirements, and the specific implementation method does not constitute a limitation on this solution.
[0127] The training control, prediction control, and failure control described above can be implemented by the branch predictor's internal control logic, prediction entry update logic, instruction fetch front-end control logic, training path control logic, prediction validity judgment logic, failure control logic, or deletion control logic. Each of these control logics can be implemented independently, or they can reuse the same control logic or be combined with other logic.
[0128] like Figure 7 As shown, this application also provides a branch predictor, including: a prediction unit, a target region determination unit, an identification unit, an acquisition unit, and a control unit. This branch predictor can be used to perform the methods described above.
[0129] The prediction unit (also known as the in-chain jump branch prediction unit) is used to generate jump branch prediction results based on multi-branch jump chain prediction information, wherein the jump branch prediction results include multiple in-chain jump branches.
[0130] The target region determination unit determines the target region between adjacent chain jump branches in the jump branch prediction result.
[0131] The identification unit (also known as the inter-chain dynamic branch identification unit) is used to identify inter-chain dynamic branches within the target area, wherein the inter-chain dynamic branches are not directly predicted by the multi-branch jump chain prediction information as intra-chain jump branches.
[0132] The acquisition unit (also known as the local prediction state acquisition unit) is used to acquire the local prediction state of the inter-chain dynamic branch itself.
[0133] The control unit is configured to perform at least one of training control, predictive control, or failure control on the multi-branch jump chain prediction information based on the local predicted state.
[0134] In some examples, the structure of the branch predictor can be as follows: Figure 8 As shown, it also includes a storage unit for storing multi-branch jump chain prediction information. In some scenarios, this storage unit may not be integrated into the branch predictor.
[0135] The branch predictor provided in this application embodiment has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the branch predictor embodiment can be referred to the corresponding content in the aforementioned method embodiment.
[0136] This application also provides a processor including a branch predictor and an instruction fetching unit. The instruction fetching unit fetches instructions from an instruction cache, and the branch predictor predicts the direction and target address of a branch instruction during the instruction fetching process, providing the predicted fetch address to the instruction fetching unit to guide the fetching unit in fetching subsequent instructions.
[0137] The processor may be an integrated circuit chip with signal processing capabilities. The aforementioned processor can be a general-purpose processor, including a Central Processing Unit (CPU), Network Processor (NP), Graphics Processing Unit (GPU), Accelerated Processing Unit (ACCU), Multimedia Application Processor (MAP), microprocessor, etc.; it can also be a Digital Signal Processor (DSP), Application Specific Integrated Circuit (ASIC), Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. Alternatively, the processor can be any conventional processor.
[0138] This application also provides an electronic device, including the processor described above. The electronic device provided in this application may include, but is not limited to, devices with a processor such as mobile phones, tablets, personal computers (PCs), netbooks, personal digital assistants (PDAs), wearable electronic devices, and virtual reality devices.
[0139] In one possible implementation, such as Figure 9 As shown, the electronic device 200 provided in this application embodiment includes: a transceiver 210, a memory 220, a communication bus 230, and a processor 240.
[0140] The transceiver 210, the memory 220, and the processor 240 are electrically connected directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses 230 or signal lines. The transceiver 210 is used to send and receive data. The memory 220 is used to store computer programs, wherein at least one computer program can be stored in the memory 220 in the form of software or firmware, or be a software functional module embedded in the operating system (OS) of the electronic device 200. The processor 240 is used to execute the software functional modules or computer programs stored in the memory 220. For example, the processor 240 is used to execute the methods described above.
[0141] The memory 220 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0142] This application also provides a non-volatile computer-readable storage medium (hereinafter referred to as the storage medium) storing a computer program, which is executed by a computer such as the electronic device 200 described above to perform the method described above.
[0143] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0144] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0145] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0146] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium and includes several instructions to cause a computer device (which may be a personal computer, laptop, server, or electronic device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned computer-readable storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0147] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for controlling multi-branch jump chain prediction information, characterized in that, include: Obtain the jump branch prediction result, which is generated based on multi-branch jump chain prediction information and includes multiple in-chain jump branches; Determine the target regions corresponding to the jump branches within adjacent chains in the jump branch prediction results; Identify inter-chain dynamic branches within the target region, wherein the inter-chain dynamic branches are not directly predicted as intra-chain jump branches by the multi-branch jump chain prediction information; Obtain the local predicted state of the inter-chain dynamic branch itself; Based on the local prediction state, at least one of the following controls is applied to the multi-branch jump chain prediction information: training control, prediction control, or failure control.
2. The method according to claim 1, characterized in that, The local prediction state includes at least one of the following: prediction confidence, directional bias, prediction source, and behavioral stability information.
3. The method according to claim 2, characterized in that, Based on the local prediction state, at least one of the following controls is applied to the multi-branch jump chain prediction information: training control, prediction control, or failure control: Based on the local prediction state, it is determined whether the inter-chain dynamic branch satisfies the implicit traversal condition, and a judgment result is obtained; wherein, the implicit traversal condition is used to determine whether the current inter-chain dynamic branch is suitable for implicit traversal by the prediction layer mapping represented by the multi-branch jump chain prediction information. Based on the judgment result, at least one of the following controls is applied to the multi-branch jump chain prediction information: training control, prediction control, or failure control.
4. The method according to claim 3, characterized in that, The local prediction state includes the prediction confidence of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: If the prediction confidence is lower than the preset confidence threshold, then the inter-chain dynamic branch is determined not to meet the implicit traversal condition. If the prediction confidence level reaches or exceeds the preset confidence threshold, then the inter-chain dynamic branch is determined to satisfy the implicit traversal condition.
5. The method according to claim 3, characterized in that, The local prediction state includes the directional bias of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: If the direction bias indicates that the inter-chain dynamic branch tends to jump to a direction that deviates from the subsequent intra-chain jump branch, then it is determined that the inter-chain dynamic branch does not satisfy the implicit traversal condition; If the direction bias indicates that the inter-chain dynamic branch tends to be implicitly passed through to reach the subsequent intra-chain jump branch, then the inter-chain dynamic branch is determined to satisfy the implicit passing condition.
6. The method according to claim 3, characterized in that, The local prediction state includes the prediction source of the inter-chain dynamic branch, and the prediction source characterizes the reliability of the prediction source of the inter-chain dynamic branch; determining whether the inter-chain dynamic branch satisfies the implicit traversal condition based on the local prediction state includes: If the prediction source indicates that the inter-chain dynamic branch is not confirmed by a preset reliable prediction structure, or is predicted by a non-preset reliable prediction structure, then it is determined that the inter-chain dynamic branch does not satisfy the implicit traversal condition. If the prediction source indicates that the inter-chain dynamic branch is confirmed by a preset reliable prediction structure, then the inter-chain dynamic branch is determined to satisfy the implicit traversal condition.
7. The method according to claim 3, characterized in that, The local prediction state includes the behavioral stability information of the inter-chain dynamic branches; determining whether the inter-chain dynamic branches satisfy the implicit traversal conditions based on the local prediction state includes: If the behavioral stability information indicates that the behavior of the inter-chain dynamic branch is unstable, then it is determined that the inter-chain dynamic branch does not satisfy the implicit traversal condition. If the behavioral stability information indicates that the behavior of the inter-chain dynamic branch is stable, then the inter-chain dynamic branch is determined to satisfy the implicit traversal condition.
8. The method according to claim 3, characterized in that, Based on the judgment result, at least one of the following controls is applied to the multi-branch jump chain prediction information: training control, predictive control, or failure control, including: When the judgment result indicates that the inter-chain dynamic branch satisfies the implicit traversal condition, the multi-branch jump chain prediction information is allowed to be trained, participate in prediction, or remain valid. When the judgment result indicates that the inter-chain dynamic branch does not meet the implicit traversal condition, the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid.
9. The method according to claim 1, characterized in that, The local prediction state includes the type of the inter-chain dynamic branch or the position of the inter-chain dynamic branch in the target region; based on the local prediction state, at least one of training control, prediction control, or failure control is applied to the multi-branch jump chain prediction information, including: If the type of the inter-chain dynamic branch is a preset type, or the position of the inter-chain dynamic branch in the target area is a preset position, then the training of the multi-branch jump chain prediction information is restricted, its participation in prediction is restricted, or it is rendered invalid.
10. The method according to any one of claims 1 to 9, wherein the training control comprises at least one of the following: Creating new multi-branch jump chain prediction information is prohibited; Updating the multi-branch jump chain prediction information is prohibited; It is prohibited to update candidate prediction information with multi-branch jump chain prediction information; Reduce the training priority of the multi-branch jump chain prediction information; Suppress repeated training of the multi-branch jump chain prediction information under the same or similar local prediction states.
11. The method according to any one of claims 1 to 9, characterized in that, The predictive control includes at least one of the following: The multi-branch jump chain prediction information is restricted from participating in the prediction; The prediction results of multiple intra-chain jump branches are limited to output by the multi-branch jump chain prediction information; The prediction results for subsequent in-chain jump branches are masked; The multi-branch jump chain prediction information is downgraded to outputting only the prediction results of the jump branches within the preceding chain; The multi-branch jump chain prediction information is ignored in the current prediction period.
12. The method according to any one of claims 1 to 9, characterized in that, The failure control includes at least one of the following: This invalidates the multi-branch jump chain prediction information; Delete the multi-branch jump chain prediction information; The multi-branch jump chain prediction information is downgraded to non-multi-branch jump chain prediction information; Clear the valid states in the multi-branch jump chain prediction information used to generate subsequent in-chain jump branch prediction results; Adjust the state of the multi-branch jump chain prediction information so that it no longer participates in multi-branch jump chain prediction; Suppress the multi-branch jump chain prediction information from re-entering training or prediction under the same or similar local prediction states.
13. A branch predictor, characterized in that, include: A prediction unit is used to generate a jump branch prediction result based on multi-branch jump chain prediction information, wherein the jump branch prediction result includes multiple in-chain jump branches; The target region determination unit determines the target region between adjacent intra-chain jump branches in the jump branch prediction result; The identification unit is used to identify inter-chain dynamic branches within the target area, wherein the inter-chain dynamic branches are not directly predicted by the multi-branch jump chain prediction information as intra-chain jump branches. The acquisition unit is used to acquire the local predicted state of the inter-chain dynamic branch itself. The control unit is configured to perform at least one of training control, predictive control, or failure control on the multi-branch jump chain prediction information based on the local predicted state.
14. A processor, characterized in that, Includes the branch predictor as described in claim 13.
15. An electronic device, characterized in that, Includes the processor as described in claim 14.
16. An electronic device, characterized in that, include: A memory and a processor, wherein the processor is connected to the memory; The memory is used to store programs; The processor is configured to invoke a program stored in the memory to perform the method as described in any one of claims 1 to 12.