Four interview questions that mix VHDL coding, FPGA memory choices and back-of-the-envelope performance arithmetic. They test whether you can model hardware in a language, judge when to hand-write a memory, and reason about throughput with a few numbers.
- If you have to write your own code (i.e. you do not have a library of memory components or a special component generation tool, what datastructures in VHDL would you use when creating a register file?
- When using VHDL for an FPGA, under what circumstances is it better to write your own VHDL code for memory, rather than instantiate memory components from a library?
- In this question there is a network that runs a protocol called BigLan. You are designing a router called the DataChopper that routs packets over the network running BigLan (i.e. they're BigLan packets). The BigLan network protocol runs at a data rate of 160 Mbps (Mega bits per second). Each BigLan packet contains 100 Bytes of routing information and 1000 Bytes of data.
You are working on the DataChopper router, which has the following performance numbers:
75MHz - clock speed
500 number of clock cycles to process the routing information for a packet
4 CPI for a byte of data - Which has a higher maximum throughput router, and how much faster is it?
- Explain the effect of an increase in packet length on the performance of the DataChopper (as measured in the maximum number of bits per second that it can process) assuming the header
remains constant at 100 bytes. - If performance doubles every two years, by what percentage does performance go up every month? This question is similar to compound growth from your economics class.
The original post gave no answers and invited discussion in the comments. Worked answers have now been added below so you can check your own; the comments are still open for other approaches.
What each question is really testing
- Register file in VHDL: do you know how VHDL models an array of registers, and how a synthesis tool turns that into flip-flops or memory?
- Write your own memory or instantiate one: do you understand the trade between portability and access to vendor-specific features?
- BigLan router: can you turn clock speed and cycles per byte into bits per second, and spot the fixed overhead that limits short packets?
- Doubling every two years: do you know that growth compounds, so the monthly rate is a root, not a division?
Short answers
- An array type of
std_logic_vector(an array of registers), written in a clocked process and read by index. - When the memory is small, when the design must be portable between FPGA vendors or to an ASIC, when you want a fast and readable simulation model, or when the synthesis tool can infer the memory well anyway.
- The network, at 160 Mb/s, is faster than the DataChopper, which handles about 147 Mb/s of packet bits. Longer packets help the router, but it can never pass 150 Mb/s.
- About 2.93% per month.
Deep dive: the numbers and details
This part holds the VHDL code, the throughput arithmetic and the compound growth calculation. Skip it if the short answers are all you need.
Question 1: a register file in VHDL
Declare an array type whose elements are the register width, then a signal of that type. Writes happen in a clocked process; reads can be combinational (asynchronous) for a classic register file with two read ports.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity regfile is
generic (WIDTH : natural := 32; DEPTH : natural := 32; AW : natural := 5);
port (
clk : in std_logic;
we : in std_logic;
waddr : in unsigned(AW-1 downto 0);
wdata : in std_logic_vector(WIDTH-1 downto 0);
raddr1 : in unsigned(AW-1 downto 0);
raddr2 : in unsigned(AW-1 downto 0);
rdata1 : out std_logic_vector(WIDTH-1 downto 0);
rdata2 : out std_logic_vector(WIDTH-1 downto 0));
end entity;
architecture rtl of regfile is
type reg_array is array (0 to DEPTH-1) of std_logic_vector(WIDTH-1 downto 0);
signal regs : reg_array := (others => (others => '0'));
begin
process (clk)
begin
if rising_edge(clk) then
if we = '1' then
regs(to_integer(waddr)) <= wdata;
end if;
end if;
end process;
rdata1 <= regs(to_integer(raddr1)); -- asynchronous read port 1
rdata2 <= regs(to_integer(raddr2)); -- asynchronous read port 2
end architecture;
Points an interviewer looks for:
- A signal of an array type, not a variable inside a process, so the storage is visible to the concurrent read statements.
numeric_stdandto_integerfor the index, not the non-standardstd_logic_arithpackages.- Awareness of what the tool will build. On AMD (Xilinx) FPGAs, for example, an array with asynchronous reads maps to LUT-based distributed RAM, while a synchronous (registered) read lets the tool use block RAM. The Vivado synthesis guide's section on RAM HDL coding techniques covers the coding styles, the choice between distributed and block RAM, and the RAM_STYLE attribute that forces one or the other.
- For a 32 x 32 register file with two read ports and one write port, the raw storage is 1,024 bits. If the tool builds it from flip-flops, the read ports become two 32-to-1 multiplexers, each 32 bits wide.
A record type is the other useful data structure, when each entry holds several fields (for example a valid bit, a tag and data).
Question 2: write your own memory or instantiate a library component?
| Write your own (inferred) memory when | Instantiate a vendor component when |
|---|---|
| The design must be portable across FPGA vendors, or move to an ASIC later | You need a feature the tool cannot infer reliably: built-in ECC, special cascade modes, asymmetric port widths on some families, or a specific read-during-write behavior |
| The memory is small (a few registers or a small FIFO) and fits in LUTs or flops | The memory is large and must land in block RAM with a guaranteed configuration |
| You want a fast, readable behavioral model for simulation | You need guaranteed timing, such as an output register inside the block RAM |
| The synthesis tool documents inference templates you can follow | A team standard or a verified IP flow requires the generated component |
The common modern answer is: infer by default, using the vendor's documented coding templates, and instantiate only when a feature or timing guarantee requires it.
Question 3: the BigLan router
Assume, as the question states, that the 500 cycles cover the 100-byte routing header and the 4 cycles per byte apply to the 1,000 data bytes.
Cycles per packet = 500 + 4 x 1000 = 4,500 cycles
Time per packet = 4,500 / 75 MHz = 60 microseconds
Bits per packet = (100 + 1000) x 8 = 8,800 bits
Router throughput = 8,800 bits / 60 us = 146.7 Mb/s
Data-only rate = 8,000 bits / 60 us = 133.3 Mb/s
Network rate = 160 Mb/s
The BigLan network is faster: 160 / 146.7 = 1.09, about 9% faster than the DataChopper. The router cannot keep up with a fully loaded link.
The question wording, "which has a higher maximum throughput router", reads as if a second router was compared in the original source. With only the data given here, the comparison that can be made is network against router, as above.
Effect of packet length. With D data bytes and the 100-byte header fixed:
Throughput(D) = 75e6 x 8 x (100 + D) / (500 + 4D) bits per second
| Data bytes D | Cycles | Throughput (all packet bits) |
|---|---|---|
| 100 | 900 | 133.3 Mb/s |
| 500 | 2,500 | 144.0 Mb/s |
| 1,000 | 4,500 | 146.7 Mb/s |
| 4,000 | 16,500 | 149.1 Mb/s |
| Very large | about 4D | approaches 150 Mb/s |
Longer packets spread the fixed 500-cycle header cost over more bytes, so throughput rises, but it is capped by the per-byte cost: 75 MHz / 4 cycles = 18.75 million bytes per second, or 150 Mb/s. Since 150 is below 160, no packet length lets this router match the network. To get there, the per-byte cost must fall below 75 x 8 / 160 = 3.75 cycles, or the clock must rise above 160 / 8 x 4 = 80 MHz.
Question 4: doubling every two years, per month
Growth compounds, so the monthly factor r satisfies r24 = 2:
r = 2^(1/24) = e^(ln 2 / 24) = e^0.02888 = 1.02930
Performance rises by about 2.93% per month. The tempting wrong answer is 100% / 24 = 4.17%, which ignores compounding and would give 2.67 times growth after 24 months (1.041724), not 2 times. The same method gives the yearly rate: 21/2 = 1.414, or 41.4% per year.
Common mistakes
- Using a process variable for the register array, so the read logic cannot see it.
- Forgetting the 500-cycle header cost in question 3, which overstates the router's rate. Even with no header at all, 8 bits per 4 cycles at 75 MHz is only 150 Mb/s.
- Dividing 100% by 24 in question 4.
You may use the comments feature below to discuss the questions further.


Your comments will be moderated before it appears here.