




























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































RegWrite MemRead ALUMux MemWrite ALUOp RegMux Branch
a. (^1 0) 0 (Reg) 0 Add 1 (ALU) 0
b. (^1 1) 1 (Imm) 0 Add 1 (Mem) 0
a. All except Data Memory and branch Add unit
b. All except branch Add unit and second read port of the Registers
Outputs that are not used No outputs
a. Branch Add Data Memory
b. Branch Add, second read port of Registers None (all units produce outputs)
a. Control is faster than registers, so the critical path is I-Mem, Regs, Mux, ALU, Mux.
b. Control is faster than registers, so the critical path is I-Mem, Regs, Mux, ALU, Mux.
4.1.5 One long path is to read instruction, read registers, use the Mux to select the immediate as the second ALU input, use ALU (compute address), access D-Mem, and use the Mux to select that as register data input, so we have I-Mem, Regs, Mux, ALU, D-Mem, Mux. The other long path is similar, but goes through Control instead of Regs (to generate the control signal for the ALU MUX). Other paths are shorter, and are similar to shorter paths described for 4.1.4.
a. Control is faster than registers, so the critical path is I-Mem, Regs, Mux, ALU, D-Mem, Mux.
b. Control is faster than registers, so the critical path is I-Mem, Regs, Mux, ALU, Mux.
4.1.6 This instruction has two kinds of long paths, those that determine the branch condition and those that compute the new PC. To determine the branch condition, we read the instruction, read registers or use the Control unit, then use the ALU Mux and then the ALU to compare the two values, then use the Zero out- put of the ALU to control the Mux that selects the new PC. As in 4.1.4 and 4.1.5:
a. The fi rst path (through Regs) is longer.
b. The fi rst path (through Regs) is longer.
To compute the PC, one path is to increment it by 4 (Add), add the offset (Add), and select that value as the new PC (Mux). The other path for computing the PC is to Read the instruction (to get the offset), use the branch Add unit and Mux. Both of the compute-PC paths are shorter than the critical path that determines the branch condition, because I-Mem is slower than the PC + 4 Add unit, and because ALU is slower than the branch Add.
Solution 4.
4.2.1 Existing blocks that can be used for this instruction are:
a. This instruction uses instruction memory, both existing read ports of Registers, the ALU, and the write port of Registers.
b. This instruction uses the instruction memory, one of the existing register read ports, the path that passed the immediate to the ALU, and the register write port.
4.2.2 New functional blocks needed for this instruction are:
a. Another read port in Registers (to read Rx) and either a second ALU (to add Rx to Rs + Rt) or a third input to the existing ALU.
b. We need to extend the existing ALU to also do shifts (adds a SLL ALU operation).
Solution 4.
4.3.
a. Both. It is mostly flip-fl ops, but it has logic that controls which flip-fl ops get read or written in each cycle
b. Both. It is mostly flip-fl ops, but it has logic that controls which flip-fl ops get read or written in each cycle
4.3.
a.
Instruction 0
This shows the lowermost bit of each word. This schematic is repeated 7 more times for the remaining seven bits. Note that there are no connec- tions for D and C flip-flop inputs because datapath figures do not specify how instruction memory is written.
b.
Reg0_
RData1_
RData2_
Reg1_
RReg
RReg
Clock
WData_
RegWrite
WReg
This is the schematic for the lowermost bit, it needs to be repeated 7 more times for the remaining bits. RReg1 is the Read Register 1 input, RReg2 is the Read Register 2 input, WReg is the Write Register input, WData is the Write Data input. RData1 and RData2 are Read Data 1 and Read Data 2 outputs. Data outputs and input have “_0” to denote that this is only bit 0 of the 8-bit signal.
4.3.
a. Because multi-input AND and OR gates have the same latency as 2-input ones, we can use many-input gates to reduce the number of gates on the path from inputs to outputs. The schematic shown for 4.3.2 turns out to already be optimal.
b. A three-input or a four-input gate has a lower latency than a cascade of two 2-input gates. This means that shorter overall latency is achieved by using 3- and 4-input gates rather than cascades of 2-input gates. In our schematic shown for 4.3.2, we should replace the three 2-input AND gates used for Clock, RegWrite, and WReg signals with two 3-input AND gates that directly determine the value of the C input for each D-element.
Solution 4.
4.4.1 We show the implementation and also determine the latency (in gates)
needed for 4.4.2.
Implementation Latency in gates
a.
b.
4.4.2 See answer for 4.4.1 above.
4.4.
Implementation
a.
A (^) Signal 1
Signal 2
b.
Signal 2
Signal 1
4.4.
a. There are four OR gates on the critical path, for a total of 136ps
b. The critical path consists of OR, XOR, OR, and OR, for a total of 510ps
4.4.
a. The cost is 2 AND gates and 4 OR gates, for a total cost of 16.
b. The cost is 1 AND gate, 4 OR gates, and 1 XOR gate, for a total cost of 12.
4.4.6 We already computed the cost of the combined circuit. Now we determine the cost of the separate circuits and the savings.
Combinend cost Separate cost Saved
a. 16 22 (+2 OR gates) (22 – 16)/22 = 27%
b. 12 14 (+1 AND gate) (14 – 12)/14 = 14%
4.5.
Cycle time Operation time
a. 90ps (OR, AND, D) 32 × 90ps = 2880ps
b. 170ps (NOT, AND, D) 32 × 170ps = 5440ps
4.5.
Cycle time Speed-up
a. 120ps (OR, AND, AND, D) (32 × 90ps)/(16 × 120ps) = 1.
b. 90ps (NOT, AND) (32 × 170ps)/(16 × 90ps) = 3.
4.5.
Circuit 1 Circuit 2
a. 14 (1 AND, 1 OR, 1 XOR, 1 D) 20 (2 AND, 1 OR, 2 XOR, 1 D)
b. 29 (1 NOT, 2 AND, 2 D) 29 (1 NOT, 2 AND, 2 D)
4.5.
Cost/Performance for Circuit 1
Cost/Performance for Circuit 2 Circuit 1 versus Circuit 2
a. 14 × 32 × 90 = 40320 20 × 16 × 120 = 38400 Cost/performance of Circuit 2 is better by about 4.7%
b. 29 × 32 × 170 = 157760 29 × 16 × 90 = 41760 Cost/performance of Circuit 2 is better by about 73.5%
Solution 4.
4.6.1 I-Mem takes longer than the Add unit, so the clock cycle time is equal to the latency of the I-Mem:
a. 400ps
b. 500ps
4.6.2 The critical path for this instruction is through the instruction memory, Sign-extend and Shift-left-2 to get the offset, Add unit to compute the new PC, and Mux to select that value instead of PC + 4. Note that the path through the other
Add unit is shorter, because the latency of I-Mem is longer that the latency of the
Add unit. We have:
a. 400ps + 20ps + 2ps + 100ps + 30ps = 552ps
b. 500ps + 90ps + 20ps + 150ps + 100ps = 860ps
4.6.3 Conditional branches have the same long-latency path that computes the
branch address as unconditional branches do. Additionally, they have a long-latency
path that goes through Registers, Mux, and ALU to compute the PCSrc condition.
The critical path is the longer of the two, and the path through PCSrc is longer for
these latencies:
a. 400ps + 200ps + 30ps + 120ps + 30ps = 780ps
b. 500ps + 220ps + 100ps + 180ps + 100ps = 1100ps
4.6.
a. All instructions except jumps that are not PC-relative (jal, jalr, j, jr)
b. Loads and stores
4.6.
a. None. I-Mem is slower, and all instructions (even NOP) need to read the instruction.
b. Loads and stores.
4.6.6 Of the two instruction (bne and add), bne has a longer critical path so it
determines the clock cycle time. Note that every path for add is shorter or equal to
than the corresponding path for bne, so changes in unit latency will not affect this.
As a result, we focus on how the unit’s latency affects the critical path of bne:
a. This unit is not on the critical path, so changes to its latency do not affect the clock cycle time unless the latency of the unit becomes so large to create a new critical path through this unit, the branch add, and the PC Mux. The latency of this path is 230ps and it needs to be above 780ps, so the latency of the Add-4 unit needs to be more 650ps for it to be on the critical path.
b. This unit is not used by BNE nor by ADD, so it cannot affect the critical path for either instruction.
Solution 4.
4.7.1 The longest-latency path for ALU operations is through I-Mem, Regs, Mux
(to select ALU operand), ALU, and Mux (to select value for register write). Note
that the only other path of interest is the PC-increment path through Add (PC + 4)
Solution 4.
4.8.1 To test for a stuck-at-0 fault on a wire, we need an instruction that puts that
wire to a value of 1 and has a different result if the value on the wire is stuck at zero:
a. Bit 7 of the instruction word is only used as part of an immediate/offset part of the instruction, so one way to test would be to execute ADDI $1, zero, 128 which is supposed to place a value of 128 into $1. If instruction bit 7 is stuck at zero, $1 will be zero because value 128 has all bits at zero except bit 7.
b. The only instructions that set this signal to 1 are loads. We can test by fi lling the data memory with zeros and executing a load instruction from a non-zero address, e.g., LW $1, 1024(zero). After this instruction, the value in $1 is supposed to be zero. If the MemtoReg signal is stuck at 0, the value in the register will be 1024 (the Mux selects the ALU output (1024) instead of the value from memory).
4.8.2 The test for stuck-at-zero requires an instruction that sets the signal to 1
and the test for stuck-at-1 requires an instruction that sets the signal to 0. Because
the signal cannot be both 0 and 1 in the same cycle, we cannot test the same signal
simultaneously for stuck-at-0 and stuck-at-1 using only one instruction. The test
for stuck-at-1 is analogous to the stuck-at-0 test:
a. We can use ADDI $1, zero, 0 which is supposed to put a value of 0 in $1. If Bit 7 of the instruction word is stuck at 1, the immediate operand becomes 128 and $1 becomes 128 instead of 0.
b. We cannot reliably test for this fault, because all instructions that set the MemtoReg signal to zero also set the ReadMem signal to zero. If one of these instructions is used as a test for MemtoReg stuck-at-1, the value written to the destination register is “random” (whatever noise is there at the data output of Data Memory). This value could be the same as the value already in the register, so if the fault exists the test may not detect it.
4.8.
a. It is possible to work around this fault, but it is very diffi cult. We must find all instructions that have zero in this bit of the offset or immediate operand and replace them with a sequence of “safe” instruction. For example, a load with such an offset must be replaced with an instruction that subtracts 128 from the address register, then the load (with the offset larger by 128 to set bit 7 of the offset to 1), then subtract 128 from the address register.
b. We cannot work around this problem, because it prevents all instructions from storing their result in registers, except for load instructions. Load instructions only move data from memory to registers, so they cannot be used to emulate ALU operations “broken” by the fault.
4.8.
a. If MemRead is stuck at 0, data memory is read for every instruction. However, for non-load instructions the value from memory is discarded by the Mux that selects the value to be written to the Register unit. As a result, we cannot design this kind of test for this fault, because the processor still operates correctly (although inefficiently).
b. (^) To test for this fault, we need an instruction whose opcode is zero and MemRead is 1. However, instructions with a zero opcode are ALU operations (not loads), so their MemRead is 0. As a result, we cannot design this kind of test for this fault, because the processor operates correctly.
4.8.
a. (^) If Jump is stuck-at-1, every instruction updates the PC as if it were a jump instruction. To test for this fault, we can execute an ADDI with a non-zero immediate operand. If the Jump signal is stuck- at-1, the PC after the ADDI executes will not be pointing to the instruction that follows the ADDI.
b. (^) To test for this fault, we need an instruction whose opcode is zero and Jump is 1. However, the opcode for the jump instruction is non-zero. As a result, we cannot design this kind of test for this fault, because the processor operates correctly.
4.8.6 Each single-instruction test “covers” all faults that, if present, result in dif- ferent behavior for the test instruction. To test for as many of these faults as possi- ble in a single instruction, we need an instruction that sets as many of these signals to a value that would be changed by a fault. Some signals cannot be tested using this single-instruction method, because the fault on a signal could still result in completely correct execution of all instruction that trigger the fault.
Solution 4.
4.9.
Binary Hexadecimal
a. 100011 00110 00001 0000000000101000 8CC
b. 000101 00001 00010 1111111111111111 1422FFFF
4.9.
Read register 1 Actually read? Read register 2 Actually read?
a. 6 (00110b ) Yes 1 (00001b ) Yes (but not used)
b. 1 (00001b ) Yes 2 (00010b ) Yes
arrive before that time. So the Control unit must generate the MemWrite in one clock cycle, minus the I-Mem access time:
Critical path Maximum time to generate MemWrite
a. 400ps + 30ps + 200ps + 30ps + 120ps + 350ps + 30ps = 1160ps
1160ps – 400ps = 760ps
b. 500ps + 100ps + 220ps + 100ps + 180ps + 1000ps + 100ps = 2200ps
2200ps – 500ps = 1700ps
4.10.2 All control signals start to be generated after I-Mem read is complete. The most slack a signal can have is until the end of the cycle, and MemWrite and Reg- Write are both needed only at the end of the cycle, so they have the most slack. The time to generate both signals without increasing the critical path is the one computed in 4.10.1.
4.10.3 MemWrite and RegWrite are only needed by the end of the cycle. RegDst, Jump, and MemtoReg are needed one Mux latency before the end of the cycle, so they are more critical than MemWrite and RegWrite. Branch is needed two Mux latencies before the end of the cycle, so it is more critical than these. MemRead is needed one D-Mem plus one Mux latency before the end of the cycle, and D-Mem has more latency than a Mux, so MemRead is more critical than Branch. ALUOp must get to ALU control in time to allow one ALU Ctrl, one ALU, one D-Mem, and one Mux latency before the end of the cycle. This is clearly more critical than MemRead. Finally, ALUSrc must get to the pre-ALU Mux in time, one Mux, one ALU, one D-Mem, and one Mux latency before the end of the cycle. Again, this is more critical than MemRead. Between ALUOp and ALUSrc, ALUOp is more critical than ALUSrc if ALU control has more latency than a Mux. If ALUOp is the most critical, it must be generated one ALU Ctrl latency before the critical-path signals can go through Mux, Regs, and Mux. If the ALUSrc signal is the most critical, it must be generated while the critical path goes through Mux and Regs. We have
The most critical control signal is
Time to generate it without affecting the clock cycle time
a. ALUOp (50ps > 30ps) 30ps + 200ps + 30ps – 50ps = 210ps
b. ALUSrc (100ps > 55ps) 100ps + 220ps = 320ps
For the next three problems, it helps to compute for each signal how much time we have to generate it before it starts affecting the critical path. We already did this for RegDst and RegWrite in 4.10.1, and in 4.10.3 we described how to do it for the remaining control signals. We have:
RegDst Jump Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite
a. (^) 730ps 730ps 700ps 380ps 730ps 210ps 760ps 230ps 760ps
b. (^) 1600ps 1600ps 1500ps 600ps 1600ps 365ps 1700ps 320ps 1700ps
The difference between the allowed time and the actual time to generate the signal
is called “slack”. For this problem, the allowed time will be the maximum time the
signal can take without affecting clock cycle time. If slack is positive, the signal
arrives before it is actually needed and it does not affect clock cycle time. If the
slack is positive, the signal is late and the clock cycle time must be adjusted. We now
compute the clack for each signal:
RegDst Jump Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite
a. 10ps 0ps 100ps –20ps 30ps 10ps 50ps 30ps –40ps
b. 0ps 0ps 100ps 100ps 200ps –35ps 200ps –80ps 0ps
4.10.4 With this in mind, the clock cycle time is what we computed in 4.10.1,
plus the absolute value of the most negative slack. We have:
Control signal with the most negative slack is
Clock cycle time with ideal Control unit (from 4.10.1)
Actual clock cycle time with these signal latencies
a. RegWrite (-40ps) 1160ps 1200ps
b. ALUSrc (-80ps) 2200ps 2280ps
4.10.5 It only makes sense to pay to speed-up signals with negative slack, because
improvements to signals with positive slack cost us without improving perfor-
mance. Furthermore, for each signal with negative slack, we need to speed it up
only until we eliminate all its negative slack, so we have:
Signals with negative slack
Per-processor cost to eliminate all negative slack
a. (^) MemRead (–20ps) RegWrite (–40ps)
60ps at $1/5ps = $
b. (^) ALUOp (–35ps) ALUSrc (–80ps)
115ps at $1/5ps = $
4.11.
ALU Add (PC + 4) Add (Branch)
a. 2 and 16 PC and 4 PC + 4 and 16 × 4
b. –16 and –3 PC and 4 PC + 4 and 12 × 4
4.11.
Read Register 1 Read Register 2 Write Register Write Data RegWrite
a. 2 3 3 0 1
b. 1 3 X (3 or 0) X 0
Solution 4.
4.12.
Pipelined Single-cycle
a. 500ps 1650ps
b. 200ps 800ps
4.12.
Pipelined Single-cycle
a. 2500ps 1650ps
b. 1000ps 800ps
4.12.
Stage to split New clock cycle time
a. MEM 400ps
b. IF 190ps
4.12.
a. 25%
b. 45%
4.12.
a. 65%
b. 60%
4.12.6 We already computed clock cycle times for pipelined and single cycle organizations in 4.12.1, and the multi-cycle organization has the same clock cycle time as the pipelined organization. We will compute execution times relative to the pipelined organization. In single-cycle, every instruction takes one (long) clock cycle. In pipelined, a long-running program with no pipeline stalls completes one instruction in every cycle. Finally, a multi-cycle organization completes a lw in 5 cycles, a sw in 4 cycles (no WB), an ALU instruction in 4 cycles (no MEM), and a beq in 4 cycles (no WB). So we have the speed-up of pipeline
Multi-cycle execution time is X times pipelined execution time, where X is
Single-cycle execution time is X times pipelined execution time, where X is
a. 0.15 × 5 + 0.85 × 4 = 4.15 1650ps/500ps = 3.
b. 0.30 × 5 + 0.70 × 4 = 4.30 800ps/200ps = 4.
Solution 4.
4.13.
Instruction sequence Dependences
a. I1: lw $1,40($6) I2: add $6,$2,$ I3: sw $6,50($1)
RAW on $1 from I1 to I RAW on $6 from I2 to I WAR on $6 from I1 to I2 and I
b. I1: lw $5,-16($5) I2: sw $5,-16($5) I3: add $5,$5,$
RAW on $5 from I1 to I2 and I WAR on $5 from I1 and I2 to I WAW on $5 from I1 to I
4.13.2 In the basic five-stage pipeline WAR and WAW dependences do not cause any hazards. Without forwarding, any RAW dependence between an instruction and the next two instructions (if register read happens in the second half of the clock cycle and the register write happens in the first half). The code that eliminates these hazards by inserting nop instructions is: