深入理解計(jì)算機(jī)系統(tǒng)第二版家庭作業(yè)答案_第1頁(yè)
深入理解計(jì)算機(jī)系統(tǒng)第二版家庭作業(yè)答案_第2頁(yè)
深入理解計(jì)算機(jī)系統(tǒng)第二版家庭作業(yè)答案_第3頁(yè)
深入理解計(jì)算機(jī)系統(tǒng)第二版家庭作業(yè)答案_第4頁(yè)
深入理解計(jì)算機(jī)系統(tǒng)第二版家庭作業(yè)答案_第5頁(yè)
已閱讀5頁(yè),還剩82頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

深入理解計(jì)算機(jī)系統(tǒng)第二版家庭作業(yè)答案深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第二章略}unsignedreplace_byte(unsignedx,unsignedcharb,inti){return(x&~(0xFF<<(i<<3)))|(b}intint_shifts_are_arithmetic(){}?intxsrl=(unsigned)x>>k;unsignedright=mask&xsrl;unsignedleft=~mask&(~(z&xsrl)+z);}}}}}}unsignedrotate_right(unsignedx,intn){}}}intsaturating_add(intx,inty){intnovf=~(pos_ovf|neg_ovf);return(pos_ovf&INT_MAX)|(novf&ans)|(neg_ovf&INT_MIN);}}unsignedunsigned_high_prod(unsignedx,unsignedy){returnsigned_high_prod(x,y)+(x>>(w-1))*y+x*(y>>(w-1));}intuadd_ok(unsignedx,unsignedy){returnx+y>=x;}voidsigned_prod_result(intx,inty,int&h,int&l){intw=sizeof(int)<<3;h=0;l=(y&1)x:0;}}h=h+((x>>(w-1))*y)+((y>>(w-1}intdivide_power2(intx,inintw=sizeof(int)<<3;} ?intb0=x&1,b2=(x>>2)&1;}最小的正非規(guī)格化數(shù)最小的正規(guī)格化數(shù)最大的規(guī)格化數(shù)擴(kuò)展精度值2^(-63)*2^(-2^14+2)2^(-2^14+2)(2^64-1)*2^(2^14-1-63)十進(jìn)制+4932HexMEV0x80000-62最小的值>10x3F01257/2560257*2^(-8)0x470018 最大的非規(guī)格化數(shù)0x00FF255/256-62255*2^(-70)-inf0xFF00 Hex為0x3AA00x3AA0416/256416*2^(-13)=13*2^(-8)格式格式B值00100111000000000000值-9/16-7/10240-inf-9/16-7/10246/2^17-4096位011100011100000011000000000000000格式A位floatfpwr2(intx){unsignedexp,frac;unsignedu;exp=0;frac=0;exp=0;frac=0;}}}unsignedf2u(floatf){}boolis_float_equal(float_bitsf1,floatf2){returnf2u(f2)==f1;}unsignedexp=(fb>>23)&0}boolis_inf(float_bitsfb){unsignedexp=(fb>>23)&0xFF;returnexp==0xFF&&frac==0;}inttestFun(float_bits(*fun1)(float_bits),float(*fun2)(float)){unsignedx=0;深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第三章{yx返回地址&s2(word_sum的返回值地址)傳遞結(jié)構(gòu)體參數(shù)就像正常的傳值。結(jié)構(gòu)體的每一個(gè)變量可以看做是單獨(dú)的參數(shù)進(jìn)行傳返回結(jié)構(gòu)體的通用策略:將返回變量的地址看做voidproc(unionele*up){up->>=*(up->>-up->;}voidgood_echo(){intx=0;while(x=getchar(),x!='\n'&&x!=EOF){putchar(x);}}voidgood_echo(){constintBufferSize=10;while(fgets(s,BufferSize,stdin)!=NULL){putchar(s[i]);}return;}{longret=0;while(tp!=NULL){}}{{v=min(traverse(tp->left),traverse(tp->right));深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第五章D.因?yàn)槌朔ú辉陉P(guān)鍵路徑上,乘法也是流水線執(zhí)行的,其限制因素為吞吐量界限。整把執(zhí)行指令寫出了就明了了。浮點(diǎn)數(shù)的話,延遲是沒(méi)問(wèn)題。時(shí)間xmm1_add單xmm1mul單元發(fā)射load單元發(fā)rdx_add單rdx的56789整數(shù)mul延遲為3mul0mul0muladdedmul整數(shù)加法延遲為1addedvoidinner4(vec_ptru,vec_ptrv,data_t*dest){data_t*udata=get_vec_start(udata_t*vdata=get_vec_start(vdata_tsum=(data_t)0;for(i=0;i<limit;i++){}?}儲(chǔ)udata[i],vdata[i]的寄存器,voidinner4(vec_ptru,vec_ptrv,data_t*dest){data_t*udata=get_vec_start(udata_t*vdata=get_vec_start(vdata_tsum=(data_t)0;for(i=0;i<limit;i++){intx1=udata[i]*vdata[i];}}void*optimized_memset(void*s,intc,size_tn){unsignedintK=sizeof(unsignedlong);unsignedchar*schar=(unsignedchar*)s;unsignedlong*lchar;unsignedlongfill=0;mCBESts1447241038184821516644mCBEStsb1819219424096448234096487244450x0120-0x0123-0x08A4-0x08A70x0704-0x0707 -0x064C-0x064F0x18F0-0x18F30x00B0-0x00B30x0E34-0x0E37 0x1238-0x123B -0x1BDC-0x1BDF操作讀寫讀地址0x4090x40A0x833命中NoYesYes讀出的值--塊偏移CO0x00命中Yes返回值0xFA塊偏移CO0x00命中No返回值-mhmhmmhmmhmhmmhmmmmmmmmmmmmmmmmmmhhhmhhhmhhhmhhhmhhhmhhhmhhhmhhh函數(shù)N=64N=60unsignedcalc_address(unsignedhead,inti,intj,i{}unsignedcalc_line(unsignedadd,intblock_size,constintline){return(add/block_size)%lin}intisHit(unsignedcache[],unsignedr,unsigneda,intblock_{a=a/block_size*block_size;unsignedtmp=cache[r];}voidtestA(intblock_size,constintline,unsignedadd,constint{unsignedcache[line];memset(cache,-1,sizeof(cachinthit=0,miss=0;for(inti=0;i<N;++i)for(intj=0;j<N;++j){unsignedaddress=calc_address(add,i,j,N);unsignedr=calc_line(address,block_size,lhit+=isHit(cache,r,address,block_size);}miss=N*N-hit;cout<<"sumA"<<hit<<""cout<<(double)miss/}voidtestB(intblock_size,constintline,unsignedadd,constint{unsignedcache[line];memset(cache,-1,sizeof(cachinthit=0,miss=0;for(intj=0;j<N;++j)for(inti=0;i<N;++i){unsignedaddress=calc_address(add,i,j,N);unsignedr=calc_line(address,block_size,line);hit+=isHit(cache,r,address,block_size);}miss=N*N-hit;cout<<"sumB"<<hit<<""cout<<(double)miss/}voidtestC(intblock_size,constintline,unsignedadd,constint{unsignedcache[line];memset(cache,-1,sizeof(cachinthit=0,miss=0;{N=60;a=calc_address(add,i,j,N);r=calc_line(a,block_size,line);hit+=isHit(cache,r,a,block_size);a=calc_address(add,i+1,j,Nr=calc_line(a,block_size,line);hit+=isHit(cache,r,a,block_size);a=calc_address(addr=calc_line(a,block_size,line);hit+=isHit(cache,r,a,block_size);a=calc_address(add,ir=calc_line(a,block_size,line);hit+=isHit(cache,r,a,block_size);}miss=N*N-hit;cout<<"sumC"<<hit<<""cout<<(double)miss/}{constunsignedstart_addressintline=cache_size/block_size;testA(block_size,line,start_address,N);testB(block_size,line,start_address,N);testC(block_size,line,start_address,N);testA(block_size,line,start_address,N);testB(block_size,line,start_address,N);testC(block_size,line,start_address,N);}dst[(j+1)*dim+i]=src[i*dim+j+1];如果加入運(yùn)算,就可以想辦法同時(shí)更新d深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第七章符號(hào)條目符號(hào)類型定義符號(hào)的模塊所屬的節(jié)bufYesexternbufp0Yesglobalbufp1YesYesglobalNo YescountYes運(yùn)行時(shí)存儲(chǔ)器地址值0x080483CB0x0804945C16(buf[1])0x080483D00x080494580x080483D80x0804954818(buf[1])0x080483DC0x0804945823(bufp1)0x080483E70x08049548節(jié)偏移重定位類型符號(hào)名字0x12相對(duì)0x19絕對(duì)0x21相對(duì)節(jié)偏移0x04節(jié)偏移0x04符號(hào)名字x絕對(duì)),行號(hào)節(jié)偏移重定位類型符號(hào)名字行號(hào)節(jié)偏移重定位類型符號(hào)名字.rodata10x0,0x4,0x8,0xc,0x10,0x14絕對(duì)深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第八章進(jìn)程對(duì)ABACADBC是否并發(fā)NoYesYesYesBCYesBCYesHelloHello01Bye2ByeHello1Bye02ByeHello10Bye2Byeintmain(intargc,char*args[{VPN0x09TLB標(biāo)記0x02TLB命中No缺頁(yè)NoPPN0x17參數(shù)值字節(jié)偏移0x0緩存索引0xF緩存標(biāo)記0x17緩存命中No返回緩存字節(jié)-VPN0x0ETLB索引0x02TLB標(biāo)記0x03TLB命中No缺頁(yè)NoPPN0x11字節(jié)偏移字節(jié)偏移緩存索引緩存標(biāo)記緩存命中No-返回緩存字節(jié)-VPN0x01TLB索引0x01TLB標(biāo)記0x00TLB命中No缺頁(yè)YesPPN-#include<sys/>#include<sys/>#include<>#include<>#include<sys/>{9.char*start;fdfd=open("",O_RDWR,0);),結(jié)尾塊向后延伸申請(qǐng)的空間,并將剛多出的空間作為一個(gè)空閑塊。設(shè)我們基于以下假設(shè):某個(gè)空閑塊匹配,上一個(gè)和下一個(gè)一定不是空閑塊(否則可以合如果要分割,則下一塊的頭部設(shè)置為(size-asize|0x010),不用合并,因?yàn)樵傧乱蛔詈?,如果下一塊已分配,則需要將下一塊頭部2.#include<>4.#defineMAX_HEAP(1<<24)5./*Privateglobalvariables*/6.staticchar*mem_heap;/*Pointstofirstbyteofheap*/7.staticchar*mem_brk;/*Pointstolastbyteofheapplus1*/8.staticchar*mem_max_addr;/*Maxlegalheapaddrplus1*/10.*mem_init-Initializethememorysystemmodel12.voidmem_init(voi14.mem_heap=(char*)malloc(MAX_HEAP);16.mem_max_addr=(char*)(mem_heap+MAX_HEAP);19.*mem_sbrk-Simplemodelofthesbrkfunction.Extendstheheap20.*byincrbytesandreturnsthestartaddressofthenewarea.In21.*thismodel,theheapcannotbeshrunk.23.void*mem_sbrk(intinc25.char*old_brk=mem_brk;26.if((incr<0)||((mem_brk+incr)>mem_max_addr)){27.errno=ENOMEM;28.fprintf(stderr,"ERROR:mem_sbrkfailed.Ranoutofmemory...\n");29.return(void*)-1;31.mem_brk+=incr;32.return(void*)old_brk;34.voidmem_end(void)/*addedbyzhanyu*/36.free(mem_heap);2./*Basicconstantsandmacros*/3.#defineWSIZE4/*Wordandheader/footersize(bytes)*/4.#defineDSIZE8/*Doublewordsize(bytes)*/5.#defineCHUNKSIZE(1<<12)/*Extendheapbythisamount(bytes)*/6.#defineMAX(x,y)((x)>(y)(x):(y))7./*Packasizeandallocatedbitintoaword*/9.if(size<=DSIZE)asize=DSIZE;10.elseasize=DSIZE*((size+(WSIZE)+(DSIZE-1))/DSIZE);11./*Searchthefreelistforafit*/12.if((bp=find_fit(asize))!=NULL){16./*Nofitfound.Getmorememoryandplacetheblock*/17.extendsize=MAX(asize,CHUNKSIZE);18.if((bp=extend_heap(extendsize/WSIZE))==NULL)returnNULL;22.staticvoidplace(void*bp,siz24.size_tcsize=GET_SIZE25.size_tnsize=GET_SIZE(HDRP(NEXT_BLKP(bp)));26.intprev_alloc=GET_PREVALLOC(HDRP(bp));27.intnext_alloc=GET_ALLOC(HDRP(NEXT_BLKP(bp)));28.if((csize-asize)>=(2*DSIZE)){29.PUT(HDRP(bp),PACK(asize,prev_alloc,1));30.PUT(FTRP(bp),PACK(asize,prev_alloc,1));31.bp=NEXT_BLKP(bp);32.PUT(HDRP(bp),PACK(csize-asize,1,0));33.PUT(FTRP(bp),PACK(csize-asize,1,0));36.PUT(HDRP(bp),PACK(csize,prev_alloc,1));37.PUT(HDRP(NEXT_BLKP(bp)),PACK(nsize,1,next_alloc));40.voidmm_end()/*addedbyzhanyu*/42.mem_end();中,最佳適配要搜索所有空間,所以肯定比首次適配是釋放一個(gè)塊時(shí),能立即和前后空閑塊合并。如果空閑塊不按順序排列的話,其實(shí)也能夠和前一個(gè)或者后一個(gè)空閑塊進(jìn)行合并,但那需要搜索前后塊在空閑鏈表中的位置,并且刪除一個(gè)再進(jìn)行合并。可以參考P576,2)d;塊大小遞增,那么最佳適配法找到的塊和首次適配找到的塊是同一個(gè),因?yàn)樽罴训?,所以分配性能?huì)很高。b,最佳適配方法無(wú)論怎樣,都要搜索所有的鏈表(除非維深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第十章intmain(intargc,char**a{Rio_readinitb(&rio,STDIN_FILENO);while((n=Rio_readnb(&rio,buf,MAXBUF))!=0)Rio_writen(STDOUT_FILENO,buf,n);}),Execve("fstatcheck",argv,envp}intmain(intargc,char**a{?dup2(fd,STDIN_FILENO);}Rio_readinitb(&rio,STDIN_FILENO);while((n=Rio_readlineb(&rio,buf,MAXLINE))!=0)Rio_writen(STDOUT_FILENO,buf,n);}深入理解計(jì)算機(jī)系統(tǒng)(第二版)家庭作業(yè)第十一章A.因?yàn)閞ead_requesthdrs中已經(jīng)打印出了請(qǐng)求報(bào)頭,所以只要打印請(qǐng)求行即可printf("%s%s%s\n",method,uri,version);另外,如果要存成文件的話,可能需要另存為Accept:text/html,application/xhtml+xml,application/xml;q=,*/*;q=Accept-Language:en-US,eAccept-Encoding:gzip,deflateelseif(strstr(filename,".mpg")||strstr(filename,".mp4"))voidchild_signal(intsig){while((pid=waitpid(-1,NULL,WNOHANG))>0);}sprintf(content,"%sTheansweris:%d+%d=%d\r\n<p>",content,n1,n2,n1+n2);sprintf(content,"%sThanksforvisiting!\r\n",contenprintf("Content-length:%d\r\n",(int)strlen(content));printf("Content-type:text/html\r\n\r\n");}),#defineM_GET0#defineM_POST1#defineM_HEAD2voiddoit(intfd){intrmtd=0;charbuf[MAXLINE],method[MAXLINE],uri[MAXLINE],version[MAXLINE];charfilename[MAXLINE],cgiargs[MAXLINE];rio_trio;/*forpost*/charpost_content[MAXLINE];/*Readrequestlineario_readinitb(&rio,fd);rio_readlineb(&rio,buf,MAXLINE);printf("%s%s%s\n",method,uri,version);elseif(strcmp(method,"POST")==0)rmtelseif(strcmp(method,"HEAD")==0)rmtclienterror(fd,method,"501","NotImplemented",}contentLen=read_requesthdrs(&rio,post_content,rmtd);is_static=parse_uri(uri,filename,cgiargs);clienterror

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論