Branch instruction processing method, branch predictor and processor

By finding part of the address of the target branch instruction in the branch prediction table, using multiple prediction information, including historical jump information and prediction result information that affects branch instruction, the problem of low prediction accuracy in the prior art is solved. Improves the processor's processing efficiency.

CN113544640BActive Publication Date: 2024-11-22HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201980093772.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-03-30
Publication Date
2024-11-22
Estimated Expiration
2039-03-30

AI Technical Summary

Technical Problem

In branch instruction prediction, existing processors only rely on the historical jump information of branch instructions, resulting in low accuracy of prediction results and failure to fully consider other influencing factors.

Method used

By finding part of the address of the target branch instruction in the branch prediction table, using multiple prediction information, including historical jump information and prediction result information that affects the branch instruction, we jointly predict whether to perform jump operations to improve prediction accuracy.

Benefits of technology

It improves the accuracy of branch instruction prediction, reduces the 'bubble' in the pipeline, and improves the processor's processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113544640B_ABST
    Figure CN113544640B_ABST
Patent Text Reader

Abstract

An embodiment of the present application provides a branch instruction processing method, a branch predictor and a processor. When predicting whether to execute a jump operation on a target branch instruction, first, according to a partial address of the target branch instruction, a target branch entry corresponding to the target branch instruction is searched in a branch prediction table; if the target branch entry is found in the branch prediction table, since the target branch entry includes a first field, and the first field is used to indicate M prediction information, the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction, and M is an integer greater than or equal to 2, in this way, it is possible to jointly predict whether to execute a jump operation on the target branch instruction based on the historical jump information of multiple target branch instructions and the information affecting the prediction result of the target branch instruction, thereby improving the accuracy of the prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method for processing branch instructions, a branch predictor, and a processor. Background Art

[0002] In order to meet the increasing demand for processor performance, processors usually use pipeline technology that can overlap execution instructions to improve efficiency. Usually, after the processor obtains a branch instruction, the front stage of the pipeline will perform a jump prediction on the branch instruction and continue to obtain instructions at the jump address indicated by the prediction result without waiting for the back stage of the pipeline to return the jump result of the branch instruction, thereby reducing the "bubbles" in the pipeline and improving the processing efficiency of the processor.

[0003] In the prior art, a two-bit branch prediction (local 2-bit branch-prediction, local2b) algorithm is usually used to predict the jump result of a branch instruction. The local 2b algorithm updates a 2-bit counter according to the historical jump information of the branch instruction, and uses the counter result to perform jump prediction. However, when the algorithm is used for jump prediction, it only predicts based on the historical jump information of the branch instruction, and does not take other influencing factors into consideration, resulting in low accuracy of the prediction result. Summary of the invention

[0004] The present application provides a branch instruction processing method, a branch predictor and a processor, which improve the accuracy of the prediction result.

[0005] In a first aspect, an embodiment of the present application provides a method for processing a branch instruction, and the method for processing a branch instruction may include:

[0006] According to a partial address of the target branch instruction, searching a target branch entry corresponding to the target branch instruction in a branch prediction table; wherein the target branch entry includes a first field, the first field is used to indicate M prediction information, and the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; M is an integer greater than or equal to 2;

[0007] If the target branch entry is found in the branch prediction table, it is predicted whether to execute a jump operation on the target branch instruction based on the prediction information indicated by the first field.

[0008] It can be seen that the branch instruction processing method provided in the embodiment of the present application, when predicting whether to execute a jump operation on the target branch instruction, first searches the target branch entry corresponding to the target branch instruction in the branch prediction table according to the partial address of the target branch instruction; if the target branch entry is found in the branch prediction table, since the target branch entry includes a first field, and the first field is used to indicate multiple prediction information, the multiple prediction information is predicted based on the historical jump information of the target branch instruction and the information affecting the prediction result of the target branch instruction, in this way, it is possible to jointly predict whether to execute a jump operation on the target branch instruction based on the historical jump information of multiple target branch instructions and the information affecting the prediction result of the target branch instruction, thereby improving the accuracy of the prediction result.

[0009] In one possible implementation, the information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction, that is, based on the historical jump information of multiple target branch instructions and the historical jump information of other branch instructions that affect the jump of the target branch instruction, it is jointly predicted whether to perform a jump operation on the target branch instruction, thereby improving the accuracy of the prediction result.

[0010] In a possible implementation, the target branch entry further includes a second field, and the second field is used to indicate the first address. If the prediction result indicates that a jump operation is to be performed, the target address of the jump operation is the first address.

[0011] In a possible implementation, the target branch entry further includes a third field, and the third field is used to indicate a branch attribute; the method may further include:

[0012] If there are idle bits in the third field, at least one prediction information among the M prediction information is stored in the idle bits, so that at least one prediction information is stored by reusing the idle bits in the third field. In this way, there is no need to increase the number of bits of the target branch entry, thereby reducing the number of bits occupied by the target branch entry.

[0013] In one possible implementation, the target branch entry also includes a fourth field, which is used to indicate that the first address is determined based on the fourth field and the second field; the second field is used to indicate the second address, which is an address in the first address that is different from the address of the target branch instruction, thereby reducing the number of bits occupied by the target branch entry while ensuring multiple prediction information.

[0014] In one possible implementation, the fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

[0015] In a possible implementation, since the compression control value indicated by the fourth field is different, the length of the second address will also change. In order not to affect the position of the bit fields occupied by other fields, the second field can be set in the last column of the target branch entry.

[0016] In a possible implementation, the M prediction information includes m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule. The method may further include:

[0017] Get the actual jump result of the target branch instruction;

[0018] The prediction result corresponding to the first rule and the prediction result corresponding to the second rule are respectively compared with the actual jump result; the prediction result corresponding to the first rule is predicted based on m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M;

[0019] According to the comparison result, the prediction information used for prediction is determined, and the prediction information used for prediction is one of the first prediction information and the second prediction information. When the multiple prediction information include two prediction rules, it is also possible to predict whether to perform a jump operation on the target branch instruction according to two different rules, so that the branch instruction processing method provided in the embodiment of the present application can be adapted to more prediction scenarios.

[0020] In a possible implementation, determining the prediction information for prediction use according to the comparison result may include:

[0021] If the prediction result corresponding to the first rule is the same as the actual jump result, the first prediction information is determined as the prediction information used for prediction; or,

[0022] If the prediction result corresponding to the second rule is the same as the actual jump result, the second prediction information is determined as the prediction information used for prediction.

[0023] In one possible implementation, the first prediction information and the second prediction information are updated according to the actual jump result, thereby improving the accuracy of the first prediction information and the second prediction information. In this way, the accuracy of the prediction result can be further improved by subsequently predicting whether to execute a jump operation on the target branch instruction based on the updated first prediction information and the second prediction information.

[0024] In a second aspect, an embodiment of the present application provides a branch predictor, which may include:

[0025] A search unit, configured to search a target branch entry corresponding to the target branch instruction in a branch prediction table according to a partial address of the target branch instruction; wherein the target branch entry includes a first field, the first field is used to indicate M prediction information, the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; M is an integer greater than or equal to 2;

[0026] The prediction unit is used to predict whether to execute a jump operation on the target branch instruction based on the prediction information indicated by the first field if a target branch entry is found in the branch prediction table.

[0027] In a possible implementation, the information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction.

