CS计算机结构实用_第1页
CS计算机结构实用_第2页
CS计算机结构实用_第3页
CS计算机结构实用_第4页
CS计算机结构实用_第5页
已阅读5页,还剩73页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

会计学1CS计算机结构实用Recap:ASingle-CycleProcessorCPI=1第1页/共79页PCInstMemorymuxALUDataMemmuxPCRegFileInstMemorymuxALUmuxPCInstMemorymuxALUDataMemPCInstMemorycmpmuxRegFileRegFileRegFileArithmetic&LogicalLoadStoreBranchCriticalPathsetupsetupWhat’sWrongwithSingle-cycle?LongcycletimeAllinstructionstakesametimeastheslowestRealmemoryisnotsoidealcannotalwaysgetjobdoneinone(short)cycleAFUcanonlybeusedonce=>highercost第2页/共79页OutlineDesigningaprocessorBuildingthedatapathAsingle-cycleimplementationAmulticycleimplementationMulticycledatapathMulticycleexecutionstepsMulticyclecontrol(AppendixC.3)Microprogramming:simplifyingcontrol(AppendixC.4)Exceptions第3页/共79页MulticycleImplementationstorageelementAcyclicCombinationalLogicstorageelementstorageelementAcyclicCombinationalLogic(A)storageelementstorageelementAcyclicCombinationalLogic(B)=>ReducecycletimeDiff.Inst.takediff.cyclesSharefunctionalunits第4页/共79页Breakuptheinstructionsintosteps,eachsteptakesacyclebalancetheamountofworktobedonerestricteachcycletouseonlyonemajorfunctionalunitAttheendofacyclestorevaluesforuseinlatercycles(easiestthingtodo)introduceadditionalinternalregisters

MulticycleApproach第5页/共79页PartitionSingle-CycleDatapathIns.fetchRFaccessALUoperationmemoryaccessAddregistersbetweensmalleststeps第6页/共79页MulticycleDatapath1memory(instr.&data),1ALU(addr,PC+4,add,…),registers(IR,MDR,A,B,ALUOut)Storageforsubsequentinst.(arch.-visible)vs.storageforsameinst.butinasubsequentcycleFig.5.25第7页/共79页MulticycleDatapathforBasicInstr.IRneedswritecontrol,butothersdon’tMUXtoselect2sourcestomemory;memoryneedsreadsignalPCandAtooneALUinput;foursourcestoanotherinputFig.5.27第8页/共79页AddingBranch/JumpThreesourcestoPCTwoPCwritesignalsFig.5.28第9页/共79页OutlineDesigningaprocessorBuildingthedatapathAsingle-cycleimplementationAmulticycleimplementationMulticycledatapathMulticycleexecutionstepsMulticyclecontrol(AppendixC.3)Microprogramming:simplifyingcontrol(AppendixC.4)Exceptions第10页/共79页InstructionFetchInstructionDecodeandRegisterFetchExecution,MemoryAddressComputation,orBranchCompletionMemoryAccessorR-typeInstructionCompletionMemoryReadCompletion(Write-back)

INSTRUCTIONSTAKEFROM3-5CYCLES!FiveExecutionSteps第11页/共79页Step1:InstructionFetchUsePCtogetinstructionandputitintheInstructionRegister(IR)IncrementthePCby4andputtheresultbackinthePCCanbedescribedsuccinctlyusingRTL(Register-TransferLanguage)

IR=Memory[PC];

PC=PC+4;

Canwefigureoutthevaluesofthecontrolsignals?

WhatistheadvantageofupdatingthePCnow?第12页/共79页Step2:InstructionDecodeandRegisterFetchReadregistersrsandrtincaseneededComputethebranchaddressincasetheinstructionisabranchRTL:

A=Reg[IR[25-21]];

B=Reg[IR[20-16]];

ALUOut=PC+(sign-ext(IR[15-0])<<2);

Wearen'tsettinganycontrollinesbasedontheinstructiontypeyet

(wearebusy"decoding"itincontrollogic)第13页/共79页ALUisperformingoneofthreefunctions,basedoninstructiontype:

MemoryReference:

ALUOut=A+sign-extend(IR[15-0]);

R-type:

ALUOut=AopB;

Branch:

if(A==B)PC=ALUOut;Step3:Execution第14页/共79页Loadsandstoresaccessmemory

MDR=Memory[ALUOut];

or

Memory[ALUOut]=B;

R-typeinstructionsfinish

Reg[IR[15-11]]=ALUOut;

Thewriteactuallytakesplaceattheendofthecycleontheedge

Step4:R-typeorMemory-access第15页/共79页Loadswritetoregister

Reg[IR[20-16]]=MDR;

Whataboutalltheotherinstructions?Step5:Write-back第16页/共79页SummaryoftheStepsFig.5.30第17页/共79页Cycle1ofaddIR=Memory[PC]; PC=PC+4;第18页/共79页Cycle2ofaddA=Reg[IR[25-21]];B=Reg[IR[20-16]];ALUOut=PC+(sign-ext(IR[15-0])<<2);第19页/共79页Cycle3ofaddALUOut=AopB;第20页/共79页Cycle4ofaddReg[IR[15-11]]=ALUOut;

第21页/共79页Howmanycycleswillittaketoexecutethiscode?

lw$t2,0($t3)

lw$t3,4($t3)

beq$t2,$t3,Label

add$t5,$t2,$t3

sw$t5,8($t3)

Label: ...

Whatisgoingonduringthe8thcycleofexecution?Inwhatcycledoestheactualadditionof$t2and$t3takesplace? SimpleQuestionassumenot第22页/共79页OutlineDesigningaprocessorBuildingthedatapathAsingle-cycleimplementationAmulticycleimplementationMulticycledatapathMulticycleexecutionstepsMulticyclecontrol(AppendixC.3)Microprogramming:simplifyingcontrol(AppendixC.4)Exceptions第23页/共79页ImplementingtheControlValueofcontrolsignalsisdependentupon:whatinstructionisbeingexecutedwhichstepisbeingperformedControlmustspecifyboththesignalstobesetinanystepandthenextstepinthesequenceControlspecificationUseafinitestatemachine(graphically)UsemicroprogrammingImplementationcanbederivedfromthespecificationandusegates,ROM,orPLA第24页/共79页Severalpossibleinitialrepresentations,sequencecontrolandlogicrepresentation,andcontrolimplementation=>allmaybedeterminedindep.

InitialRep.

FiniteStateDiagram Microprogram

Sequencing

ExplicitNextState Microprogram Control Function

Counter+ DispatchROMs

LogicRep.

LogicEquations TruthTables

Implementation PLA ROM

ControllerDesign:AnOverview“hardwiredcontrol”“microprogrammedcontrol”第25页/共79页Finitestatemachines:asetofstatesandnextstate(setbycurrentstateandinput)output(setbycurrentstateandpossiblyinput)

WewilluseaMooreMachine(outputbasedonlyonthecurrentstate)Review:FiniteStateMachines第26页/共79页ControlStateNextStateLogicOutputLogicinputs(conditions)outputs(controlpoints)StateXRegisterTransferControlPointsDependsonInputStatespecifiescontrolpointsforRTTransferatexitingstate(samefallingedge)OnestatetakesonecycleOurControlModel第27页/共79页SummaryoftheStepsFig.5.30第28页/共79页ControlSpecificationforMulticycleIR=MEM[PC]PC=PC+4A=R[rs]B=R[rt]S=PC+sx(Imm16)||00PC=IR...R-typeS=AopBR[rd]=SS=A+

sx(Imm16)R[rt]=MM=MEM[S]lw/swIfzeroPC=SjumpbeqInstructionfetchDecode/registerfetchExecuteMemoryaccessMemoryreadMEM[S]=Blwsw第29页/共79页OrganizationofMulticycleProcessorFig.5.28第30页/共79页ControlSignalsSignalname Effectwhendeasserted Effectwhenasserted

