Branching circuit for a pipelined processor

Abstract: A pipeline circuit (6) adopted for a CPU or a microprocessor in a computer system, computes the effective branch destination address of a conditional branch instruction before or in a parallel with the execution of the conditional branch instruction, judges according to a result of the execution of an instruction just before the conditional branch instruction whether or not a branch condition of the conditional branch instruction is met, and, if the branch condition is met, executes the conditional branch instruction while prefetching and decoding an instruction located at the branch destination address.

Description: BACKGROUND OF THE INVENTION Field of the Invention The present invention relates to a pipeline circuit adopted for a CPU or a microprocessor in a computer system. Particularly, the present invention relates to a pipeline circuit which computes the effective branch destination address of a condition branch instruction before or in parallel with the execution of the conditional branch instruction, judges according to a result of the execution of an instruction just before the conditional branch instruction whether or not a branch condition of the conditional branch instruction is met, and, if the branch condition is met, executes the conditional branch instruction while prefetching the decoding an instruction located at the branch destination address. Description of the Prior Art To improve the processing speed of a microprocessor or a CPU in a computer system, various pipeline circuits have been developed. Generally, the pipeline circuit decomposes a series of processes starting from an instruction fetching operation to an instruction executing operation into a plurality of steps, and processes the steps in separate circuit stages where the instruction is transferred from the first stage toward the last stage while being processed. According to the pipeline circuit, instructions are not processed one by one but processed in parallel with each other in the respective circuit stages. Fig. 1 is a view showing an example of a pipeline circuit adopted for a CPU according to a prior art. In the figure, a pipeline circuit 1 comprises an instruction fetching unit (IFU) 2, an instruction decoding unit (IDU) 3 and an instruction executing unit (EXU) 4. The IFU 2 fetches an instruction from a memory 5, stores the same in an instruction buffer (not shown), and reads out an instruction stored in the instruction buffer to send the same to the IDU 3. The IDU 3 decodes the instruction supplied from the IFU 2 and sends a decoded instruction to the EXU 4. The EXU 4 executes the decoded instruction sent from the IDU 3. Fig. 2 shows the processes carried out in the pipeline circuit 1 in handling an instruction A1 which is not a conditional branch instruction and a conditional branch instruction Bcc following the instruction A1. For the sake of explanation, an instruction fetching operation in the IFU 2 and a decoding operation in the IDU 3 are supposed to be carried out each within one clock cycle, and an effective destination address of the conditional branch instruction Bcc is supposed to be computed in the EXU 4. The instruction A1 is fetched in a clock cycle T1, decoded in a clock cycle T2 and executed in clock cycles T3 to T5. In parallel with the execution of the instruction Al, the next conditional branch instruction Bcc is supplied to the IDU 3 in the clock cycle T2, decoded in the clock cycle T3 and executed in clock cycles T6 and T7. The execution of the instruction Bcc includes judging (checking a flag) whether or not a branch condition of the instruction Bcc is met, computing a branch destination address of the instruction Bcc if the branch condition is met, etc. If the branch condition is met, an instruction C1 located at the branch destination address is fetched in a clock cycle T8 and decoded and executed in clock cycles starting from T9. As described in the above, when a conditional branch instruction is supplied to the pipeline circuit and if a branch condition of the branch instruction is met, prefetched instructions are abandoned, and an instruction located at a branch destination address starts to be fetched. Therefore, execution stage of the pipeline circuit waits for the completion of fetching and decoding the instruction located at the branch destination address so that the processing speed of a CPU including the pipeline circuit may be slowed. To solve the problem of branch in the pipeline circuit, various pipeline circuits have been developed. However, they encountered other problems, in improving the processing time of conditional branching operation, e.g. increased amounts of hardware and complicated controls. US-A-3 881 173 discloses a pipeline circuit which computes the effective branch destination address of a conditional branch instruction in parallel with the execution of said conditional branch instruction. The calculation of the branch destination address starts when a branch instruction has been decoded. Once calculated said address is held as long as it is not determined whether the branch condition is satisfied. When it is determined that the branch condition is satisfied, the fetching operation of the branch destination instruction is carried out, otherwise said fetching is not carried out. SUMMARY OF THE INVENTION An object of the present invention is to provide a pipeline circuit which can improve the performance of a CPU without drastically increasing an amount of hardware and without complicating the controls. In order to accomplish the object, the present invention as set out in claim 1 provides a pipeline circuit comprising: an instruction fetching unit for fetching an instruction code from a memory at an address specified by a program counter and storing the instruction code in an instruction buffer; an instruction decoding unit for decoding an instruction code supplied from the instruction fetching unit, sending an effective address generating request and information related to an addressing mode to an effective address generating unit, detecting, if the decoded instruction is a conditional branch instruction, the value of a status flag fixed by the execution of a previous instruction, and, if a branch condition of the conditional branch instruction is met, notifying the effective address generating unit of the fact that the branch condition has been met; an instruction executing unit for executing a decoded instruction supplied from the instruction decoding unit; and the effective address generating unit for receiving the effective address generating request and the information of addressing mode from the instruction decoding unit, reading a displacement out of the instruction buffer according to a request from the instruction decoding unit or from the effective address generating unit, computing an effective address according to the displacement, and setting the effective address in the program counter if a signal from the instruction decoding unit indicates that the branch condition has been met. If the branch condition of the conditional branch instruction is met and after an instruction located at the branch destination address is prefetched, the instruction at the branch destination address and instruction following it are successively supplied to the decoding unit after the conditional branch instruction. The pipeline circuit according to the present invention computes the effective branch destination address of a conditional branch instruction before or in parallel with the execution of the conditional branch instruction, judges according to a result of the execution of an instruction jest before the conditional branch instruction whether or not a branch condition of the conditional branch instruction is met, and, if the branch condition is met, prefetches and decodes an instruction located a the branch destination address in parallel with the execution of the conditional branch instruction. Therefore, the pipeline circuit of the present invention can improve the performance of a CPU or a microprocessor in a computer system without drastically increasing the amount of hardware and without complicating its controls. These and other objects, features and advantages of the present invention will be more apparent from the following detailed description of preferred embodiments in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS Fig. 1 is a block diagram showing a pipeline circuit according to a prior art; Fig. 2 is a timing chart showing processes carried out in the pipeline circuit of Fig. 1 in handling an instruction A1 which is not a conditional branch instruction and a conditional branch instruction Bcc following the instruction A1; Fig. 3 is a block diagram showing a pipeline circuit according to an embodiment of the present invention; Fig. 4 is a view showing formats of instructions processed in the pipeline circuit of Fig. 3; Fig. 5 is a timing chart showing processes carried out in the pipeline circuit of Fig. 3 in handling an instruction A1 which is not a conditional branch instruction and a conditional branch instruction Bcc following the instruction A1; Figs. 6(A), 6(B) and 6(C) are views showing the relation between a conditional branch instruction to be read out of an instruction buffer of the embodiment of Fig. 3 and a pointer; and Fig. 7 is a block diagram showing a pipeline circuit modified from the pipeline circuit shown in Fig. 3. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Fig. 3 is a view showing a pipeline circuit according to an embodiment of the present invention. A pipeline circuit 6 comprises an instruction fetching unit (IFU) 7, an instruction decoding unit (IDU) 8, an effective address generating unit (AGU) 9 and an executing unit (EXU) 10. The IFU 7 fetches an instruction from a memory 3 according to an address set in a program counter PCI 12 and stores the instruction in an instruction buffer 11. The address in the PCI 12 is incremented for every instruction fetching operation. As will be described later in detail, a branch destination address is set in the PCI 12 to branch the execution of a program. As shown in Fig. 4, an instruction code of this embodiment comprises an operation code of 16 bits including information related to an addressing mode, and a displacement of 16 or 32 bits. As shown in Fig. 6, the instruction buffer 11 has a capacity of "16 bits x N words," and is read by word by word. The instruction buffer 11 has a pointer indicating the address of a word to be read next. The value of the pointer is incremented whenever the contents of the instruction buffer 11 are read out. The IDU 8 decodes an instruction code supplied from the IFU 7. By decoding an operation code of the instruction, and addressing mode thereof is identified so that the IDU 8 may send an effective address generating request for an operand and information related to an addressing mode to the AGU 9. If it is a conditional branch instruction, the IDU 8 sends, similar to the cases of other instructions, a request for generating an effective branch destination address and information related to an addressing mode to the AGU 9. In addition, if it is the conditional branch instruction, an instruction just before the conditional branch instruction is executed to fix a status flag. After that, the IDU 8 detects the value of the status flag to judge whether or not a branch condition of the conditional branch instruction is met. If the branch condition is met, the IDU 8 notifies the AGU 9 of the fact that the branch condition has been met. The AGU 9 determines an addressing mode based on the information of addressing mode supplied from the IDU 8. If there is a displacement, the AGU 9 sends a displacement sending request to the IFU 7, which then directly sends the displacement to the AGU 9. Instead of outputting the displacement sending request from the AGU 9 to the IFU 7, it may be outputted from the IDU 8 to the IFU 7 as shown in Fig. 7. When receiving the displacement from the IFU 7, the AGU 9 computes an effective address according to the addressing mode. After computing the effective address, if a signal from the IDU 8 includes that the branch condition has been met, the AGU 9 sets the effective address in the program counter (PCI) 12 of the IFU 7. Accordingly, the next instruction is prefetched from the branch destination address. The EXU 10 fetches an operand from an effective address generated by the AGU 9 or writes an operand into the effective address in executing an instruction decoded by the IDU 8. Fig. 5 shows the operation of the pipeline circuit 6. In the figure, the pipeline circuit 6 receives an instruction A1 which is not a conditional branch instruction and a conditional branch instruction Bcc following the instruction A1. It is supposed that an instruction fetching operation and an instruction decoding operation are completed each within one clock cycle. As shown in Fig. 5, the instruction A1 is fetched by the IFU 7 and stored in the instruction buffer 11 in a clock cycle T1, supplied to and decoded by the IDU 8 in a clock cycle T2, and computed for its effective address by the AGU 9 in a clock cycle T3. In addition, in the clock cycle T3, the execution of the instruction A1 is started by the EXU 10 and completed in a clock cycle T5. The conditional branch instruction Bcc is prefetched in the clock cycle T2, decoded in the clock cycle T3, and computed for its branch destination address in the clock cycle T4. Even if the computation of the branch destination address is completed in the clock cycle T4, the execution of the instruction A1 will continue up to the clock cycle T5 so that a branch condition of the conditional branch instruction Bcc is not judged in the clock cycle T4. Therefore, in the clock cycle T5, the AGU 9 is in a waiting state and holds the branch destination address,. In the clock cycle T5, the execution of the instruction A1 completes to fix a status flag. Then, the IDU 8 judges according to the status flag whether or not the branch condition of the conditional branch instruction Bcc is met. If the branch condition is met, the branch destination address from the AGU 9 is set in the PCI 12. Therefore, in the next clock cycle T6, the execution of the instruction Bcc starts, while an instruction C1 located at the branch destination address is prefetched and stored in the instruction buffer 11. When the instruction C1 is fetched, a pointer of the instruction buffer 11 changes to indicate the fetched instruction C1. Therefore, in the next clock cycle T7, the instruction C1 is supplied to and decoded by the IDU 8. When the execution of the instruction Bcc is completed in the clock cycle T7, the instruction C1 starts to be executed and computed for its effective address in a clock cycle T8. If the branch condition of the instruction Bcc is not met, the branch destination address held in the AGU 9 is not set in the PCI 12. Therefore, in the clock cycle T6, the instruction C1 located at the branch destination address is not fetched, but the next instruction is fetched from a current address in the PCI 12 (in Fig. 5, and address next to an address from which an instruction A5 has been fetched) and stored in the instruction buffer 11. Further, in the clock cycle T6, an instruction A3 next to the instruction Bcc is supplied from the instruction buffer 11 to the IDU 8 in which the instruction A3 is decoded. If the number of execution cycles of an instruction just before a conditional branch instruction is small, a fact that a branch condition of the conditional branch instruction is not met may be found before the AGU 9 computes a branch destination address. In this case, the computation of the branch destination address is carried out to the end. After the conditional branch instruction Bcc is decoded, a pointer of the instruction buffer 11 will indicate a displacement of the instruction Bcc as shown in Fig. 6(B). Therefore, the displacement of the instruction Bcc may be sent as the next instruction to the IDU 8 to cause an erroneous operation. To cope with this problem, the displacement of the instruction Bcc is read out of the instruction buffer 11 such that the pointer of the instruction buffer 11 will indicate an instruction next to the instruction Bcc as shown in Fig. 6(C). Instead of computing the branch destination address to advance the pointer, it is possible to advance the pointer for the number of words of the displacement of the conditional branch instruction. However, according to this technique, controls shall be switched from one to another depending on whether a branch condition of the conditional branch instruction is found before the computation of the branch destination address or not. Therefore, the control of the instruction buffer 11 will be complicated. As described in the above, the present invention can improve the performance of a CPU without drastically increasing an amount of hardware and without complicating controls.