[0028] In a possible implementation, the target branch entry further includes a second field, and the second field is used to indicate the first address. If the prediction result indicates that a jump operation is to be performed, the target address of the jump operation is the first address.

[0029] In one possible implementation, the target branch entry also includes a third field, and the third field is used to indicate a branch attribute. The branch predictor may include: a processing unit, which is used to store at least one prediction information among the M prediction information in the idle bit if there is an idle bit in the third field.

[0030] In one possible implementation, the target branch entry also includes a fourth field, which is used to indicate that the first address is determined based on the fourth field and the second field; the second field is used to indicate the second address, which is an address in the first address that is different from the address of the target branch instruction.

[0031] In one possible implementation, the fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

[0032] In a possible implementation, the second field is set in the last column of the target branch entry.

[0033] In a possible implementation, the M prediction information includes m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule;

[0034] The processing unit is also used to obtain the actual jump result of the target branch instruction; and respectively compare the prediction result corresponding to the first rule and the prediction result corresponding to the second rule with the actual jump result; and then determine the prediction information used for prediction according to the comparison result, and the prediction information used for prediction is one of the first prediction information and the second prediction information. The prediction result corresponding to the first rule is predicted based on m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M.

[0035] In one possible implementation, the processing unit is specifically used to determine the first prediction information as the prediction information for prediction use if the prediction result corresponding to the first rule is the same as the actual jump result; or, if the prediction result corresponding to the second rule is the same as the actual jump result, determine the second prediction information as the prediction information for prediction use.

[0036] In a possible implementation manner, the first prediction information and the second prediction information are updated according to the actual jump result.

[0037] In a possible implementation, the first rule is a global enhanced GL algorithm, and the second rule is a two-bit branch prediction local2b algorithm; or, the first rule is a local2b algorithm, and the second rule is a GL algorithm.

[0038] In a third aspect, an embodiment of the present application further provides a branch predictor, which may include a prediction logic circuit and a memory;

[0039] A memory, used for storing a branch prediction table, wherein the branch prediction table includes a plurality of branch entries;

[0040] A prediction logic circuit is used to search for a target branch entry corresponding to a target branch instruction in multiple branch entries based on a partial address of the target branch instruction; wherein the target branch entry includes a first field, the first field is used to indicate M prediction information, and the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; if the target branch entry is found in the branch prediction table, then based on the prediction information indicated by the first field, it is predicted whether a jump operation is performed on the target branch instruction; wherein M is an integer greater than or equal to 2.

[0041] In a possible implementation, the information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction.

[0042] In a possible implementation, the target branch entry further includes a second field, and the second field is used to indicate the first address. If the prediction result indicates to perform a jump operation, the target address of the jump operation is the first address.

[0043] In a possible implementation, the target branch entry further includes a third field, the third field is used to indicate a branch attribute, and the branch predictor further includes an update logic circuit;

[0044] The updating logic circuit is used for storing at least one prediction information among the M prediction information in the idle bit if there is an idle bit in the third field.

[0045] In one possible implementation, the target branch entry also includes a fourth field, which is used to indicate that the first address is determined based on the fourth field and the second field; the second field is used to indicate the second address, which is an address in the first address that is different from the address of the target branch instruction.

[0046] In one possible implementation, the fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

[0047] In a possible implementation, the second field is set in the last column of the target branch entry.

[0048] In a possible implementation, the M prediction information includes m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule;

[0049] The updating logic circuit is also used to obtain the actual jump result of the target branch instruction;

[0050] The prediction logic circuit is also used to compare the prediction results corresponding to the first rule and the prediction results corresponding to the second rule with the actual jump results, and determine the prediction information used for prediction based on the comparison results, and the prediction information used for prediction is one of the first prediction information and the second prediction information; wherein the prediction result corresponding to the first rule is predicted based on m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M.

[0051] In one possible implementation, the prediction logic circuit is specifically used to determine the first prediction information as the prediction information for prediction use if the prediction result corresponding to the first rule is the same as the actual jump result; or, if the prediction result corresponding to the second rule is the same as the actual jump result, determine the second prediction information as the prediction information for prediction use.

[0052] In a possible implementation, the update logic circuit is further configured to update the first prediction information and the second prediction information according to an actual jump result.

[0053] In a possible implementation, the first rule is a global enhanced GL algorithm, and the second rule is a two-bit branch prediction local2b algorithm; or, the first rule is a local2b algorithm, and the second rule is a GL algorithm.

[0054] In a fourth aspect, an embodiment of the present application further provides a processor, which may include: a processing circuit and a branch predictor as described in any possible implementation of the second aspect or the third aspect;

[0055] The branch predictor is used to predict whether to execute a jump operation on the target branch instruction. If the prediction result indicates to execute a jump operation, the processing circuit uses the first address in the target branch entry in the branch predictor as the target address of the jump operation and executes the jump operation on the target branch instruction.

[0056] In a fifth aspect, an embodiment of the present application further provides a readable storage medium having a computer program stored thereon; when the computer program is executed, it is used to execute a method for processing branch instructions as described in any possible implementation of the first aspect above.

[0057] In a sixth aspect, an embodiment of the present application further provides a chip having a computer program stored thereon, which, when the computer program is executed by a processor, is used to execute a branch instruction processing method as described in any possible implementation of the first aspect above.

[0058] The branch instruction processing method, branch predictor and processor provided in the embodiments of the present application, when predicting whether to execute a jump operation on a target branch instruction, first search the target branch entry corresponding to the target branch instruction in the branch prediction table according to a partial address of the target branch instruction; if the target branch entry is found in the branch prediction table, since the target branch entry includes a first field, and the first field is used to indicate multiple prediction information, the multiple prediction information is predicted based on the historical jump information of the target branch instruction and the information affecting the prediction result of the target branch instruction, in this way, it is possible to jointly predict whether to execute a jump operation on the target branch instruction based on the historical jump information of multiple target branch instructions and the information affecting the prediction result of the target branch instruction, thereby improving the accuracy of the prediction result. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present application;

[0060] Figure 2A flowchart of a method for processing a branch instruction provided in an embodiment of the present application;

[0061] Figure 3 A schematic diagram of the structure of a branch entry provided in an embodiment of the present application;

[0062] Figure 4 A schematic diagram of the structure of another branch entry provided in an embodiment of the present application;

[0063] Figure 5 A schematic diagram of processing an instruction provided in an embodiment of the present application;

[0064] Figure 6 A schematic diagram of the structure of another branch entry provided in an embodiment of the present application;

[0065] Figure 7 A schematic diagram of a branch entry structure provided in an embodiment of the present application

[0066] Figure 8 A schematic diagram of an address and a first address of a target branch instruction provided in an embodiment of the present application;

[0067] Fig. 9 A schematic diagram of the structure of another branch entry provided in an embodiment of the present application;

[0068] Fig.10 A flowchart of another method for processing branch instructions provided in an embodiment of the present application;

[0069] Fig.11 A schematic diagram of a selection prediction rule provided in an embodiment of the present application;

[0070] Fig.12 A schematic diagram of switching prediction rules provided in an embodiment of the present application;

[0071] Fig.13 A schematic diagram of the structure of a branch predictor provided in an embodiment of the present application;

[0072] Fig.14 A schematic diagram of the structure of another branch predictor provided in an embodiment of the present application;

[0073] Fig.15 A schematic diagram of the structure of a processor provided in an embodiment of the present application. DETAILED DESCRIPTION

[0074] Figure 1 A schematic diagram of a system architecture provided in an embodiment of the present application, the system architecture may include an instruction memory, an instruction fetcher and a branch predictor. For example, see Figure 1As shown, the instruction memory is used to store multiple instructions, the instruction fetcher obtains the instruction from the instruction memory and sends the instruction address to the branch predictor. If the branch predictor finds the instruction in its branch prediction table according to the instruction address, it determines that the instruction is a branch instruction, and when the branch instruction is predicted to jump, it can predict according to the historical jump information of the branch instruction stored in the branch predictor, and send the prediction result to the selector. The prediction result can be the jump address, whether to jump, and other information. If it is determined to perform the prediction operation, the jump address corresponding to the prediction operation is sent to the selector. The selector determines the address for querying the branch instruction from the jump address and the address of the branch instruction sent by the instruction fetcher, and sends the address to the instruction memory, so that the memory can find the corresponding instruction according to the address, and send the instruction to the instruction fetcher (for example, the instruction address sent by the instruction fetcher to the selector can be the instruction address sent by the instruction fetcher to the branch predictor plus 1, and the plus 1 refers to the address of the next jump instruction).

[0075] In the prior art, when predicting a branch instruction through a branch predictor, the Local2b algorithm is usually used to predict whether the branch instruction will jump. However, the algorithm only predicts based on the historical jump information of the branch instruction, and does not take into account other factors that may affect it, resulting in a low accuracy of the prediction result. In order to improve the accuracy of the prediction result, an embodiment of the present application provides a prediction method for a branch instruction. When predicting whether to perform a jump operation on a target branch instruction, first search for a target branch entry corresponding to the target branch instruction in a branch prediction table based on a partial address of the target branch instruction; if the target branch entry is found in the branch prediction table, since the target branch entry includes a first field, and the first field is used to indicate M prediction information, the M prediction information is predicted based on the historical jump information of the target branch instruction and the information that affects the prediction result of the target branch instruction, and M is an integer greater than or equal to 2, so that it is possible to predict whether to perform a jump operation on the target branch instruction based on multiple (at least two) prediction information indicated by the first field, thereby improving the accuracy of the prediction result.

[0076] Before describing in detail the technical solution of the processing method of the branch instruction provided in the embodiment of the present application, several concepts involved in the embodiment of the present application are explained first. First, for branch instructions, branch instructions can be divided into four categories according to the first dimension (direct target jump or indirect target jump) and the second dimension (unconditional jump or conditional jump). Among them, the jump address of the direct target jump is fixed, while the target of the indirect target jump can be a variable, such as the value of a register, and the value of this register can change; the branch instruction of the unconditional jump is a certain jump, and the conditional jump generally determines whether to perform a jump operation according to the value of a variable. For example, when the value of the variable is 1, it is determined to perform a jump operation; when the value of the variable is 0, it is determined not to perform a jump operation. The four categories of branch instructions divided by these two dimensions are: the first category of branch instructions are direct target jumps and unconditional jumps. The jump address of the first category of branch instructions is fixed, and the jump operation will definitely be executed, that is, the first category of branch instructions does not require jump prediction; the second category of branch instructions are direct target jumps and conditional jumps. The jump address of the second category of branch instructions is fixed, but it is necessary to predict whether to execute the jump operation; the third category of branch instructions are indirect target jumps and unconditional jumps. The jump address of the third category of branch instructions needs to be predicted, and the jump operation will definitely be executed, that is, the third category of branch instructions only needs to predict the jump address; the fourth category of branch instructions are indirect target jumps and conditional jumps. The branch instruction needs to predict the jump address and needs to predict whether to execute the jump operation, that is, the fourth category of branch instructions needs to predict the jump address and whether to execute the jump operation. Secondly, for different types of branch instructions, the prediction information of the branch instruction may include information for predicting whether the branch instruction performs a jump operation, and may also include historical prediction results of the branch instruction, all of which can be used as prediction information for the branch instruction. For example, the historical jump information stored in the prediction information local2b algorithm and the gshare-like algorithm. Below, taking the branch instruction as the second type of branch instruction (i.e., a branch instruction with a fixed jump address but requiring prediction of whether to jump) as an example, the technical solution of the method for processing branch instructions provided in the embodiment of the present application is described in detail.

[0077] It should be noted that in the embodiments of the present application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In the text description of the present application, the character " / " generally indicates that the associated objects before and after are in an "or" relationship.

[0078] Figure 2A flow chart of a method for processing a branch instruction provided in an embodiment of the present application is provided. For example, see Figure 2 As shown, the processing method of the branch instruction may include:

[0079] S201. Search a branch prediction table for a target branch entry corresponding to the target branch instruction according to a partial address of the target branch instruction.

[0080] The target branch entry includes a first field, and the first field is used to indicate M prediction information. The M prediction information is predicted based on the historical jump information of the target branch instruction and the information affecting the prediction result of the target branch instruction. M is an integer greater than or equal to 2, that is, the first field is used for at least two prediction information. Optionally, the information affecting the prediction result of the target branch instruction can be the historical jump information of other branch instructions that affect the jump of the target branch instruction, or other information. It can be set according to actual needs. Here, the embodiments of the present application do not make specific restrictions. For examples, please refer to Figure 3 As shown, Figure 3 A schematic diagram of a branch entry structure provided in an embodiment of the present application. The branch entry may include a branch address of a branch instruction, which may be understood as a high-order address of the branch instruction, and may also include a first field of M attribute information indicating the branch instruction, and of course, may also include an instruction type.

[0081] Before explaining the partial address of the target branch instruction, the address of the target branch instruction is introduced first. The address of the target branch instruction is the address of the target instruction in the target branch instruction, and the address of the target branch instruction is usually not completely stored in the branch prediction table. Taking the address of the target branch instruction as 32 bits as an example, several bits can be selected from it, such as taking 10 bits from the low position to determine its position in the branch prediction table, such as which row. Then use 20 bits of the remaining 22 bits to compare and determine whether the corresponding position of the branch prediction table is stored in the target instruction. The remaining 2 bits can be invalid bits, or there can be no invalid bits. Use all the remaining 22 bits to compare and determine whether the corresponding position of the branch prediction table is stored in the target instruction. Correspondingly, when taking 10 bits from the low position to determine its position in the branch prediction table, the partial address of the target branch instruction can be understood as the low-order address of the target branch instruction, that is, the 10-bit address. Of course, it can also include an address greater than 10 bits of the low-order address, as long as the row where the target branch instruction is located can be determined in the branch prediction table according to the partial address. It is understandable that the embodiment of the present application is only described by taking the address of the target branch instruction as 32 bits as an example, but it does not mean that the embodiment of the present application is limited to this.

