Branch prediction method, branch predictor, processor and electronic device

By introducing label prediction tables of different levels in the branch predictor and determining whether to apply for new table items with higher levels based on the stable value of the target table items, the problem of frequent applications for high tables in the existing technology is solved, and more efficient branch prediction and performance optimization is achieved.

CN119781833AActive Publication Date: 2025-04-08HYGON INFORMATION TECH CO LTD

Patent Information

Application Number
CN202411947376.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-04-08
Estimated Expiration
2044-12-27

AI Technical Summary

Technical Problem

When existing branch prediction technologies deal with difficult branch instructions, there are frequent high table applications, resulting in waste of space, increased power consumption and reduced prediction accuracy.

Method used

By introducing different levels of label prediction tables into the branch predictor, and determining whether to apply for new table items of higher levels based on the stable value of the target table items, dynamically adjusting the table item allocation probability to reduce meaningless high table applications.

Benefits of technology

It effectively reduces the frequency of high-table applications, reduces space waste and power consumption, and improves the accuracy and performance of branch prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781833A_ABST
    Figure CN119781833A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a branch prediction method, a branch predictor, a processor and an electronic device. The branch predictor comprises a plurality of label prediction tables of different levels, each table item of each label prediction table in the plurality of label prediction tables comprises a prediction value representing a prediction result of the corresponding table item, and the branch prediction method comprises the following steps: in response to a selected target table item, obtaining a target prediction result based on the prediction value of the target table item; and in response to the target prediction result error, judging whether to apply for a new table item with a higher level than the target table item. According to the branch prediction method, performance loss caused by the fact that a traditional TAGE branch predictor only uses a prediction result of a high table and extra power consumption caused by application of the high table can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to a branch prediction method, a branch predictor, a processor, and an electronic device. Background Art

[0002] Modern processor cores achieve high performance by improving instruction level parallelism through pipeline technology. The processor core includes multiple pipeline stages, such as branch prediction, instruction fetch, instruction decoding, instruction dispatch and rename, instruction execution, and instruction retirement. In order to support high operating frequencies, each pipeline stage may contain multiple pipeline stages. Each pipeline stage performs limited operations, so that each clock can be minimized, and the performance of the processor core can be improved by increasing the operating frequency of the processor. Each pipeline stage can also further improve processor performance by accommodating more instructions. Summary of the invention

[0003] At least one embodiment of the present disclosure provides a branch prediction method based on a branch predictor, wherein the branch predictor includes a plurality of label prediction tables of different levels, each table entry in each label prediction table of the plurality of label prediction tables includes a prediction value representing a prediction result of a corresponding table entry, and the method includes: in response to selecting a target table entry, obtaining a target prediction result based on the prediction value of the target table entry; in response to the target prediction result being wrong, determining whether to apply for a new table entry of a higher level than the target table entry.

[0004] For example, in the method provided by at least one embodiment of the present disclosure, each of the table items also includes a stable value indicating that the corresponding table item is in a stable state or an unstable state, the stable value is a first value indicating that it is in the unstable state, and the stable value is a second value indicating that it is in the stable state, and the selected target table item includes: in response to hitting multiple table items in the multiple label prediction tables, selecting the target table item from the multiple table items based on the stable value of each table item in the multiple table items.

[0005] For example, in the method provided by at least one embodiment of the present disclosure, the selecting the target entry includes: in response to hitting a single entry in the multiple tag prediction tables, taking the hit single entry as the target entry.

[0006] For example, in the method provided by at least one embodiment of the present disclosure, the determination of whether to apply for a new entry of a higher level than the target entry includes: in response to the stable value of the target entry being the second value, not applying for a new entry of a higher level than the target entry.

[0007] For example, in the method provided by at least one embodiment of the present disclosure, in response to hitting multiple table items in the multiple label prediction tables, selecting the target table item from the multiple table items based on the stable value of each table item in the multiple table items includes: in response to the existence of an entry in the multiple table items whose stable value is the second value, selecting the table item with the stable value of the second value as the target table item.

[0008] For example, in the method provided by at least one embodiment of the present disclosure, in response to hitting multiple table entries in the multiple label prediction tables, selecting the target table entry from the multiple table entries based on the stable value of each table entry in the multiple table entries includes: in response to the absence of a table entry with a stable value of the second value in the multiple table entries, selecting the table entry with the lowest prediction difficulty for the branch situation represented by the multiple table entries as the target table entry.

[0009] For example, in the method provided by at least one embodiment of the present disclosure, after selecting the table entry with the lowest prediction difficulty for the branch situation represented by the multiple table entries as the target table entry, the method also includes: in response to the target table entry not being located in the highest level label prediction table among the multiple label prediction tables, setting the stable value of the target table entry to the second value.

[0010] For example, in the method provided by at least one embodiment of the present disclosure, each of the table entries also includes information entropy information, and the information entropy information is used to obtain an information entropy value representing the degree of difficulty in predicting the branch situation represented by the corresponding table entry, and the selecting of the table entry with the lowest prediction difficulty among the multiple table entries as the target table entry includes: selecting the table entry with the lowest information entropy value obtained according to the information entropy information among the multiple table entries as the target table entry.

[0011] For example, in the method provided by at least one embodiment of the present disclosure, the information entropy information of each of the table entries includes an access count value and a jump count value, the access count value records the number of times the corresponding table entry is hit and selected as the target table entry, and the jump count value records the number of times the actual branch result is a jump when the corresponding table entry is hit and selected as the target table entry, wherein, after obtaining the target prediction result based on the prediction value of the target table entry, the method further includes: adding 1 to the access count value of the target table entry; in response to the target prediction result being wrong and the target prediction result being no jump, adding 1 to the jump count value of the target table entry; in response to the target prediction result being correct and the target prediction result being a jump, adding 1 to the jump count value of the target table entry.

[0012] For example, in the method provided by at least one embodiment of the present disclosure, the information entropy information of each of the table entries also includes the information entropy value, and the method also includes: updating the information entropy value of the target table entry based on the access count value and jump count value of the target table entry.

[0013] For example, in the method provided by at least one embodiment of the present disclosure, the updating of the information entropy value of the target entry based on the access count value and the jump count value of the target entry includes:

[0014]

[0015] Among them, H is the information entropy value, taken is the jump count value, access is the access count value, n is the base, and the value of n is a positive integer.

[0016] For example, in the method provided by at least one embodiment of the present disclosure, each of the table entries also includes an accuracy value, which indicates the correctness of the prediction result when the corresponding table entry is hit and selected as the target table entry, and the selecting of the table entry with the lowest prediction difficulty for the branch situation represented by the multiple table entries as the target table entry includes: selecting the table entry with the highest accuracy value among the multiple table entries as the target table entry.

[0017] For example, in the method provided by at least one embodiment of the present disclosure, each of the table entries also includes a misprediction count value, and the misprediction count value indicates the number of errors in the prediction result when the corresponding table entry is hit and selected as the target table entry. The selecting of the table entry with the lowest prediction difficulty for the branch situation represented by the multiple table entries as the target table entry includes: selecting the table entry with the lowest misprediction count value among the multiple table entries as the target table entry.

[0018] For example, the method provided by at least one embodiment of the present disclosure further includes: in response to reaching a preset time interval or continuous occurrence of target prediction result errors, updating the stable values ​​of all table entries in the multiple label prediction tables to the first value.

[0019] For example, the method provided by at least one embodiment of the present disclosure also includes: when replacing an entry in any of the multiple label prediction tables, in response to the existence of an entry whose stable value is the first value, applying a preset replacement algorithm to the entry whose stable value is the first value, or in response to the absence of an entry whose stable value is the first value, applying the preset replacement algorithm to all entries.

[0020] For example, in the method provided by at least one embodiment of the present disclosure, the determination of whether to apply for a new table entry of a higher level than the target table entry includes: generating a random number within a preset interval; comparing the random number with a preset threshold, and in response to the random number being less than or equal to the preset threshold, not applying for a new table entry of a higher level than the target table entry.

[0021] For example, in the method provided by at least one embodiment of the present disclosure, the judgment of whether to apply for a new table entry with a higher level than the target table entry includes: in response to applying for the corresponding new table entry in the previous judgment, not applying for a new table entry with a higher level than the target table entry in this judgment.

[0022] For example, the method provided by at least one embodiment of the present disclosure further includes: judging whether a table entry is hit based on the address of the branch instruction to be predicted and the global branch history.

[0023] For example, in the method provided by at least one embodiment of the present disclosure, each of the table entries also includes a label value, and the judging whether the table entry is hit based on the address of the branch instruction to be predicted and the global branch history includes: for each label prediction table in the multiple label prediction tables, performing a first hash operation and a second hash operation based on the address of the branch instruction to be predicted and the global branch history to obtain a first hash result and a second hash result, wherein the first hash operation is different from the second hash operation; reading the table entry in the label prediction table according to the first hash result, and judging whether the table entry is hit based on the label value of the table entry and the second hash result.

[0024] At least one embodiment of the present disclosure provides a branch predictor, comprising: a plurality of label prediction tables of different levels, wherein each table entry of each label prediction table of the plurality of label prediction tables comprises a prediction value representing a prediction result of a corresponding table entry; a prediction module, configured to obtain a target prediction result based on the prediction value of the target table entry in response to selecting a target table entry; and a judgment module, configured to judge whether to apply for a new table entry of a higher level than the target table entry in response to the target prediction result being wrong.

[0025] At least one embodiment of the present disclosure provides a processor, which includes a branch predictor provided according to at least one embodiment of the present disclosure.

[0026] At least one embodiment of the present disclosure provides an electronic device, including a processor provided according to at least one embodiment of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure.

[0028] Figure 1A is a schematic diagram of a processor core microarchitecture;

[0029] Figure 1B A schematic diagram of a pipeline of a processor core;

[0030] Figure 1C is a schematic diagram of a branch prediction method;

