Docsity

31 Problems for Assignment - Computer Architecture and Operating System | ECE 3055, Assignments of Electrical and Electronics Engineering

Partial preview of the text

Download 31 Problems for Assignment - Computer Architecture and Operating System | ECE 3055 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

ECE 3055

Sample Problem Set : Pipelining and Memory Systems

1 Consider the following code sequence used often in block copies. This produces a special form of the load hazard and normally introduces one stall cycle.

Show how you can use forwarding to avoid the occurrence of stalls in this situation. Pro- vide your solution by modifying the view of the datapath provided below and precisely state the conditions you would check to implement such forwarding.

lw $7, 0($12)

sw $7, 0($13)

Registers ALUSrc

M u x

M u x

M u x

ALU

ID/EX MEM/WB

Data memory

M u x

Forwarding unit

EX/MEM

M u x

Add a multiplexor to the data input to memory. The inputs are as shown at left. Now the output of memory from the previous instruction can be fed to the input to memory for the current instruction.

from read data output of memory

memory data input

3 Assume branch instructions occur 22% of the time and are predicted as not taken, while in practice they are taken 42% of the time with a penalty of 2 cycles. With forwarding, the load delay slot is one cycle and can be filled 55% of the time with useful instructions. 21% of the instructions are loads and 30% of these introduce load delay hazards.

3 (a) What is the increase in CPI due to load delay slots and branch hazards?

3 (b) To improve performance, we would like to pipeline the memory accesses. This will reduce the clock cycle time by 20%, but increase the load delay slots to 2 cycles while not affecting branch delays. Is this worthwhile? Provide a quantitative justification for your answer.

load slots + branch delay slots

0.21 * 0.3 * 0.45 + 0.22 * 0.42 * 2 = 0.

CPI 2 = (0.21 * 0.3 * 0.45 * 2) + (0.22 * 0.42 * 2) = 0.

CPU Time 1 = I * CPI 1 * clock_cycle_time

CPU Time 2 = I * CPI 2 * (clock_cycle_time * 0.8)

The answer reduces to whether

(CPI + 0.213) > (CPI + 0.2415) * 0.

4 Consider the following instruction sequence with respect to the pipelined datapath with load hazard detection, data forwarding, and branch prediction (not taken) with flushing. Assume writes in WB take place in the first half of the cycle and reads take place in the second half of the cycle.

4 (a) If the first instruction in the above sequence starts at location 0x400, what are the values of the following variables in the pipeline during cycle 8. The first cycle is cycle 1.

4 (b) From the code, you can determine how many times this loop is executed. Furthermore, remember branches are predicted as not taken (with flushing), and full forwarding and load hazard detection What is the CPI value that you would obtain if you computed this value only over this block of code? Ignore the pipeline setup time.

lw $4, 0($3) lw $6, -4($3)

lw $9, -8($3)

add $7, $6, $ add $7, $9, $ add $7, $4, $ addi $5, $5, - bne $5, $0, Loop

Loop:

addi $3, $0, 0x

addi $5, $0, 72

add $7, $0, $

Both Forwarding Unit Outputs ________________

Output of the ALU ________________

IF/ID.PC _________________

EX.MEM. RegWrite _________________

ID/EX.Register.Rs

41c

1

10028

The instruction in IF is add $7, $9, $

72/51 (last time through the loop the branch is not taken)

5 Assume branch instructions occur 15% of the time and are predicted as not taken, while in practice they are taken 40% of the time with a penalty of 3 cycles. With forwarding, the load delay slot is one cycle and can be filled 60% of the time with useful instructions. 20% of the instructions are loads and 30% of these introduce load delay hazards.

5 (a) What is the increase in CPI due to load delay slots and branch hazards?

5 (b) To improve performance, we would like to pipeline the ALU. This will reduce the clock cycle time by 15%, but increase the load delay slots to 2 cycles, and the branch delays to 4 cycles. Provide a quantitative basis for determining if this is a good tradeoff.

