CS704 – Advanced Computer Architecture: Midterm Important Subjective (27 Solved Q&As)
Virtual University of Pakistan • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS704 Course Page · CS704 MCQ Pack (49 MCQs)
-
Define pipelining.
Topic: Basic Concepts
Pipelining is a technique used in advanced microprocessors in which the processor begins executing a second instruction before the first has been completed. Several instructions are in the pipeline simultaneously, each at a different processing stage. The pipeline is divided into segments, and each segment executes its operation concurrently with the other segments. When a segment completes an operation, it passes the result to the next segment and fetches the next operation from the preceding segment, so the final results of the instructions emerge at the end of the pipeline in rapid succession.
-
What is an instruction cycle?
Topic: Basic Concepts
An instruction cycle (also called the fetch-and-execute cycle, fetch-decode-execute cycle, or FDX) is the basic operation cycle of a computer. It is the process by which a computer retrieves a program instruction from its memory, determines what actions the instruction requires, and carries out those actions.
-
What is a finite state machine?
Topic: Basic Concepts
A finite-state machine (FSM), or finite-state automaton, is a mathematical model of computation used to design both computer programs and sequential logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states at any given time.
-
What is a branch predictor? Why is it used?
Topic: Basic Concepts
In computer architecture, a branch predictor is a digital circuit that tries to guess which way a branch (e.g. an if-then-else structure) will go before this is known for sure. The purpose of the branch predictor is to improve the flow in the instruction pipeline: by predicting the branch outcome and its target early, the pipeline can keep fetching useful instructions instead of stalling or fetching instructions that will have to be discarded.
-
We wish to compare machine A and machine B executing a program P. Measurements: machine A takes 2 seconds and executes 5 × 10⁹ instructions; machine B takes 1.5 seconds and executes 6 × 10⁹ instructions. Find the instruction execution rate (instructions per second) of each machine.
Topic: Performance Measurement
Execution rate = Instructions executed / Execution time. Machine A: 5 × 10⁹ / 2 = 2.5 × 10⁹ instructions per second. Machine B: 6 × 10⁹ / 1.5 = 4 × 10⁹ instructions per second. Machine B has the higher instruction execution rate.
-
Computer A has a clock cycle time of 250 ps and a CPI of 2.0 for some program, and computer B has a clock cycle time of 500 ps and a CPI of 1.2 for the same program. Which computer is faster for this program, and by how much?
Topic: Performance Measurement
Execution time ET = IC × CPI × CT. For A: ET_A = IC × 2.0 × 250 ps = 500 × IC ps. For B: ET_B = IC × 1.2 × 500 ps = 600 × IC ps. Computer A has the smaller execution time, so A is faster. A is 600/500 = 1.2 times faster than B for this program.
-
For program 1, machine M1 (clock rate 3 × 10⁹ Hz) executes 5 × 10⁹ instructions in 2.0 s and machine M2 (clock rate 5 × 10⁹ Hz) executes 6 × 10⁹ instructions in 1.5 s. Find (a) the execution rate of each machine and (b) the CPI of each machine.
Topic: Performance Measurement
a) Execution rate on M1 = 5 × 10⁹ / 2.0 = 2.5 × 10⁹ IPS. Execution rate on M2 = 6 × 10⁹ / 1.5 = 4 × 10⁹ IPS. b) CPI = Execution time × Clock rate / Instruction count. CPI on M1 = 2.0 × 3 × 10⁹ / (5 × 10⁹) = 1.2 cycles per instruction. CPI on M2 = 1.5 × 5 × 10⁹ / (6 × 10⁹) = 1.25 cycles per instruction.
-
Find the die yield for a processor chip with die size 380 mm², an estimated defect rate of 0.75 defects per cm², and α = 4.
Topic: Performance Measurement
The die area is 380 mm² = 3.8 cm², so the average number of defects per die is 0.75 × 3.8 = 2.85. Yield = (1 + Defects per die / α)^(−α) = (1 + 2.85/4)^(−4) = (1.7125)^(−4) ≈ 0.116. Only about 11.6% of the dies on a wafer are expected to be defect-free.
-
Write the code to compute C = A + B on stack, accumulator, register-memory and register-register machines, and compute the total code size for each. (Instruction sizes in bits are shown with each instruction.)
Topic: Instruction Set Design
The code sequences and total code sizes are: Stack: Push A (72), Push B (72), Add (8), Pop C (72) — total 224 bits. Accumulator: Load A (72), Add B (72), Store C (72) — total 216 bits. Register-memory: Load R1, A (80), Add R2, R1, B (88), Store C, R2 (80) — total 248 bits. Register-register: Load R1, A (80), Load R2, B (80), Add R3, R1, R2 (80), Store C, R3 (80) — total 320 bits. The accumulator machine needs the least code for this expression, and the register-register machine the most, because it needs separate loads and a store.
-
Compare the register-register, register-memory and memory-memory instruction-set architectures, giving the advantages and disadvantages of each.
Topic: Instruction Set Design
Register-register: Advantages — simple, fixed-length instruction decoding; simple code generation; a similar number of clock cycles per instruction. Disadvantages — higher instruction count than memory-reference architectures; lower instruction density leads to larger programs. Register-memory: Advantages — data can be accessed without a separate load first; the instruction format is easy to encode. Disadvantages — operands are not equivalent, since a source operand held in a register is destroyed in the operation; encoding a register number and a memory address in each instruction may restrict the number of registers; CPI varies with operand location. Memory-memory: Advantages — most compact code; does not waste registers for temporary storage. Disadvantages — large variation in instruction size; large variation in work per instruction; a memory bottleneck caused by the memory accesses.
-
An instruction format has a 5-bit opcode field. When the operand 2 field is all zeros, each opcode takes on a new meaning. The mode field is 2 bits and the w/b field is 1 bit. How many opcodes are possible in total? Suggest an efficient way to provide even more opcodes.
Topic: Instruction Set Design
i) The opcode field has 5 bits, so there are 2^5 = 32 basic opcodes. ii) When the operand 2 field is all zeros, each original opcode takes on a new meaning, giving 32 additional opcodes. iii) The mode field is 2 bits, giving 2^2 = 4 modes; for each mode a whole class of opcodes is available. iv) The w/b field is 1 bit, giving 2 values, each again providing a whole class of opcodes. Total opcodes = (32 + 32) × 4 × 2 = 512. To provide still more opcodes, some functionality must be sacrificed. The mode and w/b fields cannot be reduced, and the operand fields need 4 bits to address sixteen general-purpose registers. The same escape technique can, however, be applied to operand 1: if operand 1 is not allowed to use register R15, then an all-ones (1111) operand 1 field can give every original opcode yet another new meaning. The total becomes (32 + 32 + 32) × 4 × 2 = 768 opcodes — an increase of 256 opcodes, at the cost of sacrificing R15 in the operand 1 field.
-
We have a single-stage, non-pipelined machine with a cycle time of 5 ns and a pipelined machine with 5 pipeline stages and a cycle time of 1 ns. Assuming no stalls, what is the speedup of the pipelined machine over the single-stage machine?
Topic: Pipelining
With no stalls, the non-pipelined machine takes 5 ns per instruction while the pipelined machine completes an instruction every 1 ns. Speedup = 5 ns / 1 ns = 5.
-
For the machines of the previous question, if the pipeline stalls 1 cycle for 40% of the instructions, what is the speedup now?
Topic: Pipelining
Stalls increase the effective CPI of the pipelined machine to 1 + 0.4 × 1 = 1.4. Speedup = (1 × 5 ns) / (1.4 × 1 ns) = 5 / 1.4 ≈ 3.58. In general, speedup = pipeline depth / (1 + stall cycles per instruction).
-
Given the stage delays IF = 150 ps, ID = 70 ps, register read = 60 ps, ALU = 200 ps, memory read = 60 ps and register write = 150 ps: (a) what is the length of the clock cycle for the load instruction lw in a single-cycle datapath? (b) What is the frequency of the processor? (c) What would be the fastest clock cycle for a 5-stage pipeline, and how much faster is the pipelined datapath?
Topic: Pipelining
For lw, the clock cycle must accommodate all the stages: Time(lw) = Time(IF) + Time(ID + register read) + Time(ALU) + Time(memory read) + Time(register write) = 150 + (70 + 60) + 200 + 60 + 150 = 690 ps. The clock frequency is 1 / 690 ps ≈ 1.45 GHz. For a 5-stage pipeline, the fastest clock cycle is set by the slowest stage, which is 200 ps, giving a frequency of 1 / 200 ps = 5 GHz. The pipelined datapath is therefore 690 / 200 = 3.45 times faster than the single-cycle datapath (equivalently, 5 GHz / 1.45 GHz ≈ 3.45).
-
What is the difference between a branch instruction and a jump instruction?
Topic: Branch Prediction
A branch instruction can be an unconditional branch, which always results in branching, or a conditional branch, which may or may not cause branching depending on some condition. Branch instructions are always relative to the current program counter. Jump instructions, by contrast, modify the program counter so that execution continues at a specified memory address, (almost) regardless of the value of the current program counter.
-
What is the impact of increasing the size of the branch-prediction buffer on two branches in a program?
Topic: Branch Prediction
A single predictor predicting a single branch is generally more accurate than the same predictor serving more than one branch instruction, and it is less likely that two branches in a program will share a single predictor. Therefore, increasing the size of the prediction buffer does not have a significant effect on two branches in a program.
-
A program core consists of five conditional branches with the following outcomes for one execution (T = taken, N = not taken): Branch 1: T-T-T; Branch 2: N-N-N-N; Branch 3: T-N-T-N-T-N; Branch 4: T-T-T-N-T; Branch 5: T-T-N-T-T-N-T. Each branch has its own prediction buffer, initialised to the same state before each execution. List the predictions and accuracies for: (a) always taken; (b) a 2-bit predictor initialised to weakly predict taken.
Topic: Branch Prediction
Always taken: Branch 1 (T-T-T): 3/3 = 100%. Branch 2 (N-N-N-N): 0/4 = 0%. Branch 3 (T-N-T-N-T-N): 3/6 = 50%. Branch 4 (T-T-T-N-T): 4/5 = 80%. Branch 5 (T-T-N-T-T-N-T): 5/7 ≈ 71%. Overall: 15 correct out of 25 outcomes = 60%. 2-bit predictor initialised to weakly predict taken (predicts taken in the two 'taken' states; one wrong outcome moves it one step towards not-taken): Branch 1: predictions T, T, T — 3/3 = 100%. Branch 2: predictions T, N, N, N — 3/4 = 75%. Branch 3: predictions T, T, T, T, T, T — the alternating pattern keeps the predictor in a taken state, so only the three T outcomes are correct — 3/6 = 50%. Branch 4: predictions T, T, T, T, T — 4/5 = 80%. Branch 5: predictions T, T, T, T, T, T, T — 5/7 ≈ 71%. Overall: 18 correct out of 25 = 72%. The 2-bit predictor performs better overall because it recovers from the consistently not-taken branch 2, which the always-taken scheme never predicts correctly.
-
What is the penalty in clock cycles when the branch target buffer (BTB) stores the target instruction of an unconditional branch? Determine the improvement obtained from branch folding for unconditional branches.
Topic: Branch Prediction
Storing the target instruction of an unconditional branch in the BTB effectively removes one instruction: if there is a BTB hit in instruction fetch and the target instruction is available, that instruction is fed into decode in place of the branch instruction. The penalty is therefore −1 cycle — in other words, a performance gain of 1 cycle. If the BTB stores only the target address, fetch still has to retrieve the new instruction, giving a CPI term of 5% × (90% × 0 + 10% × 2) = 0.01 for unconditional branches (which are 5% of instructions). If the BTB stores the target instruction, the CPI term becomes 5% × (90% × (−1) + 10% × 2) = −0.035; the negative sign shows that it reduces the overall CPI. The hit percentage needed just to break even is 20%.
-
Describe static branch prediction as used in the ARM11 MPCore processor, and explain how dynamic prediction differs from it.
Topic: Branch Prediction
The second level of branch prediction in the ARM11 MPCore processor uses static branch prediction, which is based solely on the characteristics of the branch instruction and uses no history information. It predicts that all forward conditional branches are not taken and all backward branches are taken, and around 65% of all branches are preceded by enough non-branch cycles to be completely predicted. Dynamic prediction, in contrast, works by caching the previously seen branches in a BTAC (branch target address cache) and using their recorded behaviour; like all caches it suffers a compulsory miss on the first encounter with a branch, plus capacity and conflict misses. In the ARM11 design a static predictor is added alongside the dynamic predictor to counter these misses: it handles only branches that the dynamic predictor has not predicted, using the direction of the branch (the sign of the branch offset) as the prediction rule.
-
The corresponding instructions for MIPS are: ADD R3, R1, R2; SW R3, 12(R0); LW R4, 0(R0); ADD R5, R1, R4. Identify the dependencies and show the execution of these instructions on a per-cycle basis.
Topic: Dependences and Scheduling
The dependences are true (RAW) dependences: I1 (ADD R3) writes R3, which I2 (SW) reads — a RAW dependence on R3. I3 (LW) writes R4, which I4 (ADD R5) reads — a RAW dependence on R4. There are no WAR or WAW dependences, since no register is written twice and no register is written after being read, except that I1 and I4 both read R1 without writing it. The store I2 writes memory address 12 + R0 while the load I3 reads address 0 + R0, so there is no memory dependence. Execution in a 5-stage pipeline (IF, ID, EX, MEM, WB) with forwarding: Cycle 1: I1 IF. Cycle 2: I1 ID, I2 IF. Cycle 3: I1 EX, I2 ID, I3 IF. Cycle 4: I1 MEM, I2 EX, I3 ID, I4 IF. Cycle 5: I1 WB, I2 MEM, I3 EX, I4 ID. Cycle 6: I2 WB, I3 MEM, I4 stalls (load-use hazard: R4 is only available at the end of I3's MEM stage). Cycle 7: I3 WB, I4 EX (using the forwarded value of R4). Cycle 8: I4 MEM. Cycle 9: I4 WB. The forwarding of R3 from I1 removes any stall between I1 and I2, but one stall cycle is unavoidable between the load I3 and its use in I4.
-
What is meant by anti-dependence?
Topic: Dependences and Scheduling
An anti-dependence occurs between an instruction that reads a register (or memory location) and a subsequent instruction that writes a new value to the same location. Equivalently, two instructions have an anti-dependence if swapping their order would result in a true dependence. For example, an anti-dependence exists between a sw instruction, which reads $4, and a later or instruction, which overwrites $4 with a new value.
-
What is loop normalisation? How does a compiler find dependences between array references? Explain the GCD test and the idea of an affine index.
Topic: Dependences and Scheduling
Normalising the loop means rewriting it so that it starts at a standard value (usually with unit stride), which makes dependence analysis simpler. The compiler detects dependences using a dependence analysis algorithm, which works on the assumptions that the array indices are affine and that the GCD of two affine indices exists. An array index is affine if it can be written in the form a·i + b, where a and b are constants and i is the loop index variable; for example, in X[2i + 3] = X[2i] × 5.0 the index is affine with a = 2 and b = 3. In the GCD test, a dependence between the references a·i + b and c·i + d is possible only if GCD(c, a) divides (d − b). For example, in the loop for (i = 1; i < 50; i++) A[2i] = a[100i + 1], we have a = 2, b = 0, c = 100 and d = 1, so GCD(2, 100) = 2 and d − b = 1; since 2 does not divide 1, the GCD test proves that no dependence can exist. This matches reality: the loop reads a[101], a[201], …, a[5001] and writes A[2], A[4], …, A[100], so the locations read and written never overlap.
-
Differentiate between static scheduling and dynamic scheduling.
Topic: Dependences and Scheduling
A static schedule is a fixed list containing the order of the processes (tasks) and the durations for which they are scheduled; it never changes, even if a task has nothing to do or another task is missing its deadlines. In static (compiler) scheduling, when there is a stall (hazard) no further instructions are issued, and the stall is enforced by the hardware. In dynamic scheduling, the scheduler decides at run time which task or instruction to execute next, based on the tasks currently requesting the processor — the earliest-deadline-first scheduler is an example. With dynamic (hardware) scheduling, instructions following the one that stalls can still issue if they produce no structural hazards or dependences.
-
How do the operands and operations for media and signal processing differ from ordinary 64-bit integer processing?
Topic: Advanced Topics
Operands: A vertex is a common 3D data type in graphics applications with four components — (x, y, z) and w, used for colour or hidden surfaces; vertex values are usually 32-bit floating-point values, and three vertices specify a graphics primitive such as a triangle. A pixel is typically 32 bits, consisting of four 8-bit channels: R (red), G (green), B (blue) and A (attribute, e.g. transparency). DSPs add fixed-point data, representing fractions between −1 and +1, and blocked floating point, in which a block of variables shares a common exponent; accumulators are registers that are wider, to guard against round-off error in fixed-point arithmetic. Operations: Data for multimedia operations is often narrower than the 64-bit data word, and is normally in single precision rather than double precision. SIMD (single-instruction multiple-data) or vector instructions exploit this: a partitioned add on 16-bit data with a 64-bit ALU performs four 16-bit adds in a single clock cycle. The hardware cost is that carries between the four 16-bit partitions of the ALU must be prevented, and in paired-single operations (two 32-bit floating-point operations) the two partitions must be insulated so that operations on one half do not affect the other.
-
A MIPS designer wanted the integer multiply and divide instructions to operate in parallel with other integer instructions. Since multiply and divide take multiple clock cycles, it is argued whether precise exceptions can be implemented. Classify each statement as completely accurate, partially accurate or wrong, and justify: (i) It does not matter whether multiply and divide can raise an exception. The fact that they could still be executing and not completed when some other instruction raised an exception makes it impossible to implement precise exceptions. (ii) Although it is true that a multiply and divide could still be executing, it is guaranteed to complete shortly, and when it does, any exception raised for an instruction following a multiply or divide will then be precise.
Topic: Advanced Topics
Statement (i) is partially accurate. It is true that a multiply or divide instruction may still be executing when a following instruction raises an exception, and this out-of-order completion does make precise exceptions difficult: the machine state must be restorable to the point of the excepting instruction. But it is wrong to conclude that precise exceptions are impossible — the hardware can delay taking the exception until the outstanding multiply/divide completes, or make those instructions restartable, and thereby still present a precise state. Statement (ii) is wrong. Merely letting the multiply/divide run to completion does not make the exception precise: by that time, instructions following the multiply/divide — including the excepting instruction itself — may already have modified registers or memory, so the machine state would no longer match the sequential state at the excepting instruction. To implement precise exceptions the processor must also prevent, buffer or undo the effects of those later instructions (for example by stalling issue, or by holding results until all earlier instructions are known to be exception-free).
-
In a code segment, only the values b and c are live after the segment. Find any values that are not live, and identify any statement that the compiler can delete.
Topic: Advanced Topics
A value is live after a code segment if it will be used subsequently. In the given code segment, only b and c are live afterwards, so the values a, d, e and f are not needed subsequently. However, a and f are needed to compute b and a possible final value of c, so the statements computing them (statements 1, 2, 3, 5, 6 and 7) are needed because they form part of the b and c calculation chain. Statement 4 produces a value that does not contribute to any live value and is itself not live, so statement 4 may be deleted by the compiler.
-
What do the MIPS instructions MOV.S and MOV.D do?
Topic: Advanced Topics
MOV.S copies a single-precision register to another register of the same type, and MOV.D copies a double-precision register to another register of the same type. Both MOV.S and MOV.D are floating-point instructions in MIPS.