Committing and freeing registers Active list Controls committing

  • Slides: 31
Download presentation
Committing and freeing registers • Active list – Controls committing and freeing of physical

Committing and freeing registers • Active list – Controls committing and freeing of physical registers – A single action does both: Committing a register means the previously-committed register can be freed (its value is no longer needed) ECE 721, Spring 2020 Prof. Eric Rotenberg 1

Two Different Approaches • Approach #1: – Architectural Map Table • Whereas Rename Map

Two Different Approaches • Approach #1: – Architectural Map Table • Whereas Rename Map Table contains most recent versions of logical registers, Arch. Map Table contains committed versions of logical registers • Approach #2: – No Architectural Map Table ECE 721, Spring 2020 Prof. Eric Rotenberg 2

Approach #1 ECE 721, Spring 2020 Prof. Eric Rotenberg 3

Approach #1 ECE 721, Spring 2020 Prof. Eric Rotenberg 3

Active List Contents ACTIVE LIST Logical Dest. Physical Dest. : Current Mapping 3 r

Active List Contents ACTIVE LIST Logical Dest. Physical Dest. : Current Mapping 3 r 1 p 67 A 4 r 3 p 19 B 5 r 1 p 27 C 6 r 4 p 28 D Entry Exception Complete PC 1 2 HEAD TAIL 7 … ECE 721, Spring 2020 Prof. Eric Rotenberg 4

Active List Operation • Dispatch: – Reserve entry at tail, write the instruction’s logical

Active List Operation • Dispatch: – Reserve entry at tail, write the instruction’s logical and physical destination register specifiers, increment tail pointer – “Current mapping”: instruction’s physical destination register specifier ECE 721, Spring 2020 Prof. Eric Rotenberg 5

Active List Operation (cont. ) • Retire: – Wait for head instruction to complete

Active List Operation (cont. ) • Retire: – Wait for head instruction to complete – Index Arch. Map Table using the head instruction’s logical destination register specifier • Free the “previous mapping” that is contained in the Arch. Map Table: push it onto the free list. Since we are about to commit a new version, the old committed version is no longer needed for possible recovery. • Physical register indicated by “current mapping” is committed by updating the Arch. Map Table with the current mapping. – Advance head pointer ECE 721, Spring 2020 Prof. Eric Rotenberg 6

Committing and freeing registers Free List Architectural Map Table “commit” r 1 p 8

Committing and freeing registers Free List Architectural Map Table “commit” r 1 p 8 p 67 p 8 “free” (tail) ACTIVE LIST HEAD Logical Dest. Physical Dest: Current Mapping r 1 p 67 r 3 p 19 r 1 p 27 r 4 p 28 TAIL ECE 721, Spring 2020 Prof. Eric Rotenberg 7

Handling Exceptions • Set exception bit in active list • When posted exception reaches

Handling Exceptions • Set exception bit in active list • When posted exception reaches head of active list: – Flush active list: Set tail pointer equal to head pointer – Flush pipeline: Squash all instructions in frontend stages, issue queues, FUs, etc. – Restore rename map table to committed state: Copy architectural map table to rename map table – Restore free list: Push mappings of all instructions after the offending one back onto the free list – Save PC of offending instr. (gotten from head of active list) • E. g. , MIPS ISA defines EPC register where handler will return to • EPC = AL[al_head]. PC – Trap to the exception handler • PC = address of exception handler ECE 721, Spring 2020 Prof. Eric Rotenberg 8

Implementation Challenges (1) • Squashing instructions in pipeline – Global squash signal may be

Implementation Challenges (1) • Squashing instructions in pipeline – Global squash signal may be cycle time bottleneck – Extending to multiple cycles provides some relief – Still a routing bottleneck (physical design) • Alternative: wait for all in-flight instructions to “drain” from pipeline (i. e. , wait for all of them to complete) + No global squash signal – Wait extra cycles as pipeline drains. Can overlap some cycles with restoring RMT from AMT if it takes multiple cycles to copy ECE 721, Spring 2020 Prof. Eric Rotenberg 9