ALUSrcA 1stALUoperand=PC 1stALUoperand=Reg[rs]

RegWrite None Regfileiswritten

MemtoReg Reg.datainput=ALU Reg.writedatainput=MDRRegDst Reg.writedest.no.=rt Reg.writedest.no.=rd

MemRead None Memoryataddressisread

MemWrite None Memoryataddressiswritten

IorD Memoryaddress=PC Memoryaddress=ALUout

IRWrite None IR=Memory

PCWrite None PC=PCSource

PCWriteCond None IfzerothenPC=PCSourceSignalname Value Effect

ALUOp 00 ALUadds

01 ALUsubtracts

10 ALUoperatesaccordingtofunccode

ALUSrcB 00 2ndALUinput=B

01 2ndALUinput=4

10 2ndALUinput=signextendedIR[15-0]

11 2ndALUinput=signext.,shiftleft2IR[15-0]

PCSource 00 PC=ALU(PC+4)

01 PC=ALUout(branchtargetaddress)

10 PC=PC+4[31-28]:IR[25-0]<<2SingleBitControlMultipleBitControlFig.5.29第31页/共79页MappingRTtoControlSignalsInstructionfetchanddecodeportionofeveryinstructionisidentical:Fig.5.32A=R[rs]B=R[rt]S=PC+sx(Imm16)||00IR=MEM[PC]PC=PC+4第32页/共79页MappingRTtoControlSignalsFSMforcontrolling

memoryreference

instructions:Fig.5.33第33页/共79页CompleteFSMFig.5.38Statenumberassignment第34页/共79页

inputoutput

op S DatapathcontrolNS 0000000000 1001010000001000001 0000000001 0000000000110000110 0000000010 000000000010100xxxx 0000001010 0000001111 0000010000 0000100000 1001010000001000001 0000100001 0000000000110001001 0000000010 000000000010100xxxxTruthTable第35页/共79页FromFSMtoTruthTablePleasereferencethelogicequationsinFig.C.3.3andthetruthtableinFig.C.3.6Output EquationPCWrite state0+state9PCWriteCond state8IorD state3+state5… …NextState0 state4+state5+state7+state8 +state9NextState1 state0NextState2 state1((op=‘lw’)+(op=‘sw’))NextState3 state2(op=‘lw’)… ...Output Currentstates 0123456789PCWrite 1000000001PCWriteCond 0000000010IorD 0001010000… …第36页/共79页state6411nextstateopzerocontrolpointsstateopcondnextstatecontrolpointsTruthTabledatapathstateControlsignalsDesigningFSMController第37页/共79页TheControlUnitFig.C.3.2SequenceControl第38页/共79页PLAImplementationFig.C.3.9SequenceControl第39页/共79页NeedaROMof10-bitaddress,20-bitword(16-bitdatapathcontrol,4-bitnextstate)

Address ROMcontent

op S DatapathcontrolNS 0000000000 100101000000100 0000000001 000000000011000 0000000010 000000000010100 0000001010 0000001111 0000010000 0000100000 100101000000100 0000100001 000000000011000 0000000010 000000000010100ROMImplementationFig.C.12Lower4bitsofaddress

Bits19-4ofword 0000 1001010000001000 0001 0000000000011000 0010 0000000000101000 0011 0011000000000000 0100 0000001000000010 0101 0010100000000000 0110 0000000001000100 0111 0000000000000011 1000 0100000010100100 1001 10000001000000000001第40页/共79页

Address ROMcontent

op S DatapathcontrolNS 0000000000 1001010000001000001 0000000001 0000000000110000110 0000000010 000000000010100xxxx 0000001010 0000001111 0000010000 0000100000 1001010000001000001 0000100001 0000000000110001001 0000000010 000000000010100xxxxROMImplementation(TruthTable)Ratherwasteful,sinceforlotsofentries,outputsaresameoraredon’t-careCouldbreakupintotwosmallerROMs(Fig.C.3.7,C.3.8)第41页/共79页ROMvsPLAROM:usetwosmallerROMs(Fig.C.3.7,C.3.8)4statebitsgivethe16outputs,24x16bitsofROM10bits(op+state)give4nextstatebits,210x4bitsofROMTotal=4.3KbitsofROM(comparedto210x20bitsofsingleROMimplementation)PLAismuchsmallercanshareproducttermsonlyneedentriesthatproduceanactiveoutputcantakeintoaccountdon't-caresSizeis(#inputs#product-terms)+(#outputs#product-terms)

Forthisexample=(10x17)+(20x17)=460PLAcellsPLAcellsusuallyaboutthesizeofaROMcell(slightlybigger)第42页/共79页CompleteFSMFig.5.38Statenumberassignment第43页/共79页UseCounterforSequenceControlFig.C.4.1NoNext-StateLines第44页/共79页AddressSelectUnitAddrCtlValue:0 Setstateto01 DispatchROM12 DispatchROM23 Useincremented

stateFig.C.4.2第45页/共79页ControlContentsFig.C.4.3,C.4.4第46页/共79页OutlineDesigningaprocessorBuildingthedatapathAsingle-cycleimplementationAmulticycleimplementationMulticycledatapathMulticycleexecutionstepsMulticyclecontrolMicroprogramming:simplifyingcontrol(AppendixC.4)Exceptions第47页/共79页Severalpossibleinitialrepresentations,sequencecontrolandlogicrepresentation,andcontrolimplementation=>allmaybedeterminedindep.

InitialRep.

FiniteStateDiagram Microprogram

Sequencing

ExplicitNextState Microprogram Control Function

Counter+ DispatchROMs

LogicRep.

LogicEquations TruthTables

Implementation PLA ROM

ControllerDesign:AnOverview“hardwiredcontrol”“microprogrammedcontrol”第48页/共79页ControlisthehardpartofprocessordesignDatapathisfairlyregularandwell-organizedMemoryishighlyregularControlisirregularandglobalBut,thestatediagramsthatdefinethecontrollerforaninstructionsetprocessorarehighlystructuredUsethisstructureto

constructasimple

“microsequencer”Controlreducesto

programmingthis

simpledevice=>microprogrammingsequencercontroldatapathcontrolmicro-PCsequencermicroinstructionMicroprogram

…..controlsignals第49页/共79页MicroinstructionControlsignals:ThinkofthesetofcontrolsignalsthatmustbeassertedinastateasaninstructionExecutingamicroinstructionhastheeffectofassertingthecontrolsignalspecifiedbythemicroinstructionSequencingWhatmicroinstructionshouldbeexecutednext?Executesequentially(nextstateunconditionally)Branch(nextstatealsodependsoninputs)Amicroprogramisasequenceofmicroinstructionsexecutingaprogramflowchart(finitestatemachine)第50页/共79页1)Startwithalistofcontrolsignals2)Groupsignalstogetherthatmakesense(vs.random):calledfields3)Placesfieldsinsomelogicalorder

(e.g.,ALUoperation&ALUoperandsfirstandmicroinstructionsequencinglast)4)Createasymboliclegendforthemicroinstructionformat,showingnameoffieldvaluesandhowtheysetcontrolsignalsUsecomputerstodesigncomputers5)Tominimizethewidth,encodeoperationsthatwillneverbeusedatthesametimeDesigningaMicroinstructionSet第51页/共79页1-3)ControlSignalsandFieldsSignalname Effectwhendeasserted Effectwhenasserted

ALUSrcA 1stALUoperand=PC 1stALUoperand=Reg[rs]

RegWrite None Regfileiswritten

MemtoReg Reg.writedatainput=ALU Reg.writedatainput=MDRRegDst Reg.writedest.no.=rt Reg.writedest.no.=rd

