+ All Categories
Home > Documents > Computer Organization and Architecture The CPU Structure.

Computer Organization and Architecture The CPU Structure.

Date post: 20-Dec-2015
Category:
View: 236 times
Download: 4 times
Share this document with a friend
Popular Tags:
62
Computer Organization and Architecture The CPU Structure
Transcript
Page 1: Computer Organization and Architecture The CPU Structure.

Computer Organization

and Architecture

The CPU Structure

Page 2: Computer Organization and Architecture The CPU Structure.

CPU Structure

CPU must: Fetch instructions Interpret instructions Fetch data Process data Write data

Page 3: Computer Organization and Architecture The CPU Structure.

External View of CPU

Page 4: Computer Organization and Architecture The CPU Structure.

Internal View of CPU

Page 5: Computer Organization and Architecture The CPU Structure.

Registers

CPU must have some working space (temporary storage)

Called registers Number and function vary between processor

designs One of the major design decisions Top level of memory hierarchy

Page 6: Computer Organization and Architecture The CPU Structure.

User Visible Registers

General Purpose Data Address Condition Codes

Page 7: Computer Organization and Architecture The CPU Structure.

General Purpose Registers (1)

May be true general purpose May be restricted May be used for data or addressing Data

Accumulator Addressing

Segment

Page 8: Computer Organization and Architecture The CPU Structure.

General Purpose Registers (2)

Make them general purpose Increase flexibility and programmer options Increase instruction size & complexity

Make them specialized Smaller (faster) instructions Less flexibility

Page 9: Computer Organization and Architecture The CPU Structure.

How Many GP Registers?

Between 8 - 32 Fewer = more memory references More does not reduce memory references

and takes up processor real estate See also RISC

Page 10: Computer Organization and Architecture The CPU Structure.

How big?

Large enough to hold the largest address Data register should be able to hold the value

of most date types Some machines allow two contiguous

register to be used as one for holding double-length values

Page 11: Computer Organization and Architecture The CPU Structure.

Condition Code Registers

Sets of individual bits e.g. result of last operation was zero

Can be read (implicitly) by programs e.g. Jump if zero

Can not (usually) be set by programs

Page 12: Computer Organization and Architecture The CPU Structure.

Control & Status Registers

Program Counter Instruction Decoding Register Memory Address Register Memory Buffer Register

Revision: what do these all do?

Page 13: Computer Organization and Architecture The CPU Structure.

Program Status Word A set of bits Includes Condition Codes Sign of last result Zero Carry Equal Overflow Interrupt enable/disable Supervisor

Page 14: Computer Organization and Architecture The CPU Structure.

Supervisor Mode

Intel ring zero Kernel mode Allows privileged instructions to execute Used by operating system Not available to user programs

Page 15: Computer Organization and Architecture The CPU Structure.

Example Register Organizations

Page 16: Computer Organization and Architecture The CPU Structure.

Indirect Cycle

May require memory access to fetch operands

Indirect addressing requires more memory accesses

Can be thought of as additional instruction subcycle

Page 17: Computer Organization and Architecture The CPU Structure.

Instruction Cycle with Indirect

Page 18: Computer Organization and Architecture The CPU Structure.

Instruction Cycle State Diagram

Page 19: Computer Organization and Architecture The CPU Structure.

Data Flow (Instruction Fetch)

Depends on CPU design In general: Fetch

PC contains address of next instruction Address moved to MAR Address placed on address bus Control unit requests memory read Result placed on data bus, copied to MBR, then to IR Meanwhile PC incremented by 1

Page 20: Computer Organization and Architecture The CPU Structure.

Data Flow (Data Fetch)

IR is examined If indirect addressing, indirect cycle is

performed Right most N bits of MBR transferred to MAR Control unit requests memory read Result (address of operand) moved to MBR

Page 21: Computer Organization and Architecture The CPU Structure.

Data Flow (Fetch Diagram)

Page 22: Computer Organization and Architecture The CPU Structure.

Data Flow (Indirect Diagram)

Page 23: Computer Organization and Architecture The CPU Structure.

Data Flow (Execute)

May take many forms Depends on instruction being executed May include

Memory read/write Input/Output Register transfers ALU operations

Page 24: Computer Organization and Architecture The CPU Structure.

Data Flow (Interrupt) Simple Predictable Current PC saved to allow resumption after interrupt Contents of PC copied to MBR Special memory location (e.g. stack pointer) loaded to

MAR MBR written to memory PC loaded with address of interrupt handling routine Next instruction (first of interrupt handler) can be fetched

Page 25: Computer Organization and Architecture The CPU Structure.

Data Flow (Interrupt Diagram)

Page 26: Computer Organization and Architecture The CPU Structure.

Prefetch

Fetch accessing main memory Execution usually does not access main

memory Can fetch next instruction during execution of

current instruction Called instruction prefetch

Page 27: Computer Organization and Architecture The CPU Structure.

Acceleration by Pipelining

Page 28: Computer Organization and Architecture The CPU Structure.

The Instruction Cycle

Page 29: Computer Organization and Architecture The CPU Structure.

Acceleration by Pipelining

Page 30: Computer Organization and Architecture The CPU Structure.

Theoretical Performance An ideal pipeline divides a task into k independent

sequential subtasks Each subtask requires 1 time unit to complete The task itself requires k time units to complete

For n iterations of task, the execution times: With no pipelining: nk time units With pipelining: k + (n-1) time units