Implementation Challenges (2) • ECE 721, Spring 2020 Prof. Eric Rotenberg 10

Implementation Challenges (2) • ECE 721, Spring 2020 Prof. Eric Rotenberg 10

Determining number of ports for renaming structures Example: • 4 -way superscalar i. e.

Determining number of ports for renaming structures Example: • 4 -way superscalar i. e. , 4 instr. in rename bundle and 4 instr. in retire bundle T ? W H Free List ? R ? W RMT ? R AMT ? W RENAME RETIRE rename logical destination registers rename logical source registers ? R H ECE 721, Spring 2020 Active List ? W T Prof. Eric Rotenberg 11

Implementation Challenges (3) • Two options for restoring free list – Slow and complex:

Implementation Challenges (3) • Two options for restoring free list – Slow and complex: • Scan active list between head and tail, push each instruction’s current mapping back onto free list • Fortunately there is a more clever way… – Fast and simple: • Observation about free list contents: – Between H and T: List of free physical registers – Between T and H: List of physical registers allocated to instructions between active list H and T » Popping mappings from free list merely advances its head pointer but does not destroy contents • Restore free list simply by rolling back head pointer to tail pointer and noting that free list is full – head = tail – freelist_length = freelist_size (or freelist_full = true) // circular FIFO must distinguish between empty and full cases ECE 721, Spring 2020 Prof. Eric Rotenberg 12

KEY: committed registers Architectural Map Table speculative registers, allocated to active instructions speculative registers,

KEY: committed registers Architectural Map Table speculative registers, allocated to active instructions speculative registers, free Free List initial state: pipeline empty tail head Active List head tail Free List tail head tail after dispatching instructions, before recovery Active List Free List tail head after recovery Active List head tail ECE 721, Spring 2020 Prof. Eric Rotenberg 13

Approach #2 ECE 721, Spring 2020 Prof. Eric Rotenberg 14

Approach #2 ECE 721, Spring 2020 Prof. Eric Rotenberg 14

Active List Contents ACTIVE LIST Entry Logical Dest. Previous Exception Complete mapping PC 1

Active List Contents ACTIVE LIST Entry Logical Dest. Previous Exception Complete mapping PC 1 2 HEAD TAIL 3 r 1 p 8 A 4 r 3 p 33 B 5 r 1 p 67 C 6 r 4 p 46 D 7 … ECE 721, Spring 2020 Prof. Eric Rotenberg 15

Active List (after) H T Logical Dest. Previous mapping r 1 p 8 Active

Active List (after) H T Logical Dest. Previous mapping r 1 p 8 Active List (after) Logical Dest. H Previous mapping r 1 p 8 r 3 p 33 T Active List (after) Logical Dest. H Previous mapping r 1 p 8 r 3 p 33 r 1 p 67 r 4 p 46 T ECE 721, Spring 2020 Prof. Eric Rotenberg 16

Active List Operation • Rename: – Before updating the Rename Map Table with a

Active List Operation • Rename: – Before updating the Rename Map Table with a new mapping for an instruction’s logical destination register, read out the previous mapping for that logical destination register – This requires an extra read port for the logical destination register of an instruction: Approach #1 (with Arch. Map Table) phys. source reg. 1 = RMT[logical source reg. 1] phys. source reg. 2 = RMT[logical source reg. 2] // RMT read port phys. dest. reg. = pop new mapping from free list RMT[logical dest. reg. ] = phys. dest. reg. // RMT write port Approach #2 (without Arch. Map Table) phys. source reg. 1 = RMT[logical source reg. 1] phys. source reg. 2 = RMT[logical source reg. 2] previous mapping = RMT[logical dest. reg. ] // RMT read port // extra RMT read port phys. dest. reg. = pop new mapping from free list RMT[logical dest. reg. ] = phys. dest. reg. // RMT write port ECE 721, Spring 2020 Prof. Eric Rotenberg 17

Active List Operation (cont. ) • Dispatch: – Reserve entry at tail, write the