[0082] After determining the partial address of the target branch instruction, the target branch entry corresponding to the target branch instruction can be searched in the branch prediction table according to the partial address of the target branch instruction. For the branch prediction table, in the initial state, the branch prediction table is empty, that is, there is no branch entry stored in the branch prediction table. During the branch instruction processing, the processor stores the relevant information of the branch instruction in the form of a branch entry in the branch prediction table in the branch predictor for each branch instruction processed. The branch prediction table is stored in a memory in the branch predictor, so that the branch prediction table will store at least one branch entry corresponding to each branch instruction. At least one branch entry in the branch prediction table may include the target branch entry corresponding to the target branch instruction, or may not include the target branch entry corresponding to the target branch instruction. Therefore, the target branch entry corresponding to the target branch instruction can be searched in the branch prediction table according to the partial address of the target branch instruction to determine the corresponding prediction result according to the search result. It can be understood that the processor in the present application may include a branch predictor and a processing circuit. Among them, the branch predictor is mainly used to predict whether to execute a jump operation on the target branch instruction. If the prediction result indicates to execute a jump operation, the processing circuit uses the first address in the target branch entry in the branch predictor as the target address of the jump operation and executes the jump operation on the target branch instruction.

[0083] S202: If a target branch entry is found in the branch prediction table, predict whether to execute a jump operation on the target branch instruction based on the prediction information indicated by the first field.

[0084] It is understandable that the prediction result may be information such as a jump address or whether to jump.

[0085] If the target branch entry is found in the branch prediction table, it is possible to predict whether to execute a jump operation on the target branch instruction based on the prediction information indicated by the first field in the target branch entry. For example, it is possible to predict whether to execute a jump operation on the target branch instruction based on N prediction information out of the M prediction information indicated by the first field. It is understandable that when N is less than M, it means that it is possible to predict whether to execute a jump operation on the target branch instruction based on part of the prediction information out of the M prediction information; when N is equal to M, it means that it is possible to predict whether to execute a jump operation on the target branch instruction based on all the prediction information out of the M prediction information, thereby improving the accuracy of the prediction result. It is understandable that when predicting whether to execute a jump operation on the target branch instruction based on the prediction information, the number of prediction information can be set according to actual needs, and the embodiments of the present application are not further limited here.

[0086] For example, with the target branch instruction being the first branch instruction, when predicting whether to execute a jump operation on the first branch instruction, the prediction information includes not only the historical jump information of the first branch instruction, but also other factors affecting the first branch instruction, such as the historical jump information of other branch instructions (such as the second branch instruction, the third branch instruction, and the fourth branch instruction). If the historical jump information of the second branch instruction, the third branch instruction, and the fourth branch instruction is the jump result of the last time, and the jump result is represented by two bits of 0 and 1, there can be 8 combinations of jump results, corresponding to 8 prediction information, then the M prediction information can include 8 prediction information, so that it can be predicted whether to execute a jump operation on the first branch instruction based on at least two of the 8 prediction information.

[0087] After predicting whether to execute a jump operation on the target branch instruction, a prediction result can be obtained. For example, the prediction result can be represented by two bits, for example, the prediction result can be 00, 01, 10 and 11. Usually, the prediction results 00 and 01 indicate that the jump operation is not executed, and the prediction results 10 and 11 indicate that the jump operation is executed. Therefore, after obtaining the prediction result, it can be determined whether to execute the jump operation according to the prediction result.

[0088] Optionally, if the prediction result indicates that a jump operation is to be performed, the first address is used as the target address of the jump operation. For example, when a jump operation is performed using the first address as the target address of the jump operation, the branch predictor instructs the processing circuit in the processor to use the first address as the target address of the jump operation, and to perform a jump operation on the target branch instruction so as to jump to the first address; on the contrary, if the prediction result indicates that a jump operation is not to be performed, the target branch instruction is not processed.

[0089] Optionally, the target branch entry further includes a second field, and the second field is used to indicate the first address. It is understandable that the first address can be understood as a complete jump address or a partial jump address, but the complete jump address can be determined based on the partial jump address. For an example, see Figure 4 As shown, Figure 4 A schematic diagram of the structure of another branch entry provided in an embodiment of the present application.

[0090] If the prediction result indicates to execute a jump operation, the jump operation can be performed on the target branch instruction according to the second field for the first address included in the target branch entry, so that the jump is made to the first address, and branch instructions are continued to be obtained at the first address for prediction until all instructions are executed.

[0091] It can be seen that the branch instruction processing method provided in the embodiment of the present application, when predicting whether to execute a jump operation on the target branch instruction, first searches the branch prediction table for the target branch entry corresponding to the target branch instruction based on the partial address of the target branch instruction; if the target branch entry is found in the branch prediction table, since the target branch entry includes a first field, and the first field is used to indicate multiple prediction information, the multiple prediction information is predicted based on the historical jump information of the target branch instruction and the information affecting the prediction result of the target branch instruction, in this way, it is possible to jointly predict whether to execute a jump operation on the target branch instruction based on the historical jump information of multiple target branch instructions and the historical jump information of other branch instructions that affect the jump of the target branch instruction, thereby improving the accuracy of the prediction result.

[0092] For example, in order to more clearly illustrate the processing method of the branch instruction provided in the embodiment of the present application, for example, see Figure 5 As shown, Figure 5 A schematic diagram of processing an instruction provided in an embodiment of the present application. Figure 5 It can be seen that the instruction memory sequentially stores instruction A, instruction B, instruction C, instruction D and instruction E. The instruction fetcher fetches instruction A from the instruction memory and sends the address of instruction A to the branch predictor. Since the branch predictor includes branch entries corresponding to multiple branch instructions, and the branch entries store the addresses of branch instructions, the branch predictor can search in the branch prediction table according to the address of instruction A. If the instruction A is found in the branch prediction table, it can be determined that the instruction A is a branch instruction, and further predict whether to perform a jump operation on the instruction A according to multiple historical jump information of the instruction A in the branch entry corresponding to the instruction A and the historical jump information of other branch instructions that affect the jump of the instruction A. If the prediction result indicates that the jump operation is to be performed, the first address is obtained in the branch entry corresponding to the instruction A, and the processing circuit in the processor is instructed to perform a jump operation on the instruction A. If the first address is the address of instruction D, the instruction fetcher sends the address of instruction D to the instruction memory, and the instruction memory sends instruction D to the processor according to the address of instruction D, and the processor processes instruction D. It can be seen that when predicting whether to execute a jump operation on instruction A, the multiple historical jump information corresponding to instruction A and the historical jump information of other branch instructions that affect the jump of instruction A are used to jointly predict whether to execute a jump operation on instruction A, thereby improving the accuracy of the prediction result.

[0093] Figure 2The illustrated embodiment describes in detail that when predicting whether to execute a jump operation on a target branch instruction, it is possible to predict whether to execute a jump operation on a target branch instruction based on multiple prediction information, thereby improving the accuracy of the prediction result. However, since the target branch entry includes multiple prediction information, this will increase the length of the target branch entry, that is, the number of bits occupied by the target branch entry increases. At this time, it is possible to consider reducing the number of bits occupied by the target branch entry while ensuring multiple prediction information. Optionally, in an embodiment of the present application, the number of bits occupied by the target branch entry can be reduced by at least two possible implementation methods. In one possible implementation method, when the target branch entry includes a third field for indicating a branch attribute, and there are idle bits in the third field, at least one prediction information can be stored by reusing the idle bits to reduce the number of bits occupied by the target branch entry. For examples, see Figure 6 As shown, Figure 6 A schematic diagram of the structure of another branch entry provided for an embodiment of the present application. In another possible implementation, since the address of the target branch instruction is relatively close to the first address, the address of the target branch instruction and the first address have many bits in common, and therefore, the number of bits occupied by the target branch entry can be reduced by compressing the number of bits occupied by the first address. The two possible implementations will be described in detail below.