CPI = 1 + increase due to branches + increase due to loads

= 1 + 0.150.43 + 0.20.30.4*

= 1.

CPI_new = 1 + 0.150.44 + 0.20.30.4*2 = 1.

Ex_new = I * CPI_new * 0.85 * clock_cycle = I * 1.0948 * clock_cycle

Ex_old = I * CPI_old * clock_cycle = I * 1.204 * clock_cycle

This is a good trade-off.

6 Consider a new high speed SPIM processor design where we have an 8 stage pipeline. Rel- ative to the design in the text, the memory stage has been partitioned into 2 stages and the ALU stage has been partitioned in to three stages (hence the new 8 stage pipeline). As a result, the clock cycle time has been reduced to 6 ns.

6 (a) What is the latency experienced by an instruction and the theoretical maximum through- put of this processor in instructions/second? Ignore hazards.

6 (b) Now we are examining the next generation design, where we will have two such pipe- lines operating concurrently, i.e., a superscalar design. An instruction fetched from mem- ory may be executed in either pipeline. Memory is fast enough to supply two instuctions in each fetch cycle. Repeat (a) for this pipeline.

Latency = 48 ns Maximum throughput is 167 MFLOPS

Latency is unchanged -each instruction must still go through the entire pipe = 48 ns

The maximum throughput has been doubled since two instructions can complete in each clock cycle = 334 MFLOPS

8 (a) Consider the state of following procedure executing within the SPIM pipeline during cycle 6. Assume that the first instruction is fetched in cycle 0! Assume full hardware support for forwarding, branches predicted as not taken, and flushing when branches are taken. The penalties for hazards are as dictated by the datapath in the figure. Also assume concurrent read/write to the same register in the same cycle. The first instruction is at address 0x00400000. Assume that all instructions are native instructions.

8 (b) ( 5 pts ) What instructions are in each stage of the pipeline.

8 (c) ( 10 pts ) What are the values of the following fields? ALL multiplexor inputs are num- bered from the top to bottom starting at 0. MuxA is the first one from the top in EX.

8 (d) ( 10 pts ) Extensive analysis of the instruction stream of code targeted for the pipelined MIPS with forwarding has produced the following statistics. To support larger caches we have accepted a two cycle access time and therefore the IF and MEM stages have been par- titioned into two stages. The alternative is to keep the single cycle hazards but with a clock that is 10% slower. The overall pipeline is now 7 stages. Penalties for load hazards are 2 cycles and those for control hazards are also 2 cycles. We note that 20% of load instructions produce a hazard and 30% of these load delay slots can be filled via instruction scheduling.

IF sw $t0, -4($fp)

ID sw$ra, 0($fp)

EX addi $fp, $sp, 16

MEM sw $fp, 4($sp)

WB addi $sp, $sp, -

MEM/WB.MemToReg 1 (note the conven- tion for labeling)

ForwardMuxA, ForwardMuxB 01, 00

IF/ID.PC 0x

ID/EX.RegWrite 1

EX/MEM.RegWrite 0

EX/MEM.WriteRegisterAddr XX

