Branch jump prediction method, device, computer equipment and storage medium

By calculating the PC value hash value of the target condition jump instruction and querying the preset loop body prediction module, the problem of the loop body's last jump prediction error in the prior art is solved, and accurate prediction of loop body with a number of loop times greater than the historical number of branch jumps is achieved.

CN119415154BActive Publication Date: 2025-04-11芯来智融半导体科技(上海)股份有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510024892.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2025-04-11
Estimated Expiration
2045-01-07

AI Technical Summary

Technical Problem

The prior art often makes errors when predicting the last jump of the loop body, especially when the number of loops is greater than the number of historical bits of the branch jump, PHT cannot correctly predict the last jump of the loop body.

Method used

A branch jump prediction method is proposed. By receiving the target condition jump instruction, the hash value of its PC value is calculated, and inputting it into the preset loop body prediction module for querying. If hit, the jump result is corrected; if missed, the original jump result is maintained.

Benefits of technology

It effectively solves the problem of error prediction of the last jump of the loop body, and improves the accuracy of prediction of the loop body with a number of loops greater than the historical number of branch jumps.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415154B_ABST
    Figure CN119415154B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a branch jump prediction method, device, computer equipment and storage medium, the method comprising: receiving a target conditional jump instruction, predicting whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtaining a jump result, and calculating a hash value of the PC value; inputting the target conditional jump instruction into a preset loop body prediction module, querying whether the hash value of the PC value of the target conditional jump instruction is hit in a table entry of the preset loop body prediction module; if the loop body prediction module hits, correcting the jump result to obtain a corrected jump result; if the loop body prediction module does not hit, maintaining the jump result, which can solve the problem in the prior art that a large number of predictions of no jumps appear in the early stage of the loop but jumps in the final judgment, and a large number of predictions of jumps appear in the early stage of the loop but do not jump in the final judgment, and certain loop prediction errors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of branch prediction technology, and in particular, to a branch jump prediction method, apparatus, computer equipment and storage medium. Background Art

[0002] Branch prediction requires predicting the jump direction and jump address of the jump instruction. The prediction of the jump direction is usually divided into two types: static prediction and dynamic prediction. Complex processors usually use dynamic prediction to predict the jump direction, and saturation counter is the most common dynamic prediction technology.

[0003] In the related art, a "two-bit saturated counter" is usually used as a branch "direction" dynamic predictor. For each branch instruction, such as a conditional jump instruction, a two-bit saturated counter is used to mark the historical state. When a jump is encountered, the counter is incremented by 1, and when a non-jump is encountered, the counter is decremented by 1. When predicting, the prediction is made based on the value of the counter. There are four prediction mapping methods: strongly not taken, weakly not taken, weakly taken, and strongly taken. The prediction state machine of the two-bit saturated counter is as follows: Figure 1 As shown. When the current prediction state is "strongly no jump required" or "weakly no jump required", the direction of the instruction is predicted to be "no jump required (not taken)"; when the current prediction state is "weakly required jump required" or "strongly required jump required (strongly taken)", the direction of the instruction is predicted to be "required jump (taken)". Organize multiple "two-bit saturated counters" into PHT (pattern history table), "pattern" refers to the state of the saturated counter. PHT is similar to the SRAM (Static Random Access Memory) structure, which stores 2^k two-bit saturated counters for query use, and uses the branch jump history (Branchhistory) as the index of PHT. As shown Figure 2 As shown, assuming that n bits are used to record its history, 2 to the power of n entries can be indexed.

[0004] For the loop body, the above branching technology has the following defects: when the number of loops of the loop body is greater than the number of bits of the branch jump history, PHT cannot correctly predict the last jump out of the loop body.

[0005] 8000000: li a1,0

[0006] 8000002: li s1,20

[0007] 8000004: addi a1, a1, 1

[0008] 8000008: bne a1,s1,80000004

[0009] 800000a: lhu t0, 0(a1)

