A branch training filtering method, a branch training filter and a branch prediction system

By using a branch training filtering method and a branch training filter, and by comparing the actual branch direction in the feedback information with the specified branch direction, the problem of unpredictable branches interfering with predictable branches is solved, thereby improving the performance and resource utilization efficiency of the branch predictor.

CN120704742BActive Publication Date: 2026-05-19HYGON INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HYGON INFORMATION TECH CO LTD
Filing Date
2025-06-10
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

Existing branch predictors cannot distinguish between predictable and unpredictable branches, causing unpredictable branches to consume resources and interfere with the prediction accuracy of predictable branches, resulting in performance loss.

Method used

By using a branch training filtering method and a branch training filter, the actual branch direction in the feedback information is compared with the specified branch direction to prevent optimization of the branch predictor, free up resources for other branch instructions, and reduce the branch misprediction rate.

Benefits of technology

It effectively mitigates the interference of unpredictable branches on predictable branches, and improves the performance and resource utilization efficiency of the branch predictor.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120704742B_ABST
    Figure CN120704742B_ABST
Patent Text Reader

Abstract

The present specification relates to a branch training filtering method, a branch training filter and a branch prediction system. When feedback information after a branch is executed by an execution unit is received, it is determined whether the actual branch direction of the branch in the feedback information is different from a specified branch direction, and if so, optimization of the feedback information to a branch predictor is prevented, the occurrence probability of the specified branch direction reaching a threshold. According to the embodiment of the present specification, the historical branch direction of a branch returned by an instruction retirement unit is statistically analyzed, the most probable direction of the branch is determined, and the most probable direction is taken as a reference. When the actual branch direction in the feedback information of the execution unit for the branch is inconsistent with the most probable direction, the actual branch direction is prevented from correcting the branch predictor, so that more resources are released to other branch instructions without affecting the accuracy of the branch, thereby reducing the branch misprediction rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments in this specification relate to the field of branch prediction computation, and in particular to a branch training filtering method, a branch training filter, and a branch prediction system. Background Technology

[0002] Existing branch predictors do not distinguish between predictable and unpredictable branches. Both predictable and unpredictable branches compete for entries in the branch predictor and the Branch Target Buffer (BTB). For unpredictable branches, occupying entries in the branch predictor may interfere with the prediction accuracy of predictable branches. Similarly, unpredictable branches occupying BTB entries will compete with predictable branches for BTB resources, resulting in performance penalties. Summary of the Invention

[0003] To address the problems existing in the prior art, embodiments of this specification provide a branch training filtering method, a branch training filter, and a branch prediction system, which can mitigate the interference of unpredictable branches on predictable branches.

[0004] The specific technical solutions of the embodiments in this specification are as follows:

[0005] On the one hand, embodiments of this specification provide a branch training filtering method, the method comprising:

[0006] When receiving feedback information after the execution unit executes a branch, it is determined whether the actual branch direction of the branch in the feedback information is different from the specified branch direction. If so, the optimization of the branch predictor by the feedback information is prevented, and the probability of the specified branch direction is reached.

[0007] Furthermore, the method also includes:

[0008] The historical branch directions of the branches returned by the instruction retirement unit are statistically analyzed to obtain the specified branch direction.

[0009] Furthermore, statistical analysis of the historical branch directions returned by the instruction retirement unit yields the specified branch direction, which further includes:

[0010] Upon receiving the historical branch direction of the branch returned by the instruction retirement unit, determine whether there is a valid entry for the branch in the branch prediction filter table;

[0011] If it exists, determine whether the branch direction recorded in the entry of the branch is the same as the historical branch direction;

[0012] If they are the same, then determine whether the number of repetitions of the branch direction recorded in the entry of the branch has reached the number threshold.

[0013] If the threshold number of times is reached, then the branch direction is taken as the designated branch direction.

[0014] Furthermore, the method also includes:

[0015] If the number of repetitions does not reach the threshold, then the number of repetitions is increased.

[0016] Furthermore, the method also includes:

[0017] If the branch direction recorded in the entry of the branch is different from the historical branch direction, then it is determined whether the number of repetitions of the branch direction recorded in the entry of the branch reaches the number threshold.

[0018] If the target is reached, then reset the number of repetitions.

[0019] If the condition is not met, invalidate the entry in the branch.

[0020] Furthermore, the method also includes:

[0021] If there is no valid entry for the branch in the branch prediction filter table, then it is determined whether there is an invalid entry for the branch.

[0022] If it exists, create a valid entry for the branch in the branch prediction filter table.

[0023] Furthermore, the method also includes:

[0024] If there is no valid entry for the branch in the branch prediction filter table, and there is no invalid entry for the branch, then a replacement entry is determined based on the activity values ​​of multiple entries in the branch prediction filter table, a valid entry for the branch is created, and the replacement entry is replaced.