[0031] Figure 1D It is a state transition diagram of a branch prediction method based on a 2-bit saturation counter;

[0032] Figure 2 is a schematic diagram of a TAGE branch predictor;

[0033] Figure 3 A flow chart of a branch prediction method based on a branch predictor provided for at least one embodiment of the present disclosure;

[0034] Figure 4A A flow chart of a branch prediction method based on a branch predictor provided for at least one embodiment of the present disclosure;

[0035] Figure 4B A schematic diagram of a branch predictor provided for at least one embodiment of the present disclosure;

[0036] Figure 5 A schematic block diagram of a branch predictor provided for at least one embodiment of the present disclosure.

[0037] Figure 6 A schematic block diagram of a processor provided for at least one embodiment of the present disclosure; and

[0038] Figure 7 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0040] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0041] The present disclosure is described below through several specific embodiments. In order to keep the following description of the embodiments of the present disclosure clear and concise, detailed descriptions of known functions and known components (elements) may be omitted. When any component (component) of the embodiments of the present disclosure appears in more than one drawing, the component (component) is represented by the same or similar reference numeral in each drawing.

[0042] Flowcharts are used in this disclosure to illustrate the operations performed by the system according to the embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed precisely in order. On the contrary, various steps may be processed in reverse order or simultaneously as required. At the same time, other operations may also be added to these processes, or one or more operations may be removed from these processes.

[0043] Figure 1A A schematic diagram of a processor core microarchitecture.

[0044] For example, Figure 1A As shown, the processor core microarchitecture includes multiple parts such as an instruction fetch unit, a decoding unit, an allocation unit, a fixed-point execution unit, a floating-point execution unit and a memory access unit.

[0045] The instruction fetch unit takes the next instruction to be executed from the L1 instruction cache and passes it to the decode unit.

[0046] The decoding unit decodes the instructions fetched by the instruction fetch unit, converts them into microinstructions, and passes the microinstructions to the dispatch unit.

[0047] The allocation unit allocates microinstructions to different execution units according to their types. For example, the allocation unit allocates fixed-point / memory access microinstructions to fixed-point execution units and allocates floating-point / memory access microinstructions to floating-point execution units.

[0048] The fixed-point execution unit includes a fixed-point (register) renaming unit, an arithmetic logic unit (ALU), an address generation unit (AGU), an ALU scheduling queue, an AGU scheduling queue, a fixed-point physical register stack, etc. The floating-point execution unit includes a floating-point (register) renaming unit, a floating-point unit (FPU), an FPU scheduling queue, a floating-point physical register stack, etc.

[0049] The fixed-point renaming unit and floating-point renaming unit rename the source and destination registers before writing microinstructions into the dispatch queue. The ALU / AGU / FPU dispatch queue queues and schedules all received microinstructions out of order, and selects executable microinstructions for emission. The emitted microinstructions read the source from the physical register stack, and then the corresponding execution unit (ALU, AGU or FPU) executes the corresponding operation, and the execution results of each execution unit are passed to the memory access unit.

[0050] The memory access unit can receive microinstructions sent by the allocation unit, queue and schedule them for execution. The memory access unit can read data from the L1 Data Cache or write data to the L1 Data Cache.

[0051] Figure 1B It is a schematic diagram of a pipeline of a processor core, and the dotted line with an arrow in the figure represents a redirected instruction flow.

[0052] like Figure 1BAs shown, the processor core (such as the CPU core) of a single-core processor or a multi-core processor improves the parallelism between instructions through pipeline technology. The processor core includes multiple pipeline stages. For example, after the program counters from various sources are fed into the pipeline and the next program counter (PC) is selected through a multiplexer (Mux), the instruction corresponding to the program counter must go through branch prediction, instruction extraction, instruction decoding, instruction distribution and renaming, instruction execution, instruction termination, etc. Waiting queues are set between each pipeline stage as needed, and these queues are usually first-in-first-out (FIFO) queues. For example, after the branch prediction unit, a branch prediction (BP) FIFO queue is set to store branch prediction results; after the instruction extraction unit, an instruction cache (IC) FIFO is set to cache the acquired instructions; after the instruction decoding unit, a decoding (DE) FIFO is set to cache the decoded instructions; after the instruction distribution and renaming unit, a termination (RT) FIFO is set to cache the instructions waiting for confirmation after execution. At the same time, the pipeline of the processor core also includes an instruction queue to cache instructions waiting for the instruction execution unit to execute instructions after instruction distribution and renaming.

[0053] In order to support high operating frequencies, each pipeline stage may contain multiple pipeline stages (operation cycles), and each pipeline stage performs limited operations to further improve the performance of the processor core. Although each pipeline stage performs limited operations, each clock can be kept to a minimum, thereby improving the performance of the CPU core by increasing the operating frequency of the CPU. Each pipeline stage can also further improve the performance of the processor core by accommodating more instructions (i.e., superscalar technology). Superscalar refers to a method of executing multiple instructions in parallel within one cycle. A processor with increased instruction-level parallelism that can process multiple instructions within one cycle is called a superscalar processor. Superscalar processors add additional resources to conventional scalar processors, creating multiple pipelines, each of which executes instructions assigned to it, thereby achieving parallelism.

[0054] Branch prediction is an important component of a high-performance, multi-pipelined processor core. It predicts the execution path of conditional branch instructions in the program, allowing the processor to pre-fetch and execute subsequent instructions before the actual result of the branch is determined, thereby reducing the delay caused by waiting for the branch result. If a multi-pipelined CPU core does not have branch prediction, it must wait until each branch instruction is executed before knowing which instruction to jump to, which will cause multiple pipeline stages from the front end to the execution to idle, resulting in a significant performance loss. Figure 1BAs shown in the figure, branch prediction is at the front end of the processor core pipeline, and it continuously predicts the start and end addresses of the next instruction based on the result of the previous branch prediction. When a branch prediction error is found in the subsequent pipeline stage (such as after instruction decoding or after instruction execution), all instructions younger than the predicted branch instruction in the pipeline will be cleared, that is, the pipeline flush is executed, and then the branch predictor continues to predict the instruction stream from there and fills it into the pipeline.

[0055] Branch prediction includes the following three steps: identifying whether the instruction obtained in the current instruction fetch stage is a branch instruction; if it is a branch instruction, determining whether the branch instruction is a conditional branch instruction; if it is a conditional branch instruction, determining its jump destination address. During the execution of the program, the target address of the conditional branch instruction is usually fixed, that is, the target address is determined when the program is compiled.

[0056] Figure 1C A schematic diagram of a branch prediction method.

[0057] The Branch Target Buffer (BTB) is a structure used in modern processors to speed up the processing of branch instructions. The branch target buffer stores the most recently executed branch instructions and their corresponding target addresses. When the processor executes a stored branch instruction again, it can immediately obtain the target address corresponding to the branch instruction from the branch target buffer without waiting for the calculation result of the address. For example, Figure 1C As shown, the branch target buffer uses a part of the program counter (PC) value of the branch instruction (that is, the address of the branch instruction) as an index to find the internal table entry. Each table entry contains a label to verify whether the program counter value matches; if the label matches successfully, it means that the corresponding branch instruction record is hit and the corresponding target address can be output.

[0058] The branch prediction method based on a 2-bit saturated counter is a branch prediction technology widely used in modern processors. This prediction method adjusts the prediction direction by tracking the historical behavior of each branch instruction, thereby improving the prediction accuracy. For branch instructions, there are only two directions, a jump (taken) and a jump (nottaken). Each branch instruction is associated with a 2-bit saturated counter, which has four states, corresponding to four different prediction tendencies:

[0059] (1) Strongly taken: The counter is at the maximum value (saturated state), indicating that the branch instruction almost always jumps in the past multiple executions. It is predicted that the jump will occur this time, and the encoding is 11;

[0060] (2) Weakly taken: The counter is in an unsaturated state, indicating that the branch instruction will jump in most cases. It is predicted that a jump will occur this time, and the code is 10;

[0061] (3) Weakly not taken: The counter is in an unsaturated state, indicating that the branch instruction will not jump in most cases. It is predicted that no jump will occur this time, and the code is 01;

[0062] (4) Strongly not taken: The counter is at the minimum value (saturation state), indicating that the branch instruction almost always did not jump in the past multiple executions. The branch instruction will be predicted not to jump this time and is encoded as 00.

[0063] Figure 1D This is a state transition diagram of a branch prediction method based on a 2-bit saturation counter.

[0064] For example, Figure 1D As shown, whenever a branch instruction is executed, the corresponding counter is updated according to the actual jump situation. In the case where the current state is a strong jump, if the branch actually jumps, the counter value remains unchanged; if the branch does not actually jump, the counter value is reduced by 1, and the state transition is a weak jump. In the case where the current state is a weak jump, if the branch actually jumps, the counter value is increased by 1, and the state transition is a strong jump; if the branch does not actually jump, the counter value is reduced by 1, and the state transition is a weak no jump. In the case where the current state is a weak no jump, if the branch actually jumps, the counter value is increased by 1, and the state transition is a weak jump; if the branch does not actually jump, the counter value is reduced by 1, and the state transition is a strong no jump. In the case where the current state is a strong no jump, if the branch actually jumps, the counter value is increased by 1, and the state transition is a weak no jump; if the branch does not actually jump, the counter value is reduced by 1, and the state transition is a strong no jump. In the case where the current state is a strong no jump, if the branch actually jumps, the counter value is increased by 1, and the state transition is a weak no jump; if the branch does not actually jump, the counter value remains unchanged.