[0010] For the loop body code above, li is used to define the list, addi is the addition operation, bne is branch notequal, that is, unequal jump, 80000004 needs to be executed 20 times to meet the condition of exiting the loop body, lhu is Load HalfWord Unsigned, that is, the read / write memory instruction in the reduced instruction set, among which, the first 19 times 80000008 are jumps, and the 20th time is not a jump. For the PHT with only 10 historical bits, the history from the 10th to the 20th time is 10'b11_1111_1111, so the index is always the same table entry, and this table entry becomes a strong jump state after at most 3 times, so when the jump instruction 80000008 is executed for the 20th time, PHT must have wrongly predicted the jump. Therefore, for a loop body with a particularly large number of loops, or a loop body with a loop number greater than the number of branch jump history bits, the last jump out of the loop body must be wrong. Summary of the invention

[0011] Embodiments of the present application provide a branch jump prediction method, apparatus, computer device, and storage medium.

[0012] A first aspect of an embodiment of the present application provides a branch jump prediction method, comprising:

[0013] Receive the target conditional jump instruction, predict whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtain the jump result, and calculate the hash value of the PC value;

[0014] Input the target conditional jump instruction into a preset loop body prediction module, and query whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module;

[0015] When a hash value of a PC value of a target conditional jump instruction is hit in a table entry of a preset loop body prediction module, the jump result is corrected to obtain a corrected jump result;

[0016] When the hash value of the PC value of the target conditional jump instruction is not hit in the table entry of the preset loop body prediction module, the jump result is retained.

[0017] In an optional embodiment of the present application, the method further includes:

[0018] Receive the target conditional jump instruction, parse the execution type information of the instruction and send it to the execution module;

[0019] Actual jump information is calculated according to the execution type information, the jump result is compared with the actual jump information to see whether they are consistent, and parameters of at least one of the loop prediction module and the branch jump prediction module are adjusted according to the comparison result.

[0020] In an optional embodiment of the present application, adjusting parameters in the branch jump prediction module according to the comparison result includes:

[0021] When the jump result is inconsistent with the actual jump information, the prediction table corresponding to the PC value of the current instruction is queried in the preset mode history table of the branch jump prediction module, and the prediction state of the prediction table is adjusted to predict whether the next instruction in the prediction table requires a conditional jump, wherein the preset mode history table is organized by multiple two-bit saturated counters, and one two-bit saturated counter corresponds to one prediction table.

[0022] In an optional embodiment of the present application, predicting whether the instruction will jump according to the PC value of the target conditional jump instruction to obtain the jump result includes:

[0023] Calculate the hash value of the global historical jump information and PC value of the target conditional jump instruction;

[0024] Use the global history jump information and the hash value of the PC value to index the table entry in the preset mode history table;

[0025] The prediction result recorded in the index table entry is used as the jump result of whether the instruction jumps.

[0026] In an optional embodiment of the present application, the loop body prediction module includes multiple prediction tables, each prediction table entry includes a hash value, a confidence value, a current loop number, and a total loop number corresponding to the instruction, and the parameters in the loop body prediction module are adjusted according to the comparison result, including:

[0027] When the jump result is inconsistent with the actual jump information for the first time and the table entry of the loop jump predictor is empty, the hash value corresponding to the current instruction is stored, and when the current instruction is received again, the current loop number is started to be increased until the jump result of the current instruction is inconsistent with the actual jump information for the second time, and the current loop number is updated to the total loop number; when the jump result of the current instruction is consistent with the actual jump information for the first time, the confidence value is started to be added until the confidence value is greater than or equal to the preset value, and the step of inputting the target conditional jump instruction into the preset loop body prediction module and querying whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module.

[0028] In an optional embodiment of the present application, the step of inputting the target conditional jump instruction into a preset loop prediction module and querying whether a hash value of a PC value of the target conditional jump instruction is hit in a table entry of the preset loop prediction module includes:

[0029] The PC value of the target conditional jump instruction is divided into a high-order address and a low-order address, wherein the low-order address includes bits from the 1st bit to the nth bit in the PC value, and the high-order address includes bits from the nth bit to the maximum bit of the PC value, where n is a value between 1 and the maximum bit of the PC value;

[0030] The hash value of the high-order address is used as the first tag information;

