A method and system for multi-branch cooperative execution of superscalar processors
By identifying and filtering control flow instructions at the instruction fetch end of the superscalar processor to generate speculative program flow, and handling prediction errors during parallel execution of branch execution units, the pipeline stalls and resource waste caused by branch prediction errors are solved, thereby improving the processor's instruction throughput and execution efficiency.
Patent Information
- Application Number
- CN202611334684.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-17
AI Technical Summary
Existing superscalar processors struggle to effectively address pipeline stalls and resource waste caused by branch prediction errors under wide instruction fetch and wide issue conditions. This is especially true when multiple branches are executed in parallel, where the processor struggles to determine a unique recovery source and experiences high control complexity.
By scanning instructions at the instruction fetch end to identify control flow instructions, a speculative program flow is generated, and valid instructions are filtered according to the branch prediction results. The transmitter only processes the valid instructions in the speculative program flow. When the branch execution units are executed in parallel, prediction errors are detected, and the earliest predicted erroneous branch instruction is selected as the boundary according to the program order to generate a redirection mask, cancel the erroneous path instruction, and prevent state updates or exit.
It reduces invalid decoding and execution caused by branch prediction errors, improves branch execution resource utilization, ensures that the processor remains in the correct state when branch prediction is accurate, reduces pipeline stalls, and improves instruction throughput.
Smart Images

