Reduced Instruction Set Computers Pipelining: (RISC)
Reduced Instruction Set Computers Pipelining: (RISC)
Reduced Instruction Set Computers Pipelining: (RISC)
Pipelining Review
Pipelining:
Break instruction cycle into n phases (one stage per phase)
e.g. Fetch, Decode, ReadOPs, Execute1, Execute2, WriteBack
Fetch a new instruction each phase Maximum speed gain is n Hazards reduce the ability to achieve a gain of n
Types of Hazards
+ Resource
o Hazard occurs when instruction needs a resource being used by another instruction
+ Data
o RAW (hazard if read can occur before write has finished) o WAR (hazard if write can occur before read is finished) o WAW (hazard if writes occur in the unintended order)
+ Control
o Hazard occurs when a wrong fetch decision at a branch results in an extra instruction fetch and a pipeline flush
Data Hazards Read after Write (RAW) true dependency A Hazard occurs if the Read occurs before the Write is complete
e.g. Reg 1 Reg 1 + Reg 2 {write occurs after execution} Reg 3 reg 1 Reg 3 {read occurs before execution}
A Hazard occurs if the two Writes occur in the reverse order than intended
e.g. Reg A M(PTR) {2 memory accesses long write} Reg A Reg B {0 memory accesses short write}
Control Hazard
Control Hazards occur when a wrong fetch decision results in a new instruction fetch and the pipeline being flushed Solutions include: Multiple Pipeline streams
Prefetching the branch target Using a Loop Buffer Branch Prediction Delayed Branch Reordering of Instructions Multiple Copies of Registers (backups)
Hardware contribution
Have more registers
Thus more variables will be in registers
Register uses
Store local scalar variables in registers Reduces memory accesses Every procedure (function) call changes locality (typically lots of procedure calls are encountered) Parameters must be passed
Partial context switch Results must be returned Variables from calling program must be restored Partial Context switch
Implications:
If we Partition register set We can use multiple small sets of registers per context Let Calls switch to a new set of registers Let Returns switch back to the previously used set of registers
Then:
Temporary registers from one set overlap parameter registers from the next
And:
This provides parameter passing without moving data (just move one pointer)
Global Variables
How should we accommodate Global Variables?
Allocate by the compiler to memory ? Have a static set of registers for global variables ? Put them in cache ?
Individual variables
Blocks of memory
Register addressing
Memory addressing
Then:
Assign symbolic, or virtual, register to each candidate variable Map (unlimited) symbolic registers to (limited) real registers
Symbolic registers that are not used at the same time can share real registers
If you run out of real registers some variables will use memory
And then: Try to color the graph with n colors, where n is the number of real registers Nodes that can not be colored must be placed in memory
Memory to Memory vs Register to Memory Operations (RISC uses only Register to memory)
D: Memory
Register to memory or memory to register operation
(E1 register read, E2 execute & register write Particularly beneficial if E phase is long)