MemRead None Memoryataddressisread

MemWrite None Memoryataddressiswritten

IorD Memoryaddress=PC Memoryaddress=ALUout

IRWrite None IR=Memory

PCWrite None PC=PCSource

PCWriteCondNone IfzerothenPC=PCSourceSingleBitControlSignalname Value Effect

ALUOp 00 ALUadds

01 ALUsubtracts

10 ALUoperatesaccordingtofunccode

ALUSrcB 00 2ndALUinput=B

01 2ndALUinput=4

10 2ndALUinput=signextendedIR[15-0]

11 2ndALUinput=signextended,shiftleft2IR[15-0]

PCSource 00 PC=ALU(PC+4)

01 PC=ALUout(branchtargetaddress)

10 PC=PC+4[31-28]:IR[25-0]<<2MultipleBitControl第52页/共79页4)FieldsandLegendFieldName ValuesforField FunctionofFieldwithSpecificValue

ALUcontrol Add ALUadds

Subt. ALUsubtracts

Funccode ALUdoesfunctioncode

SRC1 PC 1stALUinput=PC

A 1stALUinput=A(Reg[rs])

SRC2 B 2ndALUinput=B(Reg[rt])

4 2ndALUinput=4

Extend 2ndALUinput=signext.IR[15-0]

Extshft 2ndALUinput=signex.,slIR[15-0]

Registercontrol Read A=Reg[rs];B=Reg[rt]; WriteALU Reg[rd]=ALUout WriteMDR Reg[rt]=MDRMemory ReadPC IR(MDR)=mem[PC]

ReadALU MDR=mem[ALUout]

WriteALU mem[ALUout]=B

PCwrite ALU PC=ALUoutput

ALUout-cond. IFALUzerothenPC=ALUout

jumpaddr. PC=PCSource

Sequencing Seq Gotosequentialmicroinstruction

Fetch Gotothefirstmicroinstruction

Dispatch1 DispatchusingROM1 Dispatch2 DispatchusingROM2第53页/共79页ControlSignals第54页/共79页TheMicroprogram第55页/共79页TheControllerFig.C.4.6第56页/共79页TheDispatchROMsFig.C.5.2Rformat1JUMP1BEQ1Mem1Mem1LW2SW2第57页/共79页OurPlan:UsingROMm-instructionROMmPC第58页/共79页MainMemoryexecutionunitcontrolmemoryCPUADDSUBANDDATA...UserprogramplusDatathiscanchange!ANDmicrosequencee.g.,FetchCalcOperandAddrFetchOperand(s)CalculateSaveAnswer(s)oneoftheseismappedintooneoftheseMicroinstructionInterpretation第59页/共79页MicroprogrammingUsingROM:ProsandConsEaseofdesignFlexibilityEachtoadapttochangesinorganization,timing,technologyCanmakechangeslateindesigncycle,oreveninthefieldGeneralityImplementmultipleinst.setsonsamemachineCantailorinstructionsettoapplicationCanimplementverypowerfulinstructionsets(justmorecontrolmemory)CompatibilityManyorganizations,sameinstructionsetCostlytoimplementandSlow第60页/共79页5)MicroinstructionEncodingFig.C.4.5Bits7-13canbeencodedto3bitsbecausethereareonly7patternsofthecontrolword第61页/共79页Minimalvs.MaximalEncodingMinimal(Horizontal):+morecontroloverthepotentialparallelismofoperationsinthedatapath-usesuplotsofcontrolstoreMaximal(Vertical):+useslessnumberofcontrolstore-extralevelofdecodingmayslowthemachinedown第62页/共79页ControlisspecifiedbyafinitestatediagramSpecializedstate-diagramseasilycapturedbymicrosequencersimpleincrementand“branch”fieldsdatapathcontrolfieldsControlcanalsobespecifiedbymicroprogrammingControlismorecomplicatedwith:complexinstructionsetsrestricteddatapathsSimpleinstructionsetandpowerfuldatapath=>simplecontrolcouldreducehardwareOrgoforspeed=>manyinstructionsatonce!SummaryofControl第63页/共79页OutlineDesigningaprocessorBuildingthedatapathAsingle-cycleimplementationAmulticycleimplementationMulticycledatapathMulticycleexecutionstepsMulticyclecontrolMicroprogramming:simplifyingcontrolExceptions第64页/共79页ExceptionsUserProgramSystemExceptionHandlerExceptionreturnfromexceptionNormalcontrolflow:sequential,jumps,branches,calls,returnsException=unprogrammedcontroltransfersystemtakesactiontohandletheexceptionmustrecordaddressoftheoffendinginstructionshouldknowcauseandtransfertoproperhandlerifreturnstouser,mustsave&restoreuserstate第65页/共79页Byprovidingtwomodesofexecution(user/system),computermaymanageitselfOSisaspecialprogramthatrunsintheprivilegedsystemmodeandhasaccesstoalloftheresourcesofthecomputerPresents“virtualresources”toeachuserthataremoreconvenientthanthephysicalresourcesfilesvs.disksectorsvirtualmemoryvs.physicalmemoryprotectseachuserprogramfromothersExceptionsallowthesystemtotakeactioninresponsetoeventsthatoccurwhileuserprogramisexecutingOSbeginsatthehandlerUser/SystemModes第66页/共79页TwoTypesofExceptionsInterrupts:causedbyexternaleventsandasynchronoustoexecution