Active List Operation (cont. ) • Dispatch: – Reserve entry at tail, write the instruction’s logical destination register specifier and the previous mapping of that logical register, increment tail pointer • Retire: – Wait for head instruction to complete – Push its previous mapping onto the free list. This has two implicit effects: • Frees the prior committed version of the instruction’s logical dest. register • Commits the instruction’s physical dest. register – Advance head pointer ECE 721, Spring 2020 Prof. Eric Rotenberg 18

Committing and freeing registers Free List p 8 (tail) ACTIVE LIST HEAD Logical Dest.

Committing and freeing registers Free List p 8 (tail) ACTIVE LIST HEAD Logical Dest. Previous mapping r 1 p 8 r 3 p 33 r 1 p 67 r 4 p 46 “free” “commit”: This action implicitly commits the head instruction’s version of r 1 (p 67). TAIL ECE 721, Spring 2020 Prof. Eric Rotenberg 19

Handling Exceptions • Set exception bit in active list • When posted exception reaches

Handling Exceptions • Set exception bit in active list • When posted exception reaches head of active list: – Flush pipeline: Squash all instructions in frontend stages, issue queues, FUs, etc. – Restore rename map table to committed state: Scan the active list backward from tail to head, restore previous mappings into rename map table – Restore free list: Either: • Easy: Restore head pointer as before (head=tail) • More complicated than needed: While restoring the rename map table, “undone” current mappings are pushed back onto free list – Save PC of offending instr. (gotten from head of active list) – Trap to the exception handler ECE 721, Spring 2020 Prof. Eric Rotenberg 20

Active List Rename Map Table Initial: renamed four instr. r 0 p 10 r

Active List Rename Map Table Initial: renamed four instr. r 0 p 10 r 1 p 27 r 2 p 11 r 3 p 19 r 4 p 28 Logical Dest. H … r 31 After commit of oldest instr. p 2 r 1 p 8 r 3 p 33 r 1 p 67 r 4 p 46 Logical Dest. Previous mapping r 1 p 8 r 3 p 33 r 1 p 67 r 4 p 46 T r 0 p 10 r 1 p 27 r 2 p 11 r 3 p 19 r 4 p 28 H … r 31 Previous mapping p 2 r 1: p 8 freed, implicitly committed r 1: p 67 T Suppose second instr. , now at head (H), posted an exception. Restore prev. mappings from T to H from AL to RMT. H T Original RMT (before instr. sequence) Logical Dest. Previous mapping r 1 p 8 r 0 p 10 r 3 p 33 r 1 p 8 r 1 p 67 r 2 p 11 r 4 p 46 r 3 p 33 H T HT r 4 p 46 … r 0 p 10 r 1 p 27 p 67 r 1 p 67 r 2 p 11 r 3 p 19 p 33 r 4 p 28 p 46 r 4 p 46 r 0 p 10 … r 1 p 67 … … r 31 p 2 Final RMT (after recovery) r 2 p 11 r 3 p 33 r 4 p 46 … ECE 721, Spring 2020 Prof. Eric Rotenberg r 31 p 2 21

Speculation • Speculation – Make branch predictions – To speculate is to act on

Speculation • Speculation – Make branch predictions – To speculate is to act on these predictions: fetch and execute instructions from the predicted path – What if we were wrong? predicted path ECE 721, Spring 2020 actual path Prof. Eric Rotenberg 22

Branch Misprediction Recovery Approaches These approaches wait for the mispredicted branch to reach the

Branch Misprediction Recovery Approaches These approaches wait for the mispredicted branch to reach the head of the active list (like an exception), before initiating recovery. 1. Handle like exception using approach #1 2. Handle like exception using approach #2 These approaches initiate recovery as soon as the misprediction is discovered (as soon as the branch instruction executes), from the middle of the active list. 3. Forward walk active list 4. Backward walk active list 5. Shadow Map Tables ECE 721, Spring 2020 Prof. Eric Rotenberg 23

Branch Misprediction Recovery Approaches 3, 4, & 5 • Free List: For all three

