A method and apparatus for decoupling a two-stage flexible queue pipeline for a superscalar processor
By introducing a two-stage elastic queue pipeline decoupling method in the superscalar processor, the rate fluctuations of the instruction fetch, decode, and transmit stages are independently controlled by the local handshake mechanism, which solves the pipeline stall propagation problem and improves the processor's throughput and timing convergence.
Patent Information
- Application Number
- CN202611331663.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-10
AI Technical Summary
The inconsistent instantaneous processing rates of superscalar processors during instruction fetch, decoding, and transmit phases can cause pipeline stalls to propagate easily, resulting in mutual constraints between the front and back ends and long cross-stage combination feedback paths.
A two-stage elastic queue pipeline decoupling method is adopted. By setting up a first circular queue between instruction fetch and decoding, and a second circular queue between decoding and transmission, a local handshake mechanism is used for data transmission. The rate fluctuation of each stage is controlled separately to maintain the correctness of program order and control flow recovery.
It effectively absorbs rate fluctuations during instruction fetch, decoding, and transmit phases, reduces pipeline stall propagation, improves processor throughput and timing convergence, and avoids the impact of long combined feedback paths.
Smart Images

Figure CN123067937A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of processor microarchitecture and pipeline control technology, specifically to a two-stage flexible queue pipeline decoupling method and apparatus for superscalar processors. Background Technology
[0002] A superscalar processor can fetch, decode, and issue multiple instructions within a single clock cycle. However, the instantaneous processing rates of the fetch, decode, and issue phases are not consistent due to various events such as cache hits, control flow boundaries, data dependencies, and execution resources.
[0003] In traditional architectures, direct-connect pipelines lacking elastic buffers typically rely on cross-level hold or bubble insertion for coordination. Back-end pauses can easily backpressure the program counter at each level, while front-end pauses can immediately cause a lack of instruction input to the back-end; wide instruction packets and control fields also amplify the timing burden of cross-level combined feedback.
[0004] Traditional solutions only set up a single queue between instruction fetching and decoding. Although this can absorb some of the instruction fetching rate fluctuations, the decoding results are still directly coupled with the transmitter, and some transmission and backend resource limitations may still be fed back to the frontend.
[0005] Therefore, a hierarchical decoupling structure that does not rely on a fixed transmit width is needed, so that the original instruction, the decoded micro-operation and the actual transmit micro-operation sequence are transmitted through local handshakes, while maintaining the correctness of program order and control flow recovery. Summary of the Invention
[0006] The present invention aims to at least partially solve one of the technical problems in the related art.
[0007] Therefore, the first objective of this invention is to propose a two-stage flexible queue pipeline decoupling method for superscalar processors.
[0008] The second objective of this invention is to provide a two-stage flexible queue pipeline decoupling device for superscalar processors.
[0009] The third objective of this invention is to provide a computer device.
[0010] A fourth objective of this invention is to provide a non-transitory computer-readable storage medium.
[0011] To achieve the above objectives, a first aspect of the present invention proposes a two-stage flexible queue pipeline decoupling method for superscalar processors, comprising: S1, during the instruction fetching stage, zero to W valid instructions are obtained from the instruction storage hierarchy according to a preset parallel width. The program counter value corresponding to each instruction is determined and associated, and the branch prediction information output by the branch prediction unit for the identified control flow instruction is obtained. When the first circular queue is ready to receive, the valid instructions and their associated program counter values and branch prediction information are written into the first circular queue in program order. S2, the parallel decoding unit reads up to W instructions from the head of the first circular queue and performs parallel decoding to generate corresponding micro-operations. The micro-operations generated by the decoding are written into the second circular queue in program order. After the second circular queue actually receives the decoding results, the first circular queue advances the head pointer according to the actual number of received instructions. S3, the launch allocation unit starts with the micro-operation at the head of the second circular queue and determines the ordered sequence of micro-operations that the backend can accept based on data correlation and execution resource status; S4, after the backend actually accepts the ordered micro-operation sequence, the second circular queue advances the head pointer and updates the occupancy counter according to the actual number of accepted micro-operations, and the unaccepted micro-operations continue to be stored in the second circular queue and maintain the original program order; S5, when a control flow redirection occurs, the valid items in the first and second circular queues before the redirection are synchronously invalidated.
[0012] In one embodiment of the present invention, each queue item of the first circular queue includes an instruction field, a program counter value field, and a branch prediction information field, wherein the low-alignment bits of the program counter value are omitted when writing and are added back when reading.
[0013] In one embodiment of the present invention, each queue entry of the second circular queue includes a source register, a destination register, an immediate value, an operation type, a memory access type, and a valid state; for control flow micro-operations, it also includes a predicted target address value; the execution channel selection is determined by the issue allocation unit when the micro-operation leaves the second circular queue and is not stored in the second circular queue.
[0014] In one embodiment of the present invention, each circular queue includes multiple storage banks corresponding to the preset parallel width W, and the queue depth is an integer multiple of W; consecutive write items are allocated to different storage banks according to the circular address, the read results of the queue head are rearranged according to the head pointer, and output in the program order from old to new.
[0015] In one embodiment of the present invention, the local ready signal of each level of the circular queue is determined by the depth of the circular queue, the current occupancy, and the current number of requests to push in, and the number of downstream removals that may occur in the same clock cycle is not taken as the idle quota; the first circular queue advances its head pointer only after the second circular queue actually receives the decoding result, and the second circular queue advances its head pointer only after the back end actually receives the ordered micro-operation sequence.
[0016] In one embodiment of the present invention, push and pop are allowed to occur simultaneously in the same clock cycle, and the occupancy is updated according to the difference between the two quantities; the head pointers of the first circular queue and the second circular queue advance according to the actual number of items removed, and the tail pointers advance according to the actual number of items written.
[0017] In one embodiment of the present invention, when the instruction storage hierarchy is paused, the parallel decoding unit and the transmit allocation unit continue to process the existing instructions and micro-operations in the first circular queue and the second circular queue; when the backend is paused, if the first circular queue can receive the valid instructions of the current cycle and their associated information, the instruction fetch unit continues to write to the first circular queue, and if the second circular queue can receive the decoding result of the current cycle, the parallel decoding unit continues to write to the second circular queue.
[0018] In one embodiment of the present invention, the control flow redirection specifically includes: loading the redirection target address value into the program counter, restoring the head pointer, tail pointer, and occupancy counter of the first and second circular queues to an empty state, and clearing the valid state of the instructions before redirection in the execution level entry.
[0019] To achieve the above objectives, a second aspect of the present invention provides a two-stage flexible queue pipeline decoupling device for superscalar processors, comprising: The instruction fetch unit is used to fetch zero to W valid instructions from the instruction storage hierarchy according to a preset parallel width, determine and associate the program counter value corresponding to each instruction, and identify the control flow instructions among them; A branch prediction unit is used to output branch prediction information for the control flow instructions identified by the instruction fetching unit. The first circular queue, connected to the instruction fetch unit and the branch prediction unit, is used to store the valid instructions and their associated program counter values and branch prediction information in program order. A parallel decoding unit, connected to the first circular queue, is used to read up to W instructions from the head of the first circular queue and perform parallel decoding to generate corresponding micro-operations; The second circular queue is connected to the parallel decoding unit and is used to save the micro-operations generated by the parallel decoding unit in program order. The launch allocation unit, connected to the second circular queue, is used to determine an ordered sequence of micro-operations that the backend can accept, starting from the micro-operation at the head of the second circular queue, based on data correlation and execution resource status. The adjacent units in the instruction fetching unit, the first circular queue, the parallel decoding unit, the second circular queue, and the transmit allocation unit use a local handshake mechanism to transmit data. The first circular queue generates a first ready signal based on its remaining capacity, and the second circular queue generates a second ready signal based on its remaining capacity. The redirection clearing unit is used to synchronously invalidate valid items in the first and second circular queues before the redirection when a control flow redirection occurs.
[0020] The present invention provides a method and apparatus for decoupling a two-stage elastic queue pipeline for a superscalar processor, which has the following beneficial effects: First, the present invention sets flexible capacities between instruction fetching and decoding, and between decoding and transmission, so that the overall operation of the three stages is no longer directly coupled through a unified holding chain.
[0021] Second, both levels of queues support variable-width push and pop from zero to W items, which can adapt to different superscalar widths and changes in the number of consecutive valid instructions caused by control flow boundaries and data dependencies.
[0022] Third, the first circular queue stores instructions, program counter values, and branch prediction information; the second circular queue stores compact micro-operations consisting of source registers, destination registers, immediate values, operation types, memory access types, and valid status, avoiding the duplication of saving useless fields.
[0023] Fourth, the local ready signal does not reference the number of downstream transmissions in the same period, which can cut off the long combination feedback from the back-end transmission conditions to the front-end program counter, facilitating the timing convergence of the wide data path.
[0024] Fifth, the transmitter only removes the ordered sequence of micro-operations actually received at the back end and advances the head pointer of the second circular queue according to the actual number of received micro-operations; unaccepted micro-operations continue to maintain their program order, without needing to be re-decoded due to partial transmission, and without needing to forward and compress the remaining micro-operations.
[0025] To achieve the above objectives, a third aspect of this application provides a computer device comprising: a processor and a memory; wherein the processor runs a program corresponding to the executable program code by reading executable program code stored in the memory, for implementing a two-stage flexible queue pipeline decoupling method for a superscalar processor as described in the first aspect embodiment.
[0026] To achieve the above objectives, a fourth aspect of this application provides a non-transitory computer-readable storage medium storing a computer program that, when executed by a processor, implements a two-stage flexible queue pipeline decoupling method for a superscalar processor as described in the first aspect embodiment.
[0027] Additional aspects and advantages of the invention 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 the invention. Attached Figure Description
[0028] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 This is a flowchart of a two-stage flexible queue pipeline decoupling method for a superscalar processor according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall structure of a two-stage elastic queue for a superscalar processor according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a circular queue and its head and tail pointers according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the local handshake relationship between the instruction fetching stage, the decoding stage, and the transmit stage according to an embodiment of the present invention; Figure 5 This is a comparative diagram of a direct connection structure without a First-In-First-Out (FIFO) queue and a two-level flexible queue structure under front-end pause and back-end pause scenarios according to an embodiment of the present invention. Figure 6 This is a schematic diagram of the process for clearing the valid states of the first circular queue, the second circular queue, and the execution level entry point during control flow redirection according to an embodiment of the present invention; Figure 7 It is a computer device according to an embodiment of the present invention. Detailed Implementation
[0029] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0030] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0031] The following description, with reference to the accompanying drawings, describes a two-stage flexible queue pipeline decoupling method and apparatus for superscalar processors according to an embodiment of the present invention.
[0032] Example 1 Figure 1 This is a flowchart of a two-stage flexible queue pipeline decoupling method for a superscalar processor according to an embodiment of the present invention, as follows: Figure 1 As shown, it includes: S1, during the instruction fetching stage, zero to W valid instructions are obtained from the instruction storage hierarchy according to a preset parallel width. The program counter value corresponding to each instruction is determined and associated, and the branch prediction information output by the branch prediction unit for the identified control flow instruction is obtained. When the first circular queue is ready to receive, the valid instructions and their associated program counter values and branch prediction information are written into the first circular queue in program order. Each queue entry in the first circular queue includes an instruction field, a program counter value field, and a branch prediction information field; the branch prediction information field includes a prediction hit flag, a prediction direction flag, and a prediction target address field. For instructions that have not undergone branch prediction, the prediction hit flag is set to invalid; wherein, the low-order bits of the program counter value and the prediction target address, which are determined by address alignment, are omitted when writing and are added back when reading.
[0033] S2, the parallel decoding unit reads up to W instructions from the head of the first circular queue and performs parallel decoding to generate corresponding micro-operations. The micro-operations generated by the decoding are written into the second circular queue in program order. After the second circular queue actually receives the decoding results, the first circular queue advances the head pointer according to the actual number of received instructions. Each queue entry in the second circular queue includes a source register, a destination register, an immediate value, an operation type, a memory access type, and a valid status; for control flow micro-operations, it also includes a predicted target address value; the execution channel selection is determined by the issue allocation unit when the micro-operation leaves the second circular queue and is not stored in the second circular queue.
[0034] S3, the launch allocation unit starts with the micro-operation at the head of the second circular queue and determines the ordered sequence of micro-operations that the backend can accept based on data correlation and execution resource status; S4, after the backend actually accepts the ordered micro-operation sequence, the second circular queue advances the head pointer and updates the occupancy counter according to the actual number of accepted micro-operations, and the unaccepted micro-operations continue to be stored in the second circular queue and maintain the original program order; Each circular queue can include multiple memory banks, and there is no limit to the queue depth. Items written consecutively are allocated to different memory banks according to the circular address. The results read from the head of the queue are rearranged according to the head pointer and output in the order of the program from oldest to newest. The local readiness signal of each level of the circular queue is determined by the depth of the circular queue, the current occupancy, and the current number of requests to push in. The number of downstream removals that may occur in the same clock cycle is not considered as the idle quota. The first circular queue advances its head pointer only after the second circular queue actually receives the decoding result, and the second circular queue advances its head pointer only after the back end actually receives the ordered micro-operation sequence.
[0035] Push and pop can occur simultaneously within the same clock cycle, and the occupancy is updated according to the difference between the two quantities; the head pointers of the first and second circular queues advance according to the actual number of items removed, and the tail pointers advance according to the actual number of items written. When the instruction storage hierarchy is paused, the parallel decoding unit and the transmit allocation unit continue to process the existing instructions and micro-operations in the first and second circular queues; when the backend is paused, if the first circular queue can receive the valid instructions and their associated information for the current cycle, the instruction fetch unit continues to write to the first circular queue, and if the second circular queue can receive the decoding results for the current cycle, the parallel decoding unit continues to write to the second circular queue.
[0036] S5, When a control flow redirection occurs, the valid items in the first and second circular queues before the redirection are synchronously invalidated. The control flow redirection specifically includes: loading the redirection target address value into the program counter, restoring the head pointer, tail pointer, and occupancy counter of the first and second circular queues to an empty state, and clearing the valid state of the instructions before redirection in the execution level entry.
[0037] The present invention discloses a two-stage elastic queue pipeline decoupling method for a superscalar processor, which can effectively absorb rate fluctuations between the instruction fetch, decode, and transmit stages through a two-stage elastic queue and a local handshake mechanism, reduce pipeline stall propagation, and improve processor throughput and timing convergence.
[0038] Example 2 This invention provides a method and apparatus for decoupling a two-stage flexible queue pipeline for a superscalar processor. This solution addresses the problems of pipeline stalls easily propagating through each stage, mutual constraints between the front and back ends, and long cross-stage combination feedback paths when the instantaneous processing rates are inconsistent during the instruction fetch, decode, and transmit stages.
[0039] This invention establishes a first circular queue between the instruction fetch unit and the parallel decoding unit, and a second circular queue between the parallel decoding unit and the transmit allocation unit. The first circular queue stores the valid instructions obtained during the instruction fetch stage, along with their associated program counter values and branch prediction information, in program order; the second circular queue stores the micro-operations obtained during decoding, in program order. The two circular queues control the data transmission of the preceding stage based on their remaining capacity, enabling the instruction fetch, decoding, and transmit stages to proceed according to their respective reception conditions.
[0040] Assume the processor's preset parallel width is W. The instruction fetch unit acquires zero to W valid instructions each clock cycle and, when the first circular queue is ready to receive, pushes the valid instructions of the current cycle, along with their associated program counter values and branch prediction information, into the first circular queue. The parallel decoding unit reads up to W instructions from the head of the first circular queue and generates corresponding micro-operations. Only after the second circular queue actually receives the decoding results does the first circular queue remove the corresponding instructions according to the actual number received. The transmit allocation unit starts from the first micro-operation in the second circular queue and forms an ordered sequence of micro-operations acceptable to the backend; only after the backend actually receives the micro-operations does the second circular queue remove the corresponding micro-operations according to the actual number received.
[0041] The following describes in detail the device structure, method steps, and specific implementation methods of the present invention.
[0042] The apparatus for implementing this method includes an instruction fetch unit, a branch prediction unit, a first circular queue, a parallel decoding unit, a second circular queue, a send / receive unit, an execution level entry point, and a redirection and clearing unit. The instruction fetch unit and the branch prediction unit are respectively connected to the first circular queue. The first circular queue, the parallel decoding unit, the second circular queue, the send / receive unit, and the execution level entry point are connected sequentially according to the instruction processing direction. Data transmission between the aforementioned adjacent units is performed using a local handshake mechanism.
[0043] The instruction fetch unit retrieves zero to W valid instructions for the current cycle from the instruction storage hierarchy according to a preset parallel width. It determines the actual number of instructions retrieved in the current cycle based on the slot validity mask and control flow boundaries, and determines and associates the corresponding program counter values based on the starting program counter value of the current cycle and the slot where each instruction is located. The branch prediction unit outputs branch prediction information for the control flow instructions identified by the instruction fetch unit. This branch prediction information is associated with the corresponding control flow instructions and written to the first circular queue along with the valid instructions. During normal sequential instruction fetching, the instruction fetch unit retrieves a maximum of W consecutive instructions at a time. When encountering a control flow instruction with a predicted jump, the current instruction fetch ends at that instruction, and the next instruction fetch begins from the predicted target address value.
[0044] The first circular queue is used to store the valid instructions determined by the instruction fetch unit, along with their associated program counter values and branch prediction information, in program order. Each entry in the first circular queue includes an instruction field, a program counter value field, and a branch prediction information field. The branch prediction information field includes a prediction hit flag, a prediction direction flag, and a prediction target address field. For instructions for which branch prediction has not been performed, the prediction hit flag is set to invalid. The low-order bits of the program counter value and the prediction target address value, determined by instruction address alignment, can be omitted during writing and padded back during reading.
[0045] The first circular queue has a head pointer, a tail pointer, and an occupancy counter. The head pointer points to the earliest instruction that has not yet been received by the parallel decoding unit, the tail pointer points to the next write position, and the occupancy counter indicates the number of instructions currently stored in the first circular queue. The first circular queue can write zero to W instructions and remove zero to W instructions in one clock cycle, and writing and removing are allowed to occur in the same clock cycle.
[0046] The parallel decoding unit reads up to W instructions sequentially from the head pointer of the first circular queue and generates the corresponding micro-operations in parallel. The parallel decoding unit only processes the instructions actually stored in the first circular queue; memory locations not read in the current cycle do not participate in decoding or status updates.
[0047] The second circular queue is used to store micro-operations generated by the parallel decoding unit in program order. Each micro-operation includes a source register, a destination register, an immediate value, an operation type, a memory access type, and a valid status. For control flow micro-operations, the second circular queue also stores the corresponding predicted target address value. The execution channel selection is determined by the issue allocation unit when the micro-operation leaves the second circular queue and does not need to be stored in the second circular queue.
[0048] The second circular queue also has a head pointer, a tail pointer, and an occupancy counter. The head pointer points to the earliest micro-operation that has not yet been accepted by the backend, the tail pointer points to the next write position, and the occupancy counter indicates the number of micro-operations currently stored in the second circular queue. The second circular queue can write zero to W micro-operations and remove zero to W micro-operations in one clock cycle, and allows writing and removal to occur in the same clock cycle.
[0049] Both the first and second circular queues can be configured with multiple memory banks corresponding to the parallel width W. Instructions or micro-operations written sequentially are allocated to different memory banks according to their circular addresses. Read results are rearranged according to the head pointer position and output in ascending order of program sequence. The depth of both circular queues can be set to an integer multiple of W.
[0050] Adjacent units in the instruction fetch unit, first circular queue, parallel decoding unit, second circular queue, and transmit allocation unit use a local handshake mechanism for data transmission. The first circular queue determines whether it can receive all valid instructions and their associated information for the current cycle based on its own depth, current occupied quantity, and the quantity requested for writing in this cycle; the second circular queue uses the same method to determine whether it can receive all decoding results in this cycle.
[0051] The local readiness signals of the two-level circular queues are determined by the depth of the corresponding circular queue, the current occupancy, and the current number of write requests, respectively. The number of instructions that may be removed from the next level within the same clock cycle is not pre-calculated into the available space. Only after the next level actually receives the corresponding number of instructions or micro-operations does the head pointer of the upper-level queue advance according to the actual number received.
[0052] The issue allocation unit checks up to W micro-operations sequentially, starting from the head pointer position of the second circular queue. Based on data dependencies, execution channels, memory access resources, and serialization conditions, the issue allocation unit determines the ordered sequence of micro-operations that the backend can accept, starting from the first micro-operation. If the first micro-operation cannot be issued, the head pointer of the second circular queue remains unchanged; if the backend accepts one or more micro-operations, the head pointer of the second circular queue advances according to the actual number accepted.
[0053] The redirection and clearing unit handles branch prediction errors, exceptions, returns, and other control flow redirections. When a control flow redirection occurs, the program counter is loaded with the redirection target address value, the head and tail pointers and occupancy counters of the first and second loop queues are restored to empty, and the valid state of the instructions before the redirection is cleared from the execution level entry point. Data in the queue memory does not need to be cleared item by item; the old data after clearing is no longer read or executed.
[0054] The two-stage elastic queue pipeline decoupling method can be implemented according to the following steps: Step 1: The instruction fetch unit obtains zero to W valid instructions for the current cycle from the instruction storage hierarchy according to a preset parallel width, determines and associates the program counter value corresponding to each instruction, and identifies the control flow instructions among them; the branch prediction unit outputs branch prediction information for the identified control flow instructions.
[0055] Step two: The first circular queue determines whether it can accommodate all valid instructions and their associated information based on its current remaining capacity. If there is enough space, the valid instructions, their associated program counter values, and branch prediction information are written into the first circular queue in program order, and the tail pointer is advanced and the occupancy counter is updated according to the actual number of instructions written. If there is insufficient space, the current writing is paused.
[0056] Step 3: The parallel decoding unit starts from the head pointer position of the first circular queue, reads up to W instructions from the head of the queue, performs parallel decoding on the read instructions, and generates the corresponding micro-operations.
[0057] Step four: The second circular queue determines whether it can accommodate all the decoding results based on its remaining capacity. If there is enough space, the micro-operations are written into the second circular queue in program order, and the tail pointer of the second circular queue is advanced according to the actual number written; simultaneously, the head pointer of the first circular queue is advanced according to the actual number received by the second circular queue. If the space in the second circular queue is insufficient, the decoding results are not written, and both circular queues maintain their current state.
[0058] Step 5: Starting from the first micro-operation in the second circular queue, the launch allocation unit sequentially checks the data correlation, execution channel, memory access resources, and serialization conditions of up to W micro-operations at the head of the queue to determine the ordered sequence of micro-operations that the back end of the current cycle can accept, and allocates execution channels for the micro-operations that can be launched.
[0059] Step six: After the backend actually accepts the ordered micro-operation sequence, the second circular queue advances its head pointer and updates its occupancy counter according to the actual number of accepted operations. Micro-operations not accepted by the backend continue to be stored in the second circular queue, maintaining their original program order.
[0060] Step 7: When writes and removals occur simultaneously within the same clock cycle, the first circular queue and the second circular queue update the occupancy counters according to the difference between the actual number of writes and the actual number of removals in this cycle. The head pointer advances according to the actual number of removals, and the tail pointer advances according to the actual number of writes.
[0061] Step 8: When the instruction storage hierarchy is paused, the parallel decoding unit and the issue allocation unit continue to process the existing instructions and micro-operations in the two-level circular queues; when the back end is paused, if the first circular queue can receive the valid instructions and their associated information for the current cycle, the instruction fetch unit continues to write to the first circular queue, and if the second circular queue can receive the decoding results for the current cycle, the parallel decoding unit continues to write to the second circular queue.
[0062] Step nine: When a branch prediction error, exception, return, or other control flow redirection occurs, the program counter loads the redirection target address value, the head pointer, tail pointer, and occupancy counter of the two-level circular queue are restored to an empty state, and the valid state of the instructions before redirection in the execution level entry is cleared.
[0063] The present invention will now be described with reference to the accompanying drawings. The preset parallel width of the processor is denoted as W, the depth of the first circular queue is denoted as D1, and the depth of the second circular queue is denoted as D2, wherein D1 and D2 are both integer multiples of W.
[0064] One feasible configuration is W = 4, D1 = 8, and D2 = 16. This configuration is used to correspond to the actual hardware structure and describe the operation process, and does not constitute a limitation on the parallel width and queue depth in the claims.
[0065] like Figure 2 As shown, the instruction fetch stage includes an instruction storage hierarchy, an instruction fetch unit, a branch prediction unit, and a first circular queue; the decoding stage includes a parallel decoding unit and a second circular queue; and the issue stage includes an issue allocation unit and an execution channel.
[0066] The instruction fetch unit scans the slot validity mask and control flow boundaries, retains consecutive valid instructions starting from the lowest slot, and identifies the control flow instructions within them. The branch prediction unit outputs a prediction hit flag, a prediction direction flag, and a prediction target address for the identified control flow instructions; during prediction jumps, the prediction target address becomes the next instruction fetch address, and the branch prediction information and the corresponding control flow instructions are synchronously entered into the first circular queue.
[0067] The first circular queue stores instructions, compressed program counter values, and branch prediction information in program order. The low-order bits of the program counter value, which is always aligned with the instructions, can be omitted and are padded with zeros to restore the value during reading.
[0068] like Figure 3 As shown, the queue slots are arranged in a circular order, with a head pointer and a tail pointer indicating the head position and the next write position, respectively. In the specific implementation, the circular queue can consist of W memory banks and an occupancy counter. Successive writes are allocated to different memory banks based on the circular address. The read results from the head of the queue are rearranged according to the head pointer and output in ascending order.
[0069] The first circular queue generates a valid mask for its head based on the occupancy level. The parallel decoding unit only interprets valid slots; the data content of invalid slots in the storage array can retain its old value and does not participate in state updates.
[0070] When the number of free items in the second circular queue can accommodate all the current valid decoding results, the decoding results are written to the second circular queue in the same clock cycle, and the first circular queue is popped out in the same number of items in the same clock cycle; when space is insufficient, both queues maintain their current state.
[0071] The second circular queue stores compact micro-operations consisting of a source register, destination register, immediate value, operation type, memory access type, and valid status. For control flow micro-operations, the predicted target address value after omitting the low-order address alignment bits is also stored synchronously. The execution channel selection is determined by the issue allocation unit when the micro-operation leaves the second circular queue and is not written to the second circular queue to reduce memory width and queue head selection network width.
[0072] The transmit allocation unit checks data dependencies, execution channels, memory access resources, and serialization conditions starting from the first slot of the second circular queue. If slot 0 cannot transmit, the head pointer remains unchanged; otherwise, only the micro-operation sequence that is consecutively arranged from the first slot and actually accepted by the backend is removed, and the head pointer is advanced according to the actual number accepted.
[0073] Let the current occupied quantity be C, the number of pushes be P, and the number of pops be Q. Then the occupied quantity in the next cycle will be C - Q + P. The head pointer will be incremented by Q, and the tail pointer will be incremented by P. For local readiness, DC and P are compared, and Q is not pre-counted as an idle item.
[0074] like Figure 4 As shown, the instruction fetch stage only observes the readiness of the first circular queue, the decode stage only observes the readiness of the second circular queue, and the transmit stage only generates the transmit quantity based on the backend receiving conditions; two adjacent stage transmissions are completed independently based on their corresponding readiness states and actual transmit quantities.
[0075] like Figure 5 As shown, in a direct connection structure without FIFO, a pause at the front end can easily cause a bubble at the back end, and a pause at the back end can easily back-push the program counter level by level; a two-level elastic queue pops existing items or occupies free items first, thus delaying the propagation of pauses.
[0076] like Figure 6 As shown, when a prediction error, exception, or return causes a redirection, the program counter loads the target address value first, the head pointer, tail pointer, and occupancy count of the two-level circular queue are simultaneously restored to empty, and the valid state of the old path at the execution level entry is synchronously cleared.
[0077] Table 1 describes structural capabilities rather than fixed performance percentages. Coverable pause cycles depend on queue occupancy at the time of the pause, the number of valid instructions, the number of microoperations actually issued in the current cycle, and program dependencies.
[0078] Table 1
[0079] This invention discloses a two-stage elastic queue pipeline decoupling method and apparatus for a superscalar processor. By using a two-stage elastic queue and a local handshake mechanism, it effectively absorbs rate fluctuations between the instruction fetch, decode, and transmit stages, reduces pipeline stall propagation, and improves processor throughput and timing convergence.
[0080] To implement the methods of the above embodiments, the present invention also provides a computer device, such as... Figure 7 As shown, the computer device 600 includes a memory 601 and a processor 602; wherein, the processor 602 reads executable program code stored in the memory 601 to run a program corresponding to the executable program code, so as to implement the various steps of the method described above.
[0081] To implement the above embodiments, this application also proposes a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the method described in the foregoing embodiments.
[0082] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. 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.
[0083] 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 invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.
Claims
1. A two-stage flexible queue pipeline decoupling method for superscalar processors, characterized in that, include: During the instruction fetching phase, zero to W valid instructions are obtained from the instruction storage hierarchy according to a preset parallel width. The program counter value corresponding to each instruction is determined and associated, and the branch prediction information output by the branch prediction unit for the identified control flow instruction is obtained. When the first circular queue is ready to receive, the valid instructions and their associated program counter values and branch prediction information are written into the first circular queue in program order. The parallel decoding unit reads up to W instructions from the head of the first circular queue and performs parallel decoding to generate corresponding micro-operations. The micro-operations generated by the decoding are written into the second circular queue in program order. After the second circular queue actually receives the decoding results, the first circular queue advances the head pointer according to the actual number of received instructions. The launch allocation unit starts with the micro-operation at the head of the second circular queue and determines the ordered sequence of micro-operations that the backend can accept based on data correlation and execution resource status. After the backend actually accepts the ordered micro-operation sequence, the second circular queue advances the head pointer and updates the occupancy counter according to the actual number of accepted micro-operations. Unaccepted micro-operations continue to be stored in the second circular queue and maintain the original program order. When a control flow redirection occurs, valid items in the first and second circular queues that were active before the redirection are simultaneously invalidated.
2. The method according to claim 1, characterized in that, Each queue entry in the first circular queue includes an instruction field, a program counter value field, and a branch prediction information field; the branch prediction information field includes a prediction hit flag, a prediction direction flag, and a prediction target address field. For instructions that have not undergone branch prediction, the prediction hit flag is set to invalid; wherein, the low-order bits of the program counter value and the prediction target address, which are determined by address alignment, are omitted when writing and are added back when reading.
3. The method according to claim 1, characterized in that, Each queue entry in the second circular queue includes a source register, a destination register, an immediate value, an operation type, a memory access type, and a valid status; for control flow micro-operations, it also includes a predicted target address value; the execution channel selection is determined by the issue allocation unit when the micro-operation leaves the second circular queue and is not stored in the second circular queue.
4. The method according to claim 1, characterized in that, Each circular queue can include multiple storage banks, and there is no limit to the queue depth. Items written consecutively are allocated to different storage banks according to the circular address. The results read from the head of the queue are rearranged according to the head pointer and output in the order of the program from oldest to newest.
5. The method according to claim 1, characterized in that, The local ready signal for each level of the circular queue is determined by the depth of the circular queue, the current occupancy, and the number of currently requested pushes. The number of downstream removals that may occur in the same clock cycle is not considered as the free quota. The first circular queue advances its head pointer only after the second circular queue actually receives the decoding result, and the second circular queue advances its head pointer only after the back end actually receives the ordered micro-operation sequence.
6. The method according to claim 1, characterized in that, Push and pop can occur simultaneously within the same clock cycle, and the occupancy is updated according to the difference between the two quantities; the head pointers of the first and second circular queues advance according to the actual number of items removed, and the tail pointers advance according to the actual number of items written.
7. The method according to claim 1, characterized in that, When the instruction storage hierarchy is paused, the parallel decoding unit and the transmit allocation unit continue to process the existing instructions and micro-operations in the first and second circular queues; when the backend is paused, if the first circular queue can receive the valid instructions and their associated information for the current cycle, the instruction fetch unit continues to write to the first circular queue, and if the second circular queue can receive the decoding results for the current cycle, the parallel decoding unit continues to write to the second circular queue.
8. The method according to claim 1, characterized in that, The control flow redirection specifically includes: loading the redirection target address value into the program counter, restoring the head pointer, tail pointer, and occupancy counter of the first and second circular queues to an empty state, and clearing the valid state of the instructions before redirection in the execution level entry.
9. A two-stage flexible queue pipeline decoupling device for a superscalar processor, characterized in that, include: The instruction fetch unit is used to fetch zero to W valid instructions from the instruction storage hierarchy according to a preset parallel width, and to identify the control flow instructions among them; A branch prediction unit is used to output branch prediction information for the control flow instructions identified by the instruction fetching unit. The first circular queue is connected to the instruction fetching unit and the branch prediction unit, and is used to store the valid instructions, the program counter values corresponding to each valid instruction, and the branch prediction information in the order of the program. A parallel decoding unit, connected to the first circular queue, is used to read up to W instructions from the head of the first circular queue and perform parallel decoding to generate corresponding micro-operations; The second circular queue is connected to the parallel decoding unit and is used to save the micro-operations generated by the parallel decoding unit in program order. The launch allocation unit, connected to the second circular queue, is used to determine an ordered sequence of micro-operations that the backend can accept, starting from the micro-operation at the head of the second circular queue, based on data correlation and execution resource status. The adjacent units in the instruction fetching unit, the first circular queue, the parallel decoding unit, the second circular queue, and the transmit allocation unit use a local handshake mechanism to transmit data. The first circular queue generates a first ready signal based on its remaining capacity, and the second circular queue generates a second ready signal based on its remaining capacity. The redirection clearing unit is used to synchronously invalidate valid items in the first and second circular queues before the redirection when a control flow redirection occurs.