=>maybehandledbetweeninstructionssimplysuspendandresumeuserprogramExceptions:causedbyinternaleventsandsynchronoustoexecution,e.g.,

exceptionalconditions(overflow),errors(parity),faultsinstructionmayberetriedorsimulatedandprogramcontinuedorprogrammaybeaborted第67页/共79页MIPSConventionofExceptionsMIPSconvention:exceptionmeansanyunexpectedchangeincontrolflow,withoutdistinguishinginternalorexternaluseinterruptonlywhentheeventisexternallycausedTypeofevent Fromwhere? MIPSterminology

I/Odevicerequest External Interrupt

InvokeOSfromuserprogram Internal Exception

Hardwaremalfunctions Either Exceptionor

Interrupt

Arithmeticoverflow Internal Exception

Usinganundefinedinst. Internal Exception第68页/共79页PreciseInterruptsPrecise:machinestateispreservedasifprogramexecuteduptotheoffendinginst.SamesystemcodewillworkondifferentimplementationsofthearchitecturePositionclearlyestablishedbyIBM,andtakenbyMIPSDifficultinthepresenceofpipelining,out-ot-orderexecution,...Imprecise:systemsoftwarehastofigureoutwhatiswhereandputitallbacktogetherPerformancegoalsoftenleaddesignerstoforsakepreciseinterruptssystemsoftwaredevelopers,user,marketsetc.,usuallywishtheyhadnotdonethis第69页/共79页HandlingExceptionsinOurDesignConsidertwotypesofexceptions:

undefinedinstruction&arithmeticoverflowBasicactionsonexception:Savestate:savetheaddressoftheoffendinginstructionintheexceptionprogramcounter(EPC)TransfercontroltoOSatsomespecifiedaddress

=>needtoknowthecausefortheexception

=>thenknowtheaddressofexceptionhandlerAfterservice,OScanterminatetheprogramorcontinueitsexecution,usingEPCtoreturn第70页/共79页PushitontothestackVax,68k,80x86SaveitinspecialregistersMIPSEPC,BadVaddr,Status,CauseShadowRegistersM88kSavestateinashadowoftheinternalpipelineregistersSavingState:GeneralApproaches第71页/共79页iv_basecausehandlercodeiv_basecausehandlerentrycodeTraditionalapproach:interruptvectorThecauseofexceptionisavector

givingth

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论