Branch prediction method and device, electronic equipment, storage medium and processor
By updating the low-bit address part of the instruction to be predicted and the multi-threaded shared branch target buffer in the branch prediction method, the problem of difficult to take into account the speed and accuracy of branch prediction in the prior art is solved, and more efficient branch prediction and larger capacity are achieved.
Patent Information
- Application Number
- CN202411639825.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-11-14
AI Technical Summary
While improving the accuracy of branch prediction, it is difficult to improve the speed of branch prediction, especially in multithreaded processors, where there are limitations on the capacity and efficiency of branch target buffers.
By obtaining the address information of the target to be predicted instruction, querying whether the address information hits the branch target buffer, and in response to hitting the low-bit address part of the address information of the target to be predicted instruction, multi-threaded shared branch target buffer is used to reduce the complexity and cost of hardware resources.
Improves the speed and accuracy of branch prediction, expands the capacity of branch target buffers, makes them compatible with more branch types, and improves the overall performance of the processor.
Smart Images

Figure CN119597351A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to a branch prediction method and apparatus, an electronic device, a storage medium, and a processor. Background Art
[0002] The development direction of high-performance commercial processors is to have faster and faster clock frequencies and deeper pipelines. The requirement for branch prediction (BP) is to improve the accuracy of branch prediction while also improving the speed of branch prediction. For example, a multi-level branch target buffer (BTB) structure can be used to implement branch prediction. Summary of the invention
[0003] At least one embodiment of the present disclosure provides a branch prediction method, which includes: obtaining address information of a target instruction to be predicted; querying whether the address information of the target instruction to be predicted hits a branch target buffer, wherein the branch target buffer includes multiple entries, each entry includes a first field and a second field, the first field is used to record an address tag, and the second field is used to record a target prediction address corresponding to the address tag; and in response to the address information of the target instruction to be predicted hitting a first entry of the branch target buffer, using the target prediction address in the first entry to update a low-order address portion of the address information of the target instruction to be predicted, so as to obtain an updated target address to be predicted, wherein the low-order address portion includes the lowest m bits of the address information of the target instruction to be predicted, and m is an integer greater than or equal to 1.
[0004] For example, the branch prediction method provided by at least one embodiment of the present disclosure further includes: in response to the address information of the target instruction to be predicted not hitting the branch target buffer, using the next sequential address of the target instruction to be predicted in the instruction sequence as the updated target address to be predicted.
[0005] For example, the branch prediction method provided by at least one embodiment of the present disclosure further includes: using the updated target address to be predicted to perform the next round of branch prediction operation.
[0006] For example, in the branch prediction method provided by at least one embodiment of the present disclosure, the address information includes an address identifier, the address identifier is the lowest n bits of the address information of the target instruction to be predicted, n is an integer greater than or equal to 1, and each entry also includes a third field for recording the validity of the corresponding entry; and querying whether the address information of the target instruction to be predicted hits the branch target buffer, including: in response to the address identifier of the target instruction to be predicted matching the address tag in the first entry, and the first entry is in a valid state, determining that the address information of the target instruction to be predicted hits the first entry of the branch target buffer.
[0007] For example, in the branch prediction method provided in at least one embodiment of the present disclosure, the branch target buffer is shared by multiple threads of a multi-threaded processor, and the multiple threads include at least a first thread and a second thread. Before obtaining the address information of the target instruction to be predicted, the branch prediction method also includes: selecting a first instruction to be predicted corresponding to the first thread or a second instruction to be predicted corresponding to the second thread as the target instruction to be predicted.
[0008] For example, the branch prediction method provided by at least one embodiment of the present disclosure also includes: in response to selecting the first instruction to be predicted corresponding to the first thread as the target instruction to be predicted and the address information of the first instruction to be predicted hits the first entry of the branch target buffer, using the target prediction address in the first entry to update the low-order address part of the address information of the first instruction to be predicted to obtain an updated target predicted address corresponding to the first instruction to be predicted.
[0009] For example, the branch prediction method provided by at least one embodiment of the present disclosure further includes: selecting to use the updated target address to be predicted of the first instruction to be predicted or the address information of the second instruction to be predicted to perform the next round of branch prediction operation.
[0010] For example, in the branch prediction method provided in at least one embodiment of the present disclosure, the branch target buffer is a multi-level branch target buffer, the multi-level branch target buffer includes at least a first-level branch target buffer and a second-level branch target buffer, and querying whether the address information of the target instruction to be predicted hits the branch target buffer includes: querying whether the address information of the target instruction to be predicted hits the first-level branch target buffer and / or the second-level branch target buffer.
[0011] At least one embodiment of the present disclosure also provides a branch prediction device, including: an acquisition module, configured to acquire address information of a target instruction to be predicted; a query module, including a branch target buffer, and configured to query whether the address information of the target instruction to be predicted hits the branch target buffer, wherein the branch target buffer includes multiple entries, each entry includes a first field and a second field, the first field is used to record an address tag, and the second field is used to record a target prediction address corresponding to the address tag; and an update module, configured to update a low-order address portion of the address information of the target instruction to be predicted using the target prediction address in the first entry in response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer, so as to obtain an updated target address to be predicted, wherein the low-order address portion includes the lowest m bits of the address information of the target instruction to be predicted, and m is an integer greater than or equal to 1.
[0012] For example, the branch prediction device provided by at least one embodiment of the present disclosure also includes a first multiplexer, which is coupled to the query module, the branch target buffer and the update module, and is configured to at least receive the next sequential address of the target instruction to be predicted in the instruction sequence, and read the target prediction address corresponding to the first entry hit during the query process from the branch target buffer; wherein the query module is also configured to generate a first control signal in response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer, so as to control the first multiplexer to output the target prediction address in the first entry to the update module.
[0013] For example, in the branch prediction device provided by at least one embodiment of the present disclosure, the query module is also configured to generate a second control signal in response to the address information of the target instruction to be predicted not hitting the branch target buffer, so as to control the first multiplexer to output the next sequential address of the target instruction to be predicted in the instruction sequence to the update module.
[0014] For example, in the branch prediction device provided in at least one embodiment of the present disclosure, the branch target buffer is shared by multiple threads of a multi-threaded processor, the multiple threads include at least a first thread and a second thread, and the branch prediction device also includes a second multiplexer, and the second multiplexer is configured to select a first to-be-predicted instruction corresponding to the first thread or a second to-be-predicted instruction corresponding to the second thread as the target to-be-predicted instruction.
[0015] At least one embodiment of the present disclosure also provides an electronic device, which includes at least one storage unit and at least one processing unit; wherein, at least one storage unit stores computer-readable instructions; at least one processing unit executes the computer-readable instructions stored in at least one storage unit to implement a branch prediction method provided in any of the above embodiments.
[0016] At least one embodiment of the present disclosure further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and when a processor executes the computer-readable instructions, a branch prediction method provided in any of the above embodiments is implemented.
[0017] At least one embodiment of the present disclosure further provides a processor, which includes the branch prediction device provided by any of the above embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure.
[0019] Figure 1A A flow chart of branch instruction jump prediction in a CPU pipeline;
[0020] Figure 1B A schematic diagram showing an exemplary method of using a three-level branch target buffer for branch prediction;
[0021] Figure 2 A schematic diagram showing an exemplary branch prediction based on a zero-delay branch target buffer is shown;
[0022] Figure 3 A branch prediction method provided by at least one embodiment of the present disclosure is shown;
[0023] Figure 4 A schematic diagram of performing branch prediction based on a zero-delay branch target buffer provided by at least one embodiment of the present disclosure is shown;
[0024] Figure 5 A schematic diagram showing a multi-threaded processor performing a branch prediction operation provided by at least one embodiment of the present disclosure is shown;
[0025] Figure 6 A schematic block diagram showing a branch prediction device provided by at least one embodiment of the present disclosure; and
[0026] Figure 7 A schematic block diagram of an electronic device provided by at least one embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0028] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, similar words such as "one", "one" or "the" do not indicate quantity restrictions, but indicate that there is at least one. Similar words such as "include" or "comprise" mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Similar words such as "connect" or "connected" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0029] The processor core (e.g., CPU core) of a single-core processor or a multi-core processor improves instruction level parallelism through pipeline technology. The processor core includes multiple pipeline stages. For example, after the pipeline feeds program counters from various sources and selects the next program counter (PC) through a multiplexer (Mux), the instruction corresponding to the program counter must go through branch prediction, instruction fetch, instruction decoding, instruction dispatch and rename, instruction execution, instruction termination, etc.
[0030] Branch prediction technology (BP technology) is a technology that predicts the branch jump instruction from the jump target position in advance. Based on the historical information of the instruction, it uses methods including but not limited to BTB (Branch Target Buffer) and TAGE (Tagged Geometric History Branch Predictor) for branch instruction prediction to predict the most likely jump position of the current branch instruction.
[0031] Figure 1A This is a flow chart of branch instruction jump prediction in a CPU pipeline. Figure 1AAs shown, the entire branch instruction jump prediction process is divided into the frontend and the backend. In the backend, a series of steps including instruction decoding, instruction caching, instruction distribution, instruction execution and data write-back are performed in sequence, and information such as historical jump results of instructions are collected and sent to the branch prediction unit (Branch Prediction Unit, BPU) of the front end. The BPU predicts the most likely jump position of the current branch in advance through the historical branch instruction jump information, and then sends the prediction result to the branch target queue (Fetch Target Queue, FTQ) in the backend for temporary storage, and then sends the prediction result to the instruction fetch unit (Instruction Fetch Unit, IFU). The IFU starts to fetch instructions from the memory or cache according to the predicted instruction fetch position in the branch target queue and passes them backward to avoid blocking of the CPU pipeline.
[0032] The function of the branch prediction unit (BPU) is to perform target address prediction for branch instructions, but there is a certain probability of prediction error; the branch target queue (FTQ) is a buffer queue between the BPU and the IFU, which is used to temporarily store the instruction fetch targets predicted by the branch prediction unit and send instruction fetch requests to the instruction fetch unit based on these instruction fetch targets; the instruction fetch unit (IFU) is used to read instruction data from the memory or cache and pass it backward for decoding and other operations on the read instructions.
[0033] As previously mentioned, the branch target buffer (BTB) may use a multi-level branch target buffer structure to implement branch prediction.
[0034] Figure 1B A schematic diagram showing an exemplary implementation of a three-level branch target buffer for branch prediction is shown.
[0035] like Figure 1BAs shown, the three-level branch target buffer includes a zero-delay branch target buffer (ZBTB), a first-level branch target buffer (L1BTB) and a second-level branch target buffer (L2BTB). The capacity of ZBTB is relatively small, and it is used to store branch instructions that appear more frequently and their corresponding target prediction addresses. The prediction delay of ZBTB is 0 clock cycles, that is, the branch prediction operation can be completed in the current clock cycle. The capacity of L1BTB is greater than that of ZBTB, and the prediction delay of L1BTB is usually 1 to 2 clock cycles. The capacity of L2BTB is very large. For example, a static random access memory (SRAM) can generally be used, and the prediction delay of L2BTB is usually 3 to 4 clock cycles. L1BTB and L2BTB are generally used to store branch instructions that appear less frequently and their corresponding target prediction addresses. The "target prediction address" here is the address of the instruction corresponding to the branch process executed in the historical execution process of the branch instruction.
[0036] like Figure 1B As shown, when performing a branch prediction operation, the address information of the target instruction to be predicted (i.e., the branch instruction) is first input into the multi-level BTB, and the address information of the target instruction to be predicted is queried whether it hits the ZBTB, L1ZBTB, or L2BTB. When querying whether the ZBTB is hit, the "address information" may be the linear address of the target instruction to be predicted or at least part of the linear address. When querying whether the L1ZBTB or L2BTB is hit, the "address information" may be the hash value ( Figure 1B If the address information hits the ZBTB, L1ZBTB or L2BTB, the corresponding target prediction address is read from the hit ZBTB, L1ZBTB or L2BTB (for example, Figure 1B The "ZBTB Target", "L1BTB Target" or "L2BTB Target" in the instruction sequence is used to update the address information (e.g., linear address) of the target instruction to be predicted, and obtain the updated target address to be predicted. If all levels of BTB do not hit, the next sequential address of the target instruction to be predicted in the instruction sequence is used as the updated target address to be predicted. The updated target address to be predicted is used as the input of the next round of branch prediction, and it is queried whether the updated target address to be predicted hits the multi-level BTB.
[0037] like Figure 1BAs shown, the query whether the ZBTB is hit can be realized in the current clock cycle cycle0, that is, the prediction delay of the ZBTB is 0 clock cycles. The branch prediction operation based on the L1BTB requires 2 clock cycles (cycle0~cycle1). In the clock cycle cycle0, the linear address of the branch instruction is converted into a hash value based on the hash algorithm. In the clock cycle cycle1, the obtained hash value is used to query whether the L1ZBTB is hit, that is, the prediction delay of the L1BTB is 1 clock cycle. The branch prediction operation based on the L2BTB requires 4 clock cycles (cycle0~cycle3). In the clock cycles cycle0~cycle1, it is queried whether the L1ZBTB is hit. If the L1ZBTB is not hit, the converted hash value is used to query whether the L2ZBTB is hit in the clock cycles cycle2~cycle3, that is, the prediction delay of the L2BTB is 3 clock cycles.
[0038] Figure 2 A schematic diagram showing an exemplary branch prediction based on a zero-delay branch target buffer is shown.
[0039] like Figure 2As shown, the zero-delay branch target buffer (ZBTB) includes 16 entries (for example, recorded as "entry0-entry15"). When performing branch prediction on the target instruction to be predicted, first query whether the ZBTB is hit based on the address identifier LA[21:0] of the target instruction to be predicted (the low-order address part of the address information of the target instruction to be predicted); if the address identifier LA[21:0] hits entry 1 and entry 1 is in a valid state, that is, the address identifier LA[21:0] is equal to the address tag Tag1 of entry 1, and the field Val of entry 1 indicates valid, then ZBTB outputs the target prediction address Tgt1[19:0] recorded in entry 1 (recorded in the field Target1 of entry 1), and generates a control signal ZCorrect to control the output operation of the multiplexer MUX. In order to realize the zero-latency characteristic of ZBTB, ZBTB cannot save the complete target prediction address, that is, the target prediction address recorded in the field Target1 of entry entry1 is a part of the complete target prediction address (e.g., Tgt1[63:0]), such as the low-order address part Tgt1[19:0]. Therefore, after ZBTB outputs Tgt1[19:0], the high-order address part (e.g., LA[63:20]) of the address information of the target instruction to be predicted is used to perform address splicing with Tgt1[19:0] to obtain the complete target prediction address Tgt[63:0] (i.e., the updated target address to be predicted) and provide it to the multiplexer MUX. The multiplexer MUX selects to output Tgt[63:0] to the register 201 according to the received control signal ZCorrect to update the address information of the target instruction to be predicted stored in the register 201.
[0040] like Figure 2As shown, the multiplexer MUX also receives the predicted addresses RedirectTgt[63:0], L2Tgt[63:0], L1Tgt[63:0] and SeqTgt[63:0]. RedirectTgt[63:0] is the redirection address, that is, the actual target address to be redirected when a branch prediction error is found in the execution phase. L2Tgt[63:0] and L2Tgt[63:0] respectively represent the target predicted addresses output by the first-level branch target buffer (L1BTB) and the second-level branch target buffer (L2BTB). SeqTgt[63:0] represents the next sequential address of the target to-be-predicted instruction in the instruction sequence. The predicted addresses RedirectTgt[63:0], L2Tgt[63:0], L1Tgt[63:0] and SeqTgt[63:0] correspond one-to-one to the control signals Redirect, L2Correct, L1Correct and SeqCorrect. The control signals (Redirect, L2Correct, L1Correct, ZCorrect and SeqCorrect) jointly control the output operation of the multiplexer MUX, and the priorities of these control signals from high to low are Redirect, L2Correct, L1Correct, ZCorrect and SeqCorrect.
[0041] like Figure 2 As shown, since the address information of the target instruction to be predicted includes 64 bits of data, for example, register 201 includes 64 D flip-flops (DFFs), each DFF stores 1 bit of address information, when using Tgt[63:0] to update the address information in register 201, 64 D flip-flops need to be updated in sequence, and the fan-out number of ZBTB at the hardware level (i.e., the number of DFFs to be driven by ZBTB) is 64.
[0042] The inventors of the present disclosure have noticed that in order to achieve the zero-delay feature of the ZBTB, the number of entries in the ZBTB is small and is limited by the frequency of the processor's internal clock signal, that is, increasing the number of entries in the ZBTB will increase the complexity of the sequential logic, resulting in the ZBTB being unable to achieve branch prediction within one clock cycle. Therefore, the current ZBTB has a small capacity and is not compatible with all branch types, and can only handle some relatively simple branch types.
[0043] One or more embodiments of the present disclosure provide a branch prediction method and apparatus, an electronic device, a computer-readable storage medium, and a processor.
[0044] The branch prediction method includes: obtaining address information of a target instruction to be predicted; querying whether the address information of the target instruction to be predicted hits a branch target buffer, wherein the branch target buffer includes multiple entries, each entry includes a first field and a second field, the first field is used to record an address tag, and the second field is used to record a target prediction address corresponding to the address tag; and in response to the address information of the target instruction to be predicted hitting a first entry of the branch target buffer, using the target prediction address in the first entry to update a low-order address portion of the address information of the target instruction to be predicted, so as to obtain an updated target address to be predicted, wherein the low-order address portion includes the lowest m bits of the address information of the target instruction to be predicted, and m is an integer greater than or equal to 1.
[0045] The branch prediction method directly uses the target prediction address to update the low-order address part of the address information of the target instruction to be predicted, that is, by reducing the fan-out number of the branch target buffer at the hardware level (that is, the number of storage devices to be driven by the branch target buffer), more timing resources can be saved. The saved timing resources can be used to expand the capacity of the branch target buffer, so that the branch target buffer can be compatible with more branch types.
[0046] The present disclosure is described below through several specific embodiments. In order to keep the following description of the embodiments of the present disclosure clear and concise, detailed descriptions of known functions and known components may be omitted. When any component of the embodiments of the present disclosure appears in more than one figure, the component is represented by the same or similar reference numeral in each figure.
[0047] Some embodiments and examples of the present disclosure are described in detail below with reference to the accompanying drawings.
[0048] Figure 3 The branch prediction method provided by at least one embodiment of the present disclosure is shown. The branch prediction method includes steps S301 to S303.
[0049] Step S301: Obtain address information of a target instruction to be predicted.
[0050] Step S302: Query whether the address information of the target to-be-predicted instruction hits the branch target buffer.
[0051] Step S303: In response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer, the target predicted address in the first entry is used to update the low address portion of the address information of the target instruction to be predicted to obtain an updated target address to be predicted.
[0052] For example, the target instruction to be predicted may be a branch instruction. The address information may be a linear address of the target instruction to be predicted (for example, "LA[63:0]" indicates that the address information has 64 bits), or a hash value obtained by converting the linear address based on, for example, a hash algorithm, which is not limited in the present disclosure.
[0053] For example, the low-order address part of the address information includes the lowest m bits of the address information of the target instruction to be predicted, where m is an integer greater than or equal to 1. For example, the low-order address part of the address information can be recorded as "LA[m-1:0]".
[0054] It should be noted that the branch target buffer in at least one embodiment of the present disclosure is a branch target buffer with a zero-delay characteristic, or a multi-level branch target buffer including a zero-delay branch target buffer (ZBTB). For example, the branch target buffer includes at least a first-level branch target buffer and a second-level branch target buffer, wherein the first-level branch target buffer is a branch target buffer with a zero-delay characteristic (e.g., a ZBTB).
[0055] For example, the branch target buffer includes multiple entries, each entry includes a first field and a second field, the first field is used to record an address tag, and the second field is used to record a target prediction address corresponding to the address tag. Here, the address tag (Tag) is used to identify each entry to ensure that the entry hit by the address information of the target instruction to be predicted can be accurately found when retrieving (or querying) the branch target buffer, thereby improving the accuracy and performance of branch prediction. The target prediction address refers to the address of the next instruction to which the program jumps when executing the target instruction to be predicted in the historical execution process of the target instruction to be predicted, that is, the prediction result obtained by performing branch prediction on the target instruction to be predicted.
[0056] For example, each entry may also include a third field (e.g., denoted as "Val") for recording the validity of the corresponding entry, that is, the third field is used to record whether the data in the corresponding entry is valid data, so that corresponding access control can be performed based on the validity of the entry. For example, Val=1 indicates that the entry is valid, and Val=0 indicates that the entry is invalid.
[0057] For a branch target buffer with zero latency characteristics, the branch target buffer cannot save the complete target prediction address, and cannot completely compare the address tag in the entry with the address information of the target instruction to be predicted (i.e., compare the address tag with each data in the address information), otherwise the storage requirements and access delay will increase. Therefore, the target prediction address recorded in the second field is the low-order address part of the complete target prediction address, and the low-order address part of the address information of the target instruction to be predicted is directly updated (or replaced) in the subsequent process. The number of bits of the low-order address part of the complete target prediction address (e.g., Tgt[m-1:0]) is equal to the number of bits of the low-order address part of the address information (e.g., LA[m-1:0]), and m is an integer greater than or equal to 1.
[0058] For example, when executing the above step S302 (querying whether the address information of the target instruction to be predicted hits the branch target buffer with zero delay characteristics), it can be achieved by comparing the address identifier in the address information and the address tag of each entry. Here, the address identifier is the lowest n bits of the address information of the target instruction to be predicted, and n is an integer greater than or equal to 1. For example, the address identifier can be the lowest 22 bits of the address information, which can be recorded as "LA[21:0]".
[0059] For example, the above step S302 may include: in response to the address identifier of the target instruction to be predicted matching the address tag in the first entry and the first entry being in a valid state, determining that the address information of the target instruction to be predicted hits the first entry of the branch target buffer.
[0060] For example, in response to the address identifier of the target instruction to be predicted being equal to the address tag in the first entry, and the third field Val of the first entry is 1 (indicating that the first entry is valid), it means that the address information of the target instruction to be predicted hits the first entry of the branch target buffer.
[0061] For example, in the case where the branch target buffer is a multi-level branch target buffer (i.e., including a first-level branch target buffer and a second-level branch target buffer), the above step S302 may include: querying whether the address information of the target instruction to be predicted hits the first-level branch target buffer and / or the second-level branch target buffer. The first-level branch target buffer may be a ZBTB, and the second-level branch target buffer may be an L1ZBTB. The address information of the target instruction to be predicted may hit the ZBTB, hit the L1BTB, or hit both the ZBTB and the L1BTB. When hitting the ZBTB or the L1BTB, subsequent operations may refer to the above description of Figure 1B The following example describes a situation where the address information of the target instruction to be predicted hits both the ZBTB and the L1BTB.
[0062] In an example, the predicted latency of the ZBTB is 0 clock cycles, the predicted latency of the L1BTB is 1 clock cycle, hitting the ZBTB is determined in clock cycle cycle0, and hitting the L1BTB is determined in clock cycle cycle1 next to clock cycle cycle0.
[0063] In clock cycle cycle0, it is determined that the address information LA[63:0] of the target instruction to be predicted hits entry0 of the ZBTB, for example, and the target prediction address Tgt0[19:0] recorded in entry0 is used to update the low-order address part of the address information LA[63:0] (for example, LA[19:0]) to obtain the updated target address to be predicted (recorded as "LA_0[63:0]"). In the next clock cycle cycle1 of the clock cycle cycle0, it is determined that the address information LA[63:0] of the target instruction to be predicted hits the entry entry1 of the L1BTB. If the target prediction address Tgt1[19:0] recorded in the entry entry1 is equal to Tgt0[19:0], the low address part (for example LA_0[19:0]) of LA_0[63:0] obtained in cycle0 is not updated; if Tgt1[19:0] is not equal to Tgt0[19:0], Tgt1[19:0] is used to update the low address part LA_0[19:0] of LA_0[63:0] to obtain a new updated target address to be predicted (recorded as "LA_1[63:0]").
[0064] It should be noted that in clock cycle cycle1, when querying whether the address information LA[63:0] of the target instruction to be predicted hits the L1BTB, the updated target address LA_0[63:0] will also be queried to see if it hits the ZBTB. When it is determined that LA[63:0] hits the L1BTB and Tgt1[19:0] is not equal to Tgt0[19:0], the query result of querying whether LA_0[63:0] hits the ZBTB in clock cycle cycle1 will be flushed.
[0065] The branch prediction method provided by at least one embodiment of the present disclosure may further include step S304.
[0066] Step S304: In response to the address information of the target instruction to be predicted not hitting the branch target buffer, the next sequential address of the target instruction to be predicted in the instruction sequence is used as an updated target address to be predicted.
[0067] For example, when the branch target buffer is a multi-level branch target buffer, the above step S304 may include: in response to the address information of the target to-be-predicted instruction not hitting each level of the branch target buffer in the multi-level branch target buffer, using the next sequential address of the target to-be-predicted instruction in the instruction sequence as the updated target to-be-predicted address.
[0068] At least one embodiment of the present disclosure provides a branch prediction method further comprising step S305:
[0069] Step S305: Use the updated target address to be predicted to perform the next round of branch prediction operation.
[0070] Figure 4 A schematic diagram of performing branch prediction based on a zero-delay branch target buffer provided by at least one embodiment of the present disclosure is shown.
[0071] Figure 4 The zero-delay branch target buffer ZBTB shown includes 16 entries (for example, recorded as "entry0~entry15"), and the output end of the ZBTB is directly coupled to an input end of the multiplexer. Assume that the address information of the target instruction to be predicted is 64 bits (recorded as "LA[63:0]"), and the register 401 is used to store the address information LA[63:0] of the target instruction to be predicted. The register 401 includes 64 D flip-flops (DFFs), and each DFF stores 1 bit of address information. The structure and function of the multiplexer MUX, as well as other predicted addresses (such as RedirectTgt[63:0], L2Tgt[63:0], L1Tgt[63:0] and SeqTgt[63:0]) and control signals (such as ZCorrect, etc.) received by the multiplexer MUX can refer to the above description. Figure 2 The description is not repeated here.
[0072] like Figure 4As shown, when performing branch prediction based on the zero-delay branch target buffer, the address information LA[63:0] of the target instruction to be predicted is first obtained from register 401, and then based on the address identifier LA[21:0] included in the address information LA[63:0], it is queried whether the address information of the target instruction to be predicted hits the branch target buffer. For example, the address tags Tag0 to Tag15 of all entries in the ZBTB are traversed to query whether there is an address tag that matches (i.e., is equal to) the address identifier LA[21:0]. In response to the address tag Tag1 matching the address identifier LA[21:0] and the entry entry1 corresponding to the address tag Tag1 being in a valid state, it is determined that the address information LA[63:0] of the target instruction to be predicted hits the entry entry1 in the ZBTB. Then, the ZBTB outputs the target prediction address (e.g., Tgt[19:0]) recorded by the field Target1 of the entry entry1 to the multiplexer MUX, and the ZBTB generates a control signal ZCorrect. The control signal ZCorrect controls the multiplexer MUX to provide the received target prediction address Tgt[19:0] to the corresponding 20 D flip-flops in the register 401 to update the lowest 20 bits of the address information LA[63:0] (i.e., LA[19:0]), thereby obtaining the updated target address to be predicted (e.g., recorded as "LA_0[63:0]"). The instruction corresponding to the updated target address to be predicted LA_0[63:0] is used as the target instruction to be predicted for the next round of branch prefetch operation, the updated target address to be predicted LA_0[63:0] is used as the address information for the next round of branch prefetch operation, and the lowest 22 bits of the updated target address to be predicted LA_0[63:0] are used as the address identifier (i.e., LA_0[21:0]) to query whether the ZBTB is hit.
[0073] At least one embodiment of the present disclosure provides a branch prediction method that omits the address splicing operation (see Figure 2 ), directly use the target predicted address Tgt[19:0] to update the lowest 20 bits of the address information LA[63:0] (i.e., LA[19:0]), that is, the 20 D flip-flops corresponding to the lowest 20 bits of LA[63:0] need to be updated in sequence, and the fan-out number of ZBTB at the hardware level (i.e., the number of D flip-flops to be driven by ZBTB) is 20, which is less than Figure 2 The fan-out number of the ZBTB shown at the hardware level is 64, thereby reducing the timing resources required to update the address information of the target to-be-predicted instruction (or update register 401), and the saved timing resources can be used to expand the capacity of the branch target buffer, so that the branch target buffer can be compatible with more branch types.
[0074] In the branch prediction method provided by at least one embodiment of the present disclosure, the branch target buffer can be shared by multiple threads of a multi-threaded processor, and the multiple threads include at least a first thread and a second thread. The multi-threaded processor allows multiple threads to be executed concurrently at the same time, so each thread has its own instruction sequence and state information (including address information).
[0075] For example, the branch prediction method provided by at least one embodiment of the present disclosure further includes: before acquiring the address information of the target instruction to be predicted, selecting the first instruction to be predicted corresponding to the first thread or the second instruction to be predicted corresponding to the second thread as the target instruction to be predicted. The branch prediction method maximizes the utilization of hardware resources and reduces the complexity and cost of hardware by enabling multiple threads in a multi-threaded processor to share the same branch target buffer.
[0076] For example, before obtaining the address information of the target instruction to be predicted, the thread to be scheduled is first determined from multiple threads. For example, the thread to be scheduled can be determined based on the arbitration result of the thread arbiter, or the thread to be scheduled can be determined by setting a corresponding thread arbitration policy as required. The present disclosure does not limit this. After determining the thread to be scheduled, the instruction to be predicted corresponding to the thread to be scheduled is used as the target instruction to be predicted. The rest of the branch prediction process can refer to the above steps S301 to S305, which will not be repeated here.
[0077] For example, the branch prediction method provided by at least one embodiment of the present disclosure also includes: in response to selecting the first to-be-predicted instruction corresponding to the first thread as the target to-be-predicted instruction (that is, the thread to be scheduled is the first thread), and the address information of the first to-be-predicted instruction hits the first entry of the branch target buffer, using the target prediction address in the first entry to update the low-order address part of the address information of the first to-be-predicted instruction to obtain an updated target to-be-predicted address corresponding to the first to-be-predicted instruction.
[0078] For example, the branch prediction method provided by at least one embodiment of the present disclosure further includes: selecting to use the updated target address to be predicted of the first instruction to be predicted or the address information of the second instruction to be predicted to perform the next round of branch prediction operation. Before performing the next round of branch prediction operation, it is necessary to first determine the thread targeted by the next round of branch prediction operation, that is, to redetermine the thread to be scheduled from multiple threads.
[0079] For example, Figure 5 A schematic diagram showing a multi-threaded processor performing a branch prediction operation according to at least one embodiment of the present disclosure is shown.
[0080] exist Figure 5In the example shown, the address information of the target instruction to be predicted is 64 bits, which can be recorded as "LA[63:0]". The first thread T1 and the second thread T2 of the multi-threaded processor share the same branch target buffer. The branch target buffer is a three-level branch target buffer, including a zero-delay branch target buffer (recorded as "ZBTB"), a first-level branch target buffer (recorded as "L1BTB", Figure 5 ) and a second-level branch target buffer (referred to as "L2BTB" Figure 5 (not shown). The capacity of L1BTB and L2BTB is relatively large, and the entries in L1BTB and L2BTB can record the complete target prediction address (i.e., 64-bit target prediction address). The target prediction addresses output by L1BTB and L2BTB are recorded as "L1Tgt[63:0]" and "L2Tgt[63:0]", respectively. In addition, Figure 5 The structure and function of the ZBTB in the above, the prediction address RedirectTgt[63:0], the sequence address SeqTgt[63:0], the control signals (Redirect, L2Correct, L1Correct, ZCorrect and SeqCorrect), the priority of the control signals, etc. can be referred to above. Figure 2 The description is not repeated here.
[0081] For example, the multiplexer Thread_MUX is configured to determine the threads to be scheduled from the first thread T1 and the second thread T2 according to the thread arbitration result. The thread arbitration result can be obtained directly from the thread arbitrator or based on a preset thread arbitration strategy. The multiplexer T1_MUX and register 501 are used for the first thread T1, and the multiplexer T2_MUX and register 502 are used for the second thread T2. The multiplexers T1_MUX and T2_MUX can refer to Figure 4 The structures and functions of the multiplexer MUX, register 501 and register 502 can be referred to in Figure 4 The register 401 in will not be described in detail here.
[0082] For example, register 503 includes 64 D flip-flops (DDF_0 to DFF_63), and register 503 is used to store address information Pred_LA[63:0] of the target predicted instruction corresponding to the thread to be scheduled. The address information Pred_LA[63:0] in register 503 can be directly used for the next round of branch prediction operation.
[0083] For example, during the a-th round of branch prediction operation (a is an integer greater than or equal to 1), the address identifier Pred[21:0] of the address information Pred_LA[63:0] in the register 503 is first input to the ZBTB to query whether the address information Pred_LA[63:0] hits the ZBTB; in response to the address identifier Pred[21:0] being equal to the address tag Tag1 and the entry entry1 corresponding to the address tag Tag1 being in a valid state, it is determined that the address information Pred_LA[63:0] hits the ZBTB, and the ZBTB generates a control signal ZCorrect and provides it to the multiplexer T1_MUX. Since before the a-th round of branch prediction operation, that is, in the previous round of branch prediction operation, the first thread T1 has been determined as the thread to be scheduled according to the thread arbitration result, the ZBTB provides the target prediction address Tgt[19:0] recorded in the entry entry1 to the input end of the multiplexer T1_MUX. Then, the multiplexer T1_MUX provides the target prediction address T1_Tgt[19:0] to the register 501 and the input terminal of the multiplexer Thread_MUX based on the control signal ZCorrect. Here, the target prediction address T1_Tgt[19:0] output by the multiplexer T1_MUX is the same as the target prediction address Tgt[19:0] received by the multiplexer T1_MUX, and "T1_Tgt[19:0]" is only used to distinguish "T2_Tgt[19:0]" output by the multiplexer T2_MUX.
[0084] Specifically, the multiplexer T1_MUX provides the target prediction address T1_Tgt[19:0] to the corresponding 20 D flip-flops (e.g., DDF_0 to DFF_19) in the register 501, and under the control of the timing logic, writes the 20 bits of the target prediction address T1_Tgt[19:0] into the corresponding D flip-flops in the register 501 in sequence to obtain the updated address to be predicted T1_LA[63:0] corresponding to the first thread T1. For example, the lowest bit of T1_Tgt[19:0] is written into the D flip-flop DDF_0 in the register 501. After the multiplexer Thread_MUX receives the target prediction address T1_Tgt[19:0], in response to the second thread T2 being the thread corresponding to the (a+1)th round of branch prediction operation, the multiplexer Thread_MUX selects T2_Tgt[19:0] from the target prediction addresses T1_Tgt[19:0] and T2_Tgt[19:0] to output T2_Tgt[19:0] to register 503 to update the corresponding 20 D flip-flops of register 503 to obtain the updated target predicted address Pred_LA_(a+1)[63:0].
[0085] It should be noted that the target prediction address T2_Tgt[19:0] is obtained before the a-th round of branch prediction operation, for example, when the address information of the target to-be-predicted instruction corresponding to the second thread T2 hits the ZBTB in the (a-3)-th round of branch prediction operation. The method of updating the register 503 can refer to the description of updating the register 501 above, which will not be repeated here.
[0086] Continuing with the above example, during the (a+1)th round of branch prediction operation, the address identifier Pred_LA_(a+1)[21:0] of the updated target address to be predicted Pred_LA_(a+1)[63:0] in register 503 is input to ZBTB to query whether Pred_LA_(a+1)[63:0] hits ZBTB. If the entry 15 of ZBTB is hit, since the second thread T2 is the thread corresponding to the (a+1)th round of branch prediction operation, the target prediction address recorded in the field Target15 in the entry 15 is provided to the multiplexer T2_MUX (such as Figure 5 The remaining (a+1)th round branch prediction operation process (e.g., the operation of the multiplexer T2_MUX, the multiplexer Thread_MUX, the registers 502 and 503) can refer to the above description of the ath round branch prediction operation process, which will not be repeated here.
[0087] like Figure 5 As shown, for a branch target buffer supporting a two-thread micro-architecture, when the branch prediction method provided in the embodiment of the present disclosure is adopted, the fan-out number of the ZBTB in the branch target buffer at the hardware level is 60 (3×20), that is, the ZBTB needs to drive 20 D flip-flops in register 501, 20 D flip-flops in register 502, and 20 D flip-flops in register 501. Accordingly, when the branch prediction method provided in the embodiment of the present disclosure is adopted and the number of bits of the target prediction address recorded in the entry in the ZBTB is 20 bits, the fan-out number of the ZBTB in the branch target buffer supporting a four-thread micro-architecture at the hardware level is 100, and the fan-out number of the ZBTB in the branch target buffer supporting an N-thread micro-architecture at the hardware level is (N+1)×20.
[0088] If adopted Figure 2The branch prediction method shown in the figure supports a fan-out number of 192 (3×64) at the hardware level for the branch target buffer of the two-thread micro-architecture, and a fan-out number of 320 (5×64) at the hardware level for the branch target buffer of the four-thread micro-architecture. Therefore, for a multi-threaded processor using the branch prediction method provided by the embodiment of the present disclosure, the more threads there are, the more the fan-out number of the ZBTB at the hardware level is reduced, and the more timing resources are saved.
[0089] According to at least one embodiment of the present disclosure, the branch prediction method (such as Figure 3 Correspondingly, at least one embodiment of the present disclosure further provides a branch prediction device.
[0090] The branch prediction device provided in the embodiments of the present disclosure can execute the branch prediction method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0091] For example, Figure 6 A schematic block diagram of a branch prediction device provided by at least one embodiment of the present disclosure is shown.
[0092] like Figure 6 As shown, the branch prediction device 600 includes an acquisition module 610, a query module 620 and an update module 630. The acquisition module 610 is configured to acquire the address information of the target instruction to be predicted. The query module 620 includes a branch target buffer 621, and is configured to query whether the address information of the target instruction to be predicted hits the branch target buffer 621. The branch target buffer 621 includes a plurality of entries, each entry includes a first field and a second field, the first field is used to record the address tag, and the second field is used to record the target prediction address corresponding to the address tag. The update module 630 is configured to update the low-order address part of the address information of the target instruction to be predicted using the target prediction address in the first entry in response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer 621, so as to obtain the updated target address to be predicted. The low-order address part includes the lowest m bits of the address information of the target instruction to be predicted, where m is an integer greater than or equal to 1.
[0093] For example, the branch prediction apparatus 600 is further configured to use the updated target address to be predicted to perform the next round of branch prediction operations.
[0094] For example, the branch prediction device 600 further includes a first multiplexer ( Figure 6 Not shown, please refer to Figure 5The first multiplexer is coupled to the branch target buffer 621 and the update module 630 in the query module 620. The first multiplexer is configured to at least receive the next sequential address of the target instruction to be predicted in the instruction sequence, and read the target prediction address corresponding to the first entry hit in the query process from the branch target buffer 621. The query module 620 is also configured to generate a first control signal in response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer 621, so as to control the first multiplexer to output the target prediction address in the first entry to the update module 630.
[0095] For example, the query module 620 is also configured to generate a second control signal (e.g., SeqCorrect above) in response to the address information of the target instruction to be predicted not hitting the branch target buffer 621, so as to control the multiplexer to output the next sequential address of the target instruction to be predicted in the instruction sequence to the update module 630.
[0096] For example, the branch target buffer 621 in the branch prediction device 600 may be shared by multiple threads of a multi-threaded processor, where the multiple threads include at least a first thread and a second thread. The branch prediction device 600 further includes a second multiplexer ( Figure 6 Not shown, please refer to Figure 5 The multiplexer Thread_MUX of the first thread is configured to select the first instruction to be predicted corresponding to the first thread or the second instruction to be predicted corresponding to the second thread as the target instruction to be predicted.
[0097] For example, the update module 630 is configured to, in response to selecting the first to-be-predicted instruction corresponding to the first thread as the target to-be-predicted instruction and the address information of the first to-be-predicted instruction hitting the first entry of the branch target buffer 621, update the low-order address portion of the address information of the first to-be-predicted instruction using the target prediction address in the first entry to obtain an updated target to-be-predicted address corresponding to the first to-be-predicted instruction.
[0098] For example, the branch prediction apparatus 600 is further configured to select to use the updated target address to be predicted of the first instruction to be predicted or the address information of the second instruction to be predicted to perform the next round of branch prediction operation.
[0099] For example, the branch target buffer 621 is a multi-level branch target buffer, which includes at least a first-level branch target buffer and a second-level branch target buffer. The query module 620 is configured to query whether the address information of the target instruction to be predicted hits the first-level branch target buffer and / or the second-level branch target buffer.
[0100] It is worth noting that the various units and modules included in the above-mentioned branch prediction device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present disclosure.
[0101] At least one embodiment of the present disclosure also provides an electronic device. The electronic device includes at least one storage unit and at least one processing unit. At least one storage unit stores computer-readable instructions. At least one processing unit executes the computer-readable instructions stored in at least one storage unit to implement the branch prediction method provided in any embodiment of the present disclosure. The processing unit can be any circuit unit with instruction execution capability, such as a microcontroller, etc., and the embodiments of the present disclosure are not limited to this.
[0102] The electronic device provided by the embodiment of the present disclosure and the branch prediction method provided by the above embodiment belong to the same inventive concept. For technical details not fully described in this embodiment, reference can be made to the embodiments related to the above branch prediction method, and this embodiment has the same beneficial effects as the above embodiment.
[0103] At least one embodiment of the present disclosure further provides a processor (CPU), the processor includes an instruction processing pipeline, the pipeline includes a branch predictor, and the branch predictor includes a branch prediction device of any of the above embodiments. For example, the pipeline of the processor also includes a value acquisition unit, a decoding unit, an execution unit, etc., and the embodiments of the present disclosure are not limited to this. For example, the processor can be a single-core processor or a multi-core processor, and can be based on, for example, an X86 microarchitecture, an ARM microarchitecture, a RISC-V microarchitecture, etc., and the embodiments of the present disclosure are not limited to this.
[0104] At least one embodiment of the present disclosure further provides a computer-readable storage medium. The computer-readable storage medium stores computer-readable instructions, and when a processor executes the computer-readable instructions, the branch prediction method provided by any embodiment of the present disclosure is implemented.
[0105] For example, the computer-readable storage medium may include a storage component of a tablet computer, a hard disk of a personal computer, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a compact disk read-only memory (CD-ROM), a flash memory, or any combination of the foregoing computer-readable storage media, or other applicable storage media.
[0106] At least some embodiments of the present disclosure further provide an electronic device, which includes the processor provided by any of the above embodiments. Figure 7A schematic block diagram of an electronic device provided by at least one embodiment of the present disclosure is shown.
[0107] The electronic device in the embodiments of the present disclosure can be implemented as but not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc.
[0108] Figure 7 The electronic device 700 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0109] For example, Figure 7 As shown, in some examples, the electronic device 700 includes a processor 701, which may include a processor of any of the above-mentioned embodiments, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 to a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the computer system are also stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0110] For example, the following components may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709 which may also include, for example, a network interface card such as a LAN card, a modem, etc. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data, performing communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. Removable media 711, such as magnetic disks, optical disks, magneto-optical disks, semiconductor memories, etc., are installed on the drive 710 as needed, so that the computer programs read therefrom are installed into the storage device 708 as needed. Although Figure 7 The electronic device 700 is shown to include various devices, but it should be understood that it is not required to implement or include all of the devices shown. More or fewer devices may be implemented or included instead.
[0111] For example, the electronic device 700 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 709 may communicate with a network and other devices through wireless communication, such as the Internet, an intranet and / or a wireless network such as a cellular phone network, a wireless local area network (LAN) and / or a metropolitan area network (MAN). Wireless communication may use any of a variety of communication standards, protocols, and techniques, including, but not limited to, Global System for Mobile Communications (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (W-CDMA), Code Division Multiple Access (CDMA), Time Division Multiple Access (TDMA), Bluetooth, Wi-Fi (e.g., based on IEEE 802.11a, IEEE 802.11b, IEEE 802.11g and / or IEEE 802.11n standards), Voice over Internet Protocol (VoIP), Wi-MAX, protocols for email, instant messaging and / or Short Message Service (SMS), or any other suitable communication protocol.
[0112] At least one embodiment of the present disclosure further provides a processor, which includes the branch prediction device provided by any embodiment of the present disclosure.
[0113] In addition to the above exemplary descriptions, there are a few points that need to be explained:
[0114] (1) The drawings of the embodiments of the present disclosure only relate to the structures related to the embodiments of the present disclosure, and other structures may refer to the general design.
[0115] (2) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to obtain new embodiments.
[0116] The above description is merely an exemplary embodiment of the present disclosure and is not intended to limit the protection scope of the present disclosure. The protection scope of the present disclosure is determined by the appended claims.
Claims
1. A branch prediction method, comprising: Obtain address information of the target instruction to be predicted; querying whether the address information of the target to-be-predicted instruction hits a branch target buffer, wherein the branch target buffer includes a plurality of entries, each entry includes a first field and a second field, the first field is used to record an address tag, and the second field is used to record a target predicted address corresponding to the address tag; and In response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer, the low-order address portion of the address information of the target instruction to be predicted is updated using the target predicted address in the first entry to obtain an updated target address to be predicted, The low-order address portion includes the lowest m bits of the address information of the target instruction to be predicted, where m is an integer greater than or equal to 1.
2. The branch prediction method according to claim 1, further comprising: In response to the address information of the target instruction to be predicted not hitting the branch target buffer, the next sequential address of the target instruction to be predicted in the instruction sequence is used as the updated target address to be predicted.
3. The branch prediction method according to claim 1, further comprising: The updated target address to be predicted is used to perform the next round of branch prediction operation.
4. The branch prediction method according to claim 1, wherein: The address information includes an address identifier, the address identifier is the lowest n bits of the address information of the target instruction to be predicted, n is an integer greater than or equal to 1, and each entry also includes a third field for recording the validity of the corresponding entry; as well as Querying whether the address information of the target instruction to be predicted hits the branch target buffer includes: In response to the address identifier of the target instruction to be predicted matching the address tag in the first entry, and the first entry being in a valid state, it is determined that the address information of the target instruction to be predicted hits the first entry of the branch target buffer.
5. The branch prediction method according to claim 1, wherein: The branch target buffer is shared by multiple threads of a multi-threaded processor, the multiple threads include at least a first thread and a second thread, and before acquiring the address information of the target instruction to be predicted, the branch prediction method further includes: A first instruction to be predicted corresponding to the first thread or a second instruction to be predicted corresponding to the second thread is selected as the target instruction to be predicted.
6. The branch prediction method according to claim 5, further comprising: In response to selecting the first to-be-predicted instruction corresponding to the first thread as the target to-be-predicted instruction and the address information of the first to-be-predicted instruction hitting the first entry of the branch target buffer, the target prediction address in the first entry is used to update the low-order address part of the address information of the first to-be-predicted instruction to obtain the updated target to-be-predicted address corresponding to the first to-be-predicted instruction.
7. The branch prediction method according to claim 6, further comprising: The updated target address to be predicted of the first instruction to be predicted or the address information of the second instruction to be predicted is selected to perform the next round of branch prediction operation.
8. The branch prediction method according to claim 1, wherein: The branch target buffer is a multi-level branch target buffer, and the multi-level branch target buffer includes at least a first-level branch target buffer and a second-level branch target buffer. Querying whether the address information of the target instruction to be predicted hits the branch target buffer includes: Query whether the address information of the target to-be-predicted instruction hits the first-level branch target buffer and / or the second-level branch target buffer.
9. A branch prediction device, comprising: An acquisition module, configured to acquire address information of a target instruction to be predicted; a query module, comprising a branch target buffer, and configured to query whether the address information of the target instruction to be predicted hits the branch target buffer, wherein the branch target buffer comprises a plurality of entries, each entry comprises a first field and a second field, the first field is used to record an address tag, and the second field is used to record a target predicted address corresponding to the address tag; and an updating module, configured to update a low-order address portion of the address information of the target instruction to be predicted using the target predicted address in the first entry in response to the address information of the target instruction to be predicted hitting the first entry of the branch target buffer, so as to obtain an updated target address to be predicted, The low-order address portion includes the lowest m bits of the address information of the target instruction to be predicted, where m is an integer greater than or equal to 1.
10. The branch prediction apparatus according to claim 9, further comprising: a first multiplexer coupled to the query module, the branch target buffer and the update module, and configured to at least receive a next sequential address of the target instruction to be predicted in the instruction sequence, and read a target prediction address corresponding to the first entry hit during the query from the branch target buffer; The query module is further configured to generate a first control signal to control the first multiplexer to output the target predicted address in the first entry to the update module in response to the address information of the target to-be-predicted instruction hitting the first entry of the branch target buffer.
11. The branch prediction device according to claim 10, wherein: The query module is also configured to generate a second control signal to control the first multiplexer to output the next sequential address of the target instruction to be predicted in the instruction sequence to the update module in response to the address information of the target instruction to be predicted not hitting the branch target buffer.
12. The branch prediction device according to claim 9, wherein: The branch target buffer is shared by a plurality of threads of a multi-threaded processor, the plurality of threads including at least a first thread and a second thread, The branch prediction device further includes a second multiplexer, and the second multiplexer is configured to select a first instruction to be predicted corresponding to the first thread or a second instruction to be predicted corresponding to the second thread as the target instruction to be predicted.
13. An electronic device, comprising: at least one storage unit and at least one processing unit; wherein the at least one storage unit stores computer-readable instructions; The at least one processing unit executes the computer-readable instructions stored in the at least one storage unit to implement the branch prediction method according to any one of claims 1 to 8.
14. A computer-readable storage medium, wherein: The computer-readable storage medium stores computer-readable instructions. When the processor executes the computer-readable instructions, the branch prediction method according to any one of claims 1 to 8 is implemented.
15. A processor comprising the branch prediction device according to any one of claims 9 to 12.
Citation Information
Patent Citations
Branch prediction method and device as well as processor
CN102053818A
Branch target buffer for a data processing apparatus
CN110520836A
Configuration method, branch prediction method and device and electronic equipment
CN117032805A