Branch prediction method, branch predictor, processor and electronic device
By introducing a stable value judgment mechanism into the branch predictor, the problem of unreasonable table entry allocation in the traditional TAGE branch predictor is solved, more efficient branch prediction is achieved, power consumption and performance loss are reduced, and prediction accuracy is improved.
Patent Information
- Application Number
- CN202411947376.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-10-14
- Estimated Expiration
- 2044-12-27
AI Technical Summary
Traditional TAGE branch predictors have problems with space waste and extra power consumption caused by unreasonable table entry allocation during branch prediction, and their reliance on high-level table entry requests reduces prediction accuracy.
By introducing a stable value judgment mechanism in the branch predictor, meaningless high-level table requests are avoided. A new table entry at a higher level is requested only when the prediction is wrong and the target table entry is unstable. The target table entry is selected by the stable value to improve the prediction accuracy.
It reduces invalid high-table applications, reduces power consumption and performance loss, improves the accuracy and reliability of branch prediction, and avoids the additional overhead caused by randomness.
Smart Images

Figure CN119781833B_ABST
Abstract
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 increasing instruction-level parallelism through pipelining. A processor core includes multiple pipeline stages, such as branch prediction, instruction fetch, instruction decode, dispatch and rename, execute, and retire. To support high operating frequencies, each pipeline stage may contain multiple pipeline stages. Each pipeline stage performs a limited number of operations, minimizing the need for each clock cycle. This improves core performance by increasing the processor's operating frequency. Each pipeline stage can also accommodate more instructions, further enhancing processor performance. 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 multiple label prediction tables of different levels, each table entry in each label prediction table of the multiple 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 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 entries 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 the unstable state, and the stable value is a second value indicating that it is in the stable state, and the selected target table entry includes: 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.
[0005] For example, in the method provided by at least one embodiment of the present disclosure, the selecting of 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 table entry with a higher level than the target table entry includes: in response to the stable value of the target table entry being the second value, not applying for a new table entry with a higher level than the target table entry.
[0007] 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 existence of an entry in the multiple table entries whose stable value is the second value, selecting the table entry with the stable value of the second value as the target table entry.
[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. The selecting of the table entry with the lowest degree of difficulty in predicting 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 the target prediction result is obtained 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 table entry also includes the information entropy value, and the method further 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, updating 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] Wherein, 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 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 tag prediction tables, in response to the existence of an entry with a stable value of the first value, applying a preset replacement algorithm to the entry with a stable value of the first value, or in response to the absence of an entry with a stable value of the first value, applying the preset replacement algorithm to all entries.
[0020] For example, in the method provided in 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 in at least one embodiment of the present disclosure, the determination 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: determining 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 determining 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 determining 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 in each label prediction table of 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 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, rather than limiting the present disclosure.
[0028] Figure 1A 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 This 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 flowchart of a branch prediction method based on a branch predictor provided in at least one embodiment of the present disclosure;
[0034] Figure 4A A flowchart of a branch prediction method based on a branch predictor provided in at least one embodiment of the present disclosure;
[0035] Figure 4B A schematic diagram of a branch predictor provided by at least one embodiment of the present disclosure;
[0036] Figure 5 A schematic block diagram of a branch predictor provided in accordance with at least one embodiment of the present disclosure is provided.
[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 according to at least one embodiment of the present disclosure is provided. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions 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 or scientific terms used in this disclosure should have the usual meanings understood by persons of ordinary skill in the field to which this disclosure belongs. The words "first", "second" and similar terms used in this disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Words such as "include" or "comprise" mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Words such as "connect" or "connected" are not limited to physical or mechanical connections, but may 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 object being described changes, the relative positional relationship may also change accordingly.
[0041] The present disclosure is described below using several specific embodiments. To maintain clarity and conciseness in the following description of the embodiments of the present disclosure, detailed descriptions of known functions and components may be omitted. When any component of an embodiment of the present disclosure appears in more than one drawing, that 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 systems according to the embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, the various steps may be processed in reverse order or simultaneously, as needed. Furthermore, other operations may 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 instruction fetch unit, decoding unit, allocation unit, fixed-point execution unit, floating-point execution unit and 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 the fixed-point (register) renaming unit, arithmetic logic unit (ALU), address generation unit (AGU), ALU scheduling queue, AGU scheduling queue, fixed-point physical register stack, etc. The floating-point execution unit includes the floating-point (register) renaming unit, floating-point unit (FPU), FPU scheduling queue, floating-point physical register stack, etc.
[0049] The fixed-point rename unit and floating-point rename unit rename the source and destination registers before writing microinstructions to the dispatch queue. The ALU / AGU / FPU dispatch queue queues all received microinstructions and schedule them out of order, selecting executable microinstructions for issuance. The issued microinstructions read their source from the physical register file, and the corresponding execution unit (ALU, AGU, or FPU) executes the corresponding operation. The execution results of each execution unit are passed to the memory access unit.
[0050] The memory access unit receives microinstructions sent by the allocation unit, queues them, and schedules their execution. The memory access unit can read data from or write data to the L1 Data Cache.
[0051] Figure 1B Schematic diagram of a pipeline of a processor core, where the dotted line with an arrow represents a redirected instruction flow.
[0052] like Figure 1BAs shown, the processor core (e.g., CPU core) of a single-core or multi-core processor uses pipelining to increase inter-instruction parallelism. The processor core internally comprises multiple pipeline stages. For example, after the pipeline inputs program counters from various sources and a multiplexer (Mux) selects the next program counter (PC), the instruction corresponding to that PC undergoes branch prediction, instruction fetch, instruction decoding, instruction dispatch and renaming, instruction execution, and instruction termination. Waiting queues are set up between each pipeline stage as needed. These queues are typically first-in, first-out (FIFO) queues. For example, after the branch prediction unit, there is a branch prediction (BP) FIFO queue to store branch prediction results; after the instruction fetch unit, there is an instruction cache (IC) FIFO to cache fetched instructions; after the instruction decode unit, there is a decode (DE) FIFO to cache decoded instructions; and after the instruction dispatch and renaming unit, there is a termination (RT) FIFO to cache instructions awaiting confirmation of completion 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 the instructions are distributed and renamed.
[0053] To support high operating frequencies, each pipeline stage may contain multiple pipeline stages (operation cycles), with each pipeline stage performing a limited number of operations to further improve the performance of the processor core. Although each pipeline stage performs a limited number of operations, this allows each clock cycle to be kept to a minimum, thereby improving the performance of the CPU core by increasing the CPU's operating frequency. 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 a single cycle. Processors with increased instruction-level parallelism and the ability to process multiple instructions within a single cycle are called superscalar processors. Superscalar processors add additional resources to conventional scalar processors, creating multiple pipelines, each of which executes its assigned instructions to achieve parallelism.
[0054] Branch prediction is an important component of a high-performance, multi-pipeline processor core. It predicts the execution path of conditional branch instructions in the program, allowing the processor to prefetch 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-pipeline CPU core does not have branch prediction, it must wait until each branch instruction is executed before knowing which instruction to jump to. This 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 very front end of the processor core pipeline, continuously predicting the start and end addresses of the next instruction based on the results of the previous branch prediction. When a branch prediction error is detected in a later pipeline stage (such as after instruction decoding or execution), all instructions younger than the mispredicted branch instruction in the pipeline are cleared, known as a pipeline flush. The branch predictor then continues to predict the instruction stream from that point and fills the pipeline.
[0055] Branch prediction involves three steps: identifying whether the instruction currently fetched is a branch instruction; if so, determining whether it is a conditional branch instruction; and if so, determining the target address. The target address of a conditional branch instruction is typically fixed during program execution, determined at program compile time.
[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 BTB 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 of the branch instruction from the BTB 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] A branch prediction method based on a 2-bit saturating counter is a branch prediction technique widely used in modern processors. This prediction method adjusts its prediction direction by tracking the historical behavior of each branch instruction, thereby improving prediction accuracy. For branch instructions, there are only two directions: a jump occurs (taken) and a jump does not occur (not taken). Each branch instruction is associated with a 2-bit saturating counter. This counter has four states, corresponding to four different prediction tendencies:
[0059] (1) Strongly taken: The counter is at its maximum value (saturated state), indicating that the branch instruction almost always jumps in the past executions. It is predicted that a jump will occur this time, and the code 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 saturating 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 that 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 that 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 that 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 that 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 saturating counter relies only 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. 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 can be adopted. The Global History Register (GHR) is a register with a variable bit width that is used to record the execution results of all branch instructions in the recent period, 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 global history-based branch prediction.
[0066] The Tagged Geometric History Length (TAGE) branch predictor is a typical global history-based branch predictor. History refers to the execution of branch instructions (whether a branch instruction jumps or not) during runtime. The TAGE branch predictor is a global predictor consisting of a base prediction table and multiple tag prediction tables. For different tag prediction tables, branch history sequences of varying lengths in the global branch history can be used for index calculation. This allows the TAGE branch predictor to simultaneously predict a branch instruction based on branch history sequences of varying lengths. It also evaluates the accuracy of the branch instruction under each branch history sequence, selecting the one with the highest historical accuracy as the final branch prediction criterion.
[0067] Figure 2 A schematic diagram of a TAGE branch predictor.
[0068] TAGE branch predictors generally include a base prediction table and multiple tag prediction tables at 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 is directly indexed using the address of the branch instruction to be predicted (program counter value, hereinafter referred to as PC value), 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 (GBH) to index table entries, allowing prediction tables of each level to capture historical patterns of different lengths. Lower-level label prediction tables (such as T1) correspond to shorter branch history sequences, and higher-level label prediction tables (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 exponentially. 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 tag 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 predicted value pred, a tag value tag, and a valid value u.
[0073] For example, Figure 2 As shown, the predicted value pred is realized 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 the first hash operation (Hash2 in [1]) is used to confirm whether the indexed table entry corresponds to the branch instruction currently being 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 should be different.
[0075] For example, Figure 2 As shown, the effective value u is implemented by a 2-bit counter and indicates 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 values u are replaced first.
[0076] Use as Figure 2The TAGE branch predictor performs branch prediction as follows: For the tag prediction table Ti, a first hash operation is performed on the PC value and h[0:L(i)] to obtain an index. The entry in the tag prediction table Ti is read based on the index, and the tag value tag is used to determine whether the entry is hit. When multiple entries in the tag prediction table are hit, the predicted value pred of the entry with the largest L(i) (i.e., the entry in the highest-level tag prediction table) 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 different from the prediction results of other hit entries, the effective value u of the 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 incorrect) and different from the prediction results of other hit entries, the effective value u of the entry giving the target prediction result is decremented by 1, thereby making it easier for entries with low prediction accuracy to be replaced. Furthermore, when a prediction is incorrect, if the label prediction table that gives the target prediction result is not the highest-level label prediction table (T4), a new entry must be allocated in a higher-level label prediction table. When no entry in any label prediction table matches, the target prediction result is given by the saturation counter in the entry of the T0 table.
[0077] However, the inventors of the present disclosure 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 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, it not only takes up the valuable space of the high-level label prediction table and reduces the prediction accuracy of other branches, but also causes the current branch to use the wrong table entry, further reducing the prediction accuracy of the current branch. In addition, frequent requests 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 have 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 allocation probability of new table entries when the TAGE branch predictor mispredicts, thereby reducing the probability of the cold counter problem and improving 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 provider's prediction result 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 as the total number of tag prediction tables increases; 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 so, no operation is performed. Among them, the allocation throttling function is:
[0082]
[0083] If the prediction result of the 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 high overhead and non-randomness in hardware implementation, and cannot guarantee the accurate execution of functions;
[0087] 2. The allocation throttling function used by this solution to suppress TAGE table entry applications needs to traverse all table entries, which greatly increases 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 the 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; and 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 at a higher level, thereby avoiding meaningless application of a higher table (a higher-level tag prediction table). This can reduce, for example, the performance loss caused by a traditional TAGE branch predictor using only the prediction results of the higher table and the additional power consumption caused by applying for the higher 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 to 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 omitted here. In another example, the predicted 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 predicted 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 predicted 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 in accordance with 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 entry, a target prediction result is obtained based on a prediction value of the target entry.
[0095] Step S102: In response to the target prediction result being wrong, 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 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. 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, after the processor executes the branch instruction to be predicted 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 at 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 the label prediction table T1, if a branch prediction error has occurred in the target table entry, it is necessary to determine whether to apply for a new table entry in the 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 at a higher level than the target table entry" is equivalent to "applying for a new table entry in a label prediction table at a higher level."
[0098] Unlike a traditional TAGE branch predictor that requests a high table every time it makes a prediction error, the branch prediction method provided by the embodiment of the present disclosure first determines 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 above-mentioned first value and 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, that is, it 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, selecting a target entry from the multiple entries based on a stable value of each of the multiple entries.
[0102] In 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 steps S201 and S202 above, the corresponding strategies differ depending on whether a single entry is hit or multiple entries are hit. When only a single entry is hit, the hit single entry is directly selected as the target entry; when multiple entries are hit, the target entry can be selected from the multiple hit entries by comparing the stable values of each of the multiple hit entries.
[0105] When multiple table entries are hit, the branch prediction method provided by the disclosed embodiments selects the target table entry for outputting the prediction result based on the stable value of the table entry, effectively reducing the performance loss caused by traditional TAGE branch predictors that only use the prediction results of the high-order table. Furthermore, this branch prediction method avoids the problems caused by randomness and enhances the reliability of the prediction results. It also eliminates the 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: determining 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, and 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 further includes a label value. An example of the above step S103 may include the following steps S1031 and S1032.
[0110] Step S1031: For each label prediction table in the 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.
[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 steps S1031 and S1032, label prediction tables at different levels use branch history sequences of different lengths in the global branch history to index table entries, thereby allowing prediction tables at each level to capture history patterns of different lengths. Lower-level label prediction tables correspond to shorter branch history sequences, while higher-level label prediction tables correspond 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 branch history sequence length corresponding to different level label prediction tables can also be set in other ways according to actual needs. The embodiment of the present disclosure does not limit this.
[0117] For example, the tag 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 a hit, the PC value and the branch history sequence of the corresponding length need to be subjected to a second hash operation to obtain a second hash result. Therefore, by determining whether the tag value and the second hash result are equal, it can be confirmed whether the indexed table entry corresponds to the branch instruction currently being predicted (i.e., whether the table entry is a hit). If the tag value and the second hash result are equal, the table entry is hit; if they are not equal, the table entry is missed.
[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, the "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, a determination is made based on the stable value of the target entry whether to apply for a new entry of a higher level than the target entry. When the stable value of the target entry is the second value (i.e., the target entry is in a stable state), no new entry of a higher level than the target entry is applied for, i.e., no new entry is applied for in a higher-level tag prediction table. Conversely, when the stable value of the target entry is the first value (i.e., the target entry is in an unstable state), a new entry of a higher level than the target entry is applied for, i.e., a new entry is applied for in a higher-level tag prediction table. It should be noted that if the target entry is in the highest-level tag prediction table among multiple tag prediction tables, even if the stable value of the target entry is the first value, no new entry of a higher level than the target entry is applied for. As the total number of tag prediction tables changes, the highest level will also change accordingly. For example, if the branch predictor includes three tag prediction tables, the third level is the highest level; if the branch predictor includes four tag prediction tables, the fourth level is the highest level.
[0122] The branch prediction method provided by the above embodiments of the present disclosure determines whether it is necessary to apply for a high table based on the stable value of the target table entry 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 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 numerical range, which can be set according to actual needs, such as [0, 1], which is not limited in the embodiment of the present disclosure. 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 a 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 requested. If the random number is greater than the preset threshold, a new entry with a higher level than the target entry is requested. For example, the preset threshold can be selected based on the size of a 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 requested.
[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 for in this judgment.
[0130] For example, in step S1024, a state variable can be introduced to record whether the corresponding new entry was applied in the previous judgment. The state variable can be a Boolean value. For example, before each judgment, the state variable is checked. Based on the value of the state variable, whether a new entry was applied in the previous judgment is determined, thereby determining whether a new entry is applied in the current judgment. After each judgment, the state variable needs to be updated to reflect the latest entry application status.
[0131] The branch prediction method provided by the above embodiments of the present disclosure can suppress high table application based on a random number mechanism or interval application method when prediction errors occur, and does not need to apply a high table every time a prediction error occurs, thereby avoiding meaningless high table application and reducing the additional power consumption caused by high table application of a traditional TAGE branch predictor.
[0132] In some examples, the step S201 can include the following step S2011.
[0133] The step S2011: in response to the existence of the table item with the second value in the multiple table items, selecting the table item with the second value as the target table item.
[0134] In some examples, the step S201 can include the following step S2012.
[0135] The step S2012: in response to the non-existence of the table item with the second value in the multiple table items, selecting the table item with the lowest prediction difficulty level of the branch case represented by the multiple table items as the target table item.
[0136] For example, in the step S2011 and the step S2012, it is judged whether the multiple hit table items exist the table item with the second value, that is, whether the table item in the stable state exists. If it exists, the table item in the stable state is selected as the target table item; if it does not exist, the table item with the lowest prediction difficulty level of the branch case represented by the multiple table items is selected as the target table item. It should be noted that if there are multiple table items with the lowest prediction difficulty level, that is, the prediction difficulty levels of the table items are the same, the table item with the highest level can be selected as the target table item.
[0137] For example, the prediction difficulty level can be described by indexes such as information entropy, prediction accuracy, and misprediction times of the table item, and other different indexes can also be used, and the embodiments of the present disclosure are not limited thereto.
[0138] In some examples, after the step S2012 of “selecting the table item with the lowest prediction difficulty level of the branch case represented by the multiple table items as the target table item”, the branch prediction method provided by at least one embodiment of the present disclosure further includes the following step S2013.
[0139] The step S2013: in response to the target table item not being located in the highest level label prediction table in the multiple label prediction tables, setting the stable value of the target table item as the second value.
[0140] For example, in step S2013, the target table entry is the table entry whose prediction difficulty of branch condition represented is the lowest among the multiple hit 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 as the second value. For example, assuming that the branch predictor includes four label prediction tables T1-T4, and the label prediction table T4 is the highest level, if the target table entry is not located in the label prediction table T4, that is, if the target table entry is located in the label prediction table T1, T2 or T3, the stable value of the target table entry is set as the second value.
[0141] In some examples, when the information entropy of a table entry is used to describe the prediction difficulty of the branch condition represented by the table entry, each table entry further includes information entropy information, which is used to obtain an information entropy value representing the prediction difficulty of the branch condition represented by the corresponding table entry. For example, the lower the information entropy value, the easier the branch is to be predicted, and the higher the information entropy value, the more difficult the branch is to be predicted.
[0142] Correspondingly, an example of the step S2012 “selecting the table entry whose prediction difficulty of branch condition represented is the lowest among the multiple table entries as the target table entry” can be: selecting the table entry whose information entropy value obtained according to the information entropy information is the lowest among the multiple table entries as the target table entry.
[0143] It should be noted that if there are multiple table entries whose information entropy values are the lowest, the table entry with the highest level is selected as the target table 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 that the corresponding table entry is hit and selected as the target table entry, and the jump count value records the number of times that the actual branch result is 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 a counter respectively. When a new table entry is applied, the access count value and the jump count value of the new table entry are initialized to 0.
[0146] Correspondingly, after the step S101 “obtaining the target prediction result based on the prediction value of the target table entry”, the branch prediction method provided by at least one embodiment of the present disclosure further includes the following steps S301-S303.
[0147] Step S301: increasing the access count value of the target table entry by 1.
[0148] Step S302: in response to the target prediction result being wrong and the target prediction result being not jump, increasing the jump count value of the target table entry 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 entry also includes an information entropy value. The branch prediction method provided by at least one embodiment of the present disclosure further 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 specifically 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 do not limit this.
[0159] For example, in hardware implementation, the calculation of the logarithmic function can use Taylor expansion or lookup table (LUT, LookupTable) in two ways.
[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 integer parts, which can be specifically achieved by a bit-by-bit XOR method.
[0163] For example, a lookup table is an efficient hardware implementation. , a series of The corresponding results of the values are stored in a table. When calculation is needed, you only need to look up the table to get the approximate result.
[0164] The advantages of the above two methods are that they do not require complex mathematical operations, rely only on bit operations, and are suitable for hardware implementation.
[0165] In some examples, when describing the difficulty of predicting a branch represented by an entry using its prediction accuracy, each entry also includes an accuracy value, which indicates the accuracy of the prediction result when the corresponding entry is hit and selected as the target entry. For example, a higher accuracy value indicates an easier branch to predict, while a lower accuracy value indicates a more difficult branch to predict.
[0166] For example, each table entry can 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 for 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 difficulty of predicting a branch represented by an entry using the number of mispredictions, each entry also includes a misprediction count value, which indicates the number of incorrect predictions when the corresponding entry is hit and selected as the target entry. For example, a lower misprediction count value indicates an easier-to-predict branch, while a higher misprediction count value indicates a harder-to-predict branch.
[0172] For example, the misprediction count value may be implemented by a counter. For example, when applying for a new entry, the misprediction count value is initialized to 0.
[0173] Correspondingly, an example of the step S2012 of selecting the table item with the lowest prediction difficulty from the branch cases represented by the plurality of table items as the target table item can be selecting the table item with the lowest misprediction count value from the plurality of table items as the target table item.
[0174] It should be noted that if there are multiple table items with the lowest misprediction count value, the table item with the highest level is selected as the target table item.
[0175] In some examples, the branch prediction method provided by at least one embodiment of the present disclosure can further include the following step S104.
[0176] Step S104: updating the stability values of all table items in the plurality of label prediction tables to the first value in response to reaching a preset time interval or consecutive target prediction result errors.
[0177] For example, in step S104, according to the description of the above-mentioned embodiments, when the stability value of the target table item is the second value, it indicates that the target table item is in a stable state, and at this time, even if the target table item prediction is wrong, it does not apply a high table, thereby realizing the function of application suppression. However, since branch prediction has uncertainty, the table item 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 consecutively, it is necessary to reinitialize the stability value information of all table items, that is, to update it to the first value, so as to more accurately predict in the future and reduce the performance loss caused by misprediction. For example, the preset time interval can be set according to actual needs, for example, a number of clock cycles, and the embodiments of the present disclosure do not limit this. For example, the consecutive target prediction result errors can be consecutive multiple target prediction result errors, and the specific number of times can be set according to actual needs, and the embodiments of the present disclosure do not limit this.
[0178] For example, the above-mentioned step S104 can be executed in parallel with the other steps described above, so as to update the stability value of the table item in time.
[0179] The branch prediction method provided by the above-mentioned embodiments of the present disclosure avoids continuous prediction errors by setting a stability value update strategy, reduces the performance loss caused by misprediction, and improves the prediction accuracy.
[0180] In some examples, the branch prediction method provided by at least one embodiment of the present disclosure can further include the following step S105.
[0181] Step S105: When performing entry replacement on any of the plurality of label prediction tables, in response to the presence of an entry with the stable value being the first value, applying the preset replacement algorithm to the entry with the stable value being the first value, or in response to the absence of an entry with the stable value being the first value, applying the preset replacement algorithm to all entries.
[0182] For example, the capacity of each label prediction table is fixed, such as being able to accommodate 1024 entries. As branch prediction is continuously performed, the label prediction table continuously allocates new entries until it reaches its maximum capacity. When a certain label prediction table is filled, entry replacement needs to be performed, that is, some existing entries are removed to make room for subsequent newly allocated entries. For example, the preset replacement algorithm can be a Least Recently Used (LRU), Least Frequently Used (LFU), Not Frequently Used (NFU), etc. replacement algorithm, which can be selected according to actual needs, and the present disclosure does not limit this.
[0183] For example, when performing entry replacement on a certain label prediction table, the entries with the stable value being the first value (i.e., in the unstable state) are preferentially replaced, that is, the preset replacement algorithm is applied to the entries with the stable value being the first value. If there is no entry with the stable value being the first value in the label prediction table, that is, all entries in the label prediction table are in the stable state, the preset replacement algorithm is applied to all entries in the label prediction table.
[0184] The branch prediction method provided by the above-mentioned embodiments of the present disclosure sets the 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 provided by at least one embodiment of the present disclosure. Figure 4A A specific example of the branch prediction method shown in Figure 3
[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 in Figure 4B The branch prediction method shown in Figure 4B As shown, the branch predictor comprises a base prediction table T0 and four tag prediction tables T1~T4 of different levels, each table entry of each tag prediction table comprises a prediction value pred, a tag value tag, a stable value stable, an access count value access, a taken count value taken and an information entropy value informationentropy. The description of other parts of the branch predictor provided in the embodiments of the present disclosure can refer to the description of the TAGE branch predictor in the embodiments of the present disclosure. Figure 2
[0187] For example, as shown in Figure 4A The branch prediction method based on the branch predictor provided by at least one embodiment of the present disclosure comprises the following steps S501~S530.
[0188] Step S501: judging 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, step S502 is executed; if multiple table entries are hit, step S514 is jumped to. The specific description of step S501 can refer to step S103 in the above embodiments, and will not be repeated here.
[0189] Step S502: in response to the single table entry being hit, taking the hit single table entry as a target table entry, obtaining a target prediction result based on the prediction value of the target table entry. The specific description of step S502 can refer to steps S101 and S202 in the above embodiments, and will not be repeated here.
[0190] Step S503: adding 1 to the access count value of the target table entry. The specific description of step S503 can refer to step S301 in the above embodiments, and will not be repeated here.
[0191] Step S504: judging whether the target prediction result is correct. If yes, step S505 is executed; if no, step S507 is jumped to. For example, whether the target prediction result is correct can be judged by comparing the actual branch result and the target prediction result.
[0192] Step S505: judging whether the target prediction result is a jump. If yes, step S506 is executed; if no, step S507 is jumped to.
[0193] Step S506: in response to the target prediction result being correct and the target prediction result being a jump, adding 1 to the taken count value taken of the target table entry. The specific description of step S506 can refer to step S303 in the above embodiments, and will not be repeated here.
[0194] Step S507: Update the information entropy value of the target entry based on the access count and jump count of the target entry, and this round of branch prediction ends. For a detailed description of step S507, please refer to step S304 in the above embodiment and will not be repeated here.
[0195] Step S508: Determine whether the target prediction result is a jump. If so, jump to step S510; if not, 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. The detailed description of step S509 can be referred to step S302 in the above embodiment and will not be repeated here.
[0197] Step S510: Update the information entropy value of the target entry based on the access count value and 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 repeated 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. Detailed descriptions of steps S512 and S513 can be found in the description of step S1021 in the above embodiment and are not 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 among the multiple entries, the entry with the 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 can be made to the description of step S2011 in the above embodiment and is not repeated here.
[0203] Step S516: In response to the absence of an entry with a stable value equal to the second value among the multiple entries, the entry with the lowest information entropy value among the multiple entries is selected as the target entry, and a target prediction result is obtained based on the prediction value of the target entry. If multiple entries with the lowest information entropy values exist, the entry with the highest ranking is selected as the target entry. For a detailed description of step S516, reference can be made to the description of step S2012 in the above embodiment and is not repeated here.
[0204] Step S517: Determine whether the target entry is in the highest level tag prediction table. If so, jump to step S519; if not, execute step S518. Figure 4B As for the branch predictor shown in FIG, the highest level label prediction table is label prediction table T4. It should be noted that, Figure 4B As just one example, the 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 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 and will not be repeated here.
[0206] Step S519: Increment the access count value of the target entry by 1. For a detailed description of step S519, reference may be made to the description of step S301 in the above embodiment, and 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 so, execute step S522; if not, jump to step S523.
[0209] Step S522: In response to the target prediction result being correct and being a jump, the jump count value of the target entry is increased by 1. The detailed description of step S522 can be found in the description of step S303 in the above embodiment and will not be repeated here.
[0210] Step S523: Update the information entropy value of the target entry based on the access count and jump count of the target entry, and this round of branch prediction ends. For a detailed description of step S523, please refer to step S304 in the above embodiment and will not be repeated here.
[0211] Step S524: judging 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, incrementing the jump count value of the target entry by 1. For detailed description of step S525, refer to the description of step S302 in the above embodiment, which will not be repeated here.
[0213] Step S526: updating the information entropy value of the target entry based on the access count value and the jump count value of the target entry. For detailed description of step S526, refer to the description of step S304 in the above embodiment, which will not be repeated here.
[0214] Step S527: judging whether the stability value of the target entry is 1. If yes, jump to step S530; if no, execute step S528.
[0215] Step S528: judging whether the target entry is located in the highest level label prediction table. If yes, jump to step S530; if no, execute step S529.
[0216] Step S529: in response to the stability value of the target entry being 0 and the target entry not being located in the highest level label prediction table, applying a new entry of a higher level than the target entry, and the current round of branch prediction ends.
[0217] Step S530: in response to the stability value of the target entry being 1, or in response to the stability value of the target entry being 0 and the target entry being located in the highest level label prediction table, not applying a new entry of a higher level than the target entry, and the current round of branch prediction ends. For detailed description of step S529 and step S530, refer to the description of step S1021 in the above embodiment, which will not be repeated here.
[0218] Referring to Figure 4A and Figure 4B , the principle of the branch prediction method based on the branch predictor provided in 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 entry is applied and allocated in the basic prediction table T0, and subsequent prediction is performed based on the entry in the basic prediction table T0. When a branch prediction error occurs again, a new entry is applied and allocated in the label prediction table T1, the information entropy value, the access count value, the jump count value and the stability value are initialized to 0, and subsequent prediction is performed based on the entry in the label prediction table T1. When the entry is hit subsequently, there are two cases:
[0220] 1. Obtain a 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 and jump count values.
[0221] 2. Obtain the target prediction result based on the prediction value of the table entry. If the target prediction result is incorrect, 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 and jump count values. At the same time, apply for allocation of a new table entry in the tag prediction table T2, and initialize the information entropy value, access count value, jump count value, and stable value to 0.
[0222] When branch prediction is required for the branch instruction again, entries in both label prediction tables T1 and T2 are hit simultaneously. The prediction value of the entry with a stable value of 1 is prioritized as the target prediction result. If no entry with a stable value of 1 exists, the prediction value of the entry with the lower entropy is selected as the target prediction result. Since label prediction table T2 has just been allocated, its entry entropy is 0, which is necessarily lower than the entropy of the entry in label prediction table T1. Therefore, the entry in label prediction table T2 is selected as the target entry. The above process is repeated based on the hit count, updating the entropy of the entry in label prediction table T2. When the 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. The stable value of the entry in T1 is set to 1, indicating that the current branch has the best prediction accuracy given the current branch history length. Using a higher-level entry will only reduce branch prediction accuracy. When the stable value of an entry is 1, even if a prediction error occurs, no new entry in a higher-level label prediction table is requested.
[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, the branch predictor 600 provided by at least one embodiment of the present disclosure includes a plurality of tag prediction tables 601 of different levels, a prediction module 602 and a judgment module 603 .
[0224] For example, in some examples, each entry in each tag prediction table in the plurality of tag prediction tables 601 includes a prediction value representing a prediction result of the corresponding entry.
[0225] For example, in some examples, the prediction module 602 is configured to, in response to selecting the target table item, obtain a target prediction result based on the prediction value of 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 details about the prediction module 602 and the judgment module 603, please refer to the embodiment of the above branch prediction method. Figure 3 The description of step S101 and step S102 is omitted 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, use 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 with a stable value of the second value as the target entry in response to the presence of an entry with a stable value of 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 among 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 the highest-level label prediction table among the multiple label prediction tables.
[0234] For example, in at least one embodiment of the present disclosure, each table entry also includes information entropy information, which 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 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 add 1 to the access count value of the target table entry after obtaining the target prediction result based on the prediction value of the target table entry; add 1 to the jump count value of the target table entry in response to the target prediction result being wrong and the target prediction result being no jump; and add 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.
[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 to:
[0238]
[0239] Where 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. 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 multiple table entries as the target table entry.
[0242] For example, in at least one embodiment of the present disclosure, the branch predictor further includes an update module, which is configured to update the stable values of all entries in the plurality of tag 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 the 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 table entry with a higher level than the target table 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, which 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 a 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 is not limited thereto. For example, the branch predictor 701 may be the branch predictor provided in any of the above-mentioned embodiments.
[0250] For example, in at least one example, the processor 700 may include, in addition to the branch predictor 701, 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); 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 one of the above embodiments. Figure 7 A schematic block diagram of an electronic device according to at least one embodiment of the present disclosure is provided.
[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 (such as 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 limit the functions and scope of use of the embodiments of the present disclosure.
[0253] For example, Figure 7 As shown, in some examples, electronic device 900 includes a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901. This processing device may include a processor according to any of the above-described embodiments. It can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 902 or programs loaded from a storage device 908 into a random access memory (RAM) 903. RAM 903 also stores various programs and data required for the operation of the computer system. 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 bus 904.
[0254] For example, the following components can 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 can also include, for example, a network interface card such as a LAN card, a modem, etc. The communication device 909 can allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data, and perform 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 can be installed into the storage device 908 as needed. Although Figure 7 The electronic device 900 is shown as including 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 via wireless communication, such as the Internet, an intranet, and / or a wireless network such as a cellular telephone network, a wireless local area network (LAN), and / or a metropolitan area network (MAN). Wireless communications may use any of a variety of communication standards, protocols, and technologies, 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, tablet computer, laptop computer, e-book, game console, television, digital photo frame, navigator, 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 present disclosure has been described in detail with particular references to specific embodiments thereof, it should be understood by the skilled in the art that a variety of changes in form and details can be made to the embodiments without departing from the spirit and scope of the present disclosure. Therefore, the scope of the present disclosure should not be limited to the specific embodiments described above.
[0258] In addition, although each operation is described in a particular order, this should not be understood as requiring the operations to be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing can be advantageous. Similarly, although several implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments can also be combined in a single embodiment. Conversely, various features described in the context of a single embodiment can also be implemented separately or in any suitable subcombination.
[0259] For the present disclosure, the following points need to be explained:
[0260] (1) The drawings of the embodiments of the present disclosure only involve the structures involved in the embodiments of the present disclosure, and other structures can refer to the general design.
[0261] (2) In order to be clear, the thickness of the layer or region is enlarged or reduced in the drawings used to describe the embodiments of the present disclosure, that is, the drawings are not drawn according to the actual proportion.
[0262] (3) In the case of no conflict, the embodiments of the present disclosure and the features in the embodiments can be combined to obtain new embodiments.
[0263] The above is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto, and the protection scope of the present disclosure should be subject to 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 in each label prediction table of 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 entry, obtaining a target prediction result based on a prediction value of the target entry; In response to the target prediction result being wrong, determining whether to apply for a new entry with a higher level than the target entry, Each of the table entries further includes a stability value indicating whether the corresponding table entry is in a stable state or an unstable state, wherein the first value of the stability value indicates that the corresponding table entry is in the unstable state, and the second value of the stability value indicates that the corresponding table entry is in the stable state. The selected target table item includes: In response to hitting a single entry in the plurality of tag prediction tables, taking the hit single entry as the target entry; or 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, Wherein, in response to hitting multiple entries in the multiple tag prediction tables, selecting the target entry from the multiple entries based on the 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.
2. 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 the stable value of the target entry being the second value, no new entry with a higher level than the target entry is applied for.
3. The method according to claim 1, wherein In response to hitting multiple entries in the multiple tag prediction tables, selecting the target entry from the multiple entries based on the stable value of each entry in the multiple entries further includes: In response to the absence of an entry with a stable value of the second value among the multiple entries, an entry with the lowest prediction difficulty for the branch situation represented by the multiple entries is selected as the target entry.
4. The method according to claim 3, wherein: After selecting the entry with the lowest prediction difficulty for 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.
5. The method according to claim 3, 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: An entry with the lowest information entropy value obtained according to the information entropy information among the multiple entries is selected as the target entry.
6. The method according to claim 5, wherein: The information entropy information of each entry includes an access count value and a jump count value. The access count value records the number of times the corresponding entry is hit and selected as the target entry, and the jump count value records the number of times the actual branch result is a jump when the corresponding entry is hit and selected as the target entry. After obtaining a target prediction result based on the prediction value of the target entry, the method further includes: Increasing the access count value of the target entry by 1; In response to the target prediction result being wrong and the target prediction result being not to jump, increasing 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, the jump count value of the target table entry is increased by 1.
7. The method according to claim 6, wherein: The information entropy information of each entry further 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.
8. The method according to claim 7, 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: Wherein, 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.
9. The method according to claim 3, wherein: Each of the table entries also includes an accuracy value, which indicates the accuracy of the prediction result when the corresponding table entry is hit and selected as the target table entry. The selecting, from the plurality of entries, an entry with the lowest prediction difficulty for the branch situation represented by the plurality of entries as the target entry includes: The entry with the highest accuracy value among the multiple entries is selected as the target entry.
10. The method according to claim 3, wherein: Each of the table entries further 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 selecting, from the plurality of entries, an entry with the lowest prediction difficulty for the branch situation represented by the plurality of entries as the target entry includes: An entry with the lowest misprediction count value among the multiple entries is selected as the target entry.
11. The method according to claim 1 , further comprising: In response to reaching a preset time interval or continuously occurring target prediction result errors, the stable values of all entries in the multiple label prediction tables are updated to the first value.
12. The method according to claim 1, further comprising: When replacing an entry in any of the multiple tag prediction tables, in response to the existence of an entry with a stable value of the first value, a preset replacement algorithm is applied to the entry with a stable value of the first value, or in response to the absence of an entry with a stable value of the first value, the preset replacement algorithm is applied to all entries.
13. 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 range; 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.
14. 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 for in this judgment.
15. The method according to claim 1, further comprising: Determine whether a table entry is hit based on the address of the branch instruction to be predicted and the global branch history.
16. The method according to claim 15, wherein Each of the table entries further includes a tag value, and 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 the 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 a hit is determined based on the tag value of the entry and the second hash result.
17. 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 includes 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; A judgment module is configured to judge whether to apply for a new table entry with a higher level than the target table entry in response to the target prediction result being wrong, Each of the table entries further includes a stability value indicating whether the corresponding table entry is in a stable state or an unstable state, wherein the first value of the stability value indicates that the corresponding table entry is in the unstable state, and the second value of the stability value indicates that the corresponding table entry is in the stable state. The prediction module includes a selection unit, which is configured to: In response to hitting a single entry in the plurality of tag prediction tables, taking the hit single entry as the target entry; or 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, The selection unit is further configured to: in response to the presence of an entry whose stable value is the second value among the multiple entries, select the entry whose stable value is the second value as the target entry.
18. A processor comprising the branch predictor according to claim 17.
19. An electronic device comprising the processor according to claim 18.
Citation Information
Patent Citations
New table item distribution method for TAGE branch predictor
CN113703846A
Branch prediction method, electronic equipment and readable storage medium
CN117667214A