[0025] Furthermore, the activity value is the SSRIP value predicted by the static rereference interval.

[0026] Furthermore, determining the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table further includes:

[0027] The entry with the largest SSRIP value is used as the replacement entry.

[0028] Furthermore, after preventing the feedback information from optimizing the branch predictor, the method further includes:

[0029] When the specified branch direction is a jump, the type of the branch in the branch target buffer BTB of the branch predictor is set to unconditional jump;

[0030] When the specified branch direction is no jump, the information of the branch in the BTB is released.

[0031] On the other hand, embodiments of this specification also provide a branch training filter, the branch training filter comprising:

[0032] The data filtering unit is optimized and configured to, upon receiving feedback information after the execution unit has executed a branch, determine whether the actual branch direction of the branch in the feedback information is different from the specified branch direction. If so, the feedback information is prevented from optimizing the branch predictor, and the probability of the specified branch direction occurring reaches a threshold.

[0033] Furthermore, the branch training filter also includes:

[0034] The historical branch direction statistics unit is configured to perform statistics on the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction.

[0035] Furthermore, statistical analysis of the historical branch directions returned by the instruction retirement unit yields the specified branch direction, which further includes:

[0036] Upon receiving the historical branch direction of the branch returned by the instruction retirement unit, determine whether there is a valid entry for the branch in the branch prediction filter table;

[0037] If it exists, determine whether the branch direction recorded in the entry of the branch is the same as the historical branch direction;

[0038] If they are the same, then determine whether the number of repetitions of the branch direction recorded in the entry of the branch has reached the number threshold.

[0039] If the threshold number of times is reached, then the branch direction is taken as the designated branch direction.

[0040] Furthermore, the historical branch direction statistics unit is further configured to: if the number of repetitions does not reach the number threshold, then increase the number of repetitions.

[0041] Furthermore, the historical branch direction statistics unit is further configured to: if the branch direction recorded in the branch entry is different from the historical branch direction, then determine whether the number of repetitions of the branch direction recorded in the branch entry reaches the number threshold.

[0042] If the target is reached, then reset the number of repetitions.

[0043] If the condition is not met, invalidate the entry in the branch.

[0044] Furthermore, the historical branch direction statistics unit is further configured to: if there is no valid entry for the branch in the branch prediction filter table, then determine whether there is an invalid entry for the branch;

[0045] If it exists, create a valid entry for the branch in the branch prediction filter table.

[0046] Furthermore, the historical branch direction statistics unit is further configured to: if there is no valid entry for the branch in the branch prediction filter table, and there is no invalid entry for the branch, then a replacement entry is determined based on the activity value of multiple entries in the branch prediction filter table, a valid entry for the branch is created, and the replacement entry is replaced.

[0047] Furthermore, the activity value is the SSRIP value predicted by the static rereference interval.

[0048] Furthermore, determining the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table further includes:

[0049] The entry with the largest SSRIP value is used as the replacement entry.

[0050] Furthermore, the branch training filter also includes a target buffer update control unit, configured to, after preventing the feedback information from optimizing the branch predictor, set the type of the branch in the branch target buffer (BTB) of the branch predictor to unconditional jump when the specified branch direction is a jump; and release the branch information in the BTB when the specified branch direction is no jump.

[0051] On the other hand, embodiments of this specification also provide a branch prediction system, including a branch predictor and a branch training filter;

[0052] The branch training filter is deployed on the feedback path of the branch predictor between the execution unit and the instruction retirement unit;

[0053] The branch predictor is configured to predict the branch direction.

[0054] The branch training filter is configured to execute the above method when it receives feedback information after the execution unit has executed a branch.

[0055] On the other hand, embodiments of this specification also provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.

[0056] On the other hand, embodiments of this specification also provide a computer program product, which includes a computer program that, when executed by a processor, implements the above-described method.

[0057] Using the embodiments of this specification, statistical analysis is performed on the historical branch directions of the branches returned by the instruction retirement unit to determine the probable direction of the branch. Based on the probable direction, when the actual branch direction in the feedback information of the execution unit for the branch is inconsistent with the probable direction, the correction of the branch predictor by the actual branch direction is prevented. This frees up more resources for other branch instructions without affecting the accuracy of the branch, thereby reducing the branch misprediction rate. Attached Figure Description

[0058] To more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the embodiments of this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0059] Figure 1 The diagram shown is a schematic representation of an implementation system for a branch training filtering method according to an embodiment of this specification.

[0060] Figure 2 The diagram shown is a flowchart of a branch training filtering method in an embodiment of this specification.

[0061] Figure 3 The diagram shown is a flowchart illustrating the process of statistically analyzing the historical branch directions of the branch returned by the instruction retirement unit in an embodiment of this specification to obtain the specified branch direction.

[0062] Figure 4 The diagram shown is a structural schematic of a branch training filter in an embodiment of this specification.

[0063] Figure 5 The diagram shown is a structural schematic of the computer device in an embodiment of this specification.