[0031] Using the low-order address index to preset the table entry of the loop body prediction module;

[0032] Using the tag information in the indexed table entry as the second tag information, and comparing it with the first tag information;

[0033] When the second tag information is consistent with the first tag information, determining a hash value of a PC value of a target conditional jump instruction in a table entry of a preset loop body prediction module;

[0034] When the second tag information is inconsistent with the first tag information, a hash value of a PC value of a missed target conditional jump instruction in a table entry of a preset loop body prediction module is determined.

[0035] In an optional embodiment of the present application, each table entry of the preset loop body prediction module also includes an age value. When querying the table entry corresponding to the hash value corresponding to the current instruction, for the table entry that does not match the hash value corresponding to the current instruction, its age value is reduced. When its age value is 0, the first instruction that does not match all table entries is used as the instruction of the current table entry.

[0036] A second aspect of an embodiment of the present application provides a branch jump prediction device, comprising:

[0037] The branch jump prediction module is used to receive the target conditional jump instruction, predict whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtain the jump result, and calculate the hash value of the PC value;

[0038] A loop body prediction module is used to receive a target conditional jump instruction, query whether a hash value of a PC value of the target conditional jump instruction is hit in a table entry of a preset loop body prediction module; in the case where the hash value of the PC value of the target conditional jump instruction is hit in a table entry of the preset loop body prediction module, correct the jump result to obtain a corrected jump result; in the case where the hash value of the PC value of the target conditional jump instruction is not hit in a table entry of the preset loop body prediction module, maintain the jump result.

[0039] According to a third aspect of an embodiment of the present application, a computer device is provided, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any of the above methods when executing the computer program.

[0040] According to a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0042] Figure 1 is a schematic diagram of a prediction state machine of a two-bit saturation counter in the prior art;

[0043] Figure 2 A schematic diagram of a pattern history table indexed for branch history;

[0044] Figure 3 A flow chart of a branch jump prediction method provided by one embodiment of the present application;

[0045] Figure 4 A schematic diagram of the structure of a branch jump prediction device provided by one embodiment of the present application;

[0046] Figure 5 A schematic diagram of the computer device structure provided for one embodiment of the present application. DETAILED DESCRIPTION

[0047] In the process of implementing the present application, the inventors found that, for loop bodies with particularly large loop times, or loop bodies with loop times greater than the number of branch jump history bits, the last jump out of the loop body will definitely be wrong.

[0048] In response to the above problems, a branch jump prediction method is provided in an embodiment of the present application, which receives a target conditional jump instruction, predicts whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtains a jump result, and calculates a hash value of the PC value; inputs the target conditional jump instruction into a preset loop body prediction module, queries whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module; in the case where the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module, corrects the jump result to obtain a corrected jump result; in the case where the hash value of the PC value of the target conditional jump instruction is not hit in the table entry of the preset loop body prediction module, maintains the jump result, which can solve the problem in the prior art that a large number of loops are predicted not to jump in the early stage of the loop, but jumps in the final judgment, or a large number of predicted jumps in the early stage of the loop, but no jumps in the final judgment, and certain prediction errors are caused, and at the same time, regardless of the number of loops, a good prediction result can be achieved.

[0049] The solutions in the embodiments of the present application can be implemented using various computer languages, for example, the object-oriented programming language Java and the interpreted scripting language JavaScript.

[0050] In order to make the technical solutions and advantages in the embodiments of the present application more clearly understood, the exemplary embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0051] See also Figure 3 , a branch jump prediction method provided by an embodiment of the present application includes:

[0052] S1, receiving the target conditional jump instruction, predicting whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtaining the jump result, and calculating the hash value of the PC value;

[0053] S2, inputting the target conditional jump instruction into a preset loop body prediction module, and querying whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module;

[0054] S3, when the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module, correct the jump result to obtain a corrected jump result;

[0055] S4, when the hash value of the PC value of the target conditional jump instruction is not hit in the table entry of the preset loop body prediction module, the jump result is maintained.

[0056] In an optional embodiment of the present application, the method further includes:

[0057] Receive the target conditional jump instruction, parse the execution type information of the instruction and send it to the execution module;

