









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!










Name Solution
4 May 2015, 10:00–12:00 CDT
Alias I feel like this is a good alias.
Problem 1 (20 pts)
Problem 2 (20 pts)
Problem 3 (20 pts)
Problem 4 (20 pts)
Problem 5 (20 pts)
Good Luck!
MIPS instructions to do so. If these two instructions were in the same fetch group in a two-way superscalar processor then the second one would stall, this is shown in the execution below.
addi r1, r2, 3 IF ID EX ME WB add r4, r1, r5 IF ID -> EX ME WB
An FA-ALU has two regular inputs, and a third input reserved for small quantities, here for values < 16, and it can produce a result in the same time as an ordinary two-input ALU. An FA-ALU can be used to execute instruction pairs like the one above without a stall, call such an execution a fused add.
Illustrated below is a 2-way superscalar implementation with an FA-ALU. Most bypass paths have been removed to provide space for the solution to this problem. In addition to a 4-bit input for the third operand, the FA-ALU has a control input, FA, which should be set to 1 when the third input is to be used.
Use next page for solution.
Immed
AddrD In
Addr
Addr D In
md^0
Dest. reg dst^0
Addr
25: 20:
rsv^0 Addr rtv^0
Data Data
15:
31:
15:
alu^0
rtv^0
rtv^1
Addr 25: 20:
rsv^1 Addr rtv^1
Data Data
AddrD In
dst^1
imm^0 imm^1
64
15:
alu^1 Addr D In
md^1 dst^0 dst^1
Register File
ir^0 ir^1
pc
npc
2'b 0
Dest. reg
Data Out
dst^0 dst^1
alu^1
alu^0
Data Out
Data Out Immed
FA
4
Use next page for solution.
(a) Add datapath connections to this implementation so that the FA-ALU can be used for fused adds. Hint: The datapath changes are not just for that new FA-ALU input.
(b) Add control logic.
tations. All branches are taken.
(a) Show the execution of the code below on the following implementation. The branch is taken.
format immed
IR
25:21 Addr 20:
Addr
Addr
Addr
Addr
In
dest. reg^ dst
30 2
2'b 0
15:
25:
15:
dst dst
m l
m l
Solution appears below.
Common mistakes: squashing the delay slot instruction (the and); not noticing that the branch depends on the sub.
add r4, r2, r3 IF ID EX ME WB lw r6, 8(r4) IF ID EX ME WB sub r1, r6, r5 IF ID -> EX ME WB beq r7, r1 TARG IF -> ID ----> EX ME WB and r8, r7, r10 IF ----> ID EX ME WB or r11, r12, r xor r14, r11, r TARG: sw r1, 0(r2) IF ID EX ME WB
(b) Show the execution of the MIPS FP code below on the following implementation. Assume that there is a bypass from WF to M1 and A1.
eg F
fd
Addr Addr Addr
f
15: 20:
A1 A2 A
fd
w
xw
fd
w
uses F
uses F
0 1 2
fd
w
xw
fd
w
xw
fd
w
xw xw
w
fd
format immed
IR
25:21 Addr 20:
Addr
Addr
Addr
Addr
In
dest. reg^ dst
30 2
2'b 0
15:
15:
dst dst
dest. reg
2'd 2 2'd (^1) 2'd 0
A
Int Reg F
ID-stage signals shown in purple.
Solution appears below. Common mistakes: Not realizing that the lwc1 uses WF (not WB) and therefore it must stall to avoid the structural hazard. Another common mistake is stalling in a stage other than ID.
add.s f6, f2, f3 IF ID A1 A2 A3 A4 WF add.s f1, f7, f8 IF ID A1 A2 A3 A4 WF lwc1 f9, 0(r10) IF ID ----> EX ME WF mul.s f4, f1, f9 IF ----> ID -> M1 M2 M3 M4 M5 M6 WF
with a different branch predictor. All systems use a 2^30 entry BHT. One system has a bimodal predictor, one system has a local predictor with a 12-outcome local history, and one system has a global predictor with a 12-outcome global history.
(a) Branch behavior is shown below. Branch B2 consists of a pattern in which there will be either 2, 4, or 6 T outcomes followed by exactly four N outcomes. After the fourth N the probability of exactly two Ts is (^13) and the probability of exactly four Ts is 13.
Answer each question below, the answers should be for predictors that have already warmed up.
The accuracy is 36. The work to compute this result is shown below, in which the counter was assumed to start at 3. (Any assumed start value is correct.) The prediction accuracy is based on the second pattern repetition because the counter value at the start of the pattern and the end of that pattern is the same, 0. (In contrast, the counter value at the start of the first repetition is 3 and at the end it is 0, so we can’t use the first six outcomes of B1 to compute an accuracy, though by coincidence it would be correct.)
3 2 3 3 2 1 0 0 1 2 1 0 0 <- Counter values. B1: N T T N N N N T T N N N ... x x x x x x <- Mispred location. --------------------------- <- Repeating pattern.
To answer this question consider each number of Ts separately. First, TTNNNN. When this pattern starts the counter will be zero (because every repetition ends with four Ns). So the two Ts will be mispredicted, bringing the counter to 2, and the first N will be mispredicted. The number of correct predictions is 6 − 3 = 3 and the accuracy is 12. Next consider TTTTNNNN. Here the first two Ts will be mispredicted as will the first two Ns. The number of correct predictions is 8 − 4 = 4 and the accuracy is also 12. Finally, in TTTTTTNNNN the first two Ts and Ns will be mispredicted. The number of correct predictions is 10 − 4 = 6 and the accuracy is. 6.
For an overall prediction accuracy we need to combine these numbers. Since they are all equally likely we will consider one pattern of
each length, 6, 8, and 10 together as a group. The correct prediction ratio is (^) 6+8+103+4+6 = 1324 =. 541667. If we wanted to take a weighted average of the prediction accuracies we would have to weight by both the probability of occurrence and the length. In other words if we computed 1336 + 1348 + 13106 = 158 we would have given the 106 accuracy too low a weight. Yes, it happens one third the time, but its length, 10 outcomes, is longer than the other two so it has a larger overall impact on execution time.
Four outcomes are sufficient. With three outcomes a local history of NNN could appear before an N or a T.
Because there is randomness the local predictor won’t be right 100% of the time. Notice that we always have four consecutive N’s followed by two T’s. That means if the most-recent four outcomes in the local history are N then a T is certainly the next outcome (and so the corresponding PHT entry will have warmed up to 3). Similarly. if the most recent PHT outcomes are a T followed by one, two, or three Ns the next outcome is certainly an N. The table below shows some possible local history values, the next outcome, and how often that outcome will be encountered. Stars indicate either a T or N.
Local Next Outcome History Frequency
**TTN N Every Time **TTNN N Every Time **TTNNN N Every Time **TTNNNN T Every Time **TTNNNNT T Every Time **TTNNNNTT T 2/3 of the time **TTNNNNTT N 1/3 of the time **TTNNNNTTT T Every Time **TTNNNNTTTT T 1/2 of the time. **TTNNNNTTTT N 1/2 of the time. TTNNNNTTTTTT N Every time.
First consider TTNNNN. The Ts will always be predicted correctly because at least two Ts always follow the four Ns. The first N can be mispredicted because 23 of the time the run of Ts is larger than 2. First, lets assume that the N is always mispredicted. Later, in an advanced solution, we’ll use a better misprediction probability.
The following three Ns will be correctly predicted. So for the first pattern we have 5 correct predictions and one misprediction.
Next, consider TTTTNNNN. The first four Ts will likely be predicted correctly because after the first two Ts a third T is more likely than an N. Given that we have four Ts, the probability of a fifth one is 12. Since the bias is even the 2-bit counter can predict either direction with equal likelihood. So the first N is mispredicted half the time for this pattern, and similarly the fifth T is mispredicted half the time for the 6 T pattern. Considering a set of all three patterns, the expected total number of mispredicts is just 2, so the
accuracy is (5+7 (6+8+10).5+9.5) = 1112 =. 91666.
Advanced Solution: The solution above ignores the fact that for pattern TTNNNN there is a chance that the first N is correctly predicted. That would occur if the local predictor saw at least two consecutive TTNNNN patterns before predicting a third consecutive TTNNNN. Here saw means that the local histories were the name for all three patterns when predicting the first N. A simple Markov chain can be used to determine the probability of the counter value for local history *NNNNTT (the local history used when predicting the first N). Let p 0 denote the probability that the counter value is 0, p 1 denote the probability that the counter value is 1, and so on. The problem states that the T probability is 2 / 3 in this case. Based on this we can write a balanced flow equation: ap 0 = (1 − a)p 1 , where a is the T probability. Solving we get p 1 = (^1) −aa p 0. Between p 1 and p 2 we can write ap 1 = (1 − a)p 2
and get p 2 =
a 1 −a
p 0. Skipping a few steps we get p 0 = (^) ωω 4 − (^) −^11 where ω = (^1) −aa. Using a = 23 we find p 0 = 151 and
p 1 = 152 and so the probability of correctly predicting the first N for the T2 case is 153 = 15. The number of correct predictions for T2 is 5 + 15 or an accuracy of 1315 =. 8667. Similarly, the number for T4 is 6 + 45 + 12 or an accuracy of 7380 =. 9125 and for T is 8 + 45 + 12 or an accuracy of 10093. The overall correct prediction accuracy is 109120 =. 9083.
assumption about B2’s behavior.
Based on the answer to the minimum-local-history-size question above, the minimum local history needed to predict B1 with 100% accuracy is four outcomes. But here we are dealing with a global history, which contains the outcomes of the most recently executed branches, which in this case is B1, B2, and B3. In the illustration below the outcomes of B1 have been made lower case, and the value of a six-outcome GHR is shown at time X (see the diagram) when we are about to predict B1.
Time-> X B1: n t t n n n n t t n n n ... B2: T{2,4,6} N N N N T{2,4,6} N N N N ... B3: T T T T T T T T T T T T ... ----------X tNT nNT <--- Value of 6-outcome GHR at time X.
In this part consider the same predictors as on the previous page, except this time the BHT has 2^14 entries.
Branch B1 below is perfectly biased not taken. It executes r 1 times over a short time interval, followed by a big time gap before its next bunch of r 1 executions. Branch B2 behaves similarly, except that it is biased taken and executes in bunches of length r 2 executions.
0xee4720 B1: N..N r 1 N..N r 1
B2: T..T r 2 T..T r 2
(b) Choose an address for branch B2 that will result in a BHT collision with branch B1. (Branch B1 is at address 0xee4720.)
Branch B1 will collide with B3 in a BHT lookup if the bit values used to index the BHT for the two branches are the same. Since the BHT has 214 entries and because MIPS instructions are 4-byte aligned we will use bits 15:2 of the branch address to index (to use as a lookup address for) the BHT. The value of those bits for B1 is 0x4720 >> 2 or 0x11c8 but for simplicity think of the bits as 0x4720. (Note that each hex digit spans four bits). For B2 to use the same entry the four least significant hex digits must
match. One such address is 0xaa.
(c) Assume that branch B1 and B2 collide in the BHT. For what positive values of r 1 and r 2 will this collision be most harmful? For what range of positive values of r 1 and r 2 will collisions be least harmful?
The worst values are r 1 = 1 and r 2 = 1. For those values the predictor will see one occurrence of B1 followed by one of B2, then one of B1 and so on. The 2-bit counter will not saturate at any value. In the worst case all predictions will be wrong.
Large values for r 1 , r 2 or both. When execution switches from one branch to the other there will be two mispredictions (assuming
both r 1 ≥ 2 and r 2 ≥ 2 ). The accuracy would be r^1 − r2+ 1 +rr^22 − 2 , so with the sum large the accuracy will be close to 100%.
(d) A tag can be placed in the BHT to detect collisions. Which branch will this help?
Branch B1. If there is a collision when predicting B1 we will predict B1 taken (because of B2’s history). A branch predictor that does not use a tag has no way of knowing that there’s been a collision and so when predicting B1 it will jump to the target of B (not the target of B1). In the predictor with a tag the collision will be detected (by comparing the stored tag to the tag of the address of the branch being predicted). Since a collision means that the target address is wrong, the predictor will ignore the two-bit counter (which would be 3 in this example) and instead predict not taken, which has a chance of being correct. (When a collision has been detected you wouldn’t predict taken because the target address is for some other branch sharing the entry, and so it won’t be correct.) Predicting not taken for B2 is wrong, but that’s what we’d do with or without a tag.
bytes. Hints about the cache are provided in the diagram.
(a) Answer the following, formulæ are fine as long as they consist of grade-time constants.
Addr Data
ag
Data Addr Data
Addr
Data In
Addr Data
ag
Data Addr Data
128 b
Address:
Tag
Index
Offset
The associativity is 16. The associativity is determined based on the given cache capacity, 222 bytes, and the capacity of an
individual data store, 218 bytes. Since the cache capacity is the sum of the data store sizes, the associativity must be 2
22 218 = 222 −^18 = 16.
It’s the cache capacity, 4 MiB, plus 16 × 218 −^7 (36 − 18 + 1) bits.
The code in the problems below run on a 4 MiB (2^22 byte) 4-way set-associative cache with a line size of 64 bytes. Each code fragment starts with the cache empty; consider only accesses to the arrays.
(b) Find the hit ratio executing the code below.
int sum = 0; half *a = 0x2000000; // sizeof(half) == 2 int i; int ILIMIT = 1 << 11; // = 211
for (i=0; i
which the second loop enjoys a 100% hit ratio. Explain why that value is the same as for Plan B.
Short Answer: Because with Plan A the least significant index bit is always zero or always one and so half the cache is used.
As explained in the previous answer, when using the Plan A struct we only need one line per iteration, whereas with the Plan B struct we need two lines per iteration. So you’d think that with Plan B we’d need to make BSIZE half the size to avoid cache misses. But no.
FINISH
(c) Consider a 5n-stage scalar implementation and an n-way superscalar implementation, both derived from our 5-stage design with the goal of improving performance by as much as n×. As n increases the clock fre- quency of the 5n-stage implementation increases but the frequency of the n-way superscalar implementation decreases. Explain why. Assume that both types of system are well designed.
... the critical path in each stage is shorter as n increases and so the clock frequency can be increased. (In the 5 n−stage system each stage in the 5-stage system is divided into n stages each taking (^1) n the amount of time, ideally.) Ignoring latch setup time and assuming stages can be perfectly divided, the clock frequency would be nφ, where φ is the clock frequency of the 5-stage system. Accounting for a latch setup time of tL, the clock frequency would be (^) tLφ(nnφ−1)+1. It is this increase in clock frequency that results in higher performance.
The design is becoming larger and so physical distances increase. A stage can have n× as much hardware, one set of hardware for each of n slots. However signals only go through one set of hardware, so there is no need for a reduction in clock frequency by a factor of n. The problem is that physical distances are increasing, forcing paths to be longer.
(d) A company is preparing a run of the SPEC benchmarks for their new system. While trying to tweak compiler flags to get the best performance they discover a new optimization technique and implement it in their compiler. They re-test with that compiler and disclose the test results. When is the use of the modified compiler allowed under SPEC rules? When isn’t that allowed under SPEC rules?
... provided that the compiler is seriously made available to the public. This is beneficial because the modified compiler generates better code than the old one.
... isn’t allowed if the compiler is not made public, or not seriously marketed as a product. (For example, if the compiler has a product number but does not appear in any catalog or promotional material.) Ordinarily a company would be happy to market a better compiler. If they are not doing so it might be because the compiler generates buggy code when using the new optimizations. So it is not beneficial because the compiler, though it works on the SPEC benchmarks, would generate buggy code when compiling anything else. That means that the performance numbers obtained on SPEC code do not reflect what a user might obtain on other code.