← develop-16 9312 December 1993

develop-16 9312 December 1993

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

PDF page 12

the pipeline is kept full like this, the number of cycles per instruction drops to just one. This is the goal of most RISC architectures. One cycle per instruction is the ideal case for this example, but in reality, stalls and bubbles occur, even in the best architectures. This is where the compiler comes into play. The compiler has detailed knowledge of how the program should work. It need not perform operations in the order specified in the source code; it need only guarantee that the right result is obtained. If you build into the compiler some knowledge of how to make best use of the CPU, the compiler can make a huge difference in program performance. Consider the following two C instructions: b = *a + 5; d = *c + 10; The variables a , b , c , and d are all long or pointer-to-long variables. The compiler might generate the following assembly instructions on the PowerPC microprocessor: lwz r5,0(r3) ; Load value pointed to by r3 into r5 addi r5,r5,0x0005 ; Add 5 to value in r5 lwz r6,0(r4) ; Load value pointed to by r4 into r6 addi r6,r6,0x000a ; Add 10 to value in r6 The lwz instruction (Load Word and Zero) loads a register from a source value. On a PowerPC processor, words are 32-bit values; 16-bit values are half words. The addi instruction (Add Immediate) adds the immediate value and stores the result. Figure 5 shows what happens when these instructions execute. Both addi instructions stall in the decode stage because they can’t enter the execute stage until the register is available from the lwz instruction. The compiler can prevent the stalls. Instead of following the flow of the original source code, you can rearrange the instructions as follows: lwz r5,0(r3) ; Load value pointed to by r3 into r5 lwz r6,0(r4) ; Load value pointed to by r4 into r6 addi r5,r5,0x0005 ; Add 5 to value in r5 addi r6,r6,0x000a ; Add 10 to value in r6 Now look at what happens to the instruction pipeline (Figure 6): there are no delays. By moving the add instructions to later in the instruction stream, you allow the load instructions they depend on to complete, so the add instructions can execute immediately. d e v e l o p Issue 16 10

Languages
English