[0058] Actual jump information is calculated according to the execution type information, the jump result is compared with the actual jump information to see whether they are consistent, and parameters of at least one of the loop prediction module and the branch jump prediction module are adjusted according to the comparison result.

[0059] In an optional embodiment of the present application, adjusting parameters in the branch jump prediction module according to the comparison result includes:

[0060] When the jump result is inconsistent with the actual jump information, the prediction table corresponding to the PC value of the current instruction is queried in the preset mode history table of the branch jump prediction module, and the prediction state of the prediction table is adjusted to predict whether the next instruction in the prediction table requires a conditional jump, wherein the preset mode history table is organized by multiple two-bit saturated counters, and one two-bit saturated counter corresponds to one prediction table.

[0061] In an optional embodiment of the present application, predicting whether the instruction will jump according to the PC value of the target conditional jump instruction to obtain the jump result includes:

[0062] Calculate the hash value of the global historical jump information and PC value of the target conditional jump instruction;

[0063] Use the global history jump information and the hash value of the PC value to index the table entry in the preset mode history table;

[0064] The prediction result recorded in the index table entry is used as the jump result of whether the instruction jumps.

[0065] In an optional embodiment of the present application, the prediction result recorded in the index table entry is used as the jump result of whether the instruction jumps, including:

[0066] Determine whether the prediction result is a state of strong no jump required, weak no jump required, weak jump required, and strong jump required;

[0067] In the jump history of the instruction, check whether the current instruction jumps in this state.

[0068] In an optional embodiment of the present application, searching a prediction table corresponding to the PC value of the current instruction in a preset mode history table of the branch jump prediction module includes:

[0069] Calculate the hash value of the global history jump information and PC value of the current instruction;

[0070] Use the global history jump information and the hash value of the PC value to index the table entry in the preset mode history table;

[0071] The prediction table corresponding to the retrieved table entry is used as the prediction table corresponding to the PC value of the current instruction.

[0072] In an optional embodiment of the present application, the loop body prediction module includes multiple prediction tables, each prediction table entry includes a hash value, a confidence value, a current loop number, and a total loop number corresponding to the instruction, and the parameters in the loop body prediction module are adjusted according to the comparison result, including:

[0073] When the jump result is inconsistent with the actual jump information for the first time and the table entry of the loop jump predictor is empty, the hash value corresponding to the current instruction is stored, and when the current instruction is received again, the current loop number is started to be increased until the jump result of the current instruction is inconsistent with the actual jump information for the second time, and the current loop number is updated to the total loop number; when the jump result of the current instruction is consistent with the actual jump information for the first time, the confidence value is started to be added until the confidence value is greater than or equal to the preset value, and the step of inputting the target conditional jump instruction into the preset loop body prediction module and querying whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module.

[0074] In an optional embodiment of the present application, the loop jump prediction module includes multiple prediction tables, as shown in Table 1 below, and the table items of each prediction table include the hash value (Tag value) corresponding to the instruction, the confidence value (Conf value), the current number of loops (S-cnt value) and the total number of loops (P-cnt value). The table items of each prediction table also include an age value (Age value). When querying the prediction table corresponding to the hash value corresponding to the current instruction, for the prediction table that does not match the hash value corresponding to the current instruction, its age value is reduced. When its age value is 0, the first instruction that does not match all prediction tables is used as the instruction of the current prediction table.

[0075] Table 1

[0076]

[0077] In Table 1, the Tag value is the hash value corresponding to the instruction. Every time an instruction is received, it is necessary to check whether the Tag value matches the current instruction. The hash value corresponding to the instruction is calculated by the PC value of the instruction through a preset hash algorithm. When the PC value of the instruction is 9 bits, the hash value corresponding to the instruction can also be 9 bits. The Tag value and the Age value constitute a single life cycle of the loop prediction module. If the Tag value matches the current instruction, the Conf value is judged. The Conf value indicates the confidence level of the prediction table. The Conf value increases by 1 for each successful completion of the loop entering the loop prediction module. Only when the Conf value reaches the maximum value can the loop prediction result be adopted. When the Conf value is two bits, the maximum value of the Conf value is 3. The Age value is used to record the age of the Tag value. When the tag value does not match the instruction, the age value is reduced by 1. When age is 0, the instruction in the prediction table can be replaced by a new instruction. The S-cnt value is used to mark the number of loops. It increases by 1 each time a loop is executed. When the P-cnt value is 0 and the loop ends, the S-cnt value can be updated to the P-cnt value. The P-cnt value is used to record the total number of loops. When the recorded P-cnt value is equal to the S-cnt value, the loop body prediction module completes a loop.

