Register Files
A single register stores one data word. A central processing unit requires a bank of registers that can supply operands and capture execution results simultaneously.
A multi-port register file organizes $N$ registers of $W$ bits to support concurrent read and write transactions.
External Interface Architecture
A standard processor register file provides two read ports and one write port (2R1W) to execute three-operand instructions (such as ADD rd, rs1, rs2) in a single clock cycle:
| Processor Architecture | Register Count ($N$) | Word Width ($W$) | Read Ports | Write Ports |
|---|---|---|---|---|
| RISC-V RV32I | 32 | 32 bits | 2 | 1 |
| ARM AArch64 | 31 plus SP | 64 bits | 2 | 1 |
| x87 FPU | 8 | 80 bits | 2 | 1 |
| AVX-512 | 32 | 512 bits | 2 | 1 |
Each read port requires an address input (RAddr) and a data output (RData).
The write port requires an address input (WAddr), a data input (WData), and a write enable (WE). All write operations align with the system clock.
Write Circuitry
The storage core contains $N$ individual $W$-bit parallel-load registers. The write data bus connects to the data inputs of all $N$ registers in parallel.
An address decoder activates the load enable input of the target register when write enable asserts:
$$WE_i = \text{WriteEnable} \cdot (WAddr == i)$$
When $\text{WriteEnable} = 0$, no registers load data. When $\text{WriteEnable} = 1$, only the decoded register captures input data on the active clock edge.
Read Circuitry
Read operations are combinational. Each read port consists of an independent $W$-bit wide $N$-to-1 multiplexer driven by its respective read address:
$$RData_1 = \text{Reg}[RAddr_1] \qquad RData_2 = \text{Reg}[RAddr_2]$$
Multiple read ports can read the same register address simultaneously. Data appears at the read port output after multiplexer propagation delay ($t_{\text{mux}}$) without waiting for a clock edge.
Figure 1 illustrates a 4-register file with two read ports and one write port.
In the RISC-V architecture, register x0 evaluates to constant zero. Hardware designers omit physical flip-flops for register 0 and wire the multiplexer input to logic 0.
Simultaneous Read and Write Transactions
What occurs when a read port and a write port access the same register address in the same clock cycle?
In a standard register file, the read multiplexer connects to the flip-flop outputs ($Q$). The flip-flops do not capture new data until the clock edge at the end of the cycle. Therefore, the read port returns the previous stored value. This behavior is called read-before-write.
If a system requires new data during the same clock cycle, designers add an address comparator and a bypass multiplexer. When write and read addresses match, the bypass multiplexer routes WData directly to RData.
In pipelined processors, data hazards occur across instruction boundaries. For example, an instruction writing register x3 in pipeline stage 5 executes several cycles before a subsequent instruction reads x3 in stage 2.
Pipelines resolve this hazard using pipeline forwarding (Figure 2). Forwarding multiplexers route execution results directly from the ALU or memory stage back to execution inputs without waiting for register file writeback.
Hardware Scaling Costs
Adding ports increases circuit complexity:
- Each read port adds an $N$-to-1 multiplexer for every bit ($W \times N$-to-1 multiplexers).
- Each write port adds an address decoder and an additional input to the load multiplexer of every flip-flop.
Total silicon area scales proportionally with:
$$\text{Area} \propto (R + W) \times W \times N$$
For this reason, general-purpose processors limit register ports to two reads and one write. Superscalar out-of-order processors requiring four or more write ports use large, power-intensive register files.
For capacities exceeding 64 to 128 words, flip-flop arrays become inefficient in silicon area. Large memory arrays use dedicated Static Random-Access Memory (SRAM) architectures.
Practice Exercises
Problem 1
A register file contains 32 registers of 32 bits each, with 2 read ports and 1 write port. Calculate write address width and total flip-flop count.
Solution
Calculate dimensions:
- Write address width: $n = \log_2 32 = 5\text{ bits}$.
- Total storage flip-flops:
$$32\text{ registers} \times 32\text{ bits} = 1024\text{ flip-flops}$$
Peripheral circuitry requires a 5-to-32 write decoder and two 32-to-1 read multiplexers of 32 bits width.
Problem 2
In a 4-register file, the write enable input is low ($\text{WE} = 0$), but the write address and write data lines contain active signals. Describe the circuit response.
Solution
Each register load enable evaluates: $WE_i = \text{WE} \cdot (WAddr == i)$.
Because $\text{WE} = 0$, all $WE_i = 0$. None of the internal registers update. The write address and write data signals are ignored.
Problem 3
In a five-stage pipeline, instruction ADD x3, x1, x2 is followed immediately by ADD x5, x3, x4. The first instruction writes x3 in stage 5 (Writeback). The second instruction reads x3 in stage 2 (Decode). Explain how execution forwarding resolves the stale data hazard.
Solution
Without forwarding, the second instruction reads the register file three cycles before the first instruction writes x3, reading stale data.
With execution forwarding:
- Comparator logic compares the destination address of instruction 1 (
rd = x3) with the source operand addresses of instruction 2 (rs1 = x3). - When the addresses match and the write enable is asserted, the forwarding multiplexer routes the ALU result from stage 3 directly to the ALU operand input of stage 3.
- The comparison logic excludes register
x0becausex0is hardwired to zero.
The next article examines Static RAM (SRAM) architectures and the six-transistor storage cell.