[0094] In a possible implementation, at least one prediction information is stored by reusing idle bits to reduce the number of bits occupied by the target branch entry. The specific solution is: since the target branch entry also includes a third field for indicating branch attributes, if there are idle bits in the third field, at least one prediction information among the M prediction information can be stored in the idle bits, so that at least one prediction information is stored by reusing the idle bits in the third field, so that there is no need to increase the number of bits of the target branch entry, thereby reducing the number of bits occupied by the target branch entry.

[0095] It can be understood that the branch attribute indicates the type of branch instruction, and can also indicate whether the branch instruction is for one-time use, or whether it is to be replaced first, etc. Each attribute occupies a certain number of bits. In the prior art, each time the relevant information in the branch entry is read, the usable branch attributes and the unusable branch attributes are determined according to the type of the branch instruction, and the field of the unusable branch attribute is idle. For example, in each branch entry, there are 10 bit fields of branch attributes, and the types of branch instructions are divided into three types: A, B, and C. The branch instruction of type A requires all 10 bit fields of branch attributes, the branch instruction of type B requires 8 bit fields of branch attributes, and the branch instruction of type C requires 5 bit fields of branch attributes. It can be seen that the branch instruction of type B can vacate 2 free bit fields of branch attributes, and these 2 free bit fields of branch attributes can be used to store at least one prediction information; similarly, the branch instruction of type C can vacate 5 free bit fields of branch attributes, and these 5 free bit fields of branch attributes can be used to store at least one prediction information, thereby reducing the number of bits occupied by the target branch entry.

[0096] In another possible implementation, the number of bits occupied by the target branch entry is reduced by compressing the number of bits occupied by the first address. The specific solution is: since the target branch entry also includes a fourth field, the fourth field is used to indicate that the first address is determined based on the fourth field and the second field; the second field is used to indicate the second address, and the second address is an address in the first address that is different from the address of the target branch instruction, thereby reducing the number of bits occupied by the target branch entry. For an example, see Figure 7 As shown, Figure 7 A schematic diagram of the structure of a branch entry provided in an embodiment of the present application.

[0097] Optionally, when determining the first address based on the fourth field and the second field, the fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

[0098] In this possible implementation, since the address of the target branch instruction is close to the first address, the address of the target branch instruction and the first address have many bits in common, so the number of bits occupied by the target branch entry can be reduced by compressing the number of bits occupied by the first address. Figure 8 As shown, Figure 8A schematic diagram of the address and first address of a target branch instruction provided for an embodiment of the present application. It can be seen that the address of the target branch instruction and the first address have many bits that are the same. Therefore, in order to save the number of bits occupied by the first address, the second field can be used to indicate only the second address, and the second address is an address in the first address that is different from the address of the target branch instruction. Optionally, when indicating the second address through the second field, since the number of bits that are the same as the branch instruction address and the target address changes dynamically, the target branch entry also needs to include a fourth field, and the fourth field is used to indicate that the first address can be correctly read according to the second address, that is, the first address can be determined according to the second address indicated by the fourth field and the second field, thereby determining the jump address of the target branch instruction.

[0099] Optionally, when determining the first address based on the second address indicated by the fourth field and the second field, the fourth field may be directly the number of bits of the second address; or, the fourth field may be the number of bits of the address of the target branch instruction which is the same as the first address; or, the fourth field may be the sum of the number of bits of the address of the target branch instruction and the second address, so that the first address can be determined based on the second address indicated by the fourth field and the second field.

[0100] Taking the case where the address of the target branch instruction and the first address are both 32 bits, and the address of the target branch instruction and the first address have 20 bits in common as an example, it can be seen that the address of the target branch instruction and the first address have 12 bits different from each other. In this case, the fourth field can be directly the number of bits of the second address, that is, the fourth field can be 12, and the first address can be determined based on the fourth field 12 and the second address. Alternatively, the fourth field can also be the number of bits that the address of the target branch instruction and the first address have in common, that is, the fourth field can be 20, and the first address can be determined based on the fourth field 20 and the second address. Alternatively, the fourth field can also be the number of bits of the address of the target branch instruction and the second address, that is, the fourth field can be 44 bits (the sum of 32 bits and 12 bits), and the first address can be determined based on the fourth field 44 and the second address, thereby determining the first address.

[0101] It is understandable that, due to the different compression control values ​​indicated by the fourth field, the length of the second address will also change. In order not to affect the position of the bit fields occupied by other fields, the second field can be set in the last column of the target branch entry.

[0102] It should be noted that when reducing the number of bits occupied by the target branch entry through the above two possible implementation methods, these two possible implementation methods can be used independently or mixed, and can be specifically set according to actual needs. Here, the embodiments of the present application do not make specific restrictions.

[0103] It can be seen that in the embodiment of the present application, by Figure 2 In the embodiment shown, when predicting whether to execute a jump operation on a target branch instruction, it is possible to predict whether to execute a jump operation on the target branch instruction based on multiple prediction information, thereby improving the accuracy of the prediction result. However, since the target branch entry includes multiple prediction information, this will increase the length of the target branch entry. Through the above two possible implementations, it is achieved that the number of bits occupied by the target branch entry is reduced while ensuring multiple prediction information.

[0104] It should be noted that when describing the technical solution provided by the embodiment of the present application through the above-mentioned embodiment, only the branch instruction of the second type of branch instruction is used as an example for explanation. The technical solution provided by the embodiment of the present application can also be applied to the other three types of branch instructions. For example, when the technical solution provided in the embodiment of the present application is applied to the first type of branch instruction, since the first type of branch instruction does not need to perform jump prediction, the structure of the branch entry can be directly used to store the jump address, but the prediction information in the branch entry is not used; when the technical solution provided in the embodiment of the present application is applied to the third type of branch instruction, since the third type of branch instruction only needs to predict the jump address, therefore, when jumping, the jump address defaults to the same as the last jump address, and the prediction information in the branch entry is not used; when the technical solution provided in the embodiment of the present application is applied to the fourth type of branch instruction, since the fourth type of branch instruction needs to predict the jump address and whether to perform the jump operation, therefore, when jumping, the jump address defaults to the same as the last jump address, and the prediction information in the branch entry is used to predict whether to perform the jump operation, and its prediction method is similar to the prediction method of the second type of branch instruction, and the prediction method of the second type of branch instruction can be specifically referred to, and the embodiment of the present application will not be repeated here. It can be understood that the embodiment of the present application is only described by taking these four types of branch instructions as examples, but it does not mean that the embodiment of the present application is limited to this.

[0105] Since a single prediction rule is difficult to adapt to all branch instruction prediction scenarios, two different rules can be used to predict whether to execute a jump operation on the target branch instruction. Figure 2 In the embodiment shown, when the M prediction information includes prediction information corresponding to two rules, it is possible to predict whether to execute a jump operation on the target branch instruction according to two different rules. Fig. 9 As shown, Fig. 9 A schematic diagram of the structure of another branch entry provided in an embodiment of the present application. It is understandable that the embodiment of the present application is only described by taking the prediction information corresponding to two rules included in the M prediction information as an example, and may also include prediction information corresponding to three rules, which can be specifically set according to actual needs. Here, the embodiment of the present application does not further limit the number of rules to which the prediction information included in the M prediction information belongs.