[0064] [Explanation of Figure Markers]:

[0065] 401. Optimize the data filtering unit;

[0066] 402. Historical branch direction statistics unit;

[0067] 403. Target Buffer Update Control Unit;

[0068] 502. Computer equipment;

[0069] 504, Processor;

[0070] 506. Memory;

[0071] 508. Drive mechanism;

[0072] 510. Input / Output Module;

[0073] 512. Input devices;

[0074] 514. Output devices;

[0075] 516. Presentation equipment;

[0076] 518. Graphical User Interface;

[0077] 520. Network interface;

[0078] 522. Communication link;

[0079] 524. Communication bus. Detailed Implementation

[0080] The technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the embodiments of this specification, and not all embodiments. Based on the embodiments of this specification, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the embodiments of this specification.

[0081] It should be noted that the terms "first," "second," etc., in the description, claims, and accompanying drawings of the embodiments herein are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, apparatus, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0082] It should be noted that the acquisition, storage, use, and processing of data in the technical solutions of the embodiments of this specification all comply with the relevant provisions of national laws and regulations.

[0083] It should be noted that in the embodiments of this specification, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, they do not mean that the applicant has used or necessarily used the solution.

[0084] like Figure 1 The diagram shows a schematic of an implementation system for a branch training filtering method according to an embodiment of this specification. The branch predictor predicts the branch direction based on historical branch directions and sends the prediction information (including the address of the branch target corresponding to the predicted branch direction) to the instruction fetch unit. The instruction fetch unit reads instruction data from the instruction cache based on the address of the branch target, and then sends the instruction data to the decoder. The decoder decodes the instruction, determines the operation, and sends the decoded instruction to the dispatcher. The dispatcher sends the instruction to the execution unit and the memory access unit. After the execution unit and the memory access unit execute the instruction, they send the actual branch direction to the instruction retirement unit. When the execution unit determines that the predicted branch direction and the actual branch direction are inconsistent, it considers that the branch predictor has made a prediction error and sends feedback information to the branch predictor. The feedback information includes the actual branch direction and whether the branch predictor has made a prediction error. The branch predictor then optimizes the prediction of the branch.

[0085] The retirement instruction information includes the address of the branch instruction, the actual branch direction, the branch target address, and the branch type. The address of the branch instruction indicates which branch instruction the execution unit and memory access unit specifically execute. The actual branch direction indicates the actual result after the branch is finally executed. The branch target address indicates the address of the actual branch target. The branch type can include conditional branches and absolute branches. Conditional branches indicate a jump when a condition is met, and absolute branches indicate an absolute jump.

[0086] Training a branch predictor involves updating its internal state (such as historical patterns and target address cache) using retirement instruction information to improve the accuracy of future predictions, rather than directly correcting previous erroneous predictions. The process can be summarized as follows:

[0087] (1) Update branch history

[0088] The branch predictor updates counters (such as two-bit saturation counters) in the Branch History Table (BHT) based on retirement instruction information. For example, if the branch target corresponding to the predicted branch direction is actually taken, the counter value for that predicted branch direction is increased; if the branch target corresponding to the predicted branch direction is not taken, the counter value for that predicted branch direction is decreased. This update affects the predicted direction (Taken / Not Taken) for the same branch instruction in the future.

[0089] For predictors based on global history (such as GShare) or local history (such as Perceptron), the results of retired branches are added to the history to generate context for future predictions.

[0090] (2) Update the branch target buffer (BTB)

[0091] If the branch target corresponding to the predicted branch direction is actually taken, its branch target address will be recorded in BTB.

[0092] The Branch Target Address (BTB) is used to accelerate the retrieval of the branch target address corresponding to the predicted branch direction. For example, when the predicted branch direction is a taken, the processor can quickly obtain the branch target address from the BTB, avoiding pipeline stalls caused by calculating the branch target address and reducing target computation latency. If the predicted branch direction is a not taken, the processor will directly execute the next instruction sequentially without needing to obtain the branch target address from the BTB.

[0093] After the decoder parses the instruction and determines the operation, it will also correct the branch predictor based on the decoded instruction. For example: (1) The branch predictor misjudged an instruction as a branch instruction and performed branch prediction. When the decoder in the pipeline parses the instruction and determines the operation, it finds that the instruction is not a branch instruction, so it needs to inform the branch predictor to correct it; (2) The target address is wrong. The branch predictor predicts the branch direction, retrieves the cached branch target address from the BTB and gives it to the instruction fetch unit. However, during the decoding stage of the branch instruction, the actual branch target address obtained by the decoder is inconsistent with the one recorded in the BTB. In this case, it is also necessary to inform the branch predictor to correct the cached branch target address in the BTB.

[0094] The execution unit corrects the branch predictor based on the execution result. The actual branch direction is only known after the branch instruction has been executed. The actual branch direction may be different from the predicted branch direction of the branch instruction, so the branch predictor needs to be corrected.

