@Radon
2014-11-12T06:21:21.000000Z
字数 8796
阅读 1943
1100012749
磁盘容量 ~ xr(1 - x)
--> x = 0.5
Taccess= Tavgseek + Tavgrotation + Tavgtransfer
Tavgrotation = 1/2 x(60 secs/15000 RPM) x1000 ms/sec = 2 ms.
定位时间 = 3 + 2 = 5 ms
A. 5 + 4000 / 1000 * 4 = 21ms
B. 5 * 4000 = 20000ms
| Cache | C | B | E | S | t | s | b |
|---|---|---|---|---|---|---|---|
| 1. | 2048 | 256 | |||||
| 2. | 4 | 4 | |||||
| 3. | 25 | 6 | |||||
| 4. | 32 | 5 |
A. 无
B. 0x18F0, 0x18F1, 0x18fF2, 0x18F3, 0xB0, 0xB1, 0xB2, 0xB3
C. 0xE34, 0xE35, 0xE36, 0xE37
D. 0x1BDC, 0x1BDD, 0x1BDE, 0x1BDF
void transpose(int *dst,int *src,int dim){int i, j, ii, jj, i_;int Dim = dim*4;for(i = 0, ii = 0; i < dim-3; i += 4, ii += Dim){for(j = 0, jj = 0; j < dim-3; j += 4, jj += Dim){dst[jj + i] = src[ii + j];dst[jj + i+1] = src[ii+dim + j];dst[jj + i+2] = src[ii+dim*2 + j];dst[jj + i+3] = src[ii+dim*3 + j];dst[jj+dim + i] = src[ii + j+1];dst[jj+dim + i+1] = src[ii+dim + j+1];dst[jj+dim + i+2] = src[ii+dim*2 + j+1];dst[jj+dim + i+3] = src[ii+dim*3 + j+1];dst[jj+dim*2 + i] = src[ii + j+2];dst[jj+dim*2 + i+1] = src[ii+dim + j+2];dst[jj+dim*2 + i+2] = src[ii+dim*2 + j+2];dst[jj+dim*2 + i+3] = src[ii+dim*3 + j+2];dst[jj+dim*3 + i] = src[ii + j+3];dst[jj+dim*3 + i+1] = src[ii+dim + j+3];dst[jj+dim*3 + i+2] = src[ii+dim*2 + j+3];dst[jj+dim*3 + i+3] = src[ii+dim*3 + j+3];}}i_ = i;//jfor(i = 0; i < dim; i++)for(j = i_; j < dim; j++)dst[j*dim + i] = src[i*dim + j];for(i = i_;i < dim;i++)for(j = 0;j < i_;j++)dst[j*dim + i] = src[i*dim + j];}
A. 当REG是%esp时,这段代码将会把REG-4压入栈中。
B.
movl REG,-4(%esp)subl $4,%esp
A.
void bubble_a(int *data,int count) {int i, last;for (last = count-1; last > 0; last--) {for (i = 0; i < last; i++)if (*(data+i+1) < *(data+i)) {int t = *(data+i+1);*(data+i+1) = *(data+i);*(data+i) = t;}}}int main(){int data[3] = {3,2,1};bubble_a(data,3);return 0;}
B.
.pos 0init:irmovl Stack, %esp # Set up Stack pointerirmovl Stack, %ebp # Set up base pointercall Main # Execute main programhalt# Array of 4 elements.align 4array:.long 5.long 2.long 0.long 1Main:pushl %ebprrmovl %esp,%ebpirmovl $4,%eaxpushl %eax # Push count=4irmovl array,%edxpushl %edx # Push arraycall bubble_a # bubble_a(array, 4)rrmovl %ebp,%esppopl %ebpretbubble_a:pushl %ebprrmovl %esp, %ebpmrmovl 12(%ebp), %esimrmovl 8(%ebp), %edx # edx = datairmovl $-1,%eaxaddl %eax, %esi # esi = last == count-1jle L1#innerLoopL10:xorl %eax, %eax # i = 0L7:pushl %esirrmovl %eax, %esiaddl %esi, %esiaddl %esi, %esiaddl %edx, %esimrmovl 4(%esi), %ecx #movl 4(%edx,%eax,4), %ecxmrmovl (%esi), %ebx #movl (%edx,%eax,4), %ebxsubl %ebx, %ecxjge L3addl %ebx, %ecxrmmovl %ebx, 4(%esi)rmmovl %ecx, (%esi)L3:popl %esiirmovl $1,%ecxaddl %ecx, %eaxrrmovl %eax, %ecxsubl %esi, %ecxjl L7#innerLoopirmovl $-1, %ecxaddl %ecx, %esijne L10L1:rrmovl %ebp,%esppopl %ebpret.pos 0x200Stack:
#innerLoopL10:xorl %eax, %eax # i = 0L7:pushl %esirrmovl %eax, %esiaddl %esi, %esiaddl %esi, %esiaddl %edx, %esimrmovl 4(%esi), %ecx #movl 4(%edx,%eax,4), %ecxmrmovl (%esi), %ebx #movl (%edx,%eax,4), %ebxpushl %esirrmovl %ecx, %esisubl %ebx, %esirrmovl %ecx, %esicmovl %ebx, %ecxcmovl %esi, %ebxpopl %esirmmovl %ecx, 4(%esi)rmmovl %ebx, (%esi)L3:popl %esiirmovl $1,%ecxaddl %ecx, %eaxrrmovl %eax, %ecxsubl %esi, %ecxjl L7#innerLoop
# Stage iaddl V, rB## Fetch:# icode:ifun <- M1[PC]# rA:rB <- M1[PC+1]# valC <- M4[PC+2]# valP <- PC+6## Decode:# valB <- R[rB]## Execute:# valE <- valB+valC# Set CC## Memory## Write back:# R[rB] <- valE## PC update:# PC <- valP##/* $begin seq-all-hcl */##################################################################### HCL Description of Control for Single Cycle Y86 Processor SEQ ## Copyright (C) Randal E. Bryant, David R. O'Hallaron, 2010 ####################################################################### Your task is to implement the iaddl and leave instructions## The file contains a declaration of the icodes## for iaddl (IIADDL) and leave (ILEAVE).## Your job is to add the rest of the logic to make it work##################################################################### C Include's. Don't alter these #####################################################################quote '#include <stdio.h>'quote '#include "isa.h"'quote '#include "sim.h"'quote 'int sim_main(int argc, char *argv[]);'quote 'int gen_pc(){return 0;}'quote 'int main(int argc, char *argv[])'quote ' {plusmode=0;return sim_main(argc,argv);}'##################################################################### Declarations. Do not change/remove/delete any of these ########################################################################## Symbolic representation of Y86 Instruction Codes #############intsig INOP 'I_NOP'intsig IHALT 'I_HALT'intsig IRRMOVL 'I_RRMOVL'intsig IIRMOVL 'I_IRMOVL'intsig IRMMOVL 'I_RMMOVL'intsig IMRMOVL 'I_MRMOVL'intsig IOPL 'I_ALU'intsig IJXX 'I_JMP'intsig ICALL 'I_CALL'intsig IRET 'I_RET'intsig IPUSHL 'I_PUSHL'intsig IPOPL 'I_POPL'# Instruction code for iaddl instructionintsig IIADDL 'I_IADDL'# Instruction code for leave instructionintsig ILEAVE 'I_LEAVE'##### Symbolic represenations of Y86 function codes #####intsig FNONE 'F_NONE' # Default function code##### Symbolic representation of Y86 Registers referenced explicitly #####intsig RESP 'REG_ESP' # Stack Pointerintsig REBP 'REG_EBP' # Frame Pointerintsig RNONE 'REG_NONE' # Special value indicating "no register"##### ALU Functions referenced explicitly #####intsig ALUADD 'A_ADD' # ALU should add its arguments##### Possible instruction status values #####intsig SAOK 'STAT_AOK' # Normal executionintsig SADR 'STAT_ADR' # Invalid memory addressintsig SINS 'STAT_INS' # Invalid instructionintsig SHLT 'STAT_HLT' # Halt instruction encountered##### Signals that can be referenced by control logic ######################### Fetch stage inputs #####intsig pc 'pc' # Program counter##### Fetch stage computations #####intsig imem_icode 'imem_icode' # icode field from instruction memoryintsig imem_ifun 'imem_ifun' # ifun field from instruction memoryintsig icode 'icode' # Instruction control codeintsig ifun 'ifun' # Instruction functionintsig rA 'ra' # rA field from instructionintsig rB 'rb' # rB field from instructionintsig valC 'valc' # Constant from instructionintsig valP 'valp' # Address of following instructionboolsig imem_error 'imem_error' # Error signal from instruction memoryboolsig instr_valid 'instr_valid' # Is fetched instruction valid?##### Decode stage computations #####intsig valA 'vala' # Value from register A portintsig valB 'valb' # Value from register B port##### Execute stage computations #####intsig valE 'vale' # Value computed by ALUboolsig Cnd 'cond' # Branch test##### Memory stage computations #####intsig valM 'valm' # Value read from memoryboolsig dmem_error 'dmem_error' # Error signal from data memory##################################################################### Control Signal Definitions. ##################################################################################### Fetch Stage #################################### Determine instruction codeint icode = [imem_error: INOP;1: imem_icode; # Default: get from instruction memory];# Determine instruction functionint ifun = [imem_error: FNONE;1: imem_ifun; # Default: get from instruction memory];bool instr_valid = icode in{ INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL,IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL, IIADDL, ILEAVE };# Does fetched instruction require a regid byte?bool need_regids =icode in { IRRMOVL, IOPL, IPUSHL, IPOPL,IIRMOVL, IRMMOVL, IMRMOVL, IIADDL };# Does fetched instruction require a constant word?bool need_valC =icode in { IIRMOVL, IRMMOVL, IMRMOVL, IJXX, ICALL, IIADDL };################ Decode Stage ##################################### What register should be used as the A source?int srcA = [icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL } : rA;icode in { IPOPL, IRET } : RESP;icode in { ILEAVE } : REBP;1 : RNONE; # Don't need register];## What register should be used as the B source?int srcB = [icode in { IOPL, IRMMOVL, IMRMOVL, IIADDL } : rB;icode in { IPUSHL, IPOPL, ICALL, IRET } : RESP;icode in { ILEAVE } : REBP;1 : RNONE; # Don't need register];## What register should be used as the E destination?int dstE = [icode in { IRRMOVL } && Cnd : rB;icode in { IIRMOVL, IOPL, IIADDL} : rB;icode in { IPUSHL, IPOPL, ICALL, IRET, ILEAVE } : RESP;1 : RNONE; # Don't write any register];## What register should be used as the M destination?int dstM = [icode in { IMRMOVL, IPOPL } : rA;icode in { ILEAVE } : REBP;1 : RNONE; # Don't write any register];################ Execute Stage ##################################### Select input A to ALUint aluA = [icode in { IRRMOVL, IOPL } : valA;icode in { IIRMOVL, IRMMOVL, IMRMOVL, IIADDL } : valC;icode in { ICALL, IPUSHL } : -4;icode in { IRET, IPOPL, ILEAVE } : 4;# Other instructions don't need ALU];## Select input B to ALUint aluB = [icode in { IRMMOVL, IMRMOVL, IOPL, ICALL,IPUSHL, IRET, IPOPL, IIADDL, ILEAVE } : valB;icode in { IRRMOVL, IIRMOVL } : 0;# Other instructions don't need ALU];## Set the ALU functionint alufun = [icode == IOPL : ifun;1 : ALUADD;];## Should the condition codes be updated?bool set_cc = icode in { IOPL, IIADDL };################ Memory Stage ##################################### Set read control signalbool mem_read = icode in { IMRMOVL, IPOPL, IRET, ILEAVE };## Set write control signalbool mem_write = icode in { IRMMOVL, IPUSHL, ICALL };## Select memory addressint mem_addr = [icode in { IRMMOVL, IPUSHL, ICALL, IMRMOVL } : valE;icode in { IPOPL, IRET, ILEAVE } : valA;# Other instructions don't need address];## Select memory input dataint mem_data = [# Value from registericode in { IRMMOVL, IPUSHL } : valA;# Return PCicode == ICALL : valP;# Default: Don't write anything];## Determine instruction statusint Stat = [imem_error || dmem_error : SADR;!instr_valid: SINS;icode == IHALT : SHLT;1 : SAOK;];################ Program Counter Update ############################## What address should instruction be fetched atint new_pc = [# Call. Use instruction constanticode == ICALL : valC;# Taken branch. Use instruction constanticode == IJXX && Cnd : valC;# Completion of RET instruction. Use value from stackicode == IRET : valM;# Default: Use incremented PC1 : valP;];#/* $end seq-all-hcl */