[0106] Optionally, the first rule is the global enhanced GL algorithm, and the second rule is the two-bit branch prediction local2b algorithm; or, the first rule is the local2b algorithm, and the second rule is the GL algorithm. Of course, it can also be other algorithms, which can be set according to actual needs. Here, the embodiments of the present application do not make further restrictions.

[0107] For example, taking the first rule and the second rule as the local2b algorithm and the GL algorithm respectively, when predicting whether to execute a jump operation on a target branch instruction, the M prediction information corresponding to the target branch instruction may include 1 prediction information corresponding to the local2b algorithm and the prediction information corresponding to the GL algorithm. Among them, the prediction information corresponding to the GL algorithm includes not only the historical jump information of the target branch instruction, but also other factors affecting the target branch instruction, such as the historical jump information of other branch instructions (such as the second branch instruction, the third branch instruction and the fourth branch instruction). If the historical jump information of the second branch instruction, the third branch instruction and the fourth branch instruction is the jump result of the last time, and the jump result is represented by two bits of 0 and 1, there can be 8 combinations of jump results, corresponding to 8 prediction information, then the M prediction information may include 9 prediction information (1 prediction information corresponding to the local2b algorithm and 8 prediction information corresponding to the GL algorithm), so that it is possible to predict whether to execute a jump operation on the target branch instruction based on at least two of the 9 prediction information.

[0108] Further, when the M prediction information includes prediction information corresponding to two rules, and the prediction information corresponding to the two rules is used to predict whether to execute a jump operation on the target branch instruction, how to determine which rule to use to predict whether to execute a jump operation on the target branch instruction, for example, see Fig.10 As shown, Fig.10 A flowchart of another branch instruction processing method provided in an embodiment of the present application, the branch instruction processing method may also include:

[0109] S1001. Obtain the actual jump result of the target branch instruction.

[0110] When the processor processes the target branch instruction, it takes a certain period of time to obtain the actual jump result of the target branch instruction. Therefore, the processor predicts the jump result of the target branch instruction using the prediction information corresponding to the first rule and the prediction information corresponding to the second rule, respectively, to obtain the prediction result corresponding to the first rule and the prediction result corresponding to the second rule. After obtaining the actual jump result of the target branch instruction, the following S1002 can be executed:

[0111] S1002: Compare the prediction result corresponding to the first rule and the prediction result corresponding to the second rule with the actual jump result respectively.

[0112] Among them, the prediction result corresponding to the first rule is obtained based on m1 first prediction information, and the prediction result corresponding to the second rule is obtained based on m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M.

[0113] S1003: Determine prediction information to be used for prediction according to the comparison result.

[0114] The prediction information used for prediction is one of the first prediction information and the second prediction information, and the prediction information used for prediction can be understood as the prediction information used for the next prediction.

[0115] After obtaining the prediction result corresponding to the first rule, the prediction result corresponding to the second rule, and the actual jump result, respectively, the prediction result corresponding to the first rule and the prediction result corresponding to the second rule are compared with the actual jump result. If the prediction result corresponding to the first rule is the same as the actual jump result, the first prediction information is determined as the prediction information for prediction use, that is, the first prediction information is used to predict whether to perform a jump operation on the target branch instruction next time; on the contrary, if the prediction result corresponding to the second rule is the same as the actual jump result, the second prediction information is determined as the prediction information for prediction use, thereby obtaining the prediction information for prediction use. Among them, the prediction information for prediction use can be understood as the prediction information for the next prediction use.

[0116] Optionally, when determining the prediction information for predicted use according to the comparison result, the selection counter may be updated according to the comparison result, and then the prediction information for predicted use may be determined according to the value of the selection counter. Fig.11 As shown, Fig.11 A schematic diagram of a selection prediction rule provided in an embodiment of the present application.

[0117] For example, the first rule and the second rule are respectively the local2b algorithm and the GL algorithm, wherein the GL algorithm is the prediction algorithm provided in the embodiment of the present application, and the selection counter is represented by a 2-bit value, which are 00, 01, 10 and 11 respectively, 00 and 01 represent the use of the local2b algorithm, and 10 and 11 represent the use of the GL algorithm. The counting rule for selecting the counter can be: when the local2b algorithm is used to predict whether to execute a jump operation on the target branch instruction, if the prediction result is correct, the value of the selection counter is reduced by 1, and if the prediction result is wrong, the value of the selection counter is increased by 1; when the GL algorithm is used to predict whether to execute a jump operation on the target branch instruction, if the prediction result is correct, the value of the selection counter is increased by 1, and if the prediction result is wrong, the value of the selection counter is reduced by 1.

[0118] For example, if the value of the counter is 00 in the initial state and the local2b algorithm is used for prediction, see Fig.12 As shown, Fig.12 A schematic diagram of a prediction rule switching provided in an embodiment of the present application. If the prediction result of the local2b algorithm is the same as the actual jump result, it means that the local2b algorithm predicts correctly, and the value of the selection counter is reduced by 1. Since the value of the selection counter itself is already 00, the value of the selection counter can be kept unchanged, that is, the value of the selection counter is still 00; if the prediction result of the local2b algorithm is different from the actual jump result, it means that the local2b algorithm predicts incorrectly, and the value of the selection counter is increased by 1. The value of the selection counter changes from 00 to 01. 01 represents the local2b algorithm. At this time, the local2b algorithm is still used. The method remains unchanged; if the prediction result of the local2b algorithm is different from the actual jump result, it means that the local2b algorithm has made a prediction error, and the value of the selection counter is increased by 1, and the value of the selection counter changes from 01 to 10, 10 represents the GL algorithm. At this time, switch to the GL algorithm, and subsequently use the GL algorithm for prediction. If the prediction result of the GL algorithm is different from the actual jump result, it means that the local2b algorithm has made a prediction error, and the value of the selection counter is increased by 1, and the value of the selection counter changes from 10 to 11, 11 represents the GL algorithm. At this time, the GL algorithm is still kept unchanged, so as to determine the prediction information used for prediction according to the value of the selection counter.

[0119] It is understandable that the embodiment of the present application is only explained by taking 00 and 01 to indicate the use of the local2b algorithm, and 10 and 11 to indicate the use of the GL algorithm. 00 and 01 can also be used to indicate the use of the GL algorithm, and 10 and 11 to indicate the use of the local2b algorithm. The specific settings can be made according to actual needs. Here, the embodiment of the present application does not make further restrictions. When 00 and 01 indicate the use of the GL algorithm, and 10 and 11 indicate the use of the local2b algorithm, the corresponding counting rule of the selection counter can be: when the GL algorithm is used to predict whether to perform a jump operation on the target branch instruction, if the prediction result is correct, the value of the selection counter is reduced by 1, and if the prediction result is wrong, the value of the selection counter is increased by 1; when the local2b algorithm is used to predict whether to perform a jump operation on the target branch instruction, if the prediction result is correct, the value of the selection counter is increased by 1, and if the prediction result is wrong, the value of the selection counter is reduced by 1.

[0120] It can be seen that in the embodiment of the present application, by Figure 2 In the embodiment shown, when predicting whether to execute a jump operation on a target branch instruction, it is possible to predict whether to execute a jump operation on the target branch instruction based on multiple prediction information, wherein the multiple prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction, thereby improving the accuracy of the prediction result. Furthermore, when the multiple prediction information includes two prediction rules, it is also possible to predict whether to execute a jump operation on the target branch instruction based on two different rules, so that the branch instruction processing method provided in the embodiment of the present application can be adapted to more prediction scenarios.