[0095] In the embodiments of this specification, although the branch predictor has a high accuracy in predicting a certain branch, there may be a situation where the actual branch direction is inconsistent with the predicted branch direction. However, the probability of such an actual branch direction being inconsistent with the predicted branch direction is extremely low, indicating that the actual branch direction is unpredictable. If the retirement instruction information after the actual branch direction is executed is used to optimize the branch predictor, it will consume more computing resources, destroy the stability of branch prediction, and increase the branch misprediction rate.

[0096] Therefore, in the embodiments of this specification, a branch training filter is added to the feedback path of the execution unit and the retirement unit. The branch training filter performs a branch training filtering method to filter out some feedback information that has no value, thereby mitigating the interference of unpredictable branches on predictable branches.

[0097] Figure 2 The diagram shown is a flowchart illustrating a branch training filtering method according to an embodiment of this specification. The process of filtering out worthless feedback information is depicted in this diagram. The order of steps listed in the embodiment is merely one possible execution order among many and does not represent the only possible execution order. In actual system or device products, the method can be executed sequentially or in parallel according to the embodiment or the accompanying drawings. Specifically, as shown... Figure 2 As shown, the method may include:

[0098] Step 201: Receive feedback information after the execution unit executes the branch;

[0099] Step 202: Determine whether the actual branch direction in the feedback information is different from the specified branch direction;

[0100] Step 203: If so, then prevent the feedback information from optimizing the branch predictor.

[0101] In the embodiments described in this specification, the probability of the specified branch direction occurring reaches a threshold.

[0102] Using the embodiments of this specification, statistical analysis is performed on the historical branch directions of the branches returned by the instruction retirement unit to determine the probable direction of the branch. Based on the probable direction, when the actual branch direction in the feedback information of the execution unit for the branch is inconsistent with the probable direction, the correction of the branch predictor by the actual branch direction is prevented. This frees up more resources for other branch instructions without affecting the accuracy of the branch, thereby reducing the branch misprediction rate.

[0103] According to one embodiment of this specification, the historical branch directions of the branches returned by the instruction retirement unit are statistically analyzed in advance to obtain the specified branch direction. If the probability of occurrence of the branch direction reported by the instruction retirement unit reaches a threshold, then the branch direction is the specified branch direction. Subsequently, when feedback information is received from the execution unit, if the actual branch direction in the feedback information differs from the specified branch direction, it indicates that the probability of occurrence of the actual branch direction is low, thus preventing the feedback information from optimizing the branch predictor.

[0104] For example, if the instruction retirement unit reports a branch with a high probability of occurrence, indicating a jump, and the execution unit executes that branch and determines the actual branch direction is not a jump, then the execution unit sends feedback information including the actual branch direction (which can be understood as the execution unit only providing feedback when it determines that the branch predictor's predicted branch direction differs from the actual branch direction, hence the branch predictor outputs a jump) to the branch training filter. If the branch training filter determines that the actual branch direction (not a jump) in the feedback information differs from the specified branch direction (jump), then it will no longer train the branch predictor to move towards the non-jump direction. Furthermore, after determining that the branch's high probability branch direction is a jump, the type of that branch in the BTB can be set to unconditional jump. Subsequently, the branch predictor does not need to predict the jump direction of that branch; instead, it directly obtains the address of the unconditional jump from the BTB and hands it over to the instruction fetch unit for processing, thereby freeing up more branch predictor resources for other branch instructions and improving the branch predictor's performance.

[0105] The instruction retirement unit reports that a branch with a high probability of occurrence is designated as a non-jump branch. If the execution unit executes the branch and determines that the actual branch direction is a jump, it sends feedback information including the actual branch direction to the branch training filter (this can be understood as the execution unit only providing feedback when it determines that the predicted branch direction of the branch predictor is different from the actual branch direction; therefore, the predicted branch direction output by the branch predictor is non-jump). The branch training filter determines that the actual branch direction (jump) in the feedback information is different from the designated branch direction (non-jump), and therefore stops training the branch predictor in the jump direction. Furthermore, after determining that the high-probability direction of the branch is non-jump, the information of the target branch in the BTB can be released. Non-jump indicates sequential instruction execution, eliminating the need to cache the address of the target branch; therefore, releasing the information of the target branch in the BTB reduces cache space usage.

[0106] In the embodiments of this specification, the threshold for the probability of occurrence can be an empirical value or an experimental value, and this specification does not impose any restrictions on the embodiments.

[0107] In this embodiment of the specification, in order to facilitate the statistical analysis of the historical branch directions of the branches returned by the instruction retirement unit, a branch prediction filter table is set up. The branch prediction filter table stores multiple branch entries, and the contents of the entries can be as shown in Table 1:

[0108] Table 1

[0109]

[0110] in:

[0111] The valid flag indicates whether the prediction filter entry for the branch is valid. If invalid, it means that the probability of the branch direction recorded in the entry is unlikely to exceed the threshold, and the repetition of the branch direction will no longer be counted.

[0112] The branch instruction address is used to filter branch information from the retirement instruction information returned by the instruction retirement unit;

[0113] The most likely direction is the specified branch direction;

[0114] The training success flag (optional) is determined based on whether a high-probability direction has been obtained. If a high-probability direction has been obtained, the training success flag can be set. When feedback information for that branch is received from the execution unit, it is determined whether the training success flag in the entry for that branch is set. If so, it is determined whether the actual branch direction in the feedback information is the same as the high-probability direction in the entry. If the training success flag is not set, the step of judging the actual branch direction is skipped, allowing the feedback information to optimize the branch predictor.

[0115] When the instruction retirement unit first reports the branch direction of a certain branch, it can record the branch direction in the high probability direction of that branch's entry. When the instruction retirement unit reports the branch direction of that branch again, if the reported branch direction is the same as the branch direction recorded in the high probability direction of the entry, the number of repetitions of the high probability direction recorded in the entry will increase.

[0116] The core function of SSRIP values ​​is to optimize the replacement strategy of records in the branch predictor or cache, avoiding frequent replacement of useful records, thereby improving the hit rate.

[0117] According to one embodiment of this specification, such as Figure 3 As shown in the embodiments of this specification, the historical branch directions of the branch returned by the instruction retirement unit are statistically analyzed to obtain the specified branch direction, which further includes:

[0118] Step 31: Receive the historical branch direction of the branch returned by the instruction retirement unit;

[0119] Step 32: Determine whether there are valid entries for branches in the branch prediction filter table;

[0120] Step 321: If it exists, determine whether the branch direction recorded in the branch entry is the same as the historical branch direction;

[0121] Step 3211: If they are the same, determine whether the number of times the branch direction is repeated in the branch entry has reached the number threshold.

[0122] Step 32111: If the number of attempts is reached, the branch direction is set as the specified branch direction.

[0123] This can be understood as follows: entries in the branch prediction filter table are active entries. When the branch direction and address of the branch returned by the instruction retirement unit are received, the branch prediction filter table is first searched based on the address to determine if there is an entry in the branch prediction filter table with the same address as the address returned by the instruction retirement unit. If so, the information of that entry can be retrieved from the branch prediction filter table, and it can be determined whether the branch direction recorded in the branch entry is the same as the branch direction returned by the instruction retirement unit. If they are the same, it can be determined whether the repetition count of the branch direction recorded in the branch entry has reached the count threshold. If the count threshold is reached, it means that the probability of the branch direction of that branch returned by the instruction retirement unit has reached the threshold. The branch direction of that branch returned by the instruction retirement unit is taken as the designated branch direction of that branch, and the valid flag bit in that entry can also be set.

[0124] pass Figure 3 The method shown statistically analyzes historical branch directions based on a branch filter table, enabling real-time statistics on historical branch directions. This allows for the rapid determination of a specified branch direction with a high probability, enabling the branch filter predictor to be deployed quickly to filter feedback information from the optimized branch predictor.

[0125] According to one embodiment of this specification, continuing as follows Figure 3 As shown, the step of statistically analyzing the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction further includes:

[0126] Step 32112: If the number of repetitions does not reach the threshold, increase the number of repetitions.

[0127] According to one embodiment of this specification, continuing as follows Figure 3 As shown, the step of statistically analyzing the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction further includes:

[0128] Step 3212: If the branch direction recorded in the branch entry is different from the historical branch direction, then determine whether the number of repetitions of the branch direction recorded in the branch entry has reached the number threshold.

[0129] Step 32121: If the target is reached, reset the repetition count;

[0130] Step 32122: If not achieved, invalidate the entries in the branch.

[0131] In the embodiments of this specification, during the training phase for high-probability directions, if the branch direction recorded in the table is inconsistent with the branch direction fed back by the instruction retirement unit, and the number of repetitions of the branch direction recorded in the table has not reached the threshold, it indicates that the probability of the branch direction recorded in the table appearing is low. Furthermore, if the branch direction returned by the instruction retirement unit is inconsistent with the branch direction recorded in the table, it indicates that the probability of the branch direction recorded in the table is still decreasing. This suggests that the probability of the branch direction recorded in the table appearing may be difficult to exceed the threshold, therefore the table entry for that branch is marked as invalid. In this case, the feedback information from the execution unit needs to be transmitted to the branch predictor.

[0132] If the branch direction recorded in the table is inconsistent with the actual branch direction, and the number of repetitions of the branch direction recorded in the table reaches the threshold, it means that although the branch direction recorded in the table has not yet become a high-probability direction, the probability of its occurrence is about to meet the requirements of a high-probability direction. Therefore, the number of repetitions of the branch direction should be reset, for example, by setting the number of repetitions to 0 or other specified values ​​less than the threshold, but without invalidating the table entry for that branch.

[0133] This can be understood as using effective flags to identify branch directions that have a certain probability of becoming high-probability directions and branch directions that may not become high-probability directions, and removing branch directions that may not become high-probability directions, thereby improving the processing performance of branch training filtering.

[0134] According to one embodiment of this specification, continuing as follows Figure 3 As shown, the step of statistically analyzing the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction further includes:

[0135] Step 322: If there is no valid entry for a branch in the branch prediction filter table, then determine whether there is an invalid entry for a branch.

[0136] Step 3221: If it exists, create a valid entry for that branch in the branch prediction filter table;

[0137] Step 3222: If there are no valid entries for a branch in the branch prediction filter table, and there are no invalid entries for a branch, then determine the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table.

[0138] Step 3223: Create valid entries for the branch and replace the replacement entries.

[0139] This can be understood as follows: the purpose of determining whether there are invalid entries for a branch is to improve the efficiency of the branch prediction filter table. Therefore, when there are no valid entries for a branch in the branch prediction filter table, invalid entries are searched first. If no invalid entries are found, a replacement algorithm is used to find a least recently used valid entry and replace it.

[0140] In this embodiment of the specification, to improve performance, the number of entries in the branch prediction filter table is limited. However, the activity level of the branches corresponding to each entry in the branch prediction filter table may vary. Therefore, if a new entry is to be added to the branch prediction filter table, entries with low activity levels need to be removed. Thus, this embodiment of the specification determines replacement entries based on the activity values ​​of multiple entries in the branch prediction filter table, creates a valid entry for the target branch, and replaces the replacement entries.

[0141] It is feasible to use the SSRIP value as the active value.

[0142] Determining the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table further includes:

[0143] The entry with the largest SSRIP value is used as the replacement entry.

[0144] According to one embodiment of this specification, continuing as follows Figure 3 As shown, the step of statistically analyzing the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction further includes:

[0145] Step 33: Update the active value in the entries of this branch.

[0146] In the embodiments of this specification, if a retirement unit recently receives a command to return the branch direction of a certain branch, and if the high-probability direction of that branch has not yet been fully trained (i.e., the number of repetitions of the branch direction recorded in the branch's entry has not yet reached the required number), then the entry for that branch is active. Therefore, regardless of whether the branch direction recorded in the branch's entry is the same as the branch direction returned by the retirement unit this time, the active value recorded in the branch's entry will be updated, for example, by decreasing the SSRIP value. Conversely, if no retirement unit recently receives a command to return the branch direction of that branch, the active value recorded in the branch's entry will not be updated, for example, the SSRIP value will remain unchanged.

[0147] Therefore, inactive entries are identified based on SSRIP values ​​and used as replacement entries. These replacement entries are then replaced with new, valid entries, thus avoiding increasing the number of entries in the branch prediction filter table and preventing performance degradation.

[0148] Based on the same inventive concept, embodiments of this specification also provide a branch training filter, such as... Figure 4 As shown, the branch training filter includes:

[0149] The optimized data filtering unit 401 is configured to, upon receiving feedback information after the execution unit executes a branch, determine whether the actual branch direction of the branch in the feedback information is different from the specified branch direction. If so, it prevents the feedback information from optimizing the branch predictor, and the probability of the specified branch direction occurring reaches a threshold.

[0150] The historical branch direction statistics unit 402 is configured to perform statistics on the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction.

[0151] Furthermore, statistical analysis of the historical branch directions returned by the instruction retirement unit yields the specified branch direction, which further includes:

[0152] Upon receiving the historical branch direction of the branch returned by the instruction retirement unit, determine whether there is a valid entry for the branch in the branch prediction filter table;

[0153] If it exists, determine whether the branch direction recorded in the entry of the branch is the same as the historical branch direction;

[0154] If they are the same, then determine whether the number of repetitions of the branch direction recorded in the entry of the branch has reached the number threshold.

[0155] If the threshold number of times is reached, then the branch direction is taken as the designated branch direction.

[0156] Furthermore, the historical branch direction statistics unit 402 is further configured to: if the number of repetitions does not reach the number threshold, then increase the number of repetitions.

[0157] Furthermore, the historical branch direction statistics unit 402 is further configured to: if the branch direction recorded in the branch entry is different from the historical branch direction, then determine whether the number of repetitions of the branch direction recorded in the branch entry reaches the number threshold.

[0158] If the target is reached, then reset the number of repetitions.

[0159] If the condition is not met, invalidate the entry in the branch.

[0160] Furthermore, the historical branch direction statistics unit 402 is further configured to: if there is no valid entry for the branch in the branch prediction filter table, then determine whether there is an invalid entry for the branch;

[0161] If it exists, create a valid entry for the branch in the branch prediction filter table.

[0162] Furthermore, the historical branch direction statistics unit 402 is further configured to: if there is no valid entry for the branch in the branch prediction filter table, and there is no invalid entry for the branch, then a replacement entry is determined based on the activity value of multiple entries in the branch prediction filter table, a valid entry for the branch is created, and the replacement entry is replaced.

[0163] Furthermore, the activity value is the SSRIP value predicted by the static rereference interval.

[0164] Furthermore, determining the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table further includes:

[0165] The entry with the largest SSRIP value is used as the replacement entry.

[0166] Furthermore, the branch training filter also includes a target buffer update control unit 403, configured to, after preventing the feedback information from optimizing the branch predictor, set the type of the branch in the branch target buffer (BTB) of the branch predictor to unconditional jump when the specified branch direction is a jump; and release the branch information in the BTB when the specified branch direction is no jump.

[0167] Based on the same inventive concept, embodiments of this specification also provide a branch prediction system, including a branch predictor and a branch training filter;

[0168] The branch training filter is deployed on the feedback path of the branch predictor between the execution unit and the instruction retirement unit;

[0169] The branch predictor is configured to predict the branch direction.

[0170] The branch training filter is configured to execute the above method when it receives feedback information after the execution unit has executed a branch.

[0171] The beneficial effects obtained by the above-described branch filter and branch prediction system are consistent with the beneficial effects obtained by the above-described method, and will not be repeated in the embodiments of this specification.

[0172] like Figure 5As shown, a computer device provided in this embodiment is described. The apparatus described herein can be the computer device in this embodiment, performing the methods described above. The computer device 502 may include one or more processors 504, such as one or more central processing units (CPUs), each of which can implement one or more hardware threads. The computer device 502 may also include any memory 506 for storing information of any kind, such as code, settings, data, etc. Without limitation, for example, memory 506 may include any type of RAM, any type of ROM, flash memory device, hard disk, optical disk, etc. More generally, any memory can use any technology to store information. Further, any memory can provide volatile or non-volatile retention of information. Further, any memory can represent a fixed or removable component of the computer device 502. In one case, when processor 504 executes associated instructions stored in any memory or combination of memories, the computer device 502 can perform any operation of the associated instructions. The computer device 502 also includes one or more drive mechanisms 508 for interacting with any memory, such as hard disk drive mechanisms, optical disk drive mechanisms, etc.

[0173] Computer device 502 may also include an input / output module 510 (I / O) for receiving various inputs (via input device 512) and providing various outputs (via output device 514). A specific output mechanism may include a presentation device 516 and an associated graphical user interface (GUI) 518. In other embodiments, the input / output module 510 (I / O), input device 512, and output device 514 may be omitted, and the device may function solely as a computer device within a network. Computer device 502 may also include one or more network interfaces 520 for exchanging data with other devices via one or more communication links 522. One or more communication buses 524 couple the components described above together.

[0174] Communication link 522 can be implemented in any way, such as via a local area network, a wide area network (e.g., the Internet), a point-to-point connection, or any combination thereof. Communication link 522 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.

[0175] This specification also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.

[0176] This specification also provides computer-readable instructions, wherein when a processor executes the instructions, the program therein causes the processor to perform the above-described method.

[0177] It should be understood that in the various embodiments of this specification, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this specification.

[0178] It should also be understood that, in the embodiments of this specification, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the embodiments of this specification, the character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0179] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this specification can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of the embodiments in this specification.

[0180] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0181] In the embodiments provided in this specification, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or units, or they may be electrical, mechanical, or other forms of connection.

