# COA 2027 Rank-Decider: Write-Back Dirty Evictions, VIPT Cache Constraint & 2-Bit Branch Predictors
Exam: GATE Computer Science & Information Technology (GATE CS)
Subject: Computer Organization & Architecture
Canonical URL: https://gateandnet.com/exams/gate-cs/computer-organization/cache-write-policies-vipt-and-branch-prediction

> Write-Through vs Write-Back + Write-Allocate memory traffic numericals, Virtually Indexed Physically Tagged (VIPT) synonym-free page-size bound, 1-bit vs 2-bit saturating branch predictors, and MSI/MESI coherence.

## 1. Write-Through vs Write-Back Memory Traffic (Classic 2-Mark GATE NAT)

| Policy Pair | On Write Hit | On Write Miss | Extra Metadata per Cache Line |
| :--- | :--- | :--- | :---: |
| **Write-Through + No-Write-Allocate** | Updates Cache **AND** Main Memory | Writes directly to Main Memory only | Valid bit ($1$ bit) |
| **Write-Back + Write-Allocate** | Updates Cache only, sets **`Dirty = 1`** | Fetches block into Cache, then writes (`Dirty = 1`) | Valid ($1$) + **Dirty ($1$)** bits |

> [!TRAP]
> **Dirty-Bit Eviction Trap:** In a **Write-Back** cache, a read or write miss that evicts a **clean** block (`Dirty = 0`) performs **$1$** memory block transfer (fetch new block). If the evicted victim is **dirty** (`Dirty = 1`), it performs **$2$** memory block transfers (write back dirty victim + fetch new block)!

## 2. Virtually Indexed, Physically Tagged (VIPT) L1 Caches

Why do modern CPUs use **VIPT** for L1 caches? Because bits `[Page_Offset - 1 : 0]` are **identical** in Virtual and Physical addresses! If `Set_Index + Block_Offset <= Page_Offset`, the CPU indexes the L1 SRAM sets **in parallel** with the TLB translation — achieving virtual-cache speed with physical-cache tag safety and zero aliasing!
- **Example:** With $4\text{ KB}$ ($2^{12}$) pages and an $8$-way set-associative L1 cache, maximum alias-free VIPT cache size is $8 \times 4\text{ KB} = \mathbf{32\text{ KB}}$ (exact Intel/ARM L1 design!).

## 3. Dynamic Branch Prediction: 1-Bit vs 2-Bit Saturating Counter

Consider an inner loop executing $N$ iterations per outer-loop invocation:
- **1-Bit Predictor:** Mispredicts **twice** per outer invocation — once when exiting the loop ($T \to NT$), AND once upon **re-entering** the loop on the next outer pass! Steady-state misprediction rate $= \mathbf{\frac{2}{N}}$.
- **2-Bit Saturating Counter (`00 SNT, 01 WNT, 10 WT, 11 ST`):** Requires **two consecutive wrong outcomes** to flip prediction! Exiting the loop moves `11 (ST) -> 10 (WT)` (still predicts Taken on next entry!), so steady-state misprediction rate drops in half to **$\frac{1}{N}$**!

## Solved Practice Questions & PYQs

### [GATE CS 2027 Expected NAT | NAT]
A processor uses $4\text{ KB}$ virtual pages and a **Virtually Indexed, Physically Tagged (VIPT)** L1 data cache with $64\text{-byte}$ cache blocks. To avoid virtual aliasing without OS page coloring (so Set Index + Block Offset $\le$ Page Offset), what is the **minimum set-associativity $K$** required for a **$64\text{ KB}$** L1 cache?
**Correct Answer:** 16
**Solution:** Zero-aliasing VIPT requires $\frac{\text{Cache Size}}{K} \le \text{Page Size} \implies \frac{64\text{ KB}}{K} \le 4\text{ KB} \implies K \ge \frac{64}{4} = \mathbf{16}$ ($16$-way set-associative: $6$ offset bits + $6$ set-index bits $= 12$ page-offset bits!).

### [GATE CS 2026–27 Expected | NAT]
A **Write-Back, Write-Allocate** L1 cache has hit time $1\text{ ns}$ and miss rate $5\%$. Transferring one $64\text{-byte}$ cache block to or from Main Memory takes $40\text{ ns}$, and **$30\%$ of evicted cache blocks are dirty**. What is the **Average Memory Access Time (AMAT)** in nanoseconds?
**Correct Answer:** 3.6
**Solution:** Each miss fetches the new block ($1 \times 40\text{ ns}$), and with probability $d = 0.30$ also writes back the dirty victim ($+0.30 \times 40\text{ ns}$):
$$\text{AMAT} = 1 + 0.05 \times (1 + 0.30) \times 40 = 1 + 0.05 \times 52 = 1 + 2.6 = \mathbf{3.6\text{ ns}}$$

### [GATE CS 2027 Expected | MCQ]
An inner `for` loop executes **exactly $10$ iterations** each time an outer `while` loop invokes it ($1,000$ outer invocations). What are the steady-state **branch prediction accuracies** on the inner-loop backward branch for a **1-bit predictor** vs a **2-bit saturating counter predictor**?
**Correct Answer:** A
**Solution:** Each inner-loop execution performs $9$ Taken branches + $1$ Not-Taken exit ($10$ total evaluations):
- **1-bit** mispredicts on exit **AND** on re-entry ($2/10$ mispredictions $\implies \mathbf{80\%}$ accuracy).
- **2-bit** stays in Weakly-Taken on exit, mispredicting **only on exit** ($1/10$ mispredictions $\implies \mathbf{90\%}$ accuracy)!