Branch Misprediction Recovery Approaches 3, 4, & 5 • Free List: For all three approaches, checkpoint the free list head pointer when the branch is renamed. Restoring the checkpointed free list head pointer associated with the mispredicted branch causes mappings of instructions after the branch to be freed in bulk. • Rename Map Table: Need to restore the RMT to the point of the branch. The three approaches differ in this aspect. See following slides. ECE 721, Spring 2020 Prof. Eric Rotenberg 24

Approach #3: Forward walk active list • Same structures as Approach #1 – Active

Approach #3: Forward walk active list • Same structures as Approach #1 – Active List contains current mappings, which are used to update an Architectural Map Table • When misprediction is detected: – Restore RMT from AMT right away (either flash copy or serial copy) – Fast-forward the RMT to the point of the branch in the active list, by walking the active list from head to branch and incrementally updating the RMT with the current mappings in the active list ECE 721, Spring 2020 Prof. Eric Rotenberg 25

Approach #3 (cont. ) • Approach #3 and Approach #1 seem to be equal

Approach #3 (cont. ) • Approach #3 and Approach #1 seem to be equal but opposite – Approach #1: Waits for branch to reach head of active list, then copy AMT to RMT – Approach #3: Immediately copy AMT to RMT, then walk forward from head to branch • So how is Approach #3 better? – Approach #1 is delayed by the time to execute and retire all instructions prior to the branch. E. g. , what if there is an L 2 -cache-missed load stalling retirement for 100 s of cycles? – Approach #3’s recovery latency only depends on the number of instructions prior to the branch, not the time to execute those instructions ECE 721, Spring 2020 Prof. Eric Rotenberg 26

Approach #4: Backward walk active list • Same as approach #2, except start walking

Approach #4: Backward walk active list • Same as approach #2, except start walking the active list backward from tail to branch as soon as misprediction is detected ECE 721, Spring 2020 Prof. Eric Rotenberg 27

Approach #5: Shadow Map Tables • Checkpoint (create a copy of) Rename Map Table

Approach #5: Shadow Map Tables • Checkpoint (create a copy of) Rename Map Table at every predicted branch – Checkpoint RMT after branch is renamed, since state of RMT at this point reflects renaming all instructions up to and including the branch, and none after • When branch executes (“resolves”) – Misprediction: • Restore rename map table from the mispredicted branch’s shadow map table • Reclaim the shadow map tables of the mispredicted branch and all later branches, for use by new predicted branches – Correct prediction: • Reclaim the branch’s shadow map table, for use by new predicted branches ECE 721, Spring 2020 Prof. Eric Rotenberg 28

Recovery from branch mispredictions • Recovery steps – Pipeline • Instruction fetch unit –

Recovery from branch mispredictions • Recovery steps – Pipeline • Instruction fetch unit – Set PC to the correct target of the branch – Repair the global branch history register of the branch predictor (if applicable) • Frontend stages: fetch, decode, rename, dispatch – Squash all instructions in the frontend stages since these are by definition after the resolved branch • Backend stages: schedule, register read, execute, writeback – Selectively squash only those instructions in the backend stages that come after the mispredicted branch in program order – Each instruction inherits a branch dependence bit vector in the rename stage, with one bit per unresolved branch, indicating which unresolved branches are before the instruction in program order ECE 721, Spring 2020 Prof. Eric Rotenberg 29

Recovery from branch mispredictions • Recovery steps (cont. ) – Active list • Set

Recovery from branch mispredictions • Recovery steps (cont. ) – Active list • Set tail pointer to the entry just after the mispredicted branch – Free list • Already discussed this – Rename map table • Already discussed this: five different approaches – Shadow map tables • Already discussed this for Approach #5 • Reclaim the shadow map tables of the mispredicted branch and all later branches ECE 721, Spring 2020 Prof. Eric Rotenberg 30

Modern Superscalar Microarchitecture fetch Free List head tail retire AMT head exception recovery misp.

Modern Superscalar Microarchitecture fetch Free List head tail retire AMT head exception recovery misp. rec. decode RMT Shadow Maps tail Active List complete rename PRF ready bits clr dispatch set schedule Issue Queue (IQ) register read execute Function Units (FUs) Physical RF writeback ECE 721, Spring 2020 Prof. Eric Rotenberg 31