[0182] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments described in this specification, depending on actual needs.

[0183] Furthermore, the functional units in the various embodiments of this specification can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0184] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this specification, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this specification. The aforementioned 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.

[0185] This specification describes the principles and implementation methods of the embodiments using specific examples. The above descriptions of the embodiments are only for the purpose of helping to understand the methods and core ideas of the embodiments in this specification. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the embodiments in this specification. Therefore, the content of this specification should not be construed as a limitation on the embodiments in this specification.

Claims

1. A branch training filtering method, characterized in that, The method includes: When receiving feedback information after the execution unit executes a branch, it is determined whether the actual branch direction of the branch in the feedback information is different from the specified branch direction. If so, the optimization of the branch predictor by the feedback information is prevented, and the probability of the specified branch direction is reached. After preventing the feedback information from optimizing the branch predictor, the method further includes: When the specified branch direction is a jump, the type of the branch in the branch target buffer BTB of the branch predictor is set to unconditional jump; When the specified branch direction is no jump, the information of the branch in the BTB is released.

2. The method according to claim 1, characterized in that, The method further includes: The historical branch directions of the branches returned by the instruction retirement unit are statistically analyzed to obtain the specified branch direction.

3. The method according to claim 2, characterized in that, Statistical analysis of the historical branch directions returned by the instruction retirement unit to obtain the specified branch direction further includes: Upon receiving the historical branch direction of the branch returned by the retirement unit, determine whether there is a valid entry for the branch in the branch prediction filter table; If it exists, determine whether the branch direction recorded in the entry of the branch is the same as the historical branch direction; If they are the same, then determine whether the number of repetitions of the branch direction recorded in the entry of the branch has reached the number threshold. If the threshold number of times is reached, then the branch direction is taken as the designated branch direction.