[0078] In an optional embodiment of the present application, the step of inputting the target conditional jump instruction into a preset loop prediction module and querying whether a hash value of a PC value of the target conditional jump instruction is hit in a table entry of the preset loop prediction module includes:

[0079] The PC value of the target conditional jump instruction is divided into a high-order address and a low-order address, wherein the low-order address includes bits from the 1st bit to the nth bit in the PC value, and the high-order address includes bits from the nth bit to the maximum bit of the PC value, where n is a value between 1 and the maximum bit of the PC value;

[0080] The hash value of the high-order address is used as the first tag information;

[0081] Using the low-order address index to preset the table entry of the loop body prediction module;

[0082] Using the tag information in the indexed table entry as the second tag information, and comparing it with the first tag information;

[0083] When the second tag information is consistent with the first tag information, determining a hash value of a PC value of a target conditional jump instruction in a table entry of a preset loop body prediction module;

[0084] When the second tag information is inconsistent with the first tag information, a hash value of a PC value of a missed target conditional jump instruction in a table entry of a preset loop body prediction module is determined.

[0085] In an optional embodiment of the present application, each table entry of the preset loop body prediction module also includes an age value. When querying the table entry corresponding to the hash value corresponding to the current instruction, for the table entry that does not match the hash value corresponding to the current instruction, its age value is reduced. When its age value is 0, the first instruction that does not match all table entries is used as the instruction of the current table entry.

[0086] In an optional embodiment of the present application, when the second tag information is consistent with the first tag information, the method further includes:

[0087] When the confidence value in the indexed table entry is greater than or equal to the preset value and the current loop number is equal to the total loop number, the hash value of the PC value of the target conditional jump instruction hit in the table entry of the preset loop body prediction module is determined.

[0088] It should be understood that, although the various steps in the flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0089] See also Figure 4 An embodiment of the present application provides a branch jump prediction device, comprising:

[0090] The branch jump prediction module 13 is used to receive a target conditional jump instruction, predict whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtain a jump result, and calculate a hash value of the PC value;

[0091] The loop body prediction module 14 is used to receive a target conditional jump instruction and query whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module; when the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module, the jump result is corrected to obtain a corrected jump result; when the hash value of the PC value of the target conditional jump instruction is not hit in the table entry of the preset loop body prediction module, the jump result is maintained.

[0092] exist Figure 4 In the embodiment, the branch jump prediction device further comprises:

[0093] The instruction fetch module 11 is used to fetch instructions and send the instructions to the branch jump prediction module and the loop body prediction module;

[0094] A decoding module 15, which is connected to the instruction fetching module and is used to receive instructions and send execution type information to the execution module;

[0095] The execution module 12 is used to calculate the actual jump information according to the execution type information, compare the jump result with the actual jump information to see whether they are consistent, and adjust the parameters of at least one of the loop prediction module and the branch jump prediction module according to the comparison result.

[0096] For the specific definition of the branch jump prediction device, please refer to the definition of the branch jump prediction method above, which will not be repeated here. Each module in the branch jump prediction device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the modules above.

[0097] In one embodiment, a computer device is provided, the internal structure diagram of which can be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a branch jump prediction method as described above is implemented. It includes: a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, any step in the branch jump prediction method as described above is implemented.

[0098] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, any step in the above branch jump prediction method can be implemented.