Figure CN123114546A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of processor microarchitecture and pipeline control, and in particular to a multi-branch cooperative execution method and system for superscalar processors. Background Technology
[0002] Superscalar processors improve instruction throughput by fetching, decoding, and executing multiple instructions within a single clock cycle. The fetch end typically reads a fixed-width fetch block as the pre-issue instruction stream, which may contain both regular instructions and multiple control flow instructions. For control flow instructions such as conditional branches, unconditional jumps, indirect jumps, function calls, and function returns, whether subsequent instructions belong to the correct program path depends on the branch direction and the execution result of the jump target.
[0003] To reduce pipeline stalls caused by waiting for branch execution results, existing processors typically include a branch predictor to predetermine subsequent instruction fetch addresses. Some processors can predict one or more control flow instructions within a single fetch cycle. However, under wide fetch and wide issue conditions, simply obtaining the branch jump direction and jump target address is insufficient to directly form an instruction set usable by the issuer. It is also necessary to combine the position of each control flow instruction and the program sequence to determine the instructions that should be retained in the predicted path.
[0004] If the instruction fetch terminal only provides the address of the next fetch instruction without forming a program flow consistent with the prediction result, the transmitter may receive instructions outside the predicted path. Since modern branch predictors have high prediction accuracy, these instructions outside the predicted path are very likely instructions on the wrong path. These instructions consume decoding, queue, and execution resources and increase the complexity of backend recovery control. On the other hand, when multiple branches are executed in parallel, if the branch execution result does not carry program order information of the branch instructions, it is difficult for the processor to determine a unique recovery source when multiple branches make prediction errors simultaneously or sequentially. Instructions on wrong paths located later in the program order may also update the architecture state before recovery is complete.
[0005] Therefore, multi-issue processors require a control method that integrates instruction fetching, issuing, execution, and recovery. Summary of the Invention
[0006] This application aims to at least partially address one of the technical problems in the related art.
[0007] The purpose of this application is to provide a multi-branch cooperative execution method for superscalar processors, which enables speculative program flows generated at the instruction fetch end to be directly used as the instruction source at the issue end, and enables multiple branches in the same speculative program flow to be executed in parallel while ensuring accurate state.
[0008] Another aspect of this application proposes a multi-branch cooperative execution device for a superscalar processor.
[0009] To achieve the above objectives, a first aspect of this application proposes a multi-branch cooperative execution method for a superscalar processor, comprising: S1, scan multiple instructions acquired at the instruction fetching end, identify the control flow instructions among them, and determine the position and program order of each control flow instruction in the multiple instructions; S2, based on the prediction bandwidth of the branch prediction unit, perform jump direction prediction and jump target address prediction on one or more scanned control flow instructions in the order of the program, generate an effective instruction mask and the next instruction fetch address based on the prediction results, and send the instruction selected by the effective instruction mask as a speculative program flow to the transmitter. S3, when there are at least two branch instructions that meet the launch conditions in the speculative program flow, the at least two branch instructions are sent to different branch execution units for parallel execution. Each branch execution unit returns the actual jump direction and actual jump address of each branch instruction, and compares the actual jump direction and actual jump address with the corresponding prediction result. S4. When one or more non-cancelled branch instructions are determined to be prediction errors, the earliest prediction error branch instruction is selected according to the program order. A redirection mask is generated with the earliest prediction error branch instruction as the boundary. The earliest prediction error branch instruction and the valid instructions that precede it in the program order are retained. Instructions that follow it in the program order are canceled. The canceled instructions are prevented from generating status updates or exiting instructions. Instructions are re-fetched according to the actual jump address or sequential successor address of the earliest prediction error branch instruction.
[0010] In one embodiment of this application, the step of scanning multiple instructions acquired at the instruction fetching end in one go, identifying control flow instructions among them, and determining the position and program order of each control flow instruction in the multiple instructions includes: Each valid instruction in the multiple instructions is pre-decoded to identify conditional branches, unconditional jumps, indirect jumps, function calls, and function return instructions, and the position, type, and program order of each control flow instruction in the multiple instructions are recorded.
[0011] In one embodiment of this application, generating the effective instruction mask and the next instruction fetch address based on the prediction result includes: When there is an instruction with the earliest predicted jump in the program sequence, the predicted target address of the earliest predicted jump instruction in the program sequence is used as the next fetch address; when there is no predicted jump instruction, the next fetch address is determined according to the program sequence; the valid instruction mask is used to mark instructions that are allowed to enter the subsequent pipeline according to the branch prediction result. When there are control flow instructions that have not yet obtained the prediction result, the instructions that are located after the earliest one in the program sequence are not marked as valid.
[0012] In one embodiment of this application, determining the position and program order of each control flow instruction within the plurality of instructions includes: for instructions fetched in the same fetch, determining the program order based on the sequential position of each instruction within the plurality of instructions; for instructions fetched multiple times sequentially, determining the program order based on the sequential order of each fetch and the sequential position of each instruction within the corresponding fetch; in an out-of-order issue superscalar processor, the program order is further determined based on the allocation order of each instruction in the reordering cache; The launch conditions include that the operands of each branch instruction are ready, there are no data dependencies or structural conflicts that prevent parallel execution, and at least two branch execution units are available; The step of sending the at least two branch instructions to different branch execution units for parallel execution includes: the predicted jump direction, predicted jump target address, and program sequence information of each branch instruction are transmitted together with the corresponding branch instruction to the corresponding branch execution unit; each branch execution unit calculates the actual jump direction and the actual jump target address; the actual jump direction and the actual jump target address are compared with the corresponding prediction results to generate a prediction correct flag or a prediction incorrect flag.
[0013] In one embodiment of this application, the step of selecting the earliest predicted error branch instruction according to the program order includes: when multiple non-cancelled branch instructions are judged to be predicted errors simultaneously or sequentially, the address to be re-fetched is determined only according to the earliest predicted error branch instruction in the program order, and the branch instructions in the program order that follow it do not change the address to be re-fetched. The step of generating a redirection mask using the earliest predicted error branch instruction as the boundary includes: A redirection mask is generated based on the program order relationship between each instruction and the earliest predicted error branch instruction. The mask bits corresponding to the earliest predicted error branch instruction and the valid instructions that precede it in the program order are reserved, while the mask bits corresponding to instructions that are after the earliest predicted error branch instruction and have entered the processor but have not yet exited are canceled. Instructions canceled by the redirection mask cannot be written back to general-purpose registers, committed to storage, updated to control status registers, committed to exceptions, updated to branch prediction status, or exited.
[0014] In one embodiment of this application, in a sequentially issued superscalar processor, the valid instruction mask and the redirection mask are passed along with the corresponding instruction through the speculative program flow and pipeline registers, and the validity of the corresponding instruction is controlled during the general purpose register write-back, store commit, control status register update, exception commit, branch prediction status update and instruction exit stages. In an out-of-order superscalar processor, the branch order information is stored in a reordering cache. When the earliest predicted error branch instruction in the program order is determined, the instructions in the issue queue or reserve station, reordering cache, and load memory queue that are in the program order after the earliest predicted error branch instruction are canceled, and the register renaming state saved before the earliest predicted error branch instruction enters speculative execution is restored. If an earlier branch instruction in the program sequence is predicted correctly, the valid instructions following that branch instruction in the program sequence are not cancelled; if a branch instruction following that branch instruction has completed its execution, has not been cancelled, and there are no pending exceptions from earlier in the program sequence, it exits in the program sequence. The branch prediction state is updated only when it has been determined whether the branch instruction actually jumps and the jump address when it actually jumps, and the branch instruction has not been canceled.
[0015] In one embodiment of this application, the step of re-fetching instructions based on the actual jump address or sequential successor address of the earliest predicted erroneous branch instruction includes: when the actual jump direction of the earliest predicted erroneous branch instruction is a jump, using the actual jump address as the address for re-fetching instructions; when the actual jump direction of the earliest predicted erroneous branch instruction is no jump, using the sequential successor address as the address for re-fetching instructions. Preventing the cancelled instruction from generating a status update or exiting the instruction includes: according to the redirection mask, gating the cancelled instruction before general-purpose register write-back, store commit, control status register update, exception commit, branch prediction status update and instruction exit operations, so that the cancelled instruction cannot perform the above operations; Each instruction in the speculative program flow carries branch sequence information, predicted jump direction, predicted jump target address, and sequential successor address; the branch sequence information is used to determine the order of different branch instructions, and the sequential successor address is calculated based on the actual length of the instruction. The step of predicting the jump direction and jump target address of one or more scanned control flow instructions according to the prediction bandwidth of the branch prediction unit and in program order includes: when the prediction bandwidth is less than the number of scanned control flow instructions, performing prediction in batches according to program order, or using the earliest control flow instruction that has not yet obtained the prediction result as the boundary of the current speculative program flow.
[0016] In one embodiment of this application, the jump direction prediction and jump target address prediction combine direction prediction, target prediction and return address prediction methods; for processors that support compressed instructions or variable-length instructions, the sequential successor address is calculated based on the actual instruction length; The step of sending the instructions selected by the valid instruction mask as a speculative program flow to the transmitter includes: the valid instruction mask and the multiple instructions are ANDed to form the speculative program flow, the speculative program flow along with the prediction information enters the transmitter along the pipeline, and the transmitter only receives the instructions marked as valid and the prediction direction, prediction target and branch sequence information corresponding to the instructions.
[0017] In one embodiment of this application, each branch execution unit returns the actual jump direction and actual jump address of each branch instruction, and compares the actual jump direction and actual jump address with the corresponding prediction result, including: Each branch execution unit compares the actual jump direction and actual jump address with the predicted jump direction and predicted jump target address transmitted from the instruction fetch terminal. When they match, a prediction correct flag is generated; when they do not match, a prediction incorrect flag is generated. When the execution results of multiple branches simultaneously indicate a prediction error, the arbitration unit selects only the earliest prediction error branch instruction in the program sequence as the redirection source for this recovery, and cancels the redirection requests proposed by later branch instructions in the program sequence.
[0018] Furthermore, to implement the above embodiments, this application proposes a multi-branch cooperative execution device for a superscalar processor, comprising: The instruction fetch control flow scanning unit is used to scan multiple instructions fetched at one time, identify the control flow instructions among them, and determine the position and program sequence of each control flow instruction; The branch prediction unit is used to generate the prediction direction and prediction target of one or more control flow instructions based on the prediction bandwidth. The instruction filtering unit is used to generate a valid instruction mask, the next instruction fetch address, and branch order information based on the prediction results, and send the instruction selected by the valid instruction mask to the transmitter. A launch control unit is configured to assign at least two branch instructions to different branch execution units when there are at least two branch instructions that satisfy the launch conditions. Multiple branch execution units are used to execute the branch instructions and return the actual jump direction, actual jump address, and branch order information; The branch result selection unit is used to select the earliest predicted incorrect branch in the program order when one or more branch instructions that have not been canceled are predicted incorrectly. A redirection mask generation unit is used to retain the predicted error branch and valid instructions that precede it in the program order, and cancel instructions that follow it in the program order; and a status update control unit and an instruction exit control unit are used to prevent canceled instructions from generating status updates or exiting instructions.
[0019] The method and apparatus of this application embodiment scan the control flow instructions in the fetch block at the fetch end and form a speculative program flow based on the prediction result; the transmitter only processes the valid instructions in the speculative program flow; the execution end allows multiple branches to be executed in parallel, and determines a unique recovery starting point according to the program sequence when a prediction error occurs. This expands the effective transmission range and prevents instructions on erroneous paths from altering the program execution state.
[0020] Compared with the prior art, this application has the following beneficial effects: First, the instruction fetching end performs a control flow scan before transmission and filters the instructions in the instruction fetch block that are allowed to enter the subsequent pipeline based on the branch prediction results. The transmitter then receives the filtered instructions. When the branch prediction accuracy is high, most of the filtered instructions are consistent with the actual execution results of the branches, which can reduce invalid decoding, invalid queuing, and invalid execution caused by branch prediction errors.
[0021] Second, when multiple branch instructions meet the launch conditions, the launch control unit can send multiple branch instructions to different branch execution units for parallel execution in the same cycle, reducing the pause caused by branch instructions waiting for the same branch execution unit and improving the utilization rate of branch execution resources.
[0022] Third, when the prediction of an earlier branch in the program sequence is correct, the valid instructions following it in the program sequence are not canceled; the branch instructions that have already entered the pipeline do not need to be re-fetched or reissued, their valid state and the execution results are preserved, and they exit in the program sequence after the exit conditions are met, thereby reducing control-related pauses and improving the throughput of valid instruction exits.
[0023] Fourth, when multiple branch instructions are all judged to be prediction errors, the processor selects the earliest one in the program order and determines the next instruction fetch address based on the actual jump direction and actual jump address of that branch; the next instruction fetch address is not changed for branches in the program order, thus ensuring that the processor only needs to fetch instructions based on one branch instruction.
[0024] Fifth, when a branch prediction error occurs, the processor cancels the instruction located on the error path in the pipeline before it performs general-purpose register write-back, write-to-memory, updates the control status register, commits an exception, updates the branch predictor, or exits. This prevents the instruction from changing the processor's general-purpose registers, memory, etc., thereby ensuring that the processor can execute the program correctly.
[0025] Sixth, this method does not limit the specific structure of the branch predictor or the number of pipeline stages in the processor. The processor can be configured according to design requirements, including the number of instructions fetched and issued per clock cycle, the number of branch execution units, the type of branch predictor, and the pipeline stages and queues to which the redirection mask applies.
[0026] Seventh, this method can be used with both sequential and out-of-order issue processors. Both types of processors filter instructions allowed to proceed to subsequent processing based on branch prediction results. When multiple branch instructions are determined to be incorrectly predicted, the earliest one is selected according to program order, and the instruction is re-fetched based on the actual jump result of that branch, while canceling instructions that follow in the program order. The difference lies in that sequential issue processors cancel by marking the corresponding instructions in the pipeline as invalid, while out-of-order issue processors cancel by clearing the records of the corresponding instructions in the issue queue or reserve station, reorder cache, and load memory queue, and restoring the register renaming state before the branch execution.
[0027] The technical effectiveness of this application can be evaluated by the following indicators: the proportion of instructions that are fed into the subsequent pipeline based on branch prediction results and are ultimately not canceled; the proportion of cycles in which the number of instructions issued per clock cycle reaches the maximum number of processor issues; the proportion of cycles in which the branch execution unit actually executes branch instructions; the number of instructions canceled due to branch prediction errors; the number of pipeline pause cycles caused by waiting for branch execution results; and the average number of valid instructions exited per processor clock cycle.
[0028] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0029] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 A flowchart illustrating a multi-branch cooperative execution method for a superscalar processor, provided as an embodiment of this application; Figure 2 An architecture diagram of a multi-branch cooperative execution method for a superscalar processor provided in an embodiment of this application; Figure 3 A schematic diagram illustrating the fetch control flow scanning, branch prediction, and speculative program flow formation provided in an embodiment of this application; Figure 4 This is a schematic diagram of multi-branch instruction issuance and parallel execution provided in an embodiment of this application; Figure 5This is a schematic diagram of the earliest error branch arbitration and redirection mask generation provided in the embodiments of this application; Figure 6 A schematic diagram illustrating the gating of processor states by a redirection mask provided in an embodiment of this application; Figure 7 This is a schematic diagram of mask propagation and recovery in sequential and out-of-order transmission processors provided in the embodiments of this application. Detailed Implementation
[0030] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0031] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0032] The following description, with reference to the accompanying drawings, describes a multi-branch cooperative execution method and apparatus for a superscalar processor according to embodiments of this application.
[0033] Example 1 like Figure 1 As shown, this multi-branch cooperative execution method for a superscalar processor specifically includes the following steps: S1, scan multiple instructions acquired at the instruction fetching end, identify the control flow instructions among them, and determine the position and program order of each control flow instruction in the multiple instructions.
[0034] Specifically, the instruction fetching end scans multiple instructions fetched at once to identify the control flow instructions contained therein and determine the position and program order of each control flow instruction within the multiple instructions. The control flow instructions broadly refer to instruction categories that can change the direction of program execution, including but not limited to conditional branches, unconditional jumps, indirect jumps, function calls, and function returns. Through scanning, ordinary instructions and control flow instructions can be distinguished from the fetched instruction set, and the execution sequence relationship between each control flow instruction can be established. This execution sequence relationship provides the basis for subsequent instruction selection based on prediction results and restoration based on execution results. The position indicates the specific arrangement of control flow instructions within the fetched instruction set, and the program order indicates the logical execution sequence of each control flow instruction. Together, they constitute the fundamental basis for the orderly management of control flow instructions.
[0035] As one implementation method, each valid instruction among multiple acquired instructions is pre-decoded. The pre-decoding identifies the control flow instructions within them, and the position, type, and sequence of each control flow instruction are output. This scan result is used to drive subsequent branch prediction operations, without directly using the entire scan result as the set of valid instructions at the transmitter. Through this scanning process, the control flow distribution in the instruction stream can be understood in advance before the instructions enter subsequent pipeline stages, providing accurate instruction-level information support for forming an effective speculative program flow based on the prediction results.
[0036] This step enables the processor to establish a global understanding of the control flow instructions in the instruction flow during the instruction fetch stage, thereby providing an accurate basis for subsequent branch prediction and instruction selection according to the program sequence. It avoids the blindness of prediction and selection due to the lack of control flow information, and helps to improve the targeting and effectiveness of subsequent pipeline processing.
[0037] S2, based on the prediction bandwidth of the branch prediction unit, perform jump direction prediction and jump target address prediction on one or more scanned control flow instructions in the order of the program, generate a valid instruction mask and the next instruction fetch address based on the prediction results, and send the instruction selected by the valid instruction mask as a speculative program flow to the transmitter.
[0038] Specifically, after the instruction fetching end completes the scanning of multiple fetched instructions and identifies the control flow instructions, their positions, and program order, based on the prediction bandwidth of the branch prediction unit, it predicts the jump direction and jump target address of one or more scanned control flow instructions according to the program order. The prediction bandwidth mentioned here refers to the number of control flow instructions that the branch prediction unit can process in parallel or sequentially within one prediction cycle; its specific value does not constitute a limitation on this technical solution. Based on the prediction results, a valid instruction mask and the next fetch address are generated. The valid instruction mask is used to mark instructions that are allowed to enter the subsequent pipeline according to the branch prediction results, i.e., instructions located on the prediction path; the next fetch address is determined based on the prediction results. When there is a control flow instruction predicted as a jump, the prediction target address of the earliest predicted jump control flow instruction in the program order is usually used as the next fetch address; when there is no control flow instruction predicted as a jump, the next fetch address is determined according to the program order. Subsequently, the instructions selected by the valid instruction mask are sent to the transmitter as a speculative program flow for subsequent processing. The speculative program flow contains instructions marked as valid and their corresponding prediction direction, prediction target, and branch sequence information, enabling the transmitter to issue instructions based on the speculative program flow without having to re-determine the control flow.
[0039] As one implementation method, when there are control flow instructions for which prediction results have not yet been obtained, the earliest control flow instruction in program order can be used as the boundary of the current speculative program flow. Instructions whose program order follows this instruction are not marked as valid, thereby ensuring that all instructions in the speculative program flow are within the predicted control flow path. In this way, the instruction fetching end completes the control flow screening before transmission, ensuring that the set of instructions sent to the transmitter is consistent with the prediction results.
[0040] Through the above technical means, the instruction fetch end can filter instructions based on the branch prediction results before launch, forming a speculative program flow consistent with the prediction path, thereby avoiding sending instructions outside the prediction path to the launch end, reducing invalid decoding, invalid queuing and invalid execution, and improving the processor's instruction processing efficiency.
[0041] S3, when there are at least two branch instructions that meet the launch conditions in the speculative program flow, the at least two branch instructions are sent to different branch execution units for parallel execution. Each branch execution unit returns the actual jump direction and actual jump address of each branch instruction, and compares the actual jump direction and actual jump address with the corresponding prediction result.
[0042] Specifically, after the speculative program flow is formed, the transmitting end selects instructions that meet the transmission conditions from the speculative program flow and transmits them based on the operand readiness status, data dependencies, and execution resource availability of each instruction. When at least two branch instructions that meet the transmission conditions exist simultaneously in the speculative program flow, the transmission control unit sends the at least two branch instructions to different branch execution units, enabling multiple branch instructions to be executed in parallel within the same cycle, thereby avoiding pipeline stalls caused by branch instructions waiting sequentially for the same execution unit. Each branch execution unit executes the received branch instruction, calculates the true jump direction and true jump target address of the branch instruction, and compares the true jump direction and true jump target address with the corresponding prediction result obtained by the instruction fetch end to determine whether the prediction of the branch instruction is correct. The comparison result is used to subsequently determine whether there are branch instructions with prediction errors and to identify the redirection source.
[0043] In one implementation, after completing the execution of a branch instruction, each branch execution unit returns the execution result, carrying the program sequence information of that branch instruction, to the arbitration unit. The execution result includes the actual jump direction, the actual jump target address, and a prediction correct flag or prediction incorrect flag. The issuing end selects the instructions that can be issued based on the operand readiness status, data dependencies, and execution resource usage. When at least two branch instructions meet the issuance conditions, they are simultaneously sent to different branch execution units for parallel execution. In another implementation, the predicted jump direction, predicted jump target address, and program sequence information of each branch instruction are transmitted to the corresponding branch execution unit along with the branch instruction, so that they can be compared with the actual jump result after execution.
[0044] By assigning multiple branch instructions that meet the launch conditions to different branch execution units for parallel execution, the execution throughput of branch instructions can be significantly improved, and pipeline stalls caused by branch instructions waiting for the same execution unit can be reduced. At the same time, each branch execution unit independently completes the comparison of prediction results, providing an accurate basis for subsequent selection of the earliest predicted incorrect branch instruction according to the program sequence. Thus, while ensuring the efficiency of multi-branch parallel execution, it lays the foundation for accurate control recovery.
[0045] S4. When one or more non-cancelled branch instructions are determined to be prediction errors, the earliest prediction error branch instruction is selected according to the program order. A redirection mask is generated with the earliest prediction error branch instruction as the boundary. The earliest prediction error branch instruction and the valid instructions that precede it in the program order are retained. Instructions that follow it in the program order are canceled. The canceled instructions are prevented from generating status updates or exiting instructions. Instructions are re-fetched according to the actual jump address or sequential successor address of the earliest prediction error branch instruction.
[0046] Specifically, when multiple uncancelled branch instructions are determined to be prediction errors after execution, a unique branch instruction needs to be selected from all the prediction error instructions based on their order in the program execution sequence to serve as the basis for restoring control flow. Specifically, the earliest prediction error branch instruction is selected as the basis for determining the validity boundary of subsequent instructions, comparing them according to the program order. A corresponding redirection mask is generated using this earliest prediction error branch instruction as the boundary. This mask identifies valid instructions that precede this branch instruction in the program order and those instructions themselves that should be retained, while instructions that follow this branch instruction should be canceled. Cancelled instructions must not generate any form of processor state update, including but not limited to general-purpose register write-back, memory access, control status register update, instruction exception commit, branch predictor state update, and instruction exit operations, thereby ensuring that instructions on the error path do not affect the processor's architectural state. Meanwhile, the address to be re-fetched is determined based on the actual execution result of the earliest predicted incorrect branch instruction. If the branch instruction actually jumps, its actual jump address is used as the address to be re-fetched; if the branch instruction does not actually jump, its sequential successor address is used as the address to be re-fetched, thereby redirecting the processor's instruction fetch flow to the correct program path.
[0047] As one implementation, when multiple branch execution units simultaneously return prediction error flags, the arbitration unit selects only the earliest predicted error branch instruction in the program order as the redirection source for this recovery, based on the program order information carried by each branch instruction, and ignores the redirection requests made by the later predicted error branch instructions in the program order; the redirection mask uses the earliest predicted error branch instruction as the boundary, retains the branch instruction and the valid instructions in the program order preceding it, cancels the instructions in the program order following it, and re-fetches instructions based on the actual jump address or the sequential successor address of the branch instruction.
[0048] By employing the above methods, when multiple branch instructions are simultaneously or sequentially determined to be prediction errors, a unique recovery source can be determined based on the program order, avoiding conflicts between multiple redirection requests and ensuring that the processor re-fetches instructions based only on the execution result of a single branch instruction, thereby guaranteeing the determinism of the recovery process. At the same time, by canceling instructions on the error path through redirection masks and preventing them from generating state updates, it is possible to prevent error path instructions from corrupting the processor's architectural state. While maintaining accurate exceptions and accurate states, this effectively reduces pipeline stalls caused by branch prediction errors, improving the processor's instruction execution efficiency and throughput.
[0049] Example 2 An embodiment of this application provides a multi-branch cooperative execution method for a superscalar processor, which enables the speculative program flow generated at the instruction fetch end to be directly used as the instruction source at the sender end, and enables multiple branches in the same speculative program flow to be executed in parallel while ensuring accurate state.
[0050] In this embodiment of the method, the instruction fetcher retrieves an instruction block from the instruction memory as a pre-issue instruction stream and scans the instructions in the fetch block, recording the position and program order of each control flow instruction within the fetch block. The branch prediction unit, based on its prediction bandwidth, predicts the jump direction and target address of one or more control flow instructions with the earliest program order; and based on the prediction results, determines the valid instructions in the fetch block and the next program counter (PC) value. The filtered speculative program stream, along with the prediction information, enters the issuer via the pipeline. The issuer, based on operand readiness status, instruction dependencies, and execution resource availability, can simultaneously send multiple branch instructions to multiple branch resolution units (BRUs). After each branch resolution unit returns its results, the branch result arbitration unit selects the earliest predicted incorrect branch instruction according to the program order; generates a redirection mask using this branch instruction as a boundary, cancels instructions with later program order, and redirects the instruction fetcher to the actual target address or sequential successor address of that branch. The overall architecture is as follows: Figure 2 As shown.
[0051] To achieve the aforementioned multi-branch collaborative execution, this application adopts the following technical solution: The instruction fetch end is equipped with a control flow scan unit. This unit pre-decodes the valid instructions in the instruction fetch block, identifies the control flow instructions, and outputs the location, type, and program order of these instructions. The scan results are used to drive the branch predictor, not directly as the set of valid instructions at the issue end.
[0052] The branch predictor predicts the jump direction and target address of the earliest control flow instruction in the program sequence based on the scan results and its prediction bandwidth. Based on the fetch block boundary, control flow location, and prediction results, it generates the valid instruction mask and the next fetch address for that fetch block. Instructions outside the prediction path are marked as invalid; only valid instructions within the prediction path are sent to the transmitter.
[0053] Each branch entering the transmitter carries program sequence information, predicted jump direction, predicted jump target address, and sequential successor address; the program sequence information is used to determine the order of different branches. The transmitter selects executable instructions based on data dependencies and execution resource status. When there are two or more allowed-to-be-issued branch instructions in the speculative program flow, these branches can be simultaneously sent to different branch execution units.
[0054] Each branch execution unit calculates the actual jump direction and the actual jump target, and compares them with the prediction information received from the instruction fetcher. When the execution results of multiple branches simultaneously indicate a prediction error, the arbitration unit selects only the earliest predicted incorrect branch instruction in the program sequence as the redirection source for this recovery, and cancels the redirection requests from later branch instructions in the program sequence.
[0055] The redirection mask uses the earliest mispredicted branch instruction as the boundary, preserving valid instructions preceding that branch in the program sequence and canceling instructions following that branch in the program sequence. In this embodiment, a redirection mask bit of 1 indicates preservation, and 0 indicates cancellation; other implementations may also use a redirection mask bit of 0 to indicate preservation and 1 to indicate cancellation. Cancelled instructions must not undergo general-purpose register write-back, memory access, control status register update, instruction exception, branch predictor update, or instruction exit operations.
[0056] When an earlier branch in the program sequence is predicted correctly, no cancellation control is generated for subsequent instructions. Subsequent instructions are allowed to exit if they have already completed, their path is valid, they have not been cancelled, and there are no earlier incorrectly predicted branch instructions. Therefore, parallel execution of multiple branches does not change the program order presented to the processor.
[0057] Furthermore, the multi-branch cooperative execution method of the superscalar processor can be implemented according to the following steps: Step 1: At the instruction fetch end, an instruction fetch block containing multiple instructions is received as a pre-issue instruction stream. The valid instructions in the instruction fetch block are pre-decoded to identify control flow instructions such as conditional branches, unconditional jumps, indirect jumps, call instructions, and return instructions, and their positions and program order are recorded.
[0058] Step 2: Based on the prediction bandwidth of the branch prediction unit, perform direction prediction and target address prediction on one or more control flow instructions obtained by scanning in the order of the program. If there is a predicted jump branch, the predicted target address of the earliest predicted jump branch instruction in the program order is used as the next fetch address. If there is no predicted jump branch, the next fetch address is determined in the order of the program.
[0059] Step 3: Generate a valid instruction mask based on the control flow location and prediction results. When there are control flow instructions for which prediction results have not yet been obtained, the control flow instruction with the earliest program order can be used as the boundary of the current speculative program flow. The valid instructions selected by the mask, the branch order, the predicted jump direction, and the predicted jump target address are combined to form the speculative program flow, and this program flow is sent to the transmitter along the pipeline.
[0060] Step four: The transmitter selects instructions from the speculative program flow transmit buffer based on the operand readiness status, data dependencies, execution resource usage, etc. When there are at least two branch instructions that meet the transmit conditions, each branch instruction is sent to different branch execution units for parallel execution.
[0061] Step 5: Each branch execution unit calculates the actual jump direction and the actual jump target address, compares the actual results with the predicted results, and generates a prediction correct flag or a prediction incorrect flag.
[0062] Step 6: When one or more valid branch instructions generate a prediction error flag, select the earliest prediction error branch instruction according to the program order of the branch instructions, and use the actual jump target or sequential successor address of that branch instruction as the unique redirection address.
[0063] Step 7: Generate a redirection mask with the earliest predicted erroneous branch instruction as the boundary, retain the branch instruction and the valid instructions that precede it in the program sequence, cancel the instructions that follow it in the program sequence, and ignore all requests generated by these instructions.
[0064] Step 8: According to the redirection mask, the cancelled instruction must not undergo general-purpose register write-back, memory access, control status register update, instruction exception, branch predictor update, or instruction exit operation.
[0065] Step nine: Re-fetch the instruction according to the redirected address and cancel the instruction in the pipeline that is on the wrong path. If the branch instruction in the earlier part of the program sequence is predicted correctly, no cancellation signal is generated for the instructions following that branch instruction. The valid state and execution result of these instructions are preserved, and the program exits in the order of instructions when the instruction exit condition is met.
[0066] Step 10: When the branch execution unit has determined whether the branch has jumped and its actual jump address, and the branch has not been canceled, the branch predictor is updated according to the actual jump result. For out-of-order issue processors, the instruction information of canceled instructions in the issue queue, reserve station, reorder cache and load memory queue is deleted, and information no longer needed for branch prediction error recovery is released.
[0067] Specifically, the multi-branch cooperative execution method of the superscalar processor in this embodiment scans multiple instructions acquired at the instruction fetch end, identifies the control flow instructions among them, and determines the position and program order of each control flow instruction; based on the prediction bandwidth of the branch prediction unit, it predicts the jump direction and jump target address of one or more scanned control flow instructions according to the program order; based on the prediction results, it generates a valid instruction mask, the next instruction fetch address, and branch order information, and sends the instructions selected by the valid instruction mask into a transmission packet to the transmitter; when there are at least two branch instructions in the transmission packet that meet the transmission conditions, the transmission packet is sent to the transmitter. At least two branch instructions are sent to different branch execution units; the actual jump direction and actual jump address of each branch instruction are compared with the corresponding prediction result; when one or more non-cancelled branch instructions are predicted incorrectly, the earliest predicted incorrect branch is selected according to the program order; a redirection mask is generated according to the program order of the predicted incorrect branch, retaining the predicted incorrect branch and valid instructions whose program order precedes it, canceling instructions whose program order follows it, and preventing the canceled instructions from generating state updates or exiting instructions; and re-fetching instructions according to the actual jump address or sequential successor address of the predicted incorrect branch. The multiple instructions obtained in one scan include pre-decoding each valid instruction to determine the position, type, and program order of control flow instructions. The valid instruction mask is used to mark instructions that are allowed to enter the subsequent pipeline according to the branch prediction result; the transmitter only receives instructions marked as valid and the prediction direction, prediction target, and branch order information corresponding to the instructions; when there are control flow instructions for which prediction results have not yet been obtained, instructions whose program order follows the earliest one are not marked as valid. For instructions fetched in the same session, the program order is determined based on the order of each instruction within the set of instructions. For instructions fetched multiple times sequentially, the program order is determined based on the order of each fetch and the order of each instruction within its respective fetch. In out-of-order superscalar processors, the program order can also be determined based on the order in which each instruction is allocated in the reorder cache. The issue conditions include that the operands of each branch instruction are ready, there are no data dependencies or structural conflicts that would prevent parallel execution, and at least two branch execution units are available. When multiple branch instructions that have not yet been canceled are simultaneously or sequentially determined to be prediction errors, the address for re-fetching is determined only based on the earliest prediction error branch in the program order; branch instructions that follow the prediction error branch do not change the address for re-fetching. The redirection mask is generated based on the program order relationship between each instruction and the earliest prediction error branch in the program order. The prediction error branch and valid instructions preceding it in the program order are not canceled; instructions that follow the prediction error branch and have entered the processor but have not yet exited are canceled.Instructions canceled by the redirection mask cannot undergo general-purpose register write-back, store commit, control status register update, exception commit, branch prediction status update, or instruction exit. In a sequentially issued superscalar processor, the valid instruction mask and redirection mask are passed along with the corresponding instruction through the issue packet and pipeline registers, and control the validity of the corresponding instruction during the general-purpose register write-back, store commit, control status register update, exception commit, branch prediction status update, and instruction exit stages. In an out-of-order issued superscalar processor, the branch order information is stored in the reordering cache; when the earliest predicted erroneous branch is determined, instructions in the issue queue or reserve station, reordering cache, and load store queue whose program order follows the predicted erroneous branch are canceled, and the register renaming state saved before the predicted erroneous branch entered speculative execution is restored. When an earlier branch instruction is predicted correctly, valid instructions whose program order follows the branch instruction are not canceled; branch instructions whose program order follows the branch instruction exit according to the program order when they have completed their execution, have not been canceled, and do not have any earlier pending exceptions. The branch prediction state is updated only when it has been determined whether the branch instruction actually jumps and the jump address when it actually jumps, and the branch instruction has not been canceled.
[0068] like Figure 3 As shown, the instruction fetch unit retrieves multiple instructions at once. The control flow scanning unit identifies the branch instructions and determines their positions and program order within the multiple instructions. The branch prediction unit predicts the jump direction and target address for one or more branch instructions according to the program order, based on the number of branch instructions that can be processed within a prediction cycle. Then, a valid instruction mask is generated based on the prediction results. When an earlier branch instruction in the program order is predicted as a jump, instructions following that branch instruction in the same fetch are marked as invalid. In the illustrated example, instruction 1 is predicted as a jump; therefore, even though instruction 3 has already received its prediction result, instructions 2 and 3 do not enter the subsequent pipeline.
[0069] like Figure 4 As shown, the instructions sent to the transmitter include non-branch instructions and multiple branch instructions. The transmission control unit selects the instruction to be transmitted based on conditions such as whether the operands of each instruction are ready, whether there are data dependencies, and whether the execution unit is available. When multiple branch instructions simultaneously meet the transmission conditions, they are sent to different branch execution units for parallel execution. The predicted jump direction, predicted jump address, and program sequence information of each branch instruction are transmitted along with the corresponding branch instruction so that they can be compared with the actual jump result after the branch execution is completed, and the selection is made according to the program sequence when multiple prediction errors exist.
[0070] like Figure 5As shown, the prediction result for branch 0 is correct, while the prediction results for branches 1 and 2 are incorrect. The processor selects branch 1 according to the program order and determines the address to fetch the new instruction based on whether branch 1 actually jumps and the jump address at the time of the actual jump; the execution result of branch 2 is no longer used to change the address to fetch the new instruction. The redirection mask preserves branch 1 and valid instructions in the program order preceding branch 1, and cancels instructions in the program order following branch 1. In the case where "1 indicates preservation and 0 indicates cancellation" is used in the illustration, the mask bits corresponding to instruction 0, branch 0, and branch 1 are 1, and the mask bits corresponding to branch 2 are 0.
[0071] like Figure 6 As shown, the redirection mask is used to control general-purpose register write-back, memory access, control status register update, instruction exception, branch predictor update, and instruction exit operations. For canceled instructions, general-purpose register write-back, memory access, control status register update, instruction exception, branch predictor update, and instruction exit operations are prohibited.
[0072] like Figure 7 As shown in the upper part, in the sequential launch embodiment, each instruction entering the pipeline carries a validity flag, which is passed between pipeline registers along with the corresponding instruction. When a branch prediction error occurs, instructions sequentially following that branch are marked as invalid based on the redirection mask. Before general-purpose register write-back, store commit, control status register update, exception commit, branch predictor update, and instruction exit, it is determined whether the instruction can perform the aforementioned operations based on the validity flag of the corresponding instruction.
[0073] like Figure 7 As shown in the lower part, in the out-of-order launch embodiment, the register renaming unit allocates reordering cache entries for instructions and allocates corresponding records in the launch queue or reserve station and load memory queue according to the instruction type. The program order information of each branch instruction is stored in the reordering cache, and the register renaming mapping state before the branch instruction enters speculative execution is also saved. When multiple branch instructions are determined to be prediction errors, the processor selects the earliest one in program order, restores the register renaming mapping state saved before the branch instruction enters speculative execution, and cancels instructions in the launch queue or reserve station, reordering cache, and load memory queue whose program order is after that branch instruction. Instructions that are not canceled are still exited by the reordering cache in program order. When a branch instruction with an earlier program order is predicted correctly, the valid instructions in program order that follow are not canceled; instructions that have been executed retain their execution results, and instructions that have not yet been executed are launched normally when the launch conditions are met, and finally exit in program order.
[0074] The above embodiments show that this application does not achieve multi-branch parallel execution simply by adding branch execution units. Instead, the instruction fetch end completes the identification, prediction, and screening of branch instructions, and multiple branch execution units determine the branch execution results in parallel. When there are multiple prediction errors, the earliest one is selected according to the program order to re-fetch the instruction, while canceling the instructions that follow in the program order. This reduces pipeline stalls caused by waiting for branch instructions and branch prediction errors, and improves the execution and exit efficiency of valid instructions.
[0075] In summary, this application filters instructions allowed to enter the subsequent pipeline based on branch prediction results and transmits the prediction results and program sequence information of each branch to the issue and execution stages. When one or more branch instructions are predicted incorrectly, the processor selects the earliest one in program sequence to re-fetch the instruction, while canceling instructions in the program sequence following that branch, preventing the canceled instructions from generating state updates or exiting. This method can be used as long as the processor can determine the program sequence between branch instructions and can cancel instructions in the program sequence following the selected branch when a branch prediction error occurs. This method is applicable to both sequential issue processors and out-of-order issue processors.
[0076] Example 3 In yet another embodiment, this application provides a multi-branch cooperative execution device for a superscalar processor, comprising: The instruction fetch control flow scanning unit is used to scan multiple instructions fetched at one time, identify the control flow instructions among them, and determine the position and program sequence of each control flow instruction; The branch prediction unit is used to generate the prediction direction and prediction target of one or more control flow instructions based on the prediction bandwidth. The instruction filtering unit is used to generate a valid instruction mask, the next instruction fetch address, and branch order information based on the prediction results, and send the instruction selected by the valid instruction mask to the transmitter. A launch control unit is configured to assign at least two branch instructions to different branch execution units when there are at least two branch instructions that satisfy the launch conditions. Multiple branch execution units are used to execute the branch instructions and return the actual jump direction, actual jump address, and branch order information; The branch result selection unit is used to select the earliest predicted incorrect branch in the program order when one or more branch instructions that have not been canceled are predicted incorrectly. A redirection mask generation unit is used to retain the predicted error branch and valid instructions that precede it in the program order, and cancel instructions that follow it in the program order; and a status update control unit and an instruction exit control unit are used to prevent canceled instructions from generating status updates or exiting instructions.
[0077] Furthermore, the apparatus is used to sequentially issue superscalar processors, and the valid instruction mask and redirection mask are stored together with the corresponding instructions in the issue packet and the pipeline registers at each stage.
[0078] Furthermore, the apparatus is used for out-of-order superscalar processors and also includes a register renaming unit, a send queue or reservation station, a reordering cache, and a load memory queue; the register renaming unit is used to save the register renaming state before a branch instruction enters speculative execution; when a branch instruction is predicted incorrectly, the register renaming state corresponding to the earliest predicted incorrect branch in the program order is restored, and instructions in the program order following the predicted incorrect branch are canceled.
[0079] Specifically, the device includes an instruction fetch control flow scanning unit, a branch prediction unit, a speculative program flow forming unit, a launch control unit, multiple branch execution units, a branch result arbitration unit, a redirection mask generation unit, a state gating unit, and an instruction exit control unit. Each unit is interconnected through prediction information, branch execution results, program sequence information, and redirection masks. These units can be implemented using independent hardware or can share decoding, comparison, queuing, or recovery resources.
[0080] Specifically, the implementation methods for sequential and out-of-order deployments are as follows: In a sequentially deployed superscalar processor, the prediction path valid instruction mask and redirection mask are passed step-by-step along the pipeline registers and gating the corresponding instructions during general-purpose register write-back, memory access, control status register update, instruction exception, branch predictor update, and instruction exit operations. In an out-of-order deployed superscalar processor, after an instruction completes register renaming, its program order and execution state are recorded in the Reorder Buffer (ROB), and its operands and ready state are recorded in the deploy queue or reservation station (RS). Load and store instructions also record the memory access order and related states in the Load / Store Queue (LSQ). For speculatively executed branch instructions, the processor establishes a branch checkpoint to save the register renaming mapping state at the time the branch is established and to restore control information. When a branch prediction error occurs, the processor selects the earliest predicted branch in program order, restores the register renaming state according to its branch checkpoint, and cancels instructions in each queue whose program order is later than that branch. Uncancelled instructions will still be exited by ROB in sequence.
[0081] Optional extension methods: The branch prediction unit can predict one or more control flow instructions within a prediction cycle. When the prediction bandwidth is less than the number of control flow instructions obtained from the scan, prediction can be performed in batches according to the program order, or the earliest control flow instruction whose prediction result has not yet been obtained can be used as the boundary of the current speculative program flow. The speculative program flow can use a single prediction source, or it can combine direction prediction, target prediction, and return address prediction. For processors that support compressed instructions or variable-length instructions, the sequential successor address is calculated based on the actual instruction length. Within the same instruction fetch block, the program order of each branch can be determined based on its position in the instruction fetch block; for branches from different instruction fetch blocks, the program order can be determined by combining the order in which each instruction fetch block enters the processor and the position of the branch in the corresponding instruction fetch block. In out-of-order issue superscalar processors, the program order can also be determined based on the order in which each branch is in the reorder cache, or the order in which the corresponding checkpoints of each branch are established. In this application, "older" and "younger" refer to earlier and later program orders, respectively.
[0082] This application discloses a multi-branch cooperative execution device based on a superscalar processor. The instruction fetch end reads an instruction block from the instruction memory as a pre-issue instruction stream, simultaneously scanning the branch instructions within the instruction block to determine the location and program order of each branch instruction. It then predicts the jump direction and jump target address of the scanned branch instructions and generates an instruction validity mask based on the prediction results. The instruction validity mask and the pre-issue instruction stream are ANDed to form a speculative program stream, which is then sent to the transmitter. The transmitter can simultaneously send multiple issueable branch instructions to different branch execution units for parallel execution. After each branch execution unit returns the true jump direction and true jump target address, an arbitration unit selects the earliest predicted incorrect branch instruction in the program order as the sole redirection source and generates a redirection mask to prevent instructions located on incorrect paths from changing the program execution state, thereby improving instruction execution efficiency while maintaining accurate state.
[0083] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0084] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
Claims
1. A multi-branch cooperative execution method for a superscalar processor, characterized in that, include: S1, scan multiple instructions acquired at the instruction fetching end, identify the control flow instructions among them, and determine the position and program order of each control flow instruction in the multiple instructions; S2, based on the prediction bandwidth of the branch prediction unit, perform jump direction prediction and jump target address prediction on one or more scanned control flow instructions in the order of the program, generate an effective instruction mask and the next instruction fetch address based on the prediction results, and send the instruction selected by the effective instruction mask as a speculative program flow to the transmitter. S3, when there are at least two branch instructions that meet the launch conditions in the speculative program flow, the at least two branch instructions are sent to different branch execution units for parallel execution. Each branch execution unit returns the actual jump direction and actual jump address of each branch instruction, and compares the actual jump direction and actual jump address with the corresponding prediction result. S4. When one or more non-cancelled branch instructions are determined to be prediction errors, the earliest prediction error branch instruction is selected according to the program order. A redirection mask is generated with the earliest prediction error branch instruction as the boundary. The earliest prediction error branch instruction and the valid instructions that precede it in the program order are retained. Instructions that follow it in the program order are canceled. The canceled instructions are prevented from generating status updates or exiting instructions. Instructions are re-fetched according to the actual jump address or sequential successor address of the earliest prediction error branch instruction.
2. The method as described in claim 1, characterized in that, The step of scanning multiple instructions at the instruction fetching end, identifying control flow instructions among them, and determining the position and program order of each control flow instruction within the multiple instructions includes: Each valid instruction in the multiple instructions is pre-decoded to identify conditional branches, unconditional jumps, indirect jumps, function calls, and function return instructions, and the position, type, and program order of each control flow instruction in the multiple instructions are recorded.
3. The method as described in claim 1, characterized in that, The step of generating a valid instruction mask and the next instruction fetch address based on the prediction result includes: When there is an instruction with the earliest predicted jump in the program sequence, the predicted target address of the earliest predicted jump instruction in the program sequence is used as the next fetch address; when there is no predicted jump instruction, the next fetch address is determined according to the program sequence; the valid instruction mask is used to mark instructions that are allowed to enter the subsequent pipeline according to the branch prediction result. When there are control flow instructions that have not yet obtained the prediction result, the instructions that are located after the earliest one in the program sequence are not marked as valid.
4. The method as described in claim 1, characterized in that, Determining the position and program order of each control flow instruction within the multiple instructions includes: for instructions fetched in the same session, determining the program order based on the sequential position of each instruction within the multiple instructions; for instructions fetched multiple times sequentially, determining the program order based on the sequential order of each fetch and the sequential position of each instruction within the corresponding fetch; in an out-of-order superscalar processor, the program order is also determined based on the allocation order of each instruction in the reordering cache. The launch conditions include that the operands of each branch instruction are ready, there are no data dependencies or structural conflicts that prevent parallel execution, and at least two branch execution units are available; The step of sending the at least two branch instructions to different branch execution units for parallel execution includes: the predicted jump direction, predicted jump target address, and program sequence information of each branch instruction are transmitted together with the corresponding branch instruction to the corresponding branch execution unit; each branch execution unit calculates the actual jump direction and the actual jump target address; the actual jump direction and the actual jump target address are compared with the corresponding prediction results to generate a prediction correct flag or a prediction incorrect flag.
5. The method as described in claim 1, characterized in that, The step of selecting the earliest predicted error branch instruction according to the program order includes: when multiple non-cancelled branch instructions are judged as predicted errors simultaneously or sequentially, the address to be re-fetched is determined only according to the earliest predicted error branch instruction in the program order, and the branch instructions in the program order that follow it do not change the address to be re-fetched. The step of generating a redirection mask using the earliest predicted error branch instruction as the boundary includes: A redirection mask is generated based on the program order relationship between each instruction and the earliest predicted error branch instruction. The mask bits corresponding to the earliest predicted error branch instruction and the valid instructions that precede it in the program order are reserved, while the mask bits corresponding to instructions that are after the earliest predicted error branch instruction and have entered the processor but have not yet exited are canceled. Instructions canceled by the redirection mask cannot be written back to general-purpose registers, committed to storage, updated to control status registers, committed to exceptions, updated to branch prediction status, or exited.
6. The method as described in claim 1, characterized in that, In a sequentially issued superscalar processor, the valid instruction mask and redirection mask are passed along with the corresponding instruction through the speculative program flow and pipeline registers, and the validity of the corresponding instruction is controlled during the general-purpose register write-back, store commit, control status register update, exception commit, branch prediction status update and instruction exit stages. In an out-of-order superscalar processor, the branch order information is stored in a reordering cache; Once the earliest predicted error branch instruction in the program sequence is determined, the instructions in the issue queue or reserve station, reorder cache, and load store queue that are in the program sequence after the earliest predicted error branch instruction are cancelled, and the register renaming state saved before the earliest predicted error branch instruction entered speculative execution is restored. If an earlier branch instruction in the program sequence is predicted correctly, the valid instructions following that branch instruction in the program sequence are not cancelled; if a branch instruction following that branch instruction has completed its execution, has not been cancelled, and there are no pending exceptions from earlier in the program sequence, it exits in the program sequence. The branch prediction state is updated only when it has been determined whether the branch instruction actually jumps and the jump address when it actually jumps, and the branch instruction has not been canceled.
7. The method as described in claim 1, characterized in that, The step of re-fetching instructions based on the actual jump address or sequential successor address of the earliest predicted erroneous branch instruction includes: when the actual jump direction of the earliest predicted erroneous branch instruction is a jump, using the actual jump address as the address for re-fetching instructions; when the actual jump direction of the earliest predicted erroneous branch instruction is no jump, using the sequential successor address as the address for re-fetching instructions. Preventing the cancelled instruction from generating a status update or exiting the instruction includes: according to the redirection mask, gating the cancelled instruction before general-purpose register write-back, store commit, control status register update, exception commit, branch prediction status update and instruction exit operations, so that the cancelled instruction cannot perform the above operations; Each instruction in the speculative program flow carries branch sequence information, predicted jump direction, predicted jump target address, and sequential successor address; the branch sequence information is used to determine the order of different branch instructions, and the sequential successor address is calculated based on the actual length of the instruction. The step of predicting the jump direction and jump target address of one or more scanned control flow instructions according to the prediction bandwidth of the branch prediction unit and in program order includes: when the prediction bandwidth is less than the number of scanned control flow instructions, performing prediction in batches according to program order, or using the earliest control flow instruction that has not yet obtained the prediction result as the boundary of the current speculative program flow.
8. The method as described in claim 1, characterized in that, The jump direction prediction and jump target address prediction combine direction prediction, target prediction and return address prediction methods; for processors that support compressed instructions or variable-length instructions, the sequential successor address is calculated based on the actual instruction length; The step of sending the instructions selected by the valid instruction mask as a speculative program flow to the transmitter includes: the valid instruction mask and the multiple instructions are ANDed to form the speculative program flow, the speculative program flow along with the prediction information enters the transmitter along the pipeline, and the transmitter only receives the instructions marked as valid and the prediction direction, prediction target and branch sequence information corresponding to the instructions.
9. The method as described in claim 1, characterized in that, Each branch execution unit returns the actual jump direction and actual jump address of each branch instruction, and compares the actual jump direction and actual jump address with the corresponding prediction result, including: Each branch execution unit compares the actual jump direction and actual jump address with the predicted jump direction and predicted jump target address transmitted from the instruction fetch terminal. When they match, a prediction correct flag is generated; when they do not match, a prediction incorrect flag is generated. When the execution results of multiple branches simultaneously indicate a prediction error, the arbitration unit selects only the earliest prediction error branch instruction in the program sequence as the redirection source for this recovery, and cancels the redirection requests proposed by later branch instructions in the program sequence.
10. A multi-branch cooperative execution device for a superscalar processor, characterized in that, include: The instruction fetch control flow scanning unit is used to scan multiple instructions fetched at one time, identify the control flow instructions among them, and determine the position and program sequence of each control flow instruction; The branch prediction unit is used to generate the prediction direction and prediction target of one or more control flow instructions based on the prediction bandwidth. The instruction filtering unit is used to generate a valid instruction mask, the next instruction fetch address, and branch order information based on the prediction results, and send the instruction selected by the valid instruction mask to the transmitter. A launch control unit is configured to assign at least two branch instructions to different branch execution units when there are at least two branch instructions that satisfy the launch conditions. Multiple branch execution units are used to execute the branch instructions and return the actual jump direction, actual jump address, and branch order information; The branch result selection unit is used to select the earliest predicted incorrect branch in the program order when one or more branch instructions that have not been canceled are predicted incorrectly. A redirection mask generation unit is used to retain the predicted error branches and valid instructions that precede them in the program order, and to cancel instructions that follow them in the program order. It also includes a status update control unit and an instruction exit control unit, used to prevent canceled instructions from generating status updates or exiting instructions.