4. The method according to claim 3, characterized in that, The method further includes: If the number of repetitions does not reach the threshold, then the number of repetitions is increased.

5. The method according to claim 3, characterized in that, The method further includes: If the branch direction recorded in the entry of the branch is different from the historical branch direction, then it is determined whether the number of repetitions of the branch direction recorded in the entry of the branch reaches the number threshold. If the target is reached, then reset the number of repetitions. If the condition is not met, invalidate the entry in the branch.

6. The method according to claim 3, characterized in that, The method further includes: If there is no valid entry for the branch in the branch prediction filter table, then it is determined whether there is an invalid entry for the branch. If it exists, create a valid entry for the branch in the branch prediction filter table.

7. The method according to claim 6, characterized in that, The method further includes: If there is no valid entry for the branch in the branch prediction filter table, and there is no invalid entry for the branch, then a replacement entry is determined based on the activity values ​​of multiple entries in the branch prediction filter table, a valid entry for the branch is created, and the replacement entry is replaced.

8. The method according to claim 7, characterized in that, The activity value is the SSRIP value predicted by the static rereference interval.

9. The method according to claim 8, characterized in that, Determining the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table further includes: The entry with the largest SSRIP value is used as the replacement entry.

10. A branch training filter, characterized in that, The branch training filter includes: The data filtering unit is optimized and configured to, when receiving feedback information after the execution unit executes a branch, determine whether the actual branch direction of the branch in the feedback information is different from the specified branch direction. If so, the feedback information is prevented from optimizing the branch predictor, and the probability of the specified branch direction is reached. The branch training filter further includes a target buffer update control unit, configured to, after preventing the feedback information from optimizing the branch predictor, set the branch type in the branch target buffer (BTB) of the branch predictor to unconditional jump when the specified branch direction is a jump; and release the branch information in the BTB when the specified branch direction is no jump.