lw $t0, 0($a add $a0 , $a0, addi $sp, $sp, - sw $fp, 4($sp addi $fp, $sp, sw $ra, 0($fp sw $t0, -4($fp add $a1, $t0,

Similarly, we can use scheduling can fill 70% of the branch delay slots. Compute the new CPI. If the CPI without additional pipe stages was 1.5, is this design a good idea? Justify your answer..

Instruction Frequency

Loads 22%

Stores 13%

ALU Operations 42%

Branches 18%

New CPI = 1.5+ 0.220.20.72 + 0.180.3*2 = 1.5 + 0.1696 = 1. Ex_old = I * 1.5 * 1.1 * clock_cycle_time Ex_new = I * 1.7 * clock_cycle time.

Not a good idea.

begin

-- identify all signals that will show up on the trace and -- connnect them to internal signals on the datapath -- -- what signals do we want to see from ID? -- Instr <= id_instruction; PC <= id_PC4; -- -- signals traced from EX? -- Rs <= ex_register_rs; Rt <= ex_register_rt; ALUSrc <= ex_ALUSrc; RegDst <= ex_RegDst; ALUOp <= ex_ALUOp; -- -- signals traced from MEM? -- ALURes <= mem_alu_result; MemInData <= mem_write_data; MRead <= mem_MemRead; MWrite <= mem_MemWrite; -- --signals traced from WB? -- MemOut <= wb_memory_data; ALU_WB <= wb_alu_result; WReg <= wb_wreg_addr; RegWr <= wb_RegWrite; MemToReg <= wb_MemToReg;

Relevant Text Pieces from spim_pipe.vhd.

10 (c) Rather than using forwarding and hardware support for flushing on branches, suppose that instruction scheduling could successfully fill 70% of the delay slots produced by data and control hazards. Furthermore, the clock cycle time could be reduced by 10% since the multiplexors used for forwarding were on the critical path. Is this option a better one that the use of forwarding? If expressions are not evaluated, show precisely how you can answer this question. New CPI increase due to data hazards is (0.42+0.22+0.13) * 2 * 0.2 *

New CPI increase due to control hazards is 0.18 *3 * 0.

Execution time is I * CPInew * (0.9 * cycle_time) Old Execution time is I * CPIold * cycle_time. Compare the two.

11 Consider the state of following procedure executing within the SPIM pipeline during cycle

  1. Assume that the first instruction is fetched in cycle 0! Assume full hardware support for forwarding, branches predicted as not taken, and flushing when branches are taken. The penalties for hazards are as dictated by the datapath in the figure. The first instruction is at address 0x00400000. Assume that all instructions are native instructions.

11 (a) What instructions are in each stage of the pipeline.

11 (b) What are the values of the following fields? Mux inputs are numbered from the top to bottom starting at 0. MuxA is the first one from the top in EX.

While the nop has de-asserted control signals RegDst is 0 and the rest of the pipeline reg- ister has been updated and contains the contents of the add instruction.

IF bne $2, $3, loop

ID addi $2, $2, 4

EX add $9, $9, $

MEM nop

WB lw $22, 0($2)

MEM/WB.MemToReg 1 (according to text, 0 according to my con- vention stated above)

ForwardMuxA, ForwardMuxB 00 01

IF/ID.PC 0040001c

ID/EX.RegWrite 1

EX/MEM.RegWrite 0

EX/MEM.WriteRegister 0x

func: addi $2, $4, $ addi $3, $5, $ add $3, $3, $ addi $9, $0, $ loop: lw $22, 0($2) -- WB hazard cycle -- MEM add $9, $9, $22 -- EX addi $2, $2, 4 -- ID bne $2, $3, loop -- IF hazard cycle move $2, $ jr $

12 Consider the following code sequence which computes a running sum of an array of inte- gers stored starting at location Start: through memory address End:

12 (a) Rewrite the code sequence assuming that the pipelined SPIM provides no support for fowarding or branch hazards and the compiler must ensure correctness by the proper inser- tion of nops. Assume register file write operations take place in the first half of the cycle and read operations in the second half of the cycle. Any hazards are determined by the pipeline structure in Figure 6.41!

add $7, $0, $ la $4, End la $3, Start loop: lw $6, 0($3) lw $5, 4($3) add $7, $6, $ add $7, $5, $ addi $3, $3, 8 bne $3, $4, loop

add $7, $0, $ la $4, End la $3, Start nop nop loop: lw $6, 0($3) lw $5, 4($3) nop add $7, $6, $ nop nop add $7, $5, $ addi $3, $3, 8 nop nop bne $3, $4, loop nop

12 (b) Now schedule the code in 2(a) to remove as many nops as possible.

la $3, Start la $4, End add $7, $0, $ loop: lw $6, 0($3) lw $5, 4($3) addi $3, $3, 8 add $7, $6, $ nop bne $3, $4, loop add $7, $5, $