[0099] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0100] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0101] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0102] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0103] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0104] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A branch jump prediction method, characterized in that: include: Receive the target conditional jump instruction, predict whether the current instruction jumps according to the PC value of the target conditional jump instruction, obtain the jump result, and calculate the hash value of the PC value; Input the target conditional jump instruction into a preset loop body prediction module, and query whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module; When a hash value of a PC value of a target conditional jump instruction is hit in a table entry of a preset loop body prediction module, the jump result is corrected to obtain a corrected jump result; When the hash value of the PC value of the target conditional jump instruction is not hit in the table entry of the preset loop body prediction module, the jump result is retained; The method further comprises: Receive the target conditional jump instruction, parse the execution type information of the instruction and send it to the execution module; Calculating actual jump information according to the execution type information, comparing the jump result with the actual jump information to see whether they are consistent, and adjusting parameters of at least one of the loop prediction module and the branch jump prediction module according to the comparison result; The loop prediction module includes a plurality of prediction tables, each prediction table entry includes a hash value, a confidence value, a current loop number, and a total loop number corresponding to an instruction, and adjusting parameters in the loop prediction module according to the comparison result, including: When the jump result is inconsistent with the actual jump information for the first time and the table entry of the loop jump predictor is empty, the hash value corresponding to the current instruction is stored, and when the current instruction is received again, the current loop number is started to be increased until the jump result of the current instruction is inconsistent with the actual jump information for the second time, and the current loop number is updated to the total loop number; when the jump result of the current instruction is consistent with the actual jump information for the first time, the confidence value is started to be added until the confidence value is greater than or equal to the preset value, and the step of inputting the target conditional jump instruction into the preset loop body prediction module and querying whether the hash value of the PC value of the target conditional jump instruction is hit in the table entry of the preset loop body prediction module.

2. The branch jump prediction method according to claim 1, characterized in that: According to the comparison results, the parameters in the branch jump prediction module are adjusted, including: When the jump result is inconsistent with the actual jump information, the prediction table corresponding to the PC value of the current instruction is queried in the preset mode history table of the branch jump prediction module, and the prediction state of the prediction table is adjusted to predict whether the next instruction in the prediction table requires a conditional jump, wherein the preset mode history table is organized by multiple two-bit saturated counters, and one two-bit saturated counter corresponds to one prediction table.

3. The branch jump prediction method according to claim 2, characterized in that: The step of predicting whether the instruction will jump according to the PC value of the target conditional jump instruction to obtain the jump result includes: Calculate the hash value of the global historical jump information and PC value of the target conditional jump instruction; Use the global history jump information and the hash value of the PC value to index the table entry in the preset mode history table; The prediction result recorded in the index table entry is used as the jump result of whether the instruction jumps.

4. The branch jump prediction method according to claim 1, characterized in that: The step of inputting the target conditional jump instruction into a preset loop body prediction module and querying whether a hash value of a PC value of the target conditional jump instruction is hit in a table entry of the preset loop body prediction module comprises: The PC value of the target conditional jump instruction is divided into a high-order address and a low-order address, wherein the low-order address includes bits from the 1st bit to the nth bit in the PC value, and the high-order address includes bits from the nth bit to the maximum bit of the PC value, where n is a value between 1 and the maximum bit of the PC value; The hash value of the high-order address is used as the first tag information; Using the low-order address index to preset the table entry of the loop body prediction module; Using the tag information in the indexed table entry as the second tag information, and comparing it with the first tag information; When the second tag information is consistent with the first tag information, determining a hash value of a PC value of a target conditional jump instruction in a table entry of a preset loop body prediction module; When the second tag information is inconsistent with the first tag information, a hash value of a PC value of a missed target conditional jump instruction in a table entry of a preset loop body prediction module is determined.

5. The branch jump prediction method according to claim 4, characterized in that: Each table entry of the preset loop body prediction module also includes an age value. When querying the table entry corresponding to the hash value corresponding to the current instruction, for the table entry that does not match the hash value corresponding to the current instruction, its age value is reduced. When its age value is 0, the first instruction that does not match all table entries is used as the instruction of the current table entry.

6. A computer device comprising: The method comprises a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the steps of the method according to any one of claims 1 to 5 when executing the computer program.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Branch instruction auxiliary predictor for unstable control flow loop body

    CN112988234A