This Non-provisional application claims priority under 35 U.S.C. §119(a) on Patent Application No. 2004-186568 filed in Japan on Jun. 24, 2004, the entire contents of which are hereby incorporated by reference.
1. Field of the Invention
The present invention relates to an information processor which performs pipeline processing of instructions, and a method for controlling branching in the information processor.
2. Description of the Prior Art
In an information processor which performs pipeline processing of instructions, when the instructions are sequentially supplied to the pipeline and executed one after another, the speed of executing the instructions is enhanced by overlapping the execution of the instructions. However, in the case of pipeline processing of a conditional branch instruction, a determination of which address is to be fetched next cannot be made until the completion of the decoding of the conditional branch instruction at the earliest. This may lead to the problem of the occurrence of an empty slot (branch hazard).
As a means for overcoming this problem, a branch method, which is called a delayed branch, is employed. In the branch method, an instruction code stored at an address subsequent to a conditional branch instruction is processed in an empty slot (delayed slot) successive to that conditional branch instruction, thereby eliminating a branch hazard (see, for example, Japanese Laid-Open Publication No. 4-127237 and pp. 265-270 in “Computer Architecture” by David Paterson and John Hennessy, 1st edition, 1st printing (revised), Feb. 18, 1994, Nikkei BP Publishing Center, Inc.) In this method, the instruction processed in the delayed slot is executed in the cycle in which a branch hazard would otherwise occur, such that the number of cycles required to execute the conditional branch instruction is reduced apparently.
In the method described above, the instruction stored at the address successive to the conditional branch instruction has to be an instruction that can be processed (fetched, decoded, and executed) at points in time after the conditional branch instruction is processed, or an instruction that can be executed irrespective of whether or not the branch condition in the conditional branch instruction is satisfied. Due to this restriction on the instruction stored at the successive address and processed in the delayed slot, if there is no such an instruction that can be stored at the successive address, NOP (No Operation: an invalidation instruction) is stored instead.
However, the NOP is stored in addition to the instruction that is to be executed, thereby causing a problem in that the program often increases in size.
The present invention has been made in view of the above problem, and it is therefore an object of the present invention to provide a branch control method and an information processor in which when an instruction that can be processed in a delayed slot is present, a delayed branch is implemented to eliminate a branch hazard, and even when there is no instruction that can be processed in the delayed slot, NOP does not have to be inserted in the program, such that the program does not increase in size.
In order to achieve the above object, an inventive branch control method for controlling branch operation performed by a branch instruction in an information processor that performs pipeline processing in which instructions stored in storing means are fetched sequentially includes: a discrimination step for discriminating, based on branch-control instruction information contained in an instruction code, between a first control mode, in which a succeeding instruction fetched following the branch instruction from an address successive to the branch instruction is executed regardless of whether or not a branch condition in the branch instruction is satisfied, and a second control mode, in which the succeeding instruction is executed when the branch condition is not satisfied; and a control step for performing control in such a manner that in the first control mode, the fetched succeeding instruction is executed, while branch control is performed according to whether or not the branch condition is satisfied, in the second control mode, if the branch condition is satisfied, the succeeding instruction is fetched but is not executed, while an instruction at a branch destination is fetched and executed, and in the second control mode, if the branch condition is not satisfied, the succeeding instruction is executed.
In one embodiment of the present invention, in the control step, control is performed in such a manner that in the second control mode, if the branch condition is not satisfied, the succeeding instruction is fetched following the branch instruction, and is executed.
In another embodiment of the present invention, in the control step, control is performed in such a manner that in the second control mode, if the branch condition is not satisfied, the succeeding instruction is fetched following the branch instruction, but is not executed, and thereafter the succeeding instruction is fetched again and executed.
In still another embodiment, the branch-control instruction information is contained in an instruction code of the instruction at the address successive to the branch instruction.
According to the inventive method, when an instruction which is executed regardless of whether or not the branch condition is satisfied is not stored at the address successive to the branch instruction, it is determined in the discrimination step that the second control mode is indicated, based on the branch-control instruction information, and then branch control is performed in a simple manner: when the branch condition is not satisfied, the fetched succeeding instruction is executed without interruption, thereby allowing the high-speed execution of the succeeding instruction, or the fetched succeeding instruction is not executed.
In still another embodiment, the succeeding instruction contains instruction-execution-condition information that indicates one or more instruction execution conditions for execution of the instruction; in the control step, control is performed in such a manner that in the second control mode, if the branch condition is not satisfied and the one or more instruction execution conditions of the succeeding instruction are satisfied, the instruction is executed; and in the discrimination step, it is determined that the first control mode is indicated, when the instruction-execution-condition information has a predetermined value.
Then, in the discrimination step, it is determined which one of the first and second control modes is indicated, in accordance with the form of the instruction whose execution is controlled according to the execution conditions.
In still another embodiment, the succeeding instruction contains instruction-execution-condition information that indicates one or more instruction execution conditions for execution of the instruction; and in the control step, control is performed in such a manner that in the first control mode, if the one or more instruction execution conditions of the succeeding instruction are satisfied, the instruction is executed, and in the second control mode, if the branch condition is not satisfied and the one or more instruction execution conditions are satisfied, the succeeding instruction is executed.
Then, in each of the first and second control modes, the execution of the instruction is controlled according to the execution conditions.
In still another embodiment, the succeeding instruction contains instruction-execution-condition information that indicates one or more instruction execution conditions for execution of the instruction; and in the discrimination step, the discrimination between the first control mode and the second control mode is made according to whether the instruction-execution-condition information of the succeeding instruction agrees with the branch condition of the branch instruction.
Then, the discrimination between the first control mode and the second control mode is made according to whether the instruction-execution-condition information of the succeeding instruction agrees with the branch condition of the branch instruction.
In yet another embodiment, in the control step, control is performed in such a manner that in the first control mode, the succeeding instruction is executed regardless of the instruction-execution-condition information.
Then, control is performed in such a manner that in the first control mode, the succeeding instruction is executed regardless of the instruction-execution-condition information.
In yet another embodiment, in the discrimination step, it is determined that the first control mode is indicated, when the instruction-execution-condition information of the succeeding instruction agrees with the branch condition of the branch instruction; and in the control step, in the first control mode, whether or not to execute the succeeding instruction is controlled according to the instruction-execution-condition information.
Then, it is determined that the first control mode is indicated when the instruction-execution-condition information of the succeeding instruction agrees with the branch condition of the branch instruction, and whether or not to execute the succeeding instruction is controlled according to the instruction-execution-condition information.
Also, an inventive information processor which performs pipeline processing of instructions includes: a fetch section for sequentially fetching the instructions stored in storing means; a decoding section for decoding the fetched instructions; an instruction execution section for executing the decoded instructions; discrimination means for discriminating, based on branch-control instruction information contained in an instruction code, between a first control mode, in which a succeeding instruction fetched following a branch instruction from an address successive to the branch instruction is executed regardless of whether or not a branch condition in the branch instruction is satisfied, and a second control mode, in which the succeeding instruction is executed when the branch condition is not satisfied; and control means for performing control in such a manner that in the first control mode, the fetched succeeding instruction is executed, while branch control is performed according to whether or not the branch condition is satisfied, in the second control mode, if the branch condition is satisfied, the succeeding instruction is fetched but is not executed, while an instruction at a branch destination is fetched and executed, and in the second control mode, if the branch condition is not satisfied, the succeeding instruction is executed.
In the inventive information processor, when an instruction which is executed regardless of whether or not the branch condition is satisfied is not stored at the address successive to the branch instruction, it is determined by the discrimination means that the second control mode is indicated, based on the branch-control instruction information, and whether or not to execute the succeeding instruction is controlled according to whether or not the branch condition is satisfied.
Hereinafter, preferred embodiments of the present invention will be described with reference to the accompanying drawings.
An information processor, in which instruction branching is controlled by a control method according to the present invention, includes an instruction read section, an instruction decoding section, an instruction execution section, and a control section for controlling instructions to be executed or the like. The information processor performs three-stage pipeline processing, in which instruction codes stored in memory are simultaneously fetched (IF stage), decoded (DC stage), and executed (EX stage).
When a conditional branch instruction is executed, the control section controls operation of each of the above-mentioned sections based on whether or not the branch condition is satisfied and the value of a predetermined control filed contained in an instruction code. As shown in
Specifically, as shown in
More specifically, when the conditional branch instruction at the address (N) is decoded after it is fetched, the instruction code at the address (N+1), which is processed regardless of the branch condition, is fetched. At the point in time when the decoding of the conditional branch instruction and the fetch of the subsequent instruction have been performed, it is determined, based on the decoding result of the conditional branch instruction, whether or not the branch condition is satisfied, while it is determined that DF=0, from the instruction code fetched from the address (N+1). Thereafter, depending upon whether or not the branch condition is satisfied, either the instruction at the address (N+2) or the instruction at the address (M) is fetched and decoded, while the instruction code at the address (N+1) is decoded and executed.
As also shown in
To be more specific, as in the case where DF=0, when the conditional branch instruction at the address (N) is decoded after it is fetched, the instruction code at the address (N+1) is fetched, but at this point in time, it is unknown whether or not the branch condition is satisfied. Therefore, after the instruction at the address (N+1) is fetched, if the branch condition is satisfied, the execution is blocked so as to prevent the inappropriate execution from being performed. On the other hand, when the branch condition is not satisfied, the blocking of the execution of the instruction at the address (N+1) is not performed, thereby allowing the appropriate execution to be performed.
In the above case of DF≠0, after the instruction at the address (N+1) is fetched, the execution of that instruction may be blocked as in the case where the branch condition is satisfied, even if the branch condition is not satisfied, and the instruction at the address (N+1) may be again fetched, decoded, and executed.
(1) Step 1: S001
A fetched conditional branch instruction is decoded.
(2) Step 2: S002
An instruction fetched from an address (N+1) is decoded.
(3) Step 3: S003
It is determined whether or not DF (delayed-slot instruction filed 100a) is “0”. If it is “0”, the procedure goes to Step 4 (S004). If it is not “0”, the procedure goes to Step 9 (S009).
(4) Step 4: S004
The instruction at the address subsequent to the conditional branch instruction is executed.
(5) Step 5: S005
It is determined whether or not the branch condition in the conditional branch instruction is satisfied. If it is satisfied, the procedure goes to Step 6 (S006). If it is not satisfied, the procedure goes to Step 7 (S007).
(6) Step 6: S006
An instruction at a branch destination is fetched, decoded, and executed.
(7) Step 7: S007
An instruction, which is executed if the branch condition is not satisfied, is fetched, decoded, and executed.
(8) Step 8: S008
The execution of the instruction decoded in S002 is blocked.
(9) Step 9: S009
It is determined whether or not the branch condition in the conditional branch instruction is satisfied. If it is satisfied, the procedure goes to Step 8 (S008). If it is not satisfied, the procedure goes to Step 10 (S010).
(10) Step 10: S010
The instruction code at the address subsequent to the conditional branch instruction is again fetched, decoded, and executed.
Next, a specific example of the program processed by the information processor will be described.
On the other hand,
Instead of the instruction code 100, an instruction code 200 (conditional execution instruction), which contains a condition field 200a (CF) and an instruction field 200b as shown in
When the instruction code 200 is stored at an address successive to a conditional branch instruction, the condition field 200a is used in the same manner as the delayed-slot instruction field 100a described in the first embodiment, while the condition field 200a is used as a condition field in which information on the execution of the instruction is stored, when the instruction code 200 is fetched again and executed.
Specifically, as shown in
As a result, in the case where the value CF is set to CF=“0000”, a control operation that is almost the same as the operation described in the first embodiment is performed according to a determination made in (S103) as shown in
Therefore, in this embodiment as in the first embodiment, high-speed branch processing is carried out with the program size minimized, while whether or not a delayed branch is implemented is controlled based on whether or not the value of the condition field is a given value, thereby preventing the instruction code length from increasing.
An instruction code 300 (conditional execution instruction) containing a condition filed 300a (CF) and an instruction field 300b shown in
More specifically, as shown in
Consequently, as described in the second embodiment, high-speed branch processing is achieved with the program size minimized, while the instruction code length is prevented from increasing. Moreover, even in the case of a delayed branch, it is possible to perform a conditional execution.
As shown in
Specifically, as shown in
Consequently, the same effects as those of the first embodiment are also achieved in this embodiment. In addition, in this embodiment, since the branch control is performed by comparing the branch condition of the conditional branch instruction and the execution condition for the instruction located at the successive address, a delayed-slot instruction field 100a such as described in the first embodiment does not need to be provided separately.
As shown in
To be specific, as shown in
This enables the instruction codes to be processed in orders similar to those described in the first embodiment or the like as shown in
Moreover, in the case where BCF=DCF is established, the branch condition of the conditional branch instruction agrees with the execution condition for the execution instruction at the successive address. Therefore, when the branch condition is satisfied, the instruction at the successive address is executed, and when the branch condition is not satisfied, the instruction at the successive address is not executed. This allows an instruction located at the branch destination to be stored at the address successive to the conditional branch instruction.
The foregoing embodiments have been described assuming that the delayed slot is only the slot located next to the conditional branch instruction, because the three-stage pipeline processing is performed and the decision about the branching of the conditional branch instruction is made in the DC stage, as shown in
Also, as described in the first embodiment, in the case where no delayed branch is implemented, the execution of the instruction fetched from the address (N+1) may be blocked as in the case where the branch condition is satisfied, even if the branch condition is not satisfied, and the instruction at the address (N+1) may be again fetched, decoded, and executed.
Furthermore, the number of bits in each field, the correspondences between the set values and the contents indicated by those set values, and the like, described in the foregoing embodiments, are merely examples, and the present invention is not limited to these.
As described above, in the branch control method and the information processor according to the present invention, when an instruction that can be processed in a delayed slot is present, a delayed branch is implemented so as to eliminate a branch hazard, and even when there is no such an instruction, the program does not increase in size because insertion of NOP is not required. Therefore, the inventive information processor and the inventive branch control method are applicable to an information processor which performs pipeline processing of instructions and a method for controlling branching in the information processor.
Number | Date | Country | Kind |
---|---|---|---|
2004-186568 | Jun 2004 | JP | national |