[0065] The above-mentioned branch prediction method based on a 2-bit saturated counter only relies on the branch prediction results of the last one or two times of the branch instruction itself. For more complex situations, its prediction accuracy may be insufficient. In order to deal with this situation, the results of other branch instructions can be considered when predicting branches, that is, a branch predictor based on global branch history is adopted. The Global History Register (GHR) is a register with a variable bit width, which is used to record the execution results of all branch instructions in the recent period of time, that is, the global branch history. Each time a new branch instruction is executed, the global history register will be updated to reflect the latest branch execution result. Through the information stored in the global history register, the execution results of other branch instructions can be used to assist in prediction. This prediction method is called branch prediction based on global history.

[0066] The Tagged Geometric history length (TAGE) branch predictor is a typical branch predictor based on global history. History refers to the running status of branch instructions (whether to jump) during runtime. The TAGE branch predictor is a global predictor composed of a basic prediction table and multiple label prediction tables. For different label prediction tables, branch history sequences of different lengths in the global branch history can be used for index calculation, so that the TAGE branch predictor can simultaneously perform branch predictions for a certain branch instruction based on branch history sequences of different lengths, and evaluate the accuracy of the branch instruction under each branch history sequence, and select the one with the highest historical accuracy as the judgment standard for the final branch prediction.

[0067] Figure 2 A schematic diagram of a TAGE branch predictor.