[0121] It should be noted that after obtaining the actual jump result, the first prediction information and the second prediction information can also be updated according to the actual jump result, thereby improving the accuracy of the first prediction information and the second prediction information. In this way, the updated first prediction information and the second prediction information can be used to predict whether to perform a jump operation on the target branch instruction, which can also improve the accuracy of the prediction result.

[0122] Fig.13 A schematic diagram of the structure of a branch predictor 130 provided in an embodiment of the present application, for example, see Fig.13 As shown, the branch predictor 130 may include:

[0123] A search unit 1301 is used to search for a target branch entry corresponding to a target branch instruction in a branch prediction table according to a partial address of the target branch instruction; wherein the target branch entry includes a first field, the first field is used to indicate M prediction information, and the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; M is an integer greater than or equal to 2.

[0124] The prediction unit 1302 is configured to predict whether to execute a jump operation on the target branch instruction based on the prediction information indicated by the first field if a target branch entry is found in the branch prediction table.

[0125] Optionally, the information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction.

[0126] Optionally, the target branch entry also includes a second field, and the second field is used to indicate the first address. If the prediction result indicates to perform a jump operation, the target address of the jump operation is the first address.

[0127] Optionally, the target branch entry also includes a third field, and the third field is used to indicate a branch attribute. The branch predictor 130 may include: a processing unit 1303, which is used to store at least one prediction information among the M prediction information in the idle bit if there is an idle bit in the third field.

[0128] Optionally, the target branch entry also includes a fourth field, the fourth field is used to indicate the first address determined based on the fourth field and the second field; the second field is used to indicate the second address, and the second address is an address in the first address that is different from the address of the target branch instruction.

[0129] Optionally, the fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

[0130] Optionally, the second field is set in the last column of the target branch entry.

[0131] Optionally, the M prediction information include m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule.

[0132] The processing unit 1303 is also used to obtain the actual jump result of the target branch instruction; and compare the prediction result corresponding to the first rule and the prediction result corresponding to the second rule with the actual jump result respectively; and then determine the prediction information used for prediction according to the comparison result, and the prediction information used for prediction is one of the first prediction information and the second prediction information. The prediction result corresponding to the first rule is predicted based on m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M.

[0133] Optionally, processing unit 1303 is specifically used to determine the first prediction information as the prediction information for prediction use if the prediction result corresponding to the first rule is the same as the actual jump result; or, if the prediction result corresponding to the second rule is the same as the actual jump result, determine the second prediction information as the prediction information for prediction use.

[0134] Optionally, the first prediction information and the second prediction information are updated according to the actual jump result.

[0135] Optionally, the first rule is a globally enhanced GL algorithm, and the second rule is a two-bit branch prediction local2b algorithm; or, the first rule is a local2b algorithm, and the second rule is a GL algorithm.

[0136] The branch predictor 130 provided in the embodiment of the present application can be used to perform the above Figure 2-Figure 12 The implementation principle and technical effect of the technical solution in the branch instruction processing method embodiment shown are similar to the implementation principle and technical effect in the branch instruction processing method embodiment, and will not be repeated here.

[0137] Fig.14 A schematic diagram of another branch predictor 140 provided in an embodiment of the present application, for example, see Fig.14 As shown, the branch predictor 140 may include a prediction logic circuit 1401 and a memory 1402;

[0138] The memory 1402 is used to store a branch prediction table, wherein the branch prediction table includes a plurality of branch entries.

[0139] The prediction logic circuit 1401 is used to search for a target branch entry corresponding to a target branch instruction in multiple branch entries according to a partial address of the target branch instruction; wherein the target branch entry includes a first field, and the first field is used to indicate M prediction information, and the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; if the target branch entry is found in the branch prediction table, it is predicted whether to perform a jump operation on the target branch instruction according to the prediction information indicated by the first field; wherein M is an integer greater than or equal to 2.

[0140] Optionally, the information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction.

[0141] Optionally, the target branch entry also includes a second field, and the second field is used to indicate the first address. If the prediction result indicates to perform a jump operation, the target address of the jump operation is the first address.

[0142] Optionally, the target branch entry further includes a third field, where the third field is used to indicate a branch attribute, and the branch predictor 140 further includes an update logic circuit 1403 .

[0143] The updating logic circuit 1403 is configured to store at least one prediction information among the M prediction information in the idle bit if there is an idle bit in the third field.

[0144] Optionally, the target branch entry also includes a fourth field, the fourth field is used to indicate the first address determined based on the fourth field and the second field; the second field is used to indicate the second address, and the second address is an address in the first address that is different from the address of the target branch instruction.

[0145] Optionally, the fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

[0146] Optionally, the second field is set in the last column of the target branch entry.

[0147] Optionally, the M prediction information include m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule.

[0148] The update logic circuit 1403 is also used to obtain the actual jump result of the target branch instruction.

[0149] The prediction logic circuit 1401 is also used to compare the prediction results corresponding to the first rule and the prediction results corresponding to the second rule with the actual jump results, and determine the prediction information used for prediction based on the comparison results, and the prediction information used for prediction is one of the first prediction information and the second prediction information; wherein the prediction result corresponding to the first rule is predicted based on m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M.

[0150] Optionally, the prediction logic circuit 1401 is specifically used to determine the first prediction information as the prediction information for prediction use if the prediction result corresponding to the first rule is the same as the actual jump result; or, if the prediction result corresponding to the second rule is the same as the actual jump result, determine the second prediction information as the prediction information for prediction use.

[0151] Optionally, the update logic circuit 1403 is further used to update the first prediction information and the second prediction information according to the actual jump result.

[0152] Optionally, the first rule is a globally enhanced GL algorithm, and the second rule is a two-bit branch prediction local2b algorithm; or, the first rule is a local2b algorithm, and the second rule is a GL algorithm.

[0153] The branch predictor 140 provided in the embodiment of the present application can be used to perform the above Figure 2-Figure 12 The implementation principle and technical effect of the technical solution in the branch instruction processing method embodiment shown are similar to the implementation principle and technical effect in the branch instruction processing method embodiment, and will not be repeated here.

[0154] The present application embodiment also provides a processor 150, for example, see Fig.15 As shown, Fig.15 A schematic diagram of the structure of a processor 150 provided in an embodiment of the present application, the processor 150 may include: Figure 2-Figure 12 The branch predictor 1501 and processing circuit 1502 described in .

[0155] Among them, the branch predictor 1501 is used to predict whether to perform a jump operation on the target branch instruction. If the prediction result indicates to perform a jump operation, the processing circuit 1502 uses the first address in the target branch entry in the branch predictor 1501 as the target address of the jump operation and performs a jump operation on the target branch instruction.

[0156] The processor 150 provided in the embodiment of the present application can be used to execute the above Figure 2-Figure 12 The implementation principle and technical effect of the technical solution in the branch instruction processing method embodiment shown are similar to the implementation principle and technical effect in the branch instruction processing method embodiment, and will not be repeated here.

[0157] An embodiment of the present application also provides a readable storage medium, on which a computer program is stored; when the computer program is executed, it is used to execute a method for processing branch instructions as described in any possible implementation method of the first aspect above, and its implementation principle and technical effect are similar to those in the method embodiment, and will not be repeated here.

