57
12 CPU Structure and Function Computer Organization

12 CPU Structure and Function Computer Organization

Embed Size (px)

Citation preview

Page 1: 12 CPU Structure and Function Computer Organization

12CPU Structure and Function

Computer Organization

Page 2: 12 CPU Structure and Function Computer Organization

CPU StructureCPU must:

Fetch instructionsInterpret instructionsFetch dataProcess dataWrite data

Page 3: 12 CPU Structure and Function Computer Organization

CPU With Systems Bus

Page 4: 12 CPU Structure and Function Computer Organization

CPU Internal Structure

Page 5: 12 CPU Structure and Function Computer Organization

RegistersCPU must have some working space

(temporary storage)Called registersNumber and function vary between

processor designsOne of the major design decisionsTop level of memory hierarchy

Page 6: 12 CPU Structure and Function Computer Organization

User Visible RegistersGeneral PurposeDataAddressCondition Codes

Page 7: 12 CPU Structure and Function Computer Organization

General Purpose Registers (1)

May be true general purposeMay be restrictedMay be used for data or addressingData

AccumulatorAddressing

Segment

Page 8: 12 CPU Structure and Function Computer Organization

General Purpose Registers (2)

Make them general purposeIncrease flexibility and programmer optionsIncrease instruction size & complexity

Make them specializedSmaller (faster) instructionsLess flexibility

Page 9: 12 CPU Structure and Function Computer Organization

How Many GP Registers?Between 8 - 32Fewer = more memory referencesMore does not reduce memory references

and takes up processor real estateSee also RISC

Page 10: 12 CPU Structure and Function Computer Organization

How big?Large enough to hold full addressLarge enough to hold full wordOften possible to combine two data

registersC programmingdouble int a;long int a;

Page 11: 12 CPU Structure and Function Computer Organization

Condition Code RegistersSets of individual bits

e.g. result of last operation was zeroCan be read (implicitly) by programs

e.g. Jump if zeroCan not (usually) be set by programs

Page 12: 12 CPU Structure and Function Computer Organization

Control & Status RegistersProgram CounterInstruction Decoding RegisterMemory Address RegisterMemory Buffer Register

Revision: what do these all do?

Page 13: 12 CPU Structure and Function Computer Organization

Program Status WordA set of bitsIncludes Condition CodesSign of last resultZeroCarryEqualOverflowInterrupt enable/disableSupervisor

Page 14: 12 CPU Structure and Function Computer Organization

Supervisor ModeIntel ring zeroKernel modeAllows privileged instructions to executeUsed by operating systemNot available to user programs

Page 15: 12 CPU Structure and Function Computer Organization

Other RegistersMay have registers pointing to:

Process control blocks (see O/S)Interrupt Vectors (see O/S)

N.B. CPU design and operating system design are closely linked

Page 16: 12 CPU Structure and Function Computer Organization

Example Register Organizations

Page 17: 12 CPU Structure and Function Computer Organization

Instruction CycleRevisionStallings Chapter 3

Page 18: 12 CPU Structure and Function Computer Organization

Indirect CycleMay require memory access to fetch

operandsIndirect addressing requires more memory

accessesCan be thought of as additional instruction

subcycle

Page 19: 12 CPU Structure and Function Computer Organization

Instruction Cycle with Indirect

Page 20: 12 CPU Structure and Function Computer Organization

Instruction Cycle State Diagram

Page 21: 12 CPU Structure and Function Computer Organization

Data Flow (Instruction Fetch)Depends on CPU designIn general:

FetchPC contains address of next instructionAddress moved to MARAddress placed on address busControl unit requests memory readResult placed on data bus, copied to MBR,

then to IRMeanwhile PC incremented by 1

Page 22: 12 CPU Structure and Function Computer Organization

Data Flow (Data Fetch)IR is examinedIf indirect addressing, indirect cycle is

performedRight most N bits of MBR transferred to MARControl unit requests memory readResult (address of operand) moved to MBR

Page 23: 12 CPU Structure and Function Computer Organization

Data Flow (Fetch Diagram)

Page 24: 12 CPU Structure and Function Computer Organization

Data Flow (Indirect Diagram)

Page 25: 12 CPU Structure and Function Computer Organization

Data Flow (Execute)May take many formsDepends on instruction being executedMay include

Memory read/writeInput/OutputRegister transfersALU operations

Page 26: 12 CPU Structure and Function Computer Organization

Data Flow (Interrupt)SimplePredictableCurrent PC saved to allow resumption after

interruptContents of PC copied to MBRSpecial memory location (e.g. stack

pointer) loaded to MARMBR written to memoryPC loaded with address of interrupt

handling routineNext instruction (first of interrupt handler)

can be fetched

Page 27: 12 CPU Structure and Function Computer Organization

Data Flow (Interrupt Diagram)

Page 28: 12 CPU Structure and Function Computer Organization

PrefetchFetch accessing main memoryExecution usually does not access main