[0068] The TAGE branch predictor generally includes a base prediction table and multiple tag prediction tables of different levels. Figure 2 As shown, the TAGE branch predictor includes a basic prediction table T0 and label prediction tables T1~T4. The basic prediction table T0 uses the address of the branch instruction to be predicted (program counter value, hereinafter referred to as PC value) for direct indexing, and is used to provide a basic prediction result when none of the label prediction tables T1~T4 can hit. Label prediction tables of different levels use branch history sequences of different lengths in the global branch history (GlobalBranch History, GBH) to index table entries, allowing prediction tables of each level to capture historical patterns of different lengths. Label prediction tables of lower levels (such as T1) correspond to shorter branch history sequences, and label prediction tables of higher levels (such as T4) correspond to longer branch history sequences. Specifically, the label prediction table uses the PC value and the branch history sequence of corresponding length through a first hash operation (i.e. Figure 2 The branch predictor also includes a global branch history register (not shown in the figure) for recording the global branch history.

[0069] As the level of the label prediction table increases, the length of the corresponding branch history sequence increases in geometric series. The specific calculation formula can be as follows:

[0070]

[0071] Among them, L(i) represents the length of the branch history sequence corresponding to the i-th level label prediction table Ti, is the scaling factor of the geometric series, L(1) is the length of the branch history sequence corresponding to the label prediction table T1. The branch history sequence corresponding to the length L(i) can be expressed as h[0:L(i)].

[0072] The basic prediction table and each label prediction table include a certain number of table entries (table rows). Figure 2 As shown, each entry in the basic prediction table T0 includes a 2-bit saturation counter. Each entry in each tag prediction table includes a prediction value pred, a tag value tag, and a valid value u.

[0073] For example, Figure 2 As shown, the predicted value pred is implemented by a 2-bit saturation counter. For details, please refer to the above Figure 1D The description is not repeated here.

[0074] For example, Figure 2 As shown, the tag value tag is the PC value and the branch history sequence h[0:L(i)] of the corresponding length after the second hash operation (i.e. Figure 2 The hash value obtained by using the Hash2 in the index is used to confirm whether the indexed table entry corresponds to the branch instruction to be predicted (that is, whether the table entry is hit). The first hash operation used to generate the index and the second hash operation used to generate the tag value tag should be different.

[0075] For example, Figure 2 As shown, the effective value u is implemented by a 2-bit counter, indicating the reliability of the current entry. The larger the effective value u is, the more reliable the current entry is. When replacing entries in the label prediction table, entries with smaller effective value u are replaced first.

[0076] Use as Figure 2The process of branch prediction by the TAGE branch predictor shown is as follows: for the tag prediction table Ti, the PC value and h[0:L(i)] are subjected to the first hash operation to obtain the index. The table entry of the tag prediction table Ti is read according to the index, and the tag value tag is used to determine whether the table entry is hit. When there are multiple table entries in the tag prediction table that are hit, the prediction value pred of the table entry with the largest L(i) (i.e., the table entry in the tag prediction table at the highest level) is selected as the target prediction result. If the target prediction result is the same as the actual branch result (i.e., the prediction is correct), and the target prediction result is different from the prediction results of other hit table entries, then the effective value u of the table entry giving the target prediction result is incremented by 1; if the target prediction result is different from the actual branch result (i.e., the prediction is wrong), and the target prediction result is different from the prediction results of other hit table entries, then the effective value u of the table entry giving the target prediction result is decremented by 1, so that the table entries with low prediction accuracy are easier to be replaced. Furthermore, when the prediction is wrong, if the label prediction table that gives the target prediction result is not the highest-level label prediction table (T4), it is necessary to apply for the allocation of a new table entry on the label prediction table at a higher level. When no table entry hits in all label prediction tables, the target prediction result is given by the saturated counter in the table entry of the T0 table.

[0077] However, the inventors of the present disclosure have discovered that the above-mentioned TAGE branch predictor uses the effective value u for credibility measurement, which has the following problems: when a prediction error occurs, it is necessary to apply for the allocation of a new table entry in a higher-level label prediction table (referred to as "high-table application") to adjust the effective value u according to the subsequent prediction results, so as to determine whether the allocation is reasonable, which leads to space waste when allocating table entries. If the allocated table entries are unreasonable, not only will the valuable space of the high-level label prediction table be occupied, reducing the prediction accuracy of other branches, but the current branch will also use the wrong table entry, further reducing the prediction accuracy of the current branch. In addition, frequent applications for higher-level table entries also lead to additional power consumption and time waste. Moreover, the above-mentioned TAGE branch predictor will rely more on high-level label prediction tables based on longer branch history sequences.

[0078] The inventors noticed that the traditional TAGE branch predictor can be improved. This method uses the prediction information of the TAGE branch predictor to dynamically adjust the probability of allocating new entries when the TAGE branch predictor makes a wrong prediction, so as to reduce the probability of the cold counter problem and improve the prediction accuracy of the traditional TAGE branch predictor for difficult-to-predict branch instructions. The specific implementation method is as follows: Steps S1 to S4:

[0079] S1: Generate an allocation enable signal ALLOC of a new entry according to the correctness of the prediction result. If the prediction result is correct, the allocation enable signal ALLOC is assigned a value of 0; if the prediction result is incorrect, the allocation enable signal ALLOC is assigned a value of 1.

[0080] S2: Record the saturated counter value of the hit entry in the Provider (the tag prediction table with the longest history length and the tag value tag hit) as ctrP. If |2×ctrP+1|≤1 and the prediction result of the Provider is correct, update the allocation enable signal ALLOC to 0. Otherwise, do nothing and jump to S3.

[0081] S3: If the prediction result of the TAGE branch predictor is wrong, a random number rand is generated with a value range of 0 to (MINAP-1), where MINAP is a constant that increases with the total number of tag prediction tables; the TAGE branch predictor determines whether the random number rand is not less than the allocation throttling function value. If not, the allocation enable signal ALLOC is updated to 0; if yes, no operation is performed. Among them, the allocation throttling function is:

[0082]

[0083] Among them, if the prediction result of Alternator (the tag value tag hits and has the tag prediction table with the second longest history length) is correct, INDCAT is 1; if it is incorrect, INDCAT is 0; , Predict the number of entries in the table for each label.

[0084] S4: The TAGE branch predictor determines whether a new table entry needs to be allocated for the current mispredicted branch instruction according to the state of the allocation enable signal ALLOC.

[0085] However, the inventors of the present disclosure have found that the above solution still has the following shortcomings:

[0086] 1. This solution relies on a random number generator, which has a large overhead and non-randomness in hardware implementation, and cannot guarantee the accurate execution of functions;

[0087] 2. The allocation throttling function used by this scheme to suppress TAGE table entry applications needs to traverse all table entries, which greatly increases the time and power consumption.

[0088] At least one embodiment of the present disclosure provides a branch prediction method based on a branch predictor, wherein the branch predictor includes a plurality of label prediction tables of different levels, each table entry in each label prediction table of the plurality of label prediction tables includes a prediction value representing a prediction result of a corresponding table entry, and the branch prediction method includes: in response to selecting a target table entry, obtaining a target prediction result based on the prediction value of the target table entry; in response to an error in the target prediction result, determining whether to apply for a new table entry of a higher level than the target table entry.

[0089] At least one embodiment of the present disclosure provides a branch prediction method based on a branch predictor. When a prediction error occurs, it is necessary to determine whether to apply for a new table entry of a higher level, thereby avoiding meaningless application of a high table (a higher-level tag prediction table). For example, it can reduce the performance loss caused by a traditional TAGE branch predictor using only the prediction results of the high table and the additional power consumption caused by applying for the high table.

[0090] The branch prediction method provided by at least one embodiment of the present disclosure is implemented based on a branch predictor, and the branch predictor includes a plurality of label prediction tables of different levels, each label prediction table includes a certain number of table entries, and each table entry of each label prediction table includes a prediction value representing the prediction result of the corresponding table entry. For example, the branch predictor provided by the embodiment of the present disclosure may include four label prediction tables T1~T4 with ascending levels, that is, label prediction table T1 has the lowest level and label prediction table T4 has the highest level. It should be noted that, according to actual application requirements, the branch predictor may include more or fewer label prediction tables, and the embodiment of the present disclosure does not limit the number of label prediction tables in the branch predictor.

[0091] For the description of the predicted value in the table entry, please refer to the predicted value of the traditional TAGE introduced above, which can be implemented by a 2-bit saturation counter. For details, please refer to the above Figure 1D The description is not repeated here. In another example, the prediction value can also be implemented by a 3-bit signed saturated counter, whose sign bit represents the prediction result. For example, a sign bit of 1 indicates a predicted jump, and a sign bit of 0 indicates no predicted jump. Of course, the prediction value can also be implemented by other different types of counters, and the embodiments of the present disclosure are not limited to this. When applying for a new table entry, the prediction value of the new table entry needs to be initialized, and the specific initialization value can be set according to actual needs.

[0092] Figure 3 A flowchart of a branch prediction method based on a branch predictor is provided for at least one embodiment of the present disclosure.

[0093] For example, Figure 3 As shown, the branch prediction method provided by at least one embodiment of the present disclosure includes the following steps S101 to S102.

[0094] Step S101: In response to selecting a target table item, a target prediction result is obtained based on a prediction value of the target table item.

[0095] Step S102: In response to a target prediction result error, determine whether to apply for a new entry with a higher level than the target entry.

[0096] For example, in step S101, the target table entry refers to the table entry selected from all the table entries that is most likely to provide a correct prediction result. For example, the target table entry can be selected based on factors such as the difficulty of predicting the branch situation represented by the table entry. For example, the target prediction result refers to the prediction result reflected by the prediction value of the target table entry. Assuming that the prediction value is implemented based on a 2-bit saturated counter, when the prediction value of the target table entry is 11 (strong jump) or 10 (weak jump), the target prediction result is a jump, and when the prediction value of the target table entry is 01 (weak no jump) or 00 (strong no jump), the target prediction result is no jump.

[0097] For example, in step S102, when the processor executes the predicted branch instruction and calculates the actual branch result of the condition, it can determine whether the target prediction result is correct by comparing the actual branch result and the target prediction result. If the two are inconsistent, it means that the target prediction result is wrong, that is, a branch prediction error has occurred; if the two are consistent, it means that the target prediction result is correct. For the target table entry where a branch prediction error has occurred, it is necessary to determine whether it is necessary to apply for a new table entry in a label prediction table of a higher level than the label prediction table where the target table entry is located. For example, assuming that the target table entry is located in label prediction table T1, if a branch prediction error occurs in the target table entry, it is necessary to determine whether to apply for a new table entry in label prediction table T2. In the present disclosure, for ease of description, the level of the table entry can be regarded as the level of the label prediction table where the table entry is located, so "applying for a new table entry of a higher level than the target table entry" is equivalent to "applying for a new table entry in a higher-level label prediction table".

[0098] Unlike the traditional TAGE branch predictor which requests a high table every time it makes a prediction error, the branch prediction method provided in the embodiment of the present disclosure will first determine whether it is necessary to request a high table when a prediction error occurs, thereby avoiding meaningless high table requests and reducing the performance loss caused by the traditional TAGE branch predictor only using the prediction results of the high table and the additional power consumption caused by requesting the high table.

[0099] In the branch prediction method provided by at least one embodiment of the present disclosure, each table entry in the label prediction table also includes a stable value indicating that the corresponding table entry is in a stable state or an unstable state. The stable value is a first value (for example, 0) indicating that it is in an unstable state, and the stable value is a second value (for example, 1) indicating that it is in a stable state. The embodiment of the present disclosure does not limit the specific values ​​of the first value and the second value, as long as the two are different. The stable state refers to the high stability of the prediction result of the corresponding table entry, which reflects the consistency of the performance of the corresponding table entry in multiple predictions in the past, as well as its reliability for future predictions, which means that the current branch has the best prediction effect in the current label prediction table, and using a higher-level table entry will only reduce the prediction accuracy of the branch. It should be noted that when applying for a new table entry, the stable value of the new table entry is initialized to the first value.

[0100] In some examples, the “selecting a target entry” in the above step S101 may include the following step S201 .

[0101] Step S201: In response to hitting multiple entries in multiple tag prediction tables, a target entry is selected from the multiple entries based on a stable value of each of the multiple entries.

[0102] In some other examples, the "selecting a target entry" in the above step S101 may include the following step S202.

[0103] Step S202: In response to hitting a single entry in multiple tag prediction tables, the hit single entry is used as a target entry.

[0104] For example, in the above steps S201 and S202, when processing the case of hitting a single table item and multiple table items, the corresponding strategies are different. When only a single table item is hit, the hit single table item is directly selected as the target table item; when multiple table items are hit, the target table item can be selected from the hit multiple table items by comparing the stable value of each table item in the hit multiple table items.

[0105] The branch prediction method provided by the embodiment of the present disclosure selects the target table entry for outputting the prediction result according to the stable value of the table entry when hitting multiple table entries, effectively reducing the performance loss caused by the traditional TAGE branch predictor only using the prediction result of the high table. Furthermore, the branch prediction method avoids the problems caused by randomness and enhances the reliability of the prediction result; and there is no need to traverse all table entries, reducing time and power consumption.

[0106] In some examples, the branch prediction method provided by at least one embodiment of the present disclosure further includes the following step S103.

[0107] Step S103: Determine whether a table entry is hit based on the address of the branch instruction to be predicted and the global branch history.

[0108] For example, the address of the predicted branch instruction can be represented by the program counter (PC) value. Each branch instruction has a unique PC value. The global branch history refers to the execution results of all branch instructions in the recent period of time.

[0109] In the branch prediction method provided by at least one embodiment of the present disclosure, each entry in the label prediction table also includes a label value. An example of the above step S103 may include the following steps S1031 to S1032.

[0110] Step S1031: For each label prediction table in the plurality of label prediction tables, a first hash operation and a second hash operation are performed based on the address of the branch instruction to be predicted and the global branch history to obtain a first hash result and a second hash result, wherein the first hash operation is different from the second hash operation.

[0111] Step S1032: read an entry in the tag prediction table according to the first hash result, and determine whether the entry is a hit based on the tag value of the entry and the second hash result.

[0112] For example, in step S1031 and step S1032, label prediction tables of different levels use branch history sequences of different lengths in the global branch history to index table entries, thereby allowing prediction tables of each level to capture history patterns of different lengths, with label prediction tables of lower levels corresponding to shorter branch history sequences and label prediction tables of higher levels corresponding to longer branch history sequences. Specifically, the label prediction table is indexed using a first hash result obtained by performing a first hash operation on a PC value and a branch history sequence of corresponding length.

[0113] In some examples, as the level of the label prediction table increases, the length of the corresponding branch history sequence increases exponentially. The specific calculation formula can be as follows:

[0114]

[0115] Among them, L(i) represents the length of the branch history sequence corresponding to the i-th level label prediction table Ti, is the scaling factor of the geometric series, L(1) is the length of the branch history sequence corresponding to the label prediction table T1. The branch history sequence corresponding to the length L(i) can be expressed as h[0:L(i)].

[0116] It should be noted that the above formula is only an example of obtaining the length of the branch history sequence. The length of the branch history sequence corresponding to the different level label prediction tables can also be set in other ways according to actual needs, and the embodiments of the present disclosure are not limited to this.

[0117] For example, the label value is the hash value obtained by performing a second hash operation on the PC value and the branch history sequence of the corresponding length when the table entry is initialized. When determining whether the table entry is hit, it is also necessary to perform a second hash operation on the PC value and the branch history sequence of the corresponding length to obtain a second hash result. Therefore, by determining whether the label value and the second hash result are equal, it can be confirmed whether the indexed table entry corresponds to the branch instruction to be predicted currently (that is, whether the table entry is hit). If the label value is equal to the second hash result, it means that the table entry is hit; if they are not equal, it means that the table entry is not hit.

[0118] For example, the first hash operation and the second hash operation are two different hash operations, thereby ensuring the accuracy and reliability of entry indexing and verification.

[0119] In some examples, whether to apply for a new entry with a higher level than the target entry can be determined based on the stable value of the target entry, that is, "determining whether to apply for a new entry with a higher level than the target entry" in the above step S102 can include the following step S1021.

[0120] Step S1021: In response to the stable value of the target entry being the second value, do not apply for a new entry with a higher level than the target entry.

[0121] For example, in step S1021, it is determined whether to apply for a new table item of a higher level than the target table item according to the stable value of the target table item. When the stable value of the target table item is the second value (that is, when the target table item is in a stable state), a new table item of a higher level than the target table item is not applied, that is, a new table item is not applied in a higher-level label prediction table. On the contrary, when the stable value of the target table item is the first value (that is, when the target table item is in an unstable state), a new table item of a higher level than the target table item is applied, that is, a new table item is applied in a higher-level label prediction table. It should be noted that if the target table item is located in the highest-level label prediction table among multiple label prediction tables, even if the stable value of the target table item is the first value, a new table item of a higher level than the target table item will not be applied. As the total number of label prediction tables changes, the highest level will also change accordingly. For example, if the branch predictor includes three label prediction tables, the third level is the highest level; if the branch predictor includes four label prediction tables, the fourth level is the highest level.

[0122] The branch prediction method provided in the above-mentioned embodiment of the present disclosure determines whether it is necessary to apply for a high table based on the stable value of the target table item when a prediction error occurs. It is not necessary to apply for a high table every time a prediction error occurs, thereby avoiding meaningless high table applications and reducing the additional power consumption caused by the traditional TAGE branch predictor applying for a high table.

[0123] In other examples, a random number mechanism may be used to determine whether to apply for a new entry with a higher level than the target entry, that is, the "determining whether to apply for a new entry with a higher level than the target entry" in the above step S102 may include the following steps S1022 to S1023.

[0124] Step S1022: Generate a random number within a preset interval.

[0125] Step S1023: Compare the random number with a preset threshold, and in response to the random number being less than or equal to the preset threshold, do not apply for a new entry with a higher level than the target entry.

[0126] For example, in step S1022, the preset interval is a preset value range, which can be set according to actual needs, such as [0, 1], and the embodiment of the present disclosure does not limit this. For example, a random number generator can be used to generate a random number within the preset interval.

[0127] For example, in step S1023, the random number generated in step S1022 is compared with the preset threshold. If the random number is less than or equal to the preset threshold, a new entry with a higher level than the target entry is not applied for; if the random number is greater than the preset threshold, a new entry with a higher level than the target entry is applied for. For example, the preset threshold can be selected based on the size of the preset interval. For example, when the preset interval is [0,1], the preset threshold can be set to 0.5. Assuming that the random number generated in step S1022 is 0.2, since 0.2<0.5, a new entry with a higher level than the target entry is not applied for.

[0128] In some other examples, an interval application method may be used to apply for a new entry with a higher level than the target entry, that is, the "determining whether to apply for a new entry with a higher level than the target entry" in the above step S102 may include the following step S1024.

[0129] Step S1024: In response to applying for a corresponding new entry in the previous judgment, a new entry with a higher level than the target entry is not applied in this judgment.

[0130] For example, in step S1024, a state variable may be introduced to record whether a corresponding new table item was applied in the last judgment, and the state variable may be a Boolean value. For example, the state variable is checked before each judgment, and whether a new table item was applied in the last judgment is determined according to the value of the state variable, thereby determining whether a new table item is applied in this judgment. The state variable needs to be updated after each judgment to reflect the latest table item application status.

[0131] The branch prediction method provided in the above-mentioned embodiments of the present disclosure can suppress high table requests based on a random number mechanism or an interval request method when a prediction error occurs. There is no need to request a high table every time a prediction error occurs, thereby avoiding meaningless high table requests and reducing the extra power consumption caused by the traditional TAGE branch predictor requesting a high table.

[0132] In some examples, the above step S201 may include the following step S2011.

[0133] Step S2011: In response to the presence of an entry whose stable value is the second value among the multiple entries, selecting the entry whose stable value is the second value as the target entry.

[0134] In some examples, the above step S201 may include the following step S2012.

[0135] Step S2012: In response to the absence of an entry with a stable value of the second value among the multiple entries, selecting an entry with the lowest prediction difficulty for the branch situation represented by the multiple entries as a target entry.

[0136] For example, in step S2011 and step S2012, it is determined whether there is an entry with a stable value of the second value among the multiple entries hit, that is, whether there is an entry in a stable state. If so, the entry in a stable state is selected as the target entry; if not, the entry with the lowest prediction difficulty of the branch situation represented by the multiple entries is selected as the target entry. It should be noted that if there are multiple entries with the lowest prediction difficulty, that is, if the prediction difficulty of these entries is the same, the entry with the highest level among them can be selected as the target entry.

[0137] For example, the prediction difficulty may be described by indicators such as information entropy, prediction accuracy, and the number of false predictions of table items. Other different indicators may also be used, and the embodiments of the present disclosure are not limited to this.

[0138] In some examples, after "selecting the entry with the lowest prediction difficulty of the branch situation represented by the multiple entries as the target entry" in step S2012, the branch prediction method provided by at least one embodiment of the present disclosure further includes the following step S2013.

[0139] Step S2013: In response to the target entry not being located in the highest-level label prediction table among the plurality of label prediction tables, setting the stable value of the target entry to a second value.

[0140] For example, in step S2013, the target table entry is the table entry with the lowest prediction difficulty of the branch situation represented by the hit multiple table entries. When the target table entry is not located in the highest-level label prediction table, it is considered that the target table entry is in a stable state, and the stable value of the target table entry is set to the second value. For example, assuming that the branch predictor includes four label prediction tables T1~T4, and label prediction table T4 is the highest level, if the target table entry is not located in label prediction table T4, that is, if the target table entry is located in label prediction table T1, T2 or T3, the stable value of the target table entry is set to the second value.

[0141] In some examples, when describing the prediction difficulty of the branch situation represented by the table entry through the information entropy of the table entry, each table entry also includes information entropy information, and the information entropy information is used to obtain an information entropy value representing the prediction difficulty of the branch situation represented by the corresponding table entry. For example, a lower information entropy value represents an easier branch to predict, and a higher information entropy value represents a more difficult branch to predict.

[0142] Correspondingly, an example of "selecting the entry with the lowest prediction difficulty for the branch situation represented by multiple entries as the target entry" in the above step S2012 can be: selecting the entry with the lowest information entropy value obtained according to the information entropy information from multiple entries as the target entry.

[0143] It should be noted that, if there are multiple entries with the lowest information entropy values, the entry with the highest level among them is selected as the target entry.

[0144] In some examples, the information entropy information of each table entry includes an access count value and a jump count value. The access count value records the number of times the corresponding table entry is hit and selected as the target table entry, and the jump count value records the number of times the actual branch result is a jump when the corresponding table entry is hit and selected as the target table entry.

[0145] For example, the access count value and the jump count value can be implemented by counters respectively. When applying for a new table entry, the access count value and the jump count value of the new table entry are initialized to 0.

[0146] Correspondingly, after "obtaining a target prediction result based on the prediction value of the target table entry" in step S101, the branch prediction method provided by at least one embodiment of the present disclosure further includes the following steps S301 to S303.

[0147] Step S301: increase the access count value of the target entry by 1.

[0148] Step S302: In response to the target prediction result being wrong and the target prediction result being no jump, the jump count value of the target table entry is increased by 1.

[0149] Step S303: In response to the target prediction result being correct and the target prediction result being a jump, the jump count value of the target table entry is increased by 1.

[0150] For example, in step S302, the target prediction result is wrong and the target prediction result is not to jump, which means that the actual branch result is a jump, and the jump count value of the target table entry is increased by 1.

[0151] For example, in step S303, the target prediction result is correct and the target prediction result is a jump, indicating that the actual branch result is a jump, and the jump count value of the target table entry is increased by 1.

[0152] In some examples, the information entropy information of each table entry also includes an information entropy value. The branch prediction method provided by at least one embodiment of the present disclosure also includes the following step S304.

[0153] Step S304: updating the information entropy value of the target entry based on the access count value and the jump count value of the target entry.

[0154] For example, when applying for a new table entry, the information entropy value of the new table entry is initialized to 0. The information entropy update only involves the target table entry actually used by the branch prediction, and the information entropy of other hit table entries will not be updated.

[0155] In some examples, the above step S304 can be calculated by the following formula:

[0156]

[0157] Among them, H is the information entropy value, taken is the jump count value, access is the access count value, and n is the base.

[0158] For example, the base n can take any positive integer value and can be set according to actual needs, and the embodiments of the present disclosure are not limited to this.

[0159] For example, in hardware implementation, the calculation of the logarithmic function can use Taylor expansion or a lookup table (LUT, LookupTable).

[0160] For example, when the base n=2, according to the following Taylor expansion formula, The calculation can be converted into a constant multiplied by A simple calculation of is the independent variable of the logarithmic function:

[0161]

[0162] Therefore, the comparison of the information entropy values ​​calculated in the above manner can be simplified to a comparison of the integer parts, which can be specifically implemented by a bit-by-bit XOR method.

[0163] For example, a lookup table is an efficient hardware implementation. , a series of The results corresponding to the values ​​are stored in a table. When calculation is needed, you only need to look up the table to get an approximate result.

[0164] The advantages of the above two methods are that they do not require complex mathematical operations, only rely on bit operations, and are suitable for hardware implementation.

[0165] In some examples, when describing the prediction difficulty of the branch situation represented by the table entry through the prediction accuracy of the table entry, each table entry also includes an accuracy value, and the accuracy value indicates the correctness of the prediction result when the corresponding table entry is hit and selected as the target table entry. For example, a higher accuracy value indicates that the branch is easier to predict, and a lower accuracy value indicates that the branch is more difficult to predict.

[0166] For example, each table entry may also include an access count value and a correct prediction count value for calculating the above-mentioned accuracy value. The access count value records the number of times the corresponding table entry is hit and selected as the target table entry, and the correct prediction count value indicates the number of correct prediction results when the corresponding table entry is hit and selected as the target table entry.

[0167] For example, the access count value and the correct prediction count value can be implemented by counters respectively. For example, when applying for a new table entry, the access count value and the correct prediction count value of the new table entry are initialized to 0.

[0168] The accuracy value can be calculated according to the following formula: Accuracy value = correct prediction count value / visit count value.

[0169] Correspondingly, an example of "selecting the entry with the lowest prediction difficulty of the branch situation represented by the multiple entries as the target entry" in the above step S2012 may be: selecting the entry with the highest accuracy value among the multiple entries as the target entry.

[0170] It should be noted that, if there are multiple entries with the highest accuracy values, the entry with the highest level is selected as the target entry.

[0171] In some examples, when describing the prediction difficulty of the branch situation represented by the table entry through the number of misprediction of the table entry, each table entry also includes a misprediction count value, and the misprediction count value indicates the number of errors in the prediction result when the corresponding table entry is hit and selected as the target table entry. For example, a lower misprediction count value indicates that the branch is easier to predict, and a higher misprediction count value indicates that the branch is more difficult to predict.

[0172] For example, the misprediction count value may be implemented by a counter. For example, when applying for a new table entry, the misprediction count value is initialized to 0.

[0173] Correspondingly, an example of "selecting the entry with the lowest prediction difficulty of the branch situation represented by the multiple entries as the target entry" in the above step S2012 may be: selecting the entry with the lowest misprediction count value among the multiple entries as the target entry.

[0174] It should be noted that, if there are multiple entries with the lowest misprediction count values, the entry with the highest level among them is selected as the target entry.

[0175] In some examples, the branch prediction method provided by at least one embodiment of the present disclosure may further include the following step S104.

[0176] Step S104: in response to reaching a preset time interval or continuous occurrence of target prediction result errors, updating the stable values ​​of all entries in the plurality of label prediction tables to a first value.

[0177] For example, in step S104, according to the description of the above embodiment, when the stable value of the target table entry is the second value, it means that the target table entry is in a stable state. At this time, even if the target table entry is predicted incorrectly, the high table is not applied, thereby realizing the function of application suppression. However, due to the uncertainty of branch prediction, the table entry that was originally in a stable state may no longer be reliable after a period of time. Therefore, when the preset time interval is reached or the target prediction result error occurs continuously, it is necessary to reinitialize the stable value information of all table entries, that is, update to the first value, so as to make future predictions more accurately and reduce the performance loss caused by misprediction. For example, the preset time interval can be set according to actual needs, such as a number of clock cycles, and the embodiments of the present disclosure are not limited to this. For example, the continuous occurrence of target prediction result errors can be the continuous occurrence of target prediction result errors for multiple times, and the specific number of times can be set according to actual needs, and the embodiments of the present disclosure are not limited to this.

[0178] For example, the above step S104 may be executed in parallel with the above other steps, so as to update the stable value of the entry in time.

[0179] The branch prediction method provided by the above-mentioned embodiment of the present disclosure avoids continuous prediction errors by setting a stable value update strategy, reduces the performance loss caused by misprediction, and improves prediction accuracy.

[0180] In some examples, the branch prediction method provided by at least one embodiment of the present disclosure may further include the following step S105.

[0181] Step S105: When replacing an entry in any of the multiple label prediction tables, in response to the existence of an entry whose stable value is the first value, a preset replacement algorithm is applied to the entry whose stable value is the first value, or in response to the absence of an entry whose stable value is the first value, a preset replacement algorithm is applied to all the entries.

[0182] For example, the capacity of each label prediction table is fixed, for example, it can accommodate 1024 entries. As branch prediction continues, the label prediction table will continuously allocate new entries until it reaches its maximum capacity. When a label prediction table is full, it is necessary to replace the entries, that is, remove some existing entries to make room for new entries that need to be allocated later. For example, the preset replacement algorithm can be the least recently used (Least Recently Used, LRU), least frequently used (Least Frequently Used, LFU), least frequently used (Not Frequently Used, NFU) and other replacement algorithms, which can be selected according to actual needs, and the embodiments of the present disclosure are not limited to this.

[0183] For example, when replacing entries in a label prediction table, priority is given to replacing entries whose stable value is the first value (i.e., they are in an unstable state), that is, the preset replacement algorithm is applied to the entries whose stable value is the first value; if there is no entry in the label prediction table whose stable value is the first value, that is, all the entries in the label prediction table are in a stable state, then the preset replacement algorithm is applied to all the entries in the label prediction table.

[0184] The branch prediction method provided by the above-mentioned embodiment of the present disclosure sets a table entry replacement strategy so that the label prediction table can continuously and effectively support branch prediction while optimizing performance and prediction accuracy.

[0185] Figure 4A A flowchart of a branch prediction method based on a branch predictor is provided for at least one embodiment of the present disclosure. Figure 4A For the above Figure 3 A specific example of the branch prediction method shown.

[0186] Figure 4B A schematic diagram of a branch predictor provided by at least one embodiment of the present disclosure. Figure 4A The branch prediction method shown can be based on Figure 4B The branch predictor implementation shown in Figure 1 is shown in Figure 2. Figure 4BAs shown, the branch predictor includes a basic prediction table T0 and four tag prediction tables T1 to T4 of different levels. Each entry in each tag prediction table includes a prediction value pred, a tag value tag, a stable value stable, an access count value access, a jump count value taken, and an information entropy value informationentropy. For a description of other parts of the branch predictor provided in the embodiments of the present disclosure, please refer to Figure 2 Description of the TAGE branch predictor in .

[0187] For example, Figure 4A As shown, at least one embodiment of the present disclosure provides a branch prediction method based on a branch predictor, including the following steps S501 to S530.

[0188] Step S501: Determine whether a table entry is hit based on the address of the branch instruction to be predicted and the global branch history. If a single table entry is hit, execute step S502; if multiple table entries are hit, jump to step S514. For the specific description of step S501, please refer to step S103 in the above embodiment, which will not be repeated here.

[0189] Step S502: In response to hitting a single entry, the hit single entry is used as a target entry, and a target prediction result is obtained based on the prediction value of the target entry. The specific description of step S502 can refer to step S101 and step S202 in the above embodiment, which will not be repeated here.

[0190] Step S503: adding 1 to the access count value of the target entry. For a detailed description of step S503, reference may be made to step S301 in the above embodiment, which will not be described in detail here.

[0191] Step S504: Determine whether the target prediction result is correct. If so, execute step S505; if not, jump to step S507. For example, the target prediction result can be determined by comparing the actual branch result with the target prediction result.

[0192] Step S505: Determine whether the target prediction result is a jump. If yes, execute step S506; if no, jump to step S507.

[0193] Step S506: In response to the target prediction result being correct and the target prediction result being a jump, the jump count value taken of the target entry is increased by 1. For a detailed description of step S506, reference may be made to step S303 in the above embodiment, which will not be repeated here.

[0194] Step S507: Update the information entropy value of the target entry based on the access count value and the jump count value of the target entry, and this round of branch prediction ends. For a detailed description of step S507, reference may be made to step S304 in the above embodiment, which will not be repeated here.

[0195] Step S508: Determine whether the target prediction result is a jump. If yes, jump to step S510; if no, execute step S509.

[0196] Step S509: In response to the target prediction result being wrong and the target prediction result being no jump, the jump count value taken of the target entry is increased by 1. For a detailed description of step S509, reference may be made to step S302 in the above embodiment, which will not be repeated here.

[0197] Step S510: Update the information entropy value of the target entry based on the access count value and the jump count value of the target entry. For a detailed description of step S510, reference may be made to step S304 in the above embodiment, which will not be described in detail here.

[0198] Step S511: Determine whether the stable value of the target entry is 1. If so, execute step S512; if not, jump to step S513.

[0199] Step S512: In response to the stable value of the target entry being 1, no new entry with a higher level than the target entry is requested, and this round of branch prediction ends.

[0200] Step S513: In response to the stable value of the target entry being 0, a new entry with a higher level than the target entry is requested, and this round of branch prediction ends. The specific description of steps S512 and S513 can refer to the description of step S1021 in the above embodiment, which will not be repeated here.

[0201] Step S514: In response to hitting multiple entries, determine whether there is an entry with a stable value of 1 among the multiple entries hit. If so, execute step S515; if not, jump to step S516.

[0202] Step S515: In response to the presence of an entry with a stable value of the second value in the plurality of entries, the entry with a stable value of the second value is selected as the target entry, a target prediction result is obtained based on the prediction value of the target entry, and step S519 is executed. For a detailed description of step S515, reference may be made to the description of step S2011 in the above embodiment, which will not be repeated here.

[0203] Step S516: In response to the absence of an entry with a stable value of the second value among the multiple entries, select the entry with the lowest information entropy value among the multiple entries as the target entry, and obtain the target prediction result based on the prediction value of the target entry. If there are multiple entries with the lowest information entropy values, select the entry with the highest level among them as the target entry. For the specific description of step S516, please refer to the description of step S2012 in the above embodiment, which will not be repeated here.

[0204] Step S517: Determine whether the target entry is in the highest level tag prediction table. If yes, jump to step S519; if no, execute step S518. Figure 4B For the branch predictor shown in FIG. 1 , the highest level label prediction table is label prediction table T4. It should be noted that Figure 4B As just one example, a branch predictor may include more or fewer tag prediction tables, with the top level of the tag prediction tables varying as the total number of tag prediction tables varies.

[0205] Step S518: In response to the target entry not being located in the highest-level tag prediction table among the multiple tag prediction tables, the stable value of the target entry is set to 1. For a detailed description of step S518, reference may be made to the description of step S2013 in the above embodiment, which will not be repeated here.

[0206] Step S519: adding 1 to the access count value of the target entry. For a detailed description of step S519, reference may be made to the description of step S301 in the above embodiment, which will not be repeated here.

[0207] Step S520: Determine whether the target prediction result is correct. If so, execute step S521; if not, jump to step S524. For example, the target prediction result can be determined by comparing the actual branch result with the target prediction result.

[0208] Step S521: Determine whether the target prediction result is a jump. If yes, execute step S522; if no, jump to step S523.

[0209] Step S522: In response to the target prediction result being correct and the target prediction result being a jump, the jump count value of the target entry is increased by 1. For a detailed description of step S522, reference may be made to the description of step S303 in the above embodiment, which will not be repeated here.

[0210] Step S523: Update the information entropy value of the target entry based on the access count value and the jump count value of the target entry, and this round of branch prediction ends. For a detailed description of step S523, reference may be made to step S304 in the above embodiment, which will not be repeated here.

[0211] Step S524: Determine whether the target prediction result is a jump. If yes, jump to step S526; if no, execute step S525.

[0212] Step S525: In response to the target prediction result being wrong and the target prediction result being no jump, the jump count value of the target entry is increased by 1. The specific description of step S525 may refer to the description of step S302 in the above embodiment, which will not be repeated here.

[0213] Step S526: Update the information entropy value of the target entry based on the access count value and the jump count value of the target entry. For a detailed description of step S526, reference may be made to the description of step S304 in the above embodiment, which will not be repeated here.

[0214] Step S527: Determine whether the stable value of the target entry is 1. If so, jump to step S530; if not, execute step S528.

[0215] Step S528: Determine whether the target entry is in the highest level tag prediction table. If so, jump to step S530; if not, execute step S529.

[0216] Step S529: In response to the stable value of the target entry being 0 and the target entry not being located in the highest-level label prediction table, a new entry at a higher level than the target entry is requested, and this round of branch prediction ends.

[0217] Step S530: In response to the stable value of the target entry being 1, or in response to the stable value of the target entry being 0 and the target entry being in the highest level label prediction table, no new entry at a higher level than the target entry is requested, and this round of branch prediction ends. For the specific description of steps S529 and S530, reference may be made to the description of step S1021 in the above embodiment, which will not be repeated here.

[0218] See also Figure 4A and Figure 4B The principle of the branch prediction method based on the branch predictor provided by at least one embodiment of the present disclosure is as follows:

[0219] For a branch instruction, when a branch prediction error occurs for the first time, an allocation table entry is requested in the basic prediction table T0, and subsequent predictions are made based on the table entry in the basic prediction table T0. When a branch prediction error occurs again, a new table entry is requested in the label prediction table T1, the information entropy value, access count value, jump count value, and stable value are initialized to 0, and subsequent predictions are made based on the table entry in the label prediction table T1. When the table entry is hit later, there are two situations:

[0220] 1. Obtain the target prediction result based on the prediction value of the table entry. If the target prediction result is correct, increase the access count value of the table entry. If the actual branch result is a jump, increase the jump count value of the table entry. Calculate the information entropy value based on the updated access count value and jump count value.

[0221] 2. Get the target prediction result based on the prediction value of the table item. If the target prediction result is wrong, increase the access count value of the table item. If the actual branch result is a jump, increase the jump count value of the table item. Calculate the information entropy value based on the updated access count value and jump count value. At the same time, apply for the allocation of a new table item in the label prediction table T2, and initialize the information entropy value, access count value, jump count value and stable value to 0.

[0222] When the branch instruction needs to be predicted again, the entries in the label prediction table T1 and the label prediction table T2 will be hit at the same time. The prediction value of the entry with a stable value of 1 is preferentially selected as the target prediction result. If there is no entry with a stable value of 1, the prediction value of the entry with the lower information entropy is selected as the target prediction result. Since the label prediction table T2 has just been applied, its entry information entropy is 0, which is necessarily lower than the information entropy of the entry in the label prediction table T1. Therefore, the entry in the label prediction table T2 is selected as the target entry, and the above process is repeated according to the hit situation to update the information entropy of the entry in the label prediction table T2. When the information entropy of the entry in T2 is greater than that of the entry in T1, the prediction result of the entry in T1 is selected as the target prediction result, and the stable value of the entry in T1 is set to 1, indicating that the current branch has the best prediction effect under the current branch history sequence length. Using a higher-level entry will only reduce the prediction accuracy of the branch. When the stable value of the entry is 1, even if a prediction error occurs, a new entry will not be applied for allocation in a higher-level label prediction table.

[0223] Figure 5 A schematic block diagram of a branch predictor provided by at least one embodiment of the present disclosure. Figure 5 As shown, a branch predictor 600 provided by at least one embodiment of the present disclosure includes a plurality of label prediction tables 601 of different levels, a prediction module 602 and a judgment module 603 .

[0224] For example, in some examples, each table entry of each tag prediction table in the plurality of tag prediction tables 601 includes a prediction value representing a prediction result of the corresponding table entry.

[0225] For example, in some examples, the prediction module 602 is configured to obtain a target prediction result based on a prediction value of the target table item in response to selecting the target table item;

[0226] For example, in some examples, the determination module 603 is configured to determine whether to apply for a new entry with a higher level than the target entry in response to an error in the target prediction result.

[0227] For the relevant contents of the prediction module 602 and the judgment module 603, reference can be made to the above-mentioned embodiment of the branch prediction method. Figure 3 The description of step S101 and step S102 shown in the figure will not be repeated here. Figure 5 The various modules shown can be implemented, for example, by software, hardware, firmware, or any combination thereof. For example, the prediction module 602 can be implemented as a prediction circuit, and the determination module 603 can be implemented as a determination circuit.

[0228] For example, in at least one embodiment of the present disclosure, each table entry also includes a stable value indicating that the corresponding table entry is in a stable state or an unstable state, the stable value is a first value indicating that it is in an unstable state, and the stable value is a second value indicating that it is in a stable state, and the prediction module 602 includes a selection unit, and the selection unit is configured to select a target table entry from the multiple table entries based on the stable value of each table entry in the multiple table entries in response to hitting multiple table entries in the multiple tag prediction tables.

[0229] For example, in at least one embodiment of the present disclosure, the selection unit is configured to, in response to hitting a single entry in the plurality of tag prediction tables, take the hit single entry as the target entry.

[0230] For example, in at least one embodiment of the present disclosure, the determination module 603 is further configured to: in response to the stable value of the target entry being the second value, not apply for a new entry with a higher level than the target entry.

[0231] For example, in at least one embodiment of the present disclosure, the selection unit is further configured to select an entry whose stable value is the second value as the target entry in response to the presence of an entry whose stable value is the second value among the multiple entries.

[0232] For example, in at least one embodiment of the present disclosure, the selection unit is further configured to select the entry with the lowest prediction difficulty for the branch situation represented by the multiple entries as the target entry in response to the absence of an entry with a stable value of the second value in the multiple entries.

[0233] For example, in at least one embodiment of the present disclosure, the branch predictor also includes a stable value setting module, which is configured to, after selecting a table entry with the lowest prediction difficulty for the branch situation represented by multiple table entries as a target table entry, set the stable value of the target table entry to a second value in response to the target table entry not being located in a highest-level label prediction table among multiple label prediction tables.

[0234] For example, in at least one embodiment of the present disclosure, each table entry also includes information entropy information, and the information entropy information is used to obtain an information entropy value representing the degree of difficulty in predicting the branch situation represented by the corresponding table entry. The selection unit is further configured to select the table entry with the lowest information entropy value obtained according to the information entropy information among multiple table entries as the target table entry.

[0235] For example, in at least one embodiment of the present disclosure, the information entropy information of each table entry includes an access count value and a jump count value, the access count value records the number of times the corresponding table entry is hit and selected as the target table entry, and the jump count value records the number of times the actual branch result is a jump when the corresponding table entry is hit and selected as the target table entry. The branch predictor also includes an information entropy information update module, and the information entropy information update module is configured to increase the access count value of the target table entry by 1 after obtaining the target prediction result based on the prediction value of the target table entry; in response to the target prediction result being wrong and the target prediction result being no jump, increase the jump count value of the target table entry by 1; in response to the target prediction result being correct and the target prediction result being a jump, increase the jump count value of the target table entry by 1.

[0236] For example, in at least one embodiment of the present disclosure, the information entropy information of each table entry also includes an information entropy value, and the branch predictor also includes an information entropy value update module, which is configured to update the information entropy value of the target table entry based on the access count value and jump count value of the target table entry.

[0237] For example, in at least one embodiment of the present disclosure, the information entropy value updating module is further configured as follows:

[0238]

[0239] Among them, H is the information entropy value, taken is the jump count value, access is the access count value, n is the base, and n is a positive integer.

[0240] For example, in at least one embodiment of the present disclosure, each table entry also includes an accuracy value, which indicates the correctness of the prediction result when the corresponding table entry is hit and selected as the target table entry, and the selection unit is further configured to select the table entry with the highest accuracy value among multiple table entries as the target table entry.

[0241] For example, in at least one embodiment of the present disclosure, each table entry also includes a misprediction count value, which indicates the number of errors in the prediction result when the corresponding table entry is hit and selected as the target table entry. The selection unit is further configured to select the table entry with the lowest misprediction count value among the multiple table entries as the target table entry.

[0242] For example, in at least one embodiment of the present disclosure, the branch predictor also includes an update module, which is configured to update the stable values ​​of all entries in multiple label prediction tables to a first value in response to reaching a preset time interval or continuous occurrence of target prediction result errors.

[0243] For example, in at least one embodiment of the present disclosure, the branch predictor also includes a replacement module, which is configured to: when replacing a table entry in any of the multiple label prediction tables, in response to the existence of a table entry with a stable value of the first value, apply a preset replacement algorithm to the table entry with a stable value of the first value, or in response to the absence of a table entry with a stable value of the first value, apply the preset replacement algorithm to all table entries.

[0244] For example, in at least one embodiment of the present disclosure, the judgment module 603 is further configured to: generate a random number within a preset interval; compare the random number with a preset threshold, and in response to the random number being less than or equal to the preset threshold, not apply for a new entry of a higher level than the target entry.

[0245] For example, in at least one embodiment of the present disclosure, the determination module 603 is further configured to: in response to applying for a corresponding new entry in the previous determination, not apply for a new entry with a higher level than the target entry in this determination.

[0246] For example, in at least one embodiment of the present disclosure, the branch predictor further includes a hit module, and the hit module is configured to determine whether a table entry is hit based on the address of the branch instruction to be predicted and the global branch history.

[0247] For example, in at least one embodiment of the present disclosure, each table entry also includes a label value, and the hit module is further configured to: for each label prediction table in a plurality of label prediction tables, perform a first hash operation and a second hash operation based on the address of the branch instruction to be predicted and the global branch history to obtain a first hash result and a second hash result, wherein the first hash operation is different from the second hash operation; read the table entry in the label prediction table according to the first hash result, and determine whether the table entry is hit based on the label value of the table entry and the second hash result.

[0248] Figure 6 A schematic block diagram of a processor provided for at least one embodiment of the present disclosure.

[0249] For example, Figure 6 As shown, the processor 700 provided in at least one embodiment of the present disclosure includes a branch predictor 701. For example, the processor 700 may be a single-core or multi-core central processing unit (CPU), a graphics processing unit (GPU), an AI accelerator, etc., and the present disclosure does not limit this. For example, the branch predictor 701 may be a branch predictor provided in any of the above embodiments.

[0250] For example, in at least one example, the processor 700 may include an instruction fetch unit, a decoding unit, an allocation unit, a fixed-point execution unit, a floating-point execution unit, and a memory access unit (not shown in the figure) in addition to the branch predictor 701; the processor includes multiple pipeline stages, and the instruction corresponding to the program counter is sent to the instruction fetch unit after the branch prediction of the branch predictor 701 to enter the pipeline of the processor for processing. The specific operations will not be repeated here.

[0251] At least one embodiment of the present disclosure further provides an electronic device, which includes the processor of any of the above embodiments. Figure 7 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure.

[0252] The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (PADs), portable multimedia players (PMPs), vehicle-mounted terminals (e.g., vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device 900 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0253] For example, Figure 7 As shown, in some examples, the electronic device 900 includes a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901, which may include a processor of any of the above-mentioned embodiments, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 to a random access memory (RAM) 903. In RAM 903, various programs and data required for the operation of the computer system are also stored. The processor 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0254] For example, the following components may be connected to the I / O interface 905: an input device 906 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 908 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 909 which may also include, for example, a network interface card such as a LAN card, a modem, etc. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data, performing communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. Removable media 911, such as magnetic disks, optical disks, magneto-optical disks, semiconductor memories, etc., are installed on the drive 910 as needed, so that the computer program read therefrom is installed into the storage device 908 as needed. Although Figure 7 The electronic device 900 is shown to include various devices, but it should be understood that it is not required to implement or include all of the devices shown. More or fewer devices may be implemented or included instead.

[0255] For example, the electronic device 900 may further include a peripheral interface (not shown in the figure), etc. The peripheral interface may be various types of interfaces, such as a USB interface, a lightning interface, etc. The communication device 909 may communicate with a network and other devices through wireless communication, such as the Internet, an intranet and / or a wireless network such as a cellular phone network, a wireless local area network (LAN) and / or a metropolitan area network (MAN). Wireless communication may use any of a variety of communication standards, protocols, and techniques, including, but not limited to, Global System for Mobile Communications (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (W-CDMA), Code Division Multiple Access (CDMA), Time Division Multiple Access (TDMA), Bluetooth, Wi-Fi (e.g., based on IEEE 802.11a, IEEE 802.11b, IEEE 802.11g, and / or IEEE 802.11n standards), Voice over Internet Protocol (VoIP), Wi-MAX, protocols for email, instant messaging, and / or Short Message Service (SMS), or any other suitable communication protocol.

[0256] For example, the electronic device 900 can be any device such as a mobile phone, a tablet computer, a laptop computer, an e-book, a game console, a television, a digital photo frame, a navigator, a server, etc., or it can be any combination of data processing devices and hardware, and the embodiments of the present disclosure are not limited to this.

[0257] Although the disclosure has been described in detail above with general descriptions and specific implementation methods, it is obvious to those skilled in the art that some modifications or improvements may be made to the embodiments of the disclosure. Therefore, these modifications or improvements made without departing from the spirit of the disclosure are within the scope of protection claimed by the disclosure.

[0258] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0259] There are a few points to note about this disclosure:

[0260] (1) The drawings of the embodiments of the present disclosure only relate to the structures related to the embodiments of the present disclosure. Other structures may refer to the general design.

[0261] (2) For the sake of clarity, in the drawings used to describe the embodiments of the present disclosure, the thickness of layers or regions is enlarged or reduced, that is, these drawings are not drawn according to the actual scale.

[0262] (3) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to obtain new embodiments.

[0263] The above description is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. The protection scope of the present disclosure shall be based on the protection scope of the claims.

Claims

1. A branch prediction method based on a branch predictor, wherein: The branch predictor includes a plurality of label prediction tables of different levels, each table entry of each label prediction table in the plurality of label prediction tables includes a prediction value representing a prediction result of the corresponding table entry, and the method includes: In response to selecting a target table item, obtaining a target prediction result based on a prediction value of the target table item; In response to the target prediction result being wrong, it is determined whether to apply for a new entry with a higher level than the target entry.

2. The method according to claim 1, wherein: Each of the table entries also includes a stable value indicating that the corresponding table entry is in a stable state or an unstable state, wherein the stable value is a first value indicating that the corresponding table entry is in the unstable state, and the stable value is a second value indicating that the corresponding table entry is in the stable state. The selected target table item includes: In response to hitting a plurality of entries in the plurality of tag prediction tables, the target entry is selected from the plurality of entries based on a stable value of each of the plurality of entries.

3. The method according to claim 1, wherein: The selected target table item includes: In response to hitting a single entry in the plurality of tag prediction tables, the hit single entry is used as the target entry.

4. The method according to claim 3, wherein: The determining whether to apply for a new entry with a higher level than the target entry includes: In response to the stable value of the target entry being the second value, a new entry with a higher level than the target entry is not applied for.

5. The method according to claim 2, wherein: In response to hitting multiple entries in the multiple tag prediction tables, selecting the target entry from the multiple entries based on a stable value of each of the multiple entries includes: In response to the presence of an entry whose stable value is the second value among the multiple entries, the entry whose stable value is the second value is selected as the target entry.

6. The method according to claim 2, wherein: In response to hitting multiple entries in the multiple tag prediction tables, selecting the target entry from the multiple entries based on a stable value of each of the multiple entries includes: In response to the absence of an entry whose stable value is the second value among the multiple entries, selecting an entry whose branch situation represented by the multiple entries has the lowest prediction difficulty as the target entry.

7. The method according to claim 6, wherein: After selecting the entry with the lowest prediction difficulty of the branch situation represented by the multiple entries as the target entry, the method further includes: In response to the target entry not being located in a highest-level tag prediction table among the plurality of tag prediction tables, the stable value of the target entry is set to the second value.

8. The method according to claim 6, wherein: Each of the table entries also includes information entropy information, and the information entropy information is used to obtain an information entropy value representing the degree of difficulty of predicting the branch situation represented by the corresponding table entry. The selecting the entry with the lowest prediction difficulty among the multiple entries as the target entry includes: Select an entry with the lowest information entropy value obtained according to the information entropy information from among the multiple entries as the target entry.

9. The method according to claim 8, wherein: The information entropy information of each of the table entries includes an access count value and a jump count value, wherein the access count value records the number of times the corresponding table entry is hit and selected as the target table entry, and the jump count value records the number of times the actual branch result is a jump when the corresponding table entry is hit and selected as the target table entry. Wherein, after obtaining a target prediction result based on the prediction value of the target table item, the method further includes: Add 1 to the access count value of the target entry; In response to the target prediction result being wrong and the target prediction result being no jump, adding 1 to the jump count value of the target table entry; In response to the target prediction result being correct and the target prediction result being a jump, the jump count value of the target table entry is increased by 1.

10. The method according to claim 9, wherein: The information entropy information of each entry also includes the information entropy value, and the method further includes: The information entropy value of the target entry is updated based on the access count value and the jump count value of the target entry.

11. The method according to claim 10, wherein: The updating of the information entropy value of the target entry based on the access count value and the jump count value of the target entry includes: Among them, H is the information entropy value, taken is the jump count value, access is the access count value, n is the base, and the value of n is a positive integer.

12. The method according to claim 6, wherein: Each of the table entries also includes an accuracy value, which indicates the correctness of the prediction result when the corresponding table entry is hit and selected as the target table entry. The step of selecting the entry with the lowest prediction difficulty for the branch situation represented by the multiple entries as the target entry includes: The entry with the highest accuracy value among the multiple entries is selected as the target entry.

13. The method according to claim 6, wherein: Each of the table entries also includes a misprediction count value, wherein the misprediction count value indicates the number of errors in the prediction result when the corresponding table entry is hit and selected as the target table entry. The step of selecting the entry with the lowest prediction difficulty for the branch situation represented by the multiple entries as the target entry includes: An entry with the lowest misprediction count value among the multiple entries is selected as the target entry.

14. The method according to claim 2, further comprising: In response to reaching a preset time interval or continuous occurrence of target prediction result errors, the stable values ​​of all entries in the multiple label prediction tables are updated to the first value.

15. The method according to claim 2, further comprising: When replacing an entry in any of the multiple label prediction tables, in response to the existence of an entry whose stable value is the first value, a preset replacement algorithm is applied to the entry whose stable value is the first value, or in response to the absence of an entry whose stable value is the first value, the preset replacement algorithm is applied to all entries.

16. The method according to claim 1, wherein: The determining whether to apply for a new entry with a higher level than the target entry includes: Generate a random number within a preset interval; The random number is compared with a preset threshold, and in response to the random number being less than or equal to the preset threshold, a new entry with a higher level than the target entry is not applied for.

17. The method according to claim 1, wherein: The determining whether to apply for a new entry with a higher level than the target entry includes: In response to applying for a corresponding new entry in the previous judgment, no new entry with a higher level than the target entry is applied in this judgment.

18. The method of claim 1, further comprising: Whether the table entry is hit is determined based on the address of the branch instruction to be predicted and the global branch history.

19. The method according to claim 18, wherein: Each of the table entries also includes a tag value, and the determining whether a table entry is hit based on the address of the branch instruction to be predicted and the global branch history includes: For each of the plurality of label prediction tables, performing a first hash operation and a second hash operation based on an address of a branch instruction to be predicted and a global branch history to obtain a first hash result and a second hash result, wherein the first hash operation is different from the second hash operation; An entry in the tag prediction table is read according to the first hash result, and whether the entry is hit is determined based on the tag value of the entry and the second hash result.

20. A branch predictor comprising: A plurality of label prediction tables of different levels, wherein each table entry of each label prediction table in the plurality of label prediction tables comprises a prediction value representing a prediction result of the corresponding table entry; A prediction module, configured to obtain a target prediction result based on a prediction value of the target item in response to selecting the target item; The judgment module is configured to judge whether to apply for a new entry with a higher level than the target entry in response to the target prediction result being wrong.

21. A processor comprising a branch predictor according to claim 20.

22. An electronic device comprising the processor according to claim 21.

Citation Information

Patent Citations

  • Multi-tagged branch prediction table

    CN110741343A

  • New table item distribution method for TAGE branch predictor

    CN113703846A

  • Multi-level hybrid algorithm filtering type branch prediction method and prediction system

    CN114840258A

  • Branch prediction method, electronic equipment and readable storage medium

    CN117667214A

  • Branch prediction method and device based on speculation update, and storage medium

    CN118626149A

Cited By

  • New table item distribution method and device in branch instruction predictor, equipment and medium

    CN120010927A

  • Branch prediction table updating method, terminal device and computer program product

    CN121387918A