Compilers
If a loop with 100 iterations is unrolled by replicating its body four times, how many counter checks and branches remain? (Assume 100 is divisible by 4.)
- A100
- B25
- C400
Show answer and explanation
Answer: B. 25
With four copies of the body, each iteration does the work of four original iterations, so there are 100 ÷ 4 = 25 iterations and only 25 counter checks and branches, a quarter of the original overhead. When the count is not divisible by 4, a short loop is appended to handle the remainder. 100 is the count without unrolling, and 400 mistakenly multiplies.
- A. 100 is the count without unrolling.
- B. Correct. 100 ÷ 4 = 25.
- C. 400 is a mistaken multiplication.