[0158] An embodiment of the present application also provides a chip having a computer program stored thereon. When the computer program is executed by a processor, the chip is used to execute a branch instruction processing method as described in any possible implementation method of the first aspect above. The implementation principle and technical effect are similar to those in the method embodiment and will not be repeated here.

[0159] It should be noted that the division of modules (or units) in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. The functional modules in the embodiments of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.

[0160] If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.

[0161] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed on a computer, the process or function described in the embodiment of the present application is executed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer program or instruction can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it can also be an optical medium, such as a digital versatile disc (DVD); it can also be a semiconductor medium, such as a solid state disk (SSD).

[0162] In the various embodiments of the present application, unless otherwise specified or provided in a logical conflict, the terms and / or descriptions between the different embodiments are consistent and may be referenced to each other, and the technical features in the different embodiments may be combined to form new embodiments according to their inherent logical relationships.

[0163] It is understood that the various numbers involved in the embodiments of the present application are only for the convenience of description and are not used to limit the scope of the embodiments of the present application. The size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic.

Claims

1. A method for processing a branch instruction, characterized in that: include: According to a partial address of a target branch instruction, searching a target branch entry corresponding to the target branch instruction in a branch prediction table; wherein the target branch entry includes a first field, the first field is used to indicate M prediction information, and the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; M is an integer greater than or equal to 2; If the target branch entry is found in the branch prediction table, predict whether to execute a jump operation on the target branch instruction according to the prediction information indicated by the first field; The information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction.

2. The method according to claim 1, characterized in that The target branch entry also includes a second field, where the second field is used to indicate a first address. If the prediction result indicates that a jump operation is to be performed, the target address of the jump operation is the first address.

3. The method according to claim 1 or 2, characterized in that: The target branch entry further includes a third field, and the third field is used to indicate a branch attribute; the method further includes: If there is an idle bit in the third field, at least one prediction information among the M prediction information is stored in the idle bit.

4. The method according to claim 2, characterized in that: The target branch entry also includes a fourth field, which is used to indicate a first address determined based on the fourth field and the second field; the second field is used to indicate a second address, which is an address in the first address that is different from the address of the target branch instruction.

5. The method according to claim 4, characterized in that The fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

6. The method according to claim 4 or 5, characterized in that: The second field is set in the last column of the target branch entry.

7. The method according to any one of claims 1-2, 4-5, characterized in that: The M prediction information includes m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule, and the method further includes: Obtaining an actual jump result of the target branch instruction; The prediction result corresponding to the first rule and the prediction result corresponding to the second rule are respectively compared with the actual jump result; the prediction result corresponding to the first rule is predicted based on the m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on the m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M; According to the comparison result, prediction information for prediction use is determined, where the prediction information for prediction use is one of the first prediction information and the second prediction information.

8. The method according to claim 7, characterized in that Determining prediction information for prediction use according to the comparison result includes: If the prediction result corresponding to the first rule is the same as the actual jump result, the first prediction information is determined as the prediction information used for the prediction; or, If the prediction result corresponding to the second rule is the same as the actual jump result, the second prediction information is determined as the prediction information used for the prediction.

9. The method according to claim 7, characterized in that: The first prediction information and the second prediction information are updated according to the actual jump result.

10. The method according to claim 7, characterized in that The first rule is a globally enhanced GL algorithm, and the second rule is a two-bit branch prediction local2b algorithm; or, the first rule is a local2b algorithm, and the second rule is a GL algorithm.

11. A branch predictor, characterized in that: including predictive logic circuits and memory; The memory is used to store a branch prediction table, wherein the branch prediction table includes a plurality of branch entries; The prediction logic circuit is used to search for a target branch entry corresponding to the target branch instruction in the multiple branch entries according to a partial address of the target branch instruction; wherein the target branch entry includes a first field, the first field is used to indicate M prediction information, and the M prediction information is predicted based on historical jump information of the target branch instruction and information affecting the prediction result of the target branch instruction; if the target branch entry is found in the branch prediction table, then according to the prediction information indicated by the first field, predict whether to perform a jump operation on the target branch instruction; wherein M is an integer greater than or equal to 2; The information affecting the prediction result of the target branch instruction includes historical jump information of other branch instructions that affect the jump of the target branch instruction.

12. The branch predictor according to claim 11, characterized in that The target branch entry also includes a second field, where the second field is used to indicate a first address. If the prediction result indicates that a jump operation is to be performed, the target address of the jump operation is the first address.

13. The branch predictor according to claim 11 or 12, characterized in that: The target branch entry further includes a third field, the third field is used to indicate a branch attribute, and the branch predictor further includes an update logic circuit; The update logic circuit is used to store at least one prediction information of the M prediction information in the idle bit if there is an idle bit in the third field.

14. The branch predictor according to claim 12, characterized in that: The target branch entry also includes a fourth field, which is used to indicate a first address determined based on the fourth field and the second field; the second field is used to indicate a second address, which is an address in the first address that is different from the address of the target branch instruction.

15. The branch predictor according to claim 14, characterized in that: The fourth field is the number of bits of the second address; or, the fourth field is the number of bits of the address of the target branch instruction that is the same as the first address; or, the fourth field is the sum of the number of bits of the address of the target branch instruction and the number of bits of the second address.

16. The branch predictor according to claim 14 or 15, characterized in that: The second field is set in the last column of the target branch entry.

17. The branch predictor according to claim 13, characterized in that: The M prediction information includes m1 first prediction information corresponding to the first rule and m2 second prediction information corresponding to the second rule; The update logic circuit is also used to obtain the actual jump result of the target branch instruction; The prediction logic circuit is also used to compare the prediction results corresponding to the first rule and the prediction results corresponding to the second rule with the actual jump results, respectively, and determine the prediction information used for prediction based on the comparison results, and the prediction information used for prediction is one of the first prediction information and the second prediction information; wherein the prediction result corresponding to the first rule is predicted based on the m1 first prediction information, and the prediction result corresponding to the second rule is predicted based on the m2 second prediction information; m1 and m2 are both integers greater than or equal to 1, and the sum of m1 and m2 is less than or equal to M.

18. The branch predictor according to claim 17, characterized in that: The prediction logic circuit is specifically configured to determine the first prediction information as the prediction information used for the prediction if the prediction result corresponding to the first rule is the same as the actual jump result; Alternatively, if the prediction result corresponding to the second rule is the same as the actual jump result, the second prediction information is determined as the prediction information used for the prediction.

19. The branch predictor according to claim 17, characterized in that: The update logic circuit is further used to update the first prediction information and the second prediction information according to the actual jump result.

20. The branch predictor according to claim 17, characterized in that The first rule is a globally enhanced GL algorithm, and the second rule is a two-bit branch prediction local2b algorithm; or, the first rule is a local2b algorithm, and the second rule is a GL algorithm.

21. A processor, characterized in that: include: Processing circuit and a branch predictor as claimed in any one of claims 11 to 20; The branch predictor is used to predict whether to execute a jump operation on the target branch instruction. If the prediction result indicates to execute a jump operation, the processing circuit uses the first address in the target branch entry in the branch predictor as the target address of the jump operation and executes the jump operation on the target branch instruction.

22. A readable storage medium, characterized in that: The readable storage medium stores a computer program; when the computer program is executed, it is used to execute the branch instruction processing method according to any one of claims 1 to 10.