Claims: An information processing system for processing instructions according to a pipeline circuit, comprising; an instruction decoding unit (8) connected to a fetching unit (7) for decoding an instruction transferred from said fetching unit (7); an execution unit (10) connected to said decoding unit (8) for executing the instruction decoded by said decoding unit (8), and an address generating unit (9) connected to said decoding unit (8) and said fetching unit (7) for calculating an effective address of the decoded instruction in response to an address calculation request transferred from said decoding unit (8); said fetching unit (7) including a program counter (12) for storing an address of an instruction to be fetched from said memory (3) and an instruction buffer (11) for storing a fetched instruction; said address generating unit (9) being connected to said instruction buffer (11) for calculating said effective address based on a displacement transferred from said instruction buffer (11) when said displacement is used for the address calculation; said address generating unit (9)starting calculation of a branch destination address when a conditional branch instruction has been decoded by said decoding unit (8); said branch destination address being held by said address generating unit (9) if it is not determined whether or not the branch condition is satisfied after said branch destination address is calculated by said address generating unit (9); the branch destination address being set in said program counter (12) when it is determined that the branch condition is satisfied, so that the fetching operation of said branch destination instruction is carried out; said branch destination address being not set in said program counter (12) when it is determined that the branch condition is not satisfied so that the fetching operation of said branch destination instruction is not carried out; characterized in that said branch destination address calculation is continued up to the end when it is determined that the branch condition is not satisfied before completion of the calculation of said branch destination address. The pipeline circuit in a computer system as claimed in claim 1, wherein a reading operation of instructions stored in the instruction buffer (11) is controlled by a pointer which indicates a position of a data to be read next and is advanced by one word when a data is read out of the instruction buffer (11) according to a read-out request from said instruction decoding unit (8) or from said effective address generating unit (9). The pipeline circuit in a computer system as claimed in claim 1, wherein the branch destination address of the conditional branch destination instruction is computed even if it is found, before said effective address generating unit (9) computes the effective branch destination address of the conditional branch destination instruction, that the branch condition of the conditional branch destination instruction is not met. The information processing system as claimed in claim 1, wherein said execution unit (10) is connected with said address generating unit (9) through said instruction decoding unit (9).

Inventors: USAMI KIMIYOSHI, USAMI, KIMIYOSHI
Applicants: TOSHIBA KK, KABUSHIKI KAISHA TOSHIBA
Application year: 1988
Main classification: G06F9
IPC codes: G06F9