memoryCan fetch next instruction during execution

of current instructionCalled instruction prefetch

Page 29: 12 CPU Structure and Function Computer Organization

Improved PerformanceBut not doubled:

Fetch usually shorter than executionPrefetch more than one instruction?

Any jump or branch means that prefetched instructions are not the required instructions

Add more stages to improve performance

Page 30: 12 CPU Structure and Function Computer Organization

PipeliningFetch instructionDecode instructionCalculate operands (i.e. EAs)Fetch operandsExecute instructionsWrite result

Overlap these operations

Page 31: 12 CPU Structure and Function Computer Organization

Two Stage Instruction Pipeline

Page 32: 12 CPU Structure and Function Computer Organization

Timing Diagram for Instruction Pipeline Operation

Page 33: 12 CPU Structure and Function Computer Organization

The Effect of a Conditional Branch on Instruction Pipeline Operation

Page 34: 12 CPU Structure and Function Computer Organization

Six Stage Instruction Pipeline

Page 35: 12 CPU Structure and Function Computer Organization

Alternative Pipeline Depiction

Page 36: 12 CPU Structure and Function Computer Organization

Speedup Factorswith InstructionPipelining

Page 37: 12 CPU Structure and Function Computer Organization

Dealing with BranchesMultiple StreamsPrefetch Branch TargetLoop bufferBranch predictionDelayed branching

Page 38: 12 CPU Structure and Function Computer Organization

Multiple StreamsHave two pipelinesPrefetch each branch into a separate

pipelineUse appropriate pipeline

Leads to bus & register contentionMultiple branches lead to further pipelines

being needed

Page 39: 12 CPU Structure and Function Computer Organization

Prefetch Branch TargetTarget of branch is prefetched in addition

to instructions following branchKeep target until branch is executedUsed by IBM 360/91

Page 40: 12 CPU Structure and Function Computer Organization

Loop BufferVery fast memoryMaintained by fetch stage of pipelineCheck buffer before fetching from memoryVery good for small loops or jumpsc.f. cacheUsed by CRAY-1

Page 41: 12 CPU Structure and Function Computer Organization

Loop Buffer Diagram

Page 42: 12 CPU Structure and Function Computer Organization

Branch Prediction (1)Predict never taken

Assume that jump will not happenAlways fetch next instruction 68020 & VAX 11/780VAX will not prefetch after branch if a page

fault would result (O/S v CPU design)Predict always taken

Assume that jump will happenAlways fetch target instruction

Page 43: 12 CPU Structure and Function Computer Organization

Branch Prediction (2)Predict by Opcode

Some instructions are more likely to result in a jump than thers

Can get up to 75% successTaken/Not taken switch

Based on previous historyGood for loops

Page 44: 12 CPU Structure and Function Computer Organization

Branch Prediction (3)Delayed Branch

Do not take jump until you have toRearrange instructions

Page 45: 12 CPU Structure and Function Computer Organization

Branch Prediction Flowchart

Page 46: 12 CPU Structure and Function Computer Organization

Branch Prediction State Diagram

Page 47: 12 CPU Structure and Function Computer Organization

Dealing With Branches

Page 48: 12 CPU Structure and Function Computer Organization

Intel 80486 Pipelining Fetch

From cache or external memory Put in one of two 16-byte prefetch buffers Fill buffer with new data as soon as old data consumed Average 5 instructions fetched per load Independent of other stages to keep buffers full

Decode stage 1 Opcode & address-mode info At most first 3 bytes of instruction Can direct D2 stage to get rest of instruction

Decode stage 2 Expand opcode into control signals Computation of complex address modes

Execute ALU operations, cache access, register update

Writeback Update registers & flags Results sent to cache & bus interface write buffers

Page 49: 12 CPU Structure and Function Computer Organization

80486 Instruction Pipeline Examples

Page 50: 12 CPU Structure and Function Computer Organization

Pentium 4 Registers

Page 51: 12 CPU Structure and Function Computer Organization

EFLAGS Register

Page 52: 12 CPU Structure and Function Computer Organization

Control Registers

Page 53: 12 CPU Structure and Function Computer Organization

MMX Register MappingMMX uses several 64 bit data typesUse 3 bit register address fields

8 registersNo MMX specific registers

Aliasing to lower 64 bits of existing floating point registers

Page 54: 12 CPU Structure and Function Computer Organization

Mapping of MMX Registers to Floating-Point Registers

Page 55: 12 CPU Structure and Function Computer Organization

Pentium Interrupt ProcessingInterrupts

MaskableNonmaskable

ExceptionsProcessor detectedProgrammed

Interrupt vector tableEach interrupt type assigned a numberIndex to vector table256 * 32 bit interrupt vectors

5 priority classes

Page 56: 12 CPU Structure and Function Computer Organization

PowerPC User Visible Registers

Page 57: 12 CPU Structure and Function Computer Organization

PowerPC Register Formats