Speedup of a k-stage pipeline is S = nk / [k+(n-1)] ==> k (for large n)

Page 31: Computer Organization and Architecture The CPU Structure.
Page 32: Computer Organization and Architecture The CPU Structure.
Page 33: Computer Organization and Architecture The CPU Structure.

Acceleration by Pipelining

Page 34: Computer Organization and Architecture The CPU Structure.

Pipeline Hazards

Page 35: Computer Organization and Architecture The CPU Structure.

Structural Hazards

Page 36: Computer Organization and Architecture The CPU Structure.

Data Hazards

Page 37: Computer Organization and Architecture The CPU Structure.

Data Hazards

Page 38: Computer Organization and Architecture The CPU Structure.

Data Hazards

Page 39: Computer Organization and Architecture The CPU Structure.

Control Hazards

Page 40: Computer Organization and Architecture The CPU Structure.

Control Hazards

Page 41: Computer Organization and Architecture The CPU Structure.

Control Hazards

Page 42: Computer Organization and Architecture The CPU Structure.

Control Hazards

Page 43: Computer Organization and Architecture The CPU Structure.

Control Hazards

With conditional branch we have a penalty even if the branch has not been taken. This is because we have to wait until the branch condition is available.

Branch instructions represent a major problem in assuring an optimal flow through the pipeline.

Page 44: Computer Organization and Architecture The CPU Structure.

Brief Summary

Structural hazards are due to resource conflicts.

Data hazards are produced by data dependencies between instructions.

Control hazards are produced as consequence of branch instructions.

Page 45: Computer Organization and Architecture The CPU Structure.

Branches Branch instructions can dramatically affect pipeline

performance. Control operations are very frequent in current programs.

20% - 35% of the instructions executed are branches (conditional and unconditional).

65% of the branches actually take the branch. Conditional branches are much more frequent than

unconditional (more than two times). More than 50% of conditional branches are taken.

Page 46: Computer Organization and Architecture The CPU Structure.

Dealing with Branches

Multiple Streams Loop buffer Delayed branching Branch prediction

static prediction dynamic prediction branch history table

Page 47: Computer Organization and Architecture The CPU Structure.

Multiple Streams

Have two pipelines Prefetch each branch into a separate pipeline Use appropriate pipeline

Leads to bus & register contention Multiple branches lead to further pipelines being

needed

Page 48: Computer Organization and Architecture The CPU Structure.

Loop Buffer

Very fast memory Contain the n most recently fetched instruction Maintained by fetch stage of pipeline Check buffer before fetching from memory Very good for small loops or jumps c.f. cache Used by CRAY-1

Page 49: Computer Organization and Architecture The CPU Structure.

Delayed Branching The idea with delayed branching is to let the CPU do some

useful work during some of the cycles which are shown to be stalled

With delayed branching the CPU always executes the instruction that immediately follows after the branch and only then alters (if necessary) the sequence of execution. The instruction after the branch is said to be in the branch delay slot

Leads to bus & register contention Multiple branches lead to further pipelines being needed

Page 50: Computer Organization and Architecture The CPU Structure.

Delayed Branching

Page 51: Computer Organization and Architecture The CPU Structure.

Delayed Branching

Page 52: Computer Organization and Architecture The CPU Structure.

Comparison

Page 53: Computer Organization and Architecture The CPU Structure.

Comparison

Page 54: Computer Organization and Architecture The CPU Structure.

Delayed Branching

Page 55: Computer Organization and Architecture The CPU Structure.

Branch Prediction

Correct branch prediction is very important and can produce substantial performance improvements. static prediction dynamic prediction

To take full advantage of branch prediction, we can have the instructions not only fetched but also begin execution. This is known as speculative execution

Page 56: Computer Organization and Architecture The CPU Structure.

Speculative Execution Instructions are executed before the processor

is certain that they are in the correct execution path. If it turns out that the prediction was correct, execution goes on without introducing any branch penalty. If, however, the prediction is not fulfilled, the instruction(s) started in ad-vance and all their associated data must be purged and the state previous to their execution restored.

Page 57: Computer Organization and Architecture The CPU Structure.

Static Branch Prediction

Static prediction techniques do not take into consideration execution history.

Predict never taken (Motorola 68020): assumes that the branch is not taken.

Predict always taken: assumes that the branch is taken.

Page 58: Computer Organization and Architecture The CPU Structure.

Dynamic Branch Prediction

Improve the accuracy of prediction by recording the history of conditional branches.

One-bit prediction scheme is used in order to record if the last execution resulted

in a branch taken or not. The system predicts the same behavior as for the last time.

Two-bit prediction scheme with a two-bit scheme predictions can be made

depending on the last two instances of execution.

Page 59: Computer Organization and Architecture The CPU Structure.

One-Bit Prediction Scheme

Page 60: Computer Organization and Architecture The CPU Structure.

Two-Bit Prediction Scheme

Page 61: Computer Organization and Architecture The CPU Structure.

Branch History Table History info. can be used not only to predict the

outcome of a conditional branch but also to avoid recalculation of the target address. Together with bits used for prediction, the target address can be stored for later use in a branch history table.

Using D. B. P with history tables up to 90% of predictions can be correct.

Pentium,PowerPC620 use speculative execution with D.B.P based on a branch history table.

Page 62: Computer Organization and Architecture The CPU Structure.

Branch History Table


Recommended