1、 project; Exercise 1 ; This is an assembly version of the following C code (assuming a, b and c already declared) ; ; for(int i=0;i6;i+) ; ai = ai + bi + ci; ; .data a: .space 48 b: .word 10,11,12,13,0,1 c: .word 1,2,3,4,5,6 .text ;initialize registers daddi r1,r0,a daddi r2,r0,b daddi r3,r0,c daddi
2、 r4,r0,6 Loop: lw r5,0(r1) ; element of a lw r6,0(r2) ; element of blw r7,0(r3) ; element of c dadd r8,r5,r6 ; ai + bi dadd r9,r7,r8 ; ai = ai + bi + ci; sw r9,0(r1) ; store value in ai daddi r1,r1,8 ; increment memory pointers daddi r2,r2,8 daddi r3,r3,8 daddi r4,r4,-1 ; i+ bnez r4,Loop end: halt 1
3、) Load ex1.s into the memory of MIPS64 and disable the forwarding logic, the delay slot and the Branch target buffer from the Configure menu in the main toolbar. Before running the program, try to predict where stalls occur, how many clock cycles they will take, and for what kind of hazards they occ
4、ur. Then compare your prediction with the simulation results. 答:时钟周期数=19 6 + 4 + 4 = 122 RAW data hazard=7 6 = 42 次。 仿真器的模拟结果为: 2) The program of ex1.s consists a loop plus some other instructions outside it. After running the program to completion, estimate the CPI using the Statistics window. In t
5、he case of a program containing a “hot spot” (i.e. an internal loop whose instructions are executed much more frequently than all the other instructions) the CPI can be roughly estimated just using the asymptotic CPI, i.e. where Nout and Sout are the number of instructions and the number of stalls o
6、utside the “hot spot”, respectively, L is the number of loop cycles of the innermost loop, and IChot and Shot are the number of instructions and the number of stalls of the “hot spot”. Compare the asymptotic CPI with the value resulting from simulations. Are results compatible? 答:Simulator CPI=(11+7
7、)*6+4+5+5+1)/(11*6)=1.848CPIAsymptotic=(11+7)/11=1.636执行情况如下:3) Enable the forwarding logic and execute the code again. Compute the CPI again. Justify the remaining stalls and comment why some of them occur after ID stage rather than after IF.答: Simulator CPI=(11+1)*6+5+5+4)/(11*6)=1.303 CPI Asympto
8、tic=(11+1)/11=1.091不相同。因为存在forwarding,ID阶段可以先读取寄存器的地址,默认的寄存器的值为错,bnez指令需要放回寄存器中的值,所以不接受daddi指令。EXE阶段forwarding的值,而要等到WB后的值。4) Disable the forwarding logic and assume that the MIPS hardware cannot detect hazards. Modify the source code by inserting NOPs where appropriate without reordering the code (
9、NOP stuffing technique). Check with the simulator that no stall occurs, and check whether the CPI has changed. Do we have better performance? 答:加入NOP: .data a: .space 48 b: .word 10,11,12,13,0,1 c: .word 1,2,3,4,5,6 .text daddi r1,r0,a daddi r2,r0,b daddi r3,r0,c daddi r4,r0,6 Loop: lw r5,0(r1) lw r
10、6,0(r2) lw r7,0(r3) NOP dadd r8,r5,r6 NOP NOP dadd r9,r7,r8 NOP NOP sw r9,0(r1) daddi r1,r1,8 daddi r2,r2,8 daddi r3,r3,8 daddi r4,r4, -1 NOP NOP bnez r4,Loop end: halt 加入了nop后,没有stall,CPI改变,性能变弱。 5)Reschedule the instructions (code moving technique) in order to avoid stalls without modifying the pr
11、ogram semantics (check the final result to see if after moving the instructions the result is the same). Recompute the normal and asymptotic CPI values. 答:代码如下: 执行情况:.text ;initialize registers daddi r1,r0,a daddi r2,r0,b daddi r3,r0,c daddi r4,r0,6 Loop: lw r5,0(r1) lw r6,0(r2) lw r7,0(r3) daddi r2
12、,r2,8 dadd r8,r5,r6 daddi r3,r3,8 dadd r9,r7,r8 daddi r4,r4,-1 sw r9,0(r1) daddi r1,r1,8 bnez r4,Loop end: halt 故CPI Asymptotic =(11+3)/11=1.273实际为1.2966) Combine rescheduling and forwarding techniques and note the differences with respect to the forwardingonly and reschedulingonly cases. Try to ena
13、ble the “Branch target buffer” look at the simulation code and determine the CPI. Has performance improved? Try to modify the original code by adding 6 additional input values in a and b. What do you expect from CPI?答:加入forwarding的执行情况: 在此基础上加入“Branch target buffer”,得到的结果如下: forwarding: rescheduling
14、: 把循环的次数增加到 12次的时,增加输入的个数,CPI 又会有提高。代码如下: .data a: .space 96 b: .word 10,11,12,13,0,1,1,0,13,12,11,10 c: .word 1,2,3,4,5,6,6,5,4,3,2,1 .text ;initialize registers daddi r1,r0,a daddi r2,r0,b daddi r3,r0,c daddi r4,r0,12 Loop: lw r5,0(r1) lw r6,0(r2) lw r7,0(r3) daddi r2,r2,8 dadd r8,r5,r6 daddi r3,r
15、3,8 dadd r9,r7,r8 daddi r4,r4,-1 sw r9,0(r1) daddi r1,r1,8 bnez r4,Loop end: halt 程序的执行情况如下: rescheduling: 增加循环次数后,代码变为: .data a: .space 96 b: .word 10,11,12,13,0,1,1,0,13,12,11,10 c: .word 1,2,3,4,5,6,6,5,4,3,2,1 .text ;initialize registers daddi r1,r0,a daddi r2,r0,b daddi r3,r0,c daddi r4,r0,12 Loop: lw r5,0(r1) ; element of a
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1