Method and apparatus for scheduling to reduce space and increase speed of microprocessor operations6738893Abstract A process for scheduling computer processor execution of operations in a plurality of instruction word formats including the steps of arranging commands into properly formatted instruction words beginning at one end into a sequence selected to provide the most rapid execution of the operations, and then rearranging the operations within the plurality of instruction words from the other end of the sequence into instruction words selected to occupy the least space in memory. Claims What is claimed is: Description BACKGROUND OF THE INVENTION
A1: add t1, ebp, 12
A2: ld t2, [t1]
A3: add t3, t2, 7
A4: st t3, [t1]
A5: add t4, esp, -4
A6: st eax, [t4]
A7: sub edi, ecx, ebx
A8: add t5, esp, -8
A9: st ecx, [t5]
A10: add t6, esp, -12
A11: st edx, [t6]
A12: add t7, esp, -16
A13: st ebx, [t7]
A14: add t8, esp, -20
A15: st eax, [t8]
A16: add t9, esp, -24
A17: st ecx, [t9]
A18: br next
In this sequence, registers designated in the form t(n) are temporary registers of the host processor; the remaining register operands are from the X86 architecture, the target architecture in this example. For the purpose of this illustration, it will be assumed that there are only two instruction formats. These formats are illustrated in Table 1. One of these is a sixteen-byte instruction format that can hold a memory operation, two ALU operations, and a branch operation. Sixteen-byte instructions must begin at byte addresses that are multiples of sixteen. A second is an eight-byte instruction format that can hold a memory operation and an ALU operation. Eight-byte instructions must begin at byte addresses that are multiples of eight.
TABLE 1
##STR1##
Additionally it will be assumed that the result of any load or ALU operation can be used in the next cycle by the ALU, but such result must wait an extra cycle before use as either an address or data by a load or store operation. The method utilizes what is referred to as a directed acyclic graph for determining the commands to be provided in each sequentially issued instruction word. A data structure (node) is provided for each command which might be placed in an instruction word to detail the idiosyncrasies of that command. For example, a particular command may require four cycles to execute, may utilize the results of some other command as an operand, and may have other idiosyncrasies. Directed edges connect nodes in the graph and represent scheduling constraints. If node A precedes node B, then command A must be scheduled prior to command B. Edges have integer weights that further constrain the schedule. A weight of value k on an edge from node A to node B indicates that command B must be scheduled at least k instructions (cycles) later than command A in the final schedule. FIG. 1 illustrates the various commands in the above sequence A1-A18 which depend on one another and shows the various dependencies. All of the commands which are available for inclusion in an instruction word are reviewed by the scheduling process. A command is available for scheduling when all of its predecessors in the directed acyclic graph have been scheduled, and when the current scheduling cycle count is such that all constraints given by weights on incoming edges are satisfied (i.e., all latencies from preceding commands are satisfied). From those commands available, the scheduler selects a command which does not depend on the results of any other command. If more than one such command exists, then the scheduler selects first the command which is most critical. The criticality is based on its effect on the other commands to be executed. One command is more critical than another when the scheduler predicts that issuing the former command earlier is likely to produce a better (i.e., shorter/more dense) schedule than issuing the latter command earlier. To determine criticality, schedulers often compute a priority function which assigns a priority number to each command. Then to determine the relative criticality of two nodes representing two commands, their priorities are compared numerically. A place is reserved for the first command selected in a first instruction word to be initiated during a first cycle of operation. If additional commands are available which might also be placed into the first instruction word, an attempt is made by the scheduler using the packing process to fit them into the word. If an execution unit is available for the inclusion of a second command, then a place is reserved for the second command in the first instruction word. A number of choices are made by the scheduler in determining the above schedule. In order to generate each next instruction word, the scheduler looks first at any remaining commands which might have been placed in the first instruction word and all additional commands which are available to be included in a second instruction word. The scheduling constraints for each of the commands in the first instruction word are considered to determine on what cycle a next instruction word may issue. In each case, the most critical command based on scheduling constraints is selected. That is, each command requires some number of cycles to execute. As may be seen, the first command A1 provides output which is used in the following command A2; command A2 which is a load cannot be started until at least two cycles have passed. On the other hand, the second command A2 provides output which is used in the following command A3, and command A3 provides output which is used in command A4. However, command A3 cannot be started until at least one cycle has passed after command A2 is completed; and command A4 which is a store using the results of command A3 cannot commence until two cycles after command. Because of these conditions, command A2 cannot be placed in an instruction words which commences before cycle 3, command A3 in an instruction word that commences before cycle 4, and command A4 in an instruction word that commences before cycle 6. Moreover, command A18 cannot be placed in an instruction word which commences before cycle 7. When a cycle in which a next instruction word is to issue has been chosen, commands to include in that instruction word are selected in the manner described above. This process continues until there are no more commands available which are capable of being executed by execution units which are not already reserved or there are no more execution units free to execute available commands. When no more commands may be placed into the first instruction word, the instruction word is essentially "closed;" and the scheduling of a next instruction word commences. A detailed explanation of such a scheduling technique is provided at Chapter 17, Advanced Compiler Design & Implementation, Steven S. Muchnick, published by Morgan Kaufmann. Using this technique, the instruction words which have been generated function to execute as quickly as is possible for the particular processor. For example, the exemplary computer system provides instruction words capable of holding both two and four equal-length instructions shown in Table 1. Utilizing the prior art process described above, it would be typical to schedule a sequence of instruction words all of which provide space for four commands because the longer format holds more commands and thus requires fewer instruction words. Since each instruction word whether long or short requires approximately the same time to execute (apart from instruction cache/memory effects), a sequence of fewer instruction words generally requires the least time to execute. When this prior art technique is applied to the sequence of operations listed above, the following cycle schedule is produced:
M1: add t1, ebp, 12 ; add t4, esp, -4
M2: add t5, esp, -8 ; add t6, esp, -12
M3: ld t2, [t1] ; add t7, esp, -16 ; add t8, esp, -20
M4: st eax, [t4] ; add t3, t2, 7 ; add t9, esp, -24
M5: st ecx, [t5] ; sub edi, ecx, ebx
M6: st t3, [t1]
M7: st edx, [t6]
M8: st ebx, [t7]
M9: st eax, [t8]
M10: st ecx, [t9] ; ; br next
As should be noted, in this prior art scheduling process, once the commands to be placed in an instruction word have been determined in the manner described, the instruction word will ultimately be generated and placed in line for execution. Presuming that four commands have been found which may be executed together in such an instruction word and that an instruction word format holding just these four commands is available, then the formation of the instruction word will be complete. If, however, only three commands have been found which may be executed together in such an instruction word and that an instruction word format holding four commands is the only instruction word available for these commands, then the fourth command slot of the instruction word is filled with a no-op command. The naive format selection described above along with NOP insertion, assuming a starting address that is 8 mod 16 (e.g., Oxabcd8) and that sixteen-byte (four operation) instructions must be aligned to addresses that are 0 mod 16, the following sequence of instructions is scheduled:
M1: add t1, ebp, 12 ; add t4, esp, -4
M2: nop ; add t5, esp, -8 ; add t6, esp, -12 ; nop
M3: ld t2, [t1] ; add t7, esp, -16 ; add t8, esp, -20 ; nop
M4: st eax, [t4] ; add t3, t2, 7 ; add t9, esp, -24 ; nop
M5; st ecx, [t5] ; sub edi, ecx, ebx
M6: st t3, [t1] ; nop
M7: st edx, [t6] ; nop
M8: st ebx, [t7] ; nop
M9: st eax, [t8] ; nop ; nop ; nop
M10: st ecx, [t9] ; nop ; nop ; br next
where instructions M2, M3, M4, and M10 are naturally wide (i.e., sixteen bytes each) due to the number of commands or the formats allowed (memory+branch only in a sixteen-byte instruction), instruction M2 has been widened to sixteen bytes because of the alignment restriction on instruction M3, and instruction M9 has been widened to sixteen bytes because of the alignment restriction on instruction M10. It will be noted that in this prior art technique, since the instruction words are selected only to execute quickly, a number of no-op commands are utilized by VLIW processors to complete the instruction words. No-op commands for such processors must also be placed in instruction words during cycles in which latency requirements keep commands from being executed. The use of these no-op commands requires a significant amount of memory space both in system memory and in instruction caches. Ultimately, the use of storage space, especially instruction cache storage, to hold no-op commands slows overall program execution by the system. The present invention improves the performance of the system by eliminating a significant portion of the no-op instructions required by prior art scheduling processes. The present invention accomplishes this result by scheduling commands into instruction words based on both execution time and space considerations. In one embodiment of the invention, the process is carried out by placing space constraints on the filling of each instruction word. For example, in the exemplary VLIW computer system which provides instruction words capable of holding both two and four equal-length instructions, a constraint that no four command instruction word may issue unless it holds at least three commands will eliminate long format instruction words which do not make efficient use of instruction word space. When this additional constraint is added to the normal constraints of scheduling discussed above, the space occupied by sequences of instruction words will be reduced. Other criteria might also be applied which reduce the amount of space utilized. One problem of this embodiment is that applying a constraint which eliminates the ability to utilize any number of instructions in any particular instruction word format may increase the execution time required by the scheduled sequence. For example, in order to fill all long format instruction words with at least three commands, it may be necessary to incur greater latencies between useful instruction words. A second embodiment of the invention is designed to reduce the space utilized by a sequence of instruction words without increasing the execution time. In this embodiment, a first scheduling pass is made which may, like the prior art process in that the process, consider only the number of cycles required to execute the resulting sequence. However after the first scheduling pass for time has been completed, a second scheduling pass is undertaken using the results of the first pass. This second pass (shown in FIG. 2) uses the same number of instruction words as determined by the first pass so that the resulting sequence executes in the same time as would a sequence based only on the first scheduling pass. The second pass does not change any of the time constraints placed on the schedule by the execution latencies of the commands. However, the second pass begins at the opposite end of the sequence of instruction words, goes backward through the sequence, and optimizes the space required by the instruction words without perturbing the correct operation of the sequence by preserving all relevant latency constraints. For example, the second pass reviews the proposed last instruction word of the sequence to determine if it includes any no-op commands. If, in reviewing the instruction word, the process finds one or more no-op commands, the process reviews the next to last instruction word in the proposed sequence to determine if there is a place reserved in that instruction word for a command which can be moved to the position in the last command presently reserved for a no-op without violating any of the constraints. The process may look as far back in the sequence of instruction words resulting from the first pass as is necessary to find any such command and move that command into the space reserved for the no-op command. This second space pass of the process continues in the same manner back through the sequence finding no-ops in each preceding instruction word, looking for commands in earlier instruction words which might fill that position, and filling the no-op space if such commands exist. The result will often be a sequence of instruction words which takes less space in memory and caches. For example, the above-described sequence of commands; the naive format selection with NOP insertion, assuming a starting address that is 8 mod 16 (e.g., Oxabcd8) and that 16-byte (four operation) instructions must be aligned to addresses that are 0 mod 16 produces the following sequence:
M1: add t1,ebp,12 ; add t4, esp, -4
M2: nop ; add t5, esp, -8 ; add t6, esp,-12 ; nop
M3: ld t2, [t1] ; add t7, esp, -16 ; add t8, esp,-20 ; nop
M4: st eax, [t4] ; add t3, t2, 7 ; add t9, esp,-24 ; nop
M5; st ecx, [t5] ; sub edi, ecx, ebx
M6: st t3, [t1] ; nop
M7: st edx, [t6] ; nop
M8: st ebx, [t7] ; nop
M9: st eax, [t8] ; nop ; nop ; nop
M10: st ecx, [t9] ; nop ; nop ; br next
Which occupies a total of 120 bytes of memory space. The space pass operates after the cycle pass, from the last instruction to the first instruction. In this instance, it operates from instruction M10 towards instruction M1. In the embodiment described, although proposed instruction word formats exist after the first time pass, the formats are not yet fixed. Consequently, a proposed short instruction word may be expanded to a long instruction word where useful to accomplish the purpose of reducing the space required by the scheduled sequence. Looking at instruction M10, there is only one command that can be moved there, namely the subtract command (A7) originally positioned in instruction M5 can be moved there because nothing depends on it in the schedule. Thus after processing instruction M10, the new schedule is:
M1: ; add t1, ebp, 12 ; add t4, esp, -4
M2: ; add t5, esp, -8 ; add t6, esp,-12
M3: ld t2, [t1] ; add t7, esp, -16 ; add t8, esp,-20
M4: st eax, [t4] ; add t3, t2, 7 ; add t9, esp,-24
M5; st ecx, [t5]
M6: st t3, [t1]
M7: st edx, [t6]
M8: st ebx, [t7]
M9: st eax, [t8]
M10: st ecx, [t9] ; sub edi, ecx, ebx ; ; br next
Processing instruction M9 shows that there is nothing that can be moved, so the schedule remains the same. Next, there is one command that can be moved to M8, namely the command originally placed in instruction M4 that computes t9 (A16), since by moving the command to this position, the latency for t9 (to store in instruction M10) is still satisfied. No other command can be moved into instruction M8. Thus, the new schedule after processing M8 is:
M1: ; add t1, ebp, 12 ; add t4, esp, -4
M2: ; add t5, esp, -8 ; add t6, esp,-12
M3: ld t2, [t1] ; add t7, esp, -16 ; add t8, esp,-20
M4: st eax, [t4] ; add t3, t2, 7 ;
M5; st ecx, [t5]
M6: st t3, [t1]
M7: st edx, [t6]
M8: st ebx, [t7] ; add t9, esp, -24
M9: st eax, [t8]
M10: st ecx, [t9] ; sub edi, ecx, ebx ; ; br next
Similarly, the command that computes t8 (A14) can be moved from instruction M3 into instruction M7, the command computing t7 (A12) can be moved from instruction M3 into instruction M6, and the command computing t6 (A10) can be moved from instruction M2 into instruction M5. Thus, after processing instruction M5 in the space pass, the schedule is:
M1: ; add t1, ebp, 12 ; add t4, esp, -4
M2: ; add t5, esp, -8
M3: ld t2, [t1]
M4: st eax, [t4] ; add t3, t2, 7
M5; st ecx, [t5] ; add t6, esp, -12
M6: st t3, [t1] ; add t7, esp, -16
M7: st edx, [t6] ; add t8, esp, -20
M8: st ebx, [t7] ; add t9, esp, -24
M9: st eax, [t8]
M10: st ecx, [t9] ; sub edi, ecx, ebx ; ; br next
Continuing in this manner, no command can be moved to it from an earlier instruction when processing instruction M4. However when processing instruction M3, the command computing t5 (A8) can be moved to it, leaving instruction M2 empty. When processing instruction M2, we find that the command computing t4 (A5) can be moved to it, so the final schedule is:
M1: ; add t1, ebp, 12
M2: ; add t4, esp, -4
M3: ld t2, [t1] ; add t5, esp, -8
M4: st eax, [t41 ; add t3, t2, 7
M5; st ecx, [t5] ; add t6, esp, -12
M6; st t3, [t1] ; add t7, esp, -16
M7: st edx, [t6] ; add t8, esp, -20
M8: st ebx, [t7] ; add t9, esp, -24
M9: st eax, [t8]
M10: st ecx, [t9] ; sub edi, ecx, ebx ; ; br next
When the scheduler now chooses formats with NOP insertion, again subject to the constraints above, the results are:
M1: nop ; add t1, ebp, 12
M2: nop ; add t4, esp, -4
M3: ld t2, [t1] ; add t5, esp, -8
M4: st eax, [t41 ; add t3, t2, 7
M5; st ecx, [t5] ; add t6, esp, -12
M6: st t3, [t1] ; add t7, esp, -16
M7: st edx, [t6] ; add t8, esp, -20
M8: st ebx, [t7] ; add t9, esp, -24
M9: st eax, [t8] ; nop
M10: st ecx, [t9] ; sub edi, ecx, ebx ; nop ; br next
where instruction M10 is both naturally wide and aligned properly (remember that the assumption that start is at an address that is 8 mod 16). The total space required for the modified sequence is:
Nine 8-byte instructions = 72 bytes
One 16-byte instruction = 16 bytes
Total = 88 bytes
This achieves almost a one-third reduction in the space required in memory and the instruction cache. In the embodiment described, a proposed short instruction word may be expanded to a long instruction word where useful to accomplish the purpose of reducing the space required by the scheduled sequence. Other similar considerations may be utilized in deciding whether to move a command from one instruction word to another. In order to assure that the time constraints established by the various edge conditions remain in place while undertaking a second space pass through the scheduling process, it is useful to simply reverse the conditions formulated on the first pass, i.e., reverse the directed acyclic graph shown in FIG. 2. Although the present invention has been described in terms of a preferred embodiment, it will be appreciated that various modifications and alterations might be made by those skilled in the art without departing from the spirit and scope of the invention. The invention should therefore be measured in terms of the claims which follow.
|
Same subclass Same class Consider this |
||||||||||