11. The branch training filter according to claim 10, characterized in that, The branch training filter also includes: The historical branch direction statistics unit is configured to perform statistics on the historical branch directions of the branch returned by the instruction retirement unit to obtain the specified branch direction.

12. The branch training filter according to claim 11, characterized in that, Statistical analysis of the historical branch directions returned by the instruction retirement unit to obtain the specified branch direction further includes: Upon receiving the historical branch direction of the branch returned by the retirement unit, determine whether there is a valid entry for the branch in the branch prediction filter table; If it exists, determine whether the branch direction recorded in the entry of the branch is the same as the historical branch direction; If they are the same, then determine whether the number of repetitions of the branch direction recorded in the entry of the branch has reached the number threshold. If the threshold number of times is reached, then the branch direction is taken as the designated branch direction.

13. The branch training filter according to claim 12, characterized in that, The historical branch direction statistics unit is further configured to: if the number of repetitions does not reach the number threshold, then increase the number of repetitions.

14. The branch training filter according to claim 12, characterized in that, The historical branch direction statistics unit is further configured to: if the branch direction recorded in the branch entry is different from the historical branch direction, then determine whether the number of repetitions of the branch direction recorded in the branch entry reaches the number threshold. If the target is reached, then reset the number of repetitions. If the condition is not met, invalidate the entry in the branch.

15. The branch training filter according to claim 12, characterized in that, The historical branch direction statistics unit is further configured to: if there is no valid entry for the branch in the branch prediction filter table, then determine whether there is an invalid entry for the branch. If it exists, create a valid entry for the branch in the branch prediction filter table.

16. The branch training filter according to claim 15, characterized in that, The historical branch direction statistics unit is further configured to: if there is no valid entry for the branch in the branch prediction filter table, and there is no invalid entry for the branch, then a replacement entry is determined based on the activity value of multiple entries in the branch prediction filter table, a valid entry for the branch is created, and the replacement entry is replaced.

17. The branch training filter according to claim 16, characterized in that, The activity value is the SSRIP value predicted by the static rereference interval.

18. The branch training filter according to claim 17, characterized in that, Determining the replacement entry based on the activity values ​​of multiple entries in the branch prediction filter table further includes: The entry with the largest SSRIP value is used as the replacement entry.

19. A branch prediction system, characterized in that, Includes branch predictors and branch training filters; The branch training filter is deployed on the feedback path of the branch predictor between the execution unit and the instruction retirement unit; The branch predictor is configured to predict the branch direction. The branch training filter is configured to execute the method described in any one of claims 1-9 when it receives feedback information after the execution unit has executed a branch.

20. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 9.

21. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 9.