復(fù)旦信息科學(xué)與工程學(xué)院考試試題csapp exama_第1頁
復(fù)旦信息科學(xué)與工程學(xué)院考試試題csapp exama_第2頁
復(fù)旦信息科學(xué)與工程學(xué)院考試試題csapp exama_第3頁
復(fù)旦信息科學(xué)與工程學(xué)院考試試題csapp exama_第4頁
復(fù)旦信息科學(xué)與工程學(xué)院考試試題csapp exama_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

Problem1.(15ConsiderthefollowingassemblycodeforaCforProblem1.(15ConsiderthefollowingassemblycodeforaCforjleBasedontheassemblyabove,fillinthebelowincorrespondingCsourcecode.(Note:youmayonlyusethesymbolicx,y,andresultinyourexpressionsbelow—donotuseregisterintloop(intx,int{for ; ;result++) } return}第2Problem2.(12ConsiderthefollowingincompletedefinitionofaCstructalongwithincompletecodeforafunctionProblem2.(12ConsiderthefollowingincompletedefinitionofaCstructalongwithincompletecodeforafunctionfuncgivenstructnode structnode*next;structnode*prev;}node_tn;node_tm= m->y/=16;}WhenthisCcodewascompiledonanIA-32machinerunningLinux,)followingassemblycodewasgeneratedforfunctionGiventhesecodefragments,fillintheblanksintheCcodegivenNotethatthereisauniqueanswer.Thetypesmustbechosenfromfollowingtable,assumingthesizesandalignment第3122448122448Problem3.(15ThefollowingproblemconcernsoptimizingaprocedureforperformanceProblem3.(15ThefollowingproblemconcernsoptimizingaprocedureforperformanceonanIntelPentiumIII.RecallthecharacteristicsofthefunctionalunitsforthisConsiderthefollowingtwoLoopintloop1(int*a,intx,int{inty=x*x;inti;for(i=0;i<n;i++)x=y*a[i];return}Loopintloop2(int*a,intx,int{inty=x*x;inti;for(i=0;i<n;i++)x=x*a[i];return}WhencompiledwithGCC,weobtainthefollowingassemblycodeforinnerLoopLoopononeofFishmachines,findthatLoop1requiresclockcyclesperiteration,whileLoop2requires第4LatencyIssueIntegerAddIntegerMultiplyIntegerDivideFloatingPointMultiplyFloatingPointDivideLoadorStore(CacheHit)1435111121A.ExplainhowitisthatLoopA.ExplainhowitisthatLoop1isfasterthanLoop2,eventhoughitonemoreB.Byusingthecompilerflag-funroll-loops,wecancompilethecodeuse4-wayloopunrolling.ThisspeedsupLoop1.Explain)C.Evenwithloopunrolling,wefindtheperformanceofLoop2thesame.ExplainProblem4.(24Thisproblemtestsyourunderstandingofcacheconflictmisses.thefollowingmatrixtransposeintarray[2][2];transpose(arraydst,arraysrc){i,for(i=0;i<2;i++){for(j=0;j<2;j++){dst[j][i]第5}}}runningonahypotheticalmachinewiththefollowing·sizeof(int)==·Thesrcarraystartsataddress0andthedstarraystartsataddress·There}}}runningonahypotheticalmachinewiththefollowing·sizeof(int)==·Thesrcarraystartsataddress0andthedstarraystartsataddress·ThereisasingleL1cachethatisdirectmappedandwrite-allocate,withblocksizeof8·Accessestothesrcanddstarraysaretheonlysourcesofreadandmisses,A.Supposethecachehasatotalsizeof16databytes(i.e.,theblocktimesthenumberofsetsis16bytes)andthatthecacheisinitiallyThenforeachrowandcol,indicatewhethereachaccesstosrc[row][col]dst[row][col]isahit(h)oramiss(m).Forexample,readingsrc[0][0]ismissandwritingdst[0][0]isalsoaB.RepeatpartAforacachewithatotalsizeof32data第6srcColColRowmRowdstColColRowmRowsrcColColRowmRowdstColColRowmRowProblem5.(24ThisproblemtestsyourProblem5.(24Thisproblemtestsyourunderstandingofexceptionalcontrolflowinprograms.AssumewearerunningcodeonaUnixproblemsallconcernthevalueofthevariablePartI(9intmain(){intfor(i=0;i<2;counterprintf("counter=%d\n",}printf("counter=%d\n",counter);return0;}A.Howmanytimeswouldthevalueofcounterbeprinted? )B.Whatisthevalueofcounterprintedinthefirstline? C.Whatisthevalueofcounterprintedinthelastline? PartII(9pid_tintcounter=voidhandler1(int{counterprintf("counter=%d\n",fflush(stdout);/*Flushestheprintedstringtostdout*/kill(pid,SIGUSR1);}第7voidhandler2(intvoidhandler2(int{counter+=printf("counter=%d\n",counter);}voidmain()if((pid=fork())==0){kill(getppid(),SIGUSR1);while(1){};}elsepid_tp;intif((p=wait(&status))>{counter+=printf("counter=%d\n",}}}WhatistheoutputofthisPartIII(6intcounter=0;{counter}int{intfor(i=0;i<5;i++){if(fork()0){}}/*waitforallchildrentodie第8while(wait(NULL)!=-1);return0;}A.Doestheprogramoutputthesamewhile(wait(NULL)!=-1);return0;}A.Doestheprogramoutputthesamevalueofcountereverytimewe B.IftheanswertoAisYes,indicatethevalueofthecounterOtherwise,listallpossiblevaluesofthecounterAnswer:counter= )Problem6.(22Thefollowingproblemconcernsthewayvirtualaddressesareintophysical·Thememoryisbyte·Memoryaccessesareto1-bytewords(not4-byte·Virtualaddressesare16bits·Physicaladdressesare13bits·Thepagesizeis512·TheTLBis8-waysetassociativewith16total·Thecacheis2-waysetassociative,witha4bytelinesizeand16totalInthefollowingtables,allnumbersaregiveninhexadecimal.contentsoftheTLB,thepagetableforthefirst32pages,andthecacheare第9PartI(9A.Thebelowshowstheformatofavirtualaddress.Indicatelabelingthediagram)PartI(9A.Thebelowshowstheformatofavirtualaddress.Indicatelabelingthediagram)thefields(iftheyexist)thatwouldbeusedtothefollowing:(Ifafielddoesn’texist,don’tdrawitontheThevirtualpageThevirtualpage第102-waySetAssociativeTag Tag 01234567 99112355590B0103058406B2436D8F09A1B2C4DEBB77330000C00FPage 0 1 TheTLB TheTLB 987654 10B.Theboxbelowshowstheformatofaphysicaladdress.labelingthediagram)thefieldsthatwouldusedThephysical TheTLB TheTLB 987654 10B.Theboxbelowshowstheformatofaphysicaladdress.labelingthediagram)thefieldsthatwouldusedThephysicalpage)ThephysicalpageTheblockoffsetwithinthecacheThecacheThecache 10PartII(13Forthegivenvirtualaddress,indicatetheTLBphysicaladdress,andthecachebytevaluereturnedinhex.IndicatetheTLBmisses,whetherapagefaultoccurs,andwhetheracachemissIfthereisacachemiss,enter“-”for“CacheBytereturned”.Ifthereisafault,enter“-”for“P

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論