您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > Computer Organization and Design PPT3
COMPUTERORGANIZATIONANDDESIGNTheHardware/SoftwareInterface5thEditionChapter3ArithmeticforComputersChapter3—ArithmeticforComputers—2ArithmeticforComputersOperationsonintegersAdditionandsubtractionMultiplicationanddivisionDealingwithoverflowFloating-pointrealnumbersRepresentationandoperations§3.1IntroductionChapter3—ArithmeticforComputers—3IntegerAdditionExample:7+6§3.2AdditionandSubtractionOverflowifresultoutofrangeAdding+veand–veoperands,nooverflowAddingtwo+veoperandsOverflowifresultsignis1Addingtwo–veoperandsOverflowifresultsignis0Chapter3—ArithmeticforComputers—4IntegerSubtractionAddnegationofsecondoperandExample:7–6=7+(–6)+7:00000000…00000111–6:11111111…11111010+1:00000000…00000001OverflowifresultoutofrangeSubtractingtwo+veortwo–veoperands,nooverflowSubtracting+vefrom–veoperandOverflowifresultsignis0Subtracting–vefrom+veoperandOverflowifresultsignis1Chapter3—ArithmeticforComputers—5DealingwithOverflowSomelanguages(e.g.,C)ignoreoverflowUseMIPSaddu,addui,subuinstructionsOtherlanguages(e.g.,Ada,Fortran)requireraisinganexceptionUseMIPSadd,addi,subinstructionsOnoverflow,invokeexceptionhandlerSavePCinexceptionprogramcounter(EPC)registerJumptopredefinedhandleraddressmfc0(movefromcoprocessorreg)instructioncanretrieveEPCvalue,toreturnaftercorrectiveactionChapter3—ArithmeticforComputers—6ArithmeticforMultimediaGraphicsandmediaprocessingoperatesonvectorsof8-bitand16-bitdataUse64-bitadder,withpartitionedcarrychainOperateon8×8-bit,4×16-bit,or2×32-bitvectorsSIMD(single-instruction,multiple-data)SaturatingoperationsOnoverflow,resultislargestrepresentablevaluec.f.2s-complementmoduloarithmeticE.g.,clippinginaudio,saturationinvideoChapter3—ArithmeticforComputers—7MultiplicationStartwithlong-multiplicationapproach1000×100110000000000010001001000Lengthofproductisthesumofoperandlengthsmultiplicandmultiplierproduct§3.3MultiplicationChapter3—ArithmeticforComputers—8MultiplicationHardwareInitially0Chapter3—ArithmeticforComputers—9OptimizedMultiplierPerformstepsinparallel:add/shiftOnecycleperpartial-productadditionThat’sok,iffrequencyofmultiplicationsislowChapter3—ArithmeticforComputers—10FasterMultiplierUsesmultipleaddersCost/performancetradeoffCanbepipelinedSeveralmultiplicationperformedinparallelChapter3—ArithmeticforComputers—11MIPSMultiplicationTwo32-bitregistersforproductHI:most-significant32bitsLO:least-significant32-bitsInstructionsmultrs,rt/multurs,rt64-bitproductinHI/LOmfhird/mflordMovefromHI/LOtordCantestHIvaluetoseeifproductoverflows32bitsmulrd,rs,rtLeast-significant32bitsofproduct–rdChapter3—ArithmeticforComputers—12DivisionCheckfor0divisorLongdivisionapproachIfdivisor≤dividendbits1bitinquotient,subtractOtherwise0bitinquotient,bringdownnextdividendbitRestoringdivisionDothesubtract,andifremaindergoes0,adddivisorbackSigneddivisionDivideusingabsolutevaluesAdjustsignofquotientandremainderasrequired100110001001010-1000101011010-100010n-bitoperandsyieldn-bitquotientandremainderquotientdividendremainderdivisor§3.4DivisionChapter3—ArithmeticforComputers—13DivisionHardwareInitiallydividendInitiallydivisorinlefthalfChapter3—ArithmeticforComputers—14OptimizedDividerOnecycleperpartial-remaindersubtractionLooksalotlikeamultiplier!SamehardwarecanbeusedforbothChapter3—ArithmeticforComputers—15FasterDivisionCan’tuseparallelhardwareasinmultiplierSubtractionisconditionalonsignofremainderFasterdividers(e.g.SRTdevision)generatemultiplequotientbitsperstepStillrequiremultiplestepsChapter3—ArithmeticforComputers—16MIPSDivisionUseHI/LOregistersforresultHI:32-bitremainderLO:32-bitquotientInstructionsdivrs,rt/divurs,rtNooverflowordivide-by-0checkingSoftwaremustperformchecksifrequiredUsemfhi,mflotoaccessresultChapter3—ArithmeticforComputers—17FloatingPointRepresentationfornon-integralnumbersIncludingverysmallandverylargenumbersLikescientificnotation–2.34×1056+0.002×10–4+987.02×109Inbinary±1.xxxxxxx2×2yyyyTypesfloatanddoubleinCnormalizednotnormalized§3.5FloatingPointChapter3—ArithmeticforComputers—18FloatingPointStandardDefinedbyIEEEStd754-1985DevelopedinresponsetodivergenceofrepresentationsPortabilityissuesforscientificcodeNowalmostuniversallyadoptedTworepresentationsSingleprecision(32-bit)Doubleprecision(64-bit)Chapter3—ArithmeticforComputers—19IEEEFloating-PointFormatS:signbit(0non-negative,1negative)Normalizesignificand:1.0≤|significand|2.0Alwayshasaleadingpre-binary-point1bit,sononeedtorepresentitexplicitly(hiddenbit)SignificandisFractionwiththe“1.”restoredExponent:excessrepresentation:actualexponent+BiasEnsuresexponentisunsignedSingle:Bias=127;Double:Bias=1203SExponentFractionsingle:8bitsdouble:11bitssingle:23bitsdouble:52bitsBias)(ExponentS2Fraction)(11)(xChapter3—ArithmeticforComputers—20Single-PrecisionRangeExponents00000000and11111111reservedSmallestvalueExponent:00000001actualexponent=1–127=–126Fraction:000…00significand=1.0±1.0×2–126≈±1.2×10–38Largestvalueexponent:11111110actualexponent=254–127=+127Fraction
本文标题:Computer Organization and Design PPT3
链接地址:https://www.777doc.com/doc-6439415 .html