Question bank · RTL / Front-end Design Engineer
RTL Design interview questions
The 100 questions RTL design interviewers really ask, picked from recent interview reports at chip product companies and design-service firms. Logic puzzles, Verilog traps, FSMs, clock dividers, timing numericals, CDC, FIFO depth and arbiters, each with a worked answer, the follow-up you will get next, and diagrams where they help.
How RTL Design interviews actually run
From recent interview reports at product companies and design-service firms in India and abroad. Rounds vary by company; this is the common shape.
- Online testMostly for freshers and campus drives. Aptitude, 20 to 40 digital electronics MCQs (K-maps, counters, flip-flop conversions, timing), and often basic C. Some product companies add a short Verilog section.
- Technical round 1Digital fundamentals on a whiteboard: build gates from muxes, sequence detector FSM, clock divider, edge detector, setup and hold. Often a short Verilog snippet to debug or predict.
- Technical round 2Design depth: FIFO depth numericals, synchronous and asynchronous FIFO, CDC, reset, arbiters, timing numericals, pipelining. Experienced candidates get micro-architecture and low-power questions here.
- Coding and scriptingWrite RTL live (FIFO, counter, arbiter, small datapath). Product companies often add a Python or Perl task: parse a log or CSV, count or filter lines.
- Project deep diveIn almost every report. Expect 20 to 40 minutes on your own project or internship: why each design choice, what broke, how you verified it, what you would change.
- Manager and HRTeam fit, how you handle pressure and deadlines, why this role. Senior candidates get asked about ownership and conflict.
- Be able to write a synchronous FIFO, an asynchronous FIFO, a sequence detector and a clock divider from memory, in compilable Verilog.
- Practise FIFO depth and setup/hold numericals until you can do them in two minutes with the working shown.
- For every CDC question, say the problem first (metastability, data incoherence or a lost pulse), then the fix.
- Prepare a 2-minute and a 10-minute version of each project, with one diagram you can draw.
Digital logic puzzles
1Implement NOT, AND, OR and XOR using only 2:1 multiplexers.
A 2:1 mux gives y = s ? in1 : in0. Drive the select with a and choose what goes on the data inputs:
- NOT:
in0 = 1,in1 = 0, soy = ~a. - AND:
in0 = 0,in1 = b. Whena = 0the output is 0, otherwise it isb. - OR:
in0 = b,in1 = 1. Whena = 1the output is 1, otherwise it isb. - XOR:
in0 = b,in1 = ~b. If only truebis available, make~bwith a second mux wired as NOT, so XOR takes two 2:1 muxes.
Likely follow-up: Why is a mux called a universal logic element?
Any function of n variables can be built from a 2^n:1 mux by tying the inputs to the truth-table outputs and driving the selects with the variables. With one variable folded onto the data inputs (as above), a 2^(n-1):1 mux is enough.
2Build a 4:1 mux from 2:1 muxes. How many 2:1 muxes does an N:1 mux need?
Use two 2:1 muxes on the first level, both selected by s[0] (one picks between I0/I1, the other between I2/I3). A third 2:1 mux selected by s[1] picks between their outputs. That is 3 muxes.
In general a tree of 2:1 muxes for N inputs needs N − 1 muxes, because every mux removes exactly one candidate. The depth of the tree is ceil(log2 N) mux delays.
3Design a 10:1 mux using 4:1 muxes. What is the minimum number, and how are the selects driven?
The minimum is three 4:1 muxes. Each 4:1 mux removes 3 candidates, so going from 10 inputs to 1 needs at least ceil(9 / 3) = 3.
- Mux A takes I0–I3 and mux B takes I4–I7, both selected by
s[1:0]. - Mux C (the output mux) takes A, B, I8 and I9.
- For
s = 0..7, C must pick A or B, so its select is{0, s[2]}. Fors = 8or9, it must pick I8 or I9, so its select is{1, s[0]}. - So
selC = s[3] ? {1'b1, s[0]} : {1'b0, s[2]}, which is one small 2:1 mux (or two gates) of glue logic.
Likely follow-up: What happens for s = 10 to 15?
They are don’t-cares in a 10:1 mux. Say so, and mention that in a real design you would either assert on them or define a safe default.
4Draw a CMOS NAND2 gate. Why are NAND gates preferred over NOR gates in CMOS?
A NAND2 has two PMOS transistors in parallel from VDD to the output and two NMOS transistors in series from the output to ground. The output goes low only when both A and B are 1.
A NOR2 is the opposite: PMOS in series, NMOS in parallel. Hole mobility is roughly 2 to 3 times lower than electron mobility, so PMOS devices are already the weak ones. Putting them in series (NOR) makes the pull-up even slower, and the fix is to make them much wider, which costs area and input capacitance. In a NAND the slow PMOS are in parallel and the fast NMOS take the series stack, so it is smaller and faster for the same drive.
5What is the minimum number of 2-input NAND gates needed to build an XOR gate?
Four. Let n1 = NAND(a, b). Then n2 = NAND(a, n1), n3 = NAND(b, n1), and y = NAND(n2, n3) = a ^ b.
Check one case: a = 1, b = 0 gives n1 = 1, n2 = NAND(1,1) = 0, n3 = NAND(0,1) = 1, y = NAND(0,1) = 1. Correct.
Likely follow-up: And XNOR?
Five NAND gates (XOR plus an inverter), or four NOR gates using the same structure as above, since the dual structure gives XNOR.
6Convert a D flip-flop into a T flip-flop and into a JK flip-flop.
Write the next-state equation of the target flop and drive D with it.
- T flip-flop:
Q+ = T ^ Q, soD = T ^ Q(an XOR in front of D). - JK flip-flop:
Q+ = J·Q' + K'·Q, soD = (J & ~Q) | (~K & Q).
The reverse question also comes up: a JK flop becomes a D flop with J = D, K = ~D, and a T flop becomes a D flop with T = D ^ Q.
7What is the difference between a latch and a flip-flop, and where are latches used on purpose?
A latch is level-sensitive: while its enable is active it is transparent and the output follows the input. A flip-flop is edge-triggered: it samples only at the clock edge. A flip-flop is usually two latches back to back (master and slave) on opposite clock phases.
Latches are used on purpose in three places:
- Clock gating cells, where a latch holds the enable stable while the clock is high (see the clock gating question).
- Time borrowing in high-speed designs: a slow stage can use part of the next stage’s time because the latch is transparent for half a cycle.
- Area and power, for example latch-based register files and memories, since a latch is roughly half a flop.
In ordinary RTL an unintended latch is a bug, usually from an incomplete if or case.
8XOR a clock with a delayed copy of itself. What do you get, and is it a good way to double a clock?
clk ^ clk_delayed produces a short pulse on every edge of the clock, rising and falling, so the pulse rate is twice the clock frequency. The pulse width equals the delay.
It is fine as a pulse generator or in an exam answer, but poor as a real clock: the width and duty cycle depend on a delay that varies with process, voltage and temperature, the clock tree and STA tools cannot time it cleanly, and duty-cycle errors on the input show up as uneven periods. A real design uses a PLL or DLL to multiply a clock.
9What is a static hazard? Remove the hazard in f = a·b' + b·c.
A static-1 hazard is a brief 0 glitch on an output that should stay 1 while one input changes. It happens because two product terms hand over through paths of different delay.
In f = a·b' + b·c, with a = 1 and c = 1, the output is 1 for both values of b. When b changes, the term a·b' turns off and b·c turns on, and if one switches before the other there is a short 0.
The fix is to add the consensus term a·c, which covers that transition on the K-map: f = a·b' + b·c + a·c. The function does not change, but the output now stays 1.
In synchronous design this glitch is harmless on data that a flop samples later. It matters on clocks, asynchronous resets and any signal that crosses a clock domain.
10How do you detect overflow when adding two signed (2’s complement) numbers?
Overflow happens only when both operands have the same sign and the result has a different sign:
assign ovf = (a[N-1] == b[N-1]) && (sum[N-1] != a[N-1]);
An equivalent test is carry_into_msb ^ carry_out_of_msb. For unsigned numbers the overflow is simply the carry out.
Range reminder: an N-bit 2’s complement number goes from -2^(N-1) to 2^(N-1) - 1, so 8 bits cover −128 to +127. To negate a number, invert all bits and add 1.
11Convert binary to Gray code and Gray to binary. Why is Gray code used in hardware?
- Binary to Gray:
g = b ^ (b >> 1), sog[i] = b[i+1] ^ b[i]and the MSB is copied. - Gray to binary:
b[N-1] = g[N-1], thenb[i] = b[i+1] ^ g[i]. This is a chain of XORs from the MSB down.
always @* begin
bin[N-1] = gray[N-1];
for (i = N-2; i >= 0; i = i - 1)
bin[i] = bin[i+1] ^ gray[i];
end
Consecutive Gray values differ in exactly one bit. When a counter value crosses a clock domain, a sampling flop that catches it mid-change sees either the old value or the new value, never a random mix. That is why asynchronous FIFO pointers are Gray coded.
12Compute the parity of a 32-bit word in hardware. How many levels of logic does it take?
Even parity is the XOR of all bits: assign parity = ^data; (reduction XOR). Synthesis builds a balanced tree of 2-input XOR gates, so 32 bits need 31 XOR gates and 5 levels (log2 32).
If a serial version is asked, keep one flop and XOR each incoming bit into it.
13How many states does a 4-bit Johnson counter have, and how is it different from a ring counter?
A Johnson (twisted ring) counter feeds the inverted output of the last flop back to the first. An N-flop Johnson counter has 2N states, so a 4-bit one has 8: 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001.
A ring counter feeds the last flop straight back and circulates a single 1, so it has only N states, but each state is one-hot and needs no decoding.
Johnson states can each be decoded with a single 2-input gate. Both counters have unused states (2^N − 2N for Johnson), so a robust design adds self-correction or a reset to escape an illegal state.
14How many flip-flops do you need for a mod-N counter, and how would you build a mod-10 counter?
You need ceil(log2 N) flops in binary, so mod-10 needs 4.
Count up and wrap at 9 synchronously:
always @(posedge clk or negedge rst_n)
if (!rst_n) cnt <= 4'd0;
else if (en) cnt <= (cnt == 4'd9) ? 4'd0 : cnt + 4'd1;
Avoid the textbook trick of using the decoded value 10 to drive an asynchronous clear on a ripple counter. The clear pulse is a glitch of uncertain width and can leave some flops uncleared.
Verilog and SystemVerilog
15Explain blocking and non-blocking assignments. What hardware do these two blocks give?
// Block A // Block B
always @(posedge clk) begin always @(posedge clk) begin
q1 = d; q1 <= d;
q2 = q1; q2 <= q1;
end end
A blocking assignment (=) updates the variable immediately, so the next line sees the new value. A non-blocking assignment (<=) evaluates the right side now but updates the left side at the end of the time step, after every block triggered by this edge has run.
- Block A:
q2gets the newq1, which isd. Synthesis gives one flop (or two flops both fed fromd). The shift register is gone. - Block B:
q2gets the oldq1. This is a proper 2-stage shift register.
The rule: use <= in clocked blocks and = in combinational always @* blocks, and never mix them on the same variable.
Likely follow-up: Swap two registers without a temporary variable.
a <= b; b <= a; in one clocked block. Both right sides are read before either left side is updated.
16What does this print, and why?
reg a;
initial begin
a = 1;
a <= 0;
$display("display a=%b", a);
$strobe ("strobe a=%b", a);
end
It prints display a=1 and then strobe a=0.
$display runs immediately in the active region, before the non-blocking update to 0 has happened. $strobe waits until the end of the time step (the postponed region), after all non-blocking updates, so it sees 0. $monitor also reports end-of-time-step values, and prints again whenever one of its arguments changes.
17Find the bug in this code.
always @(*) begin
if (sel == 2'b00) y = a;
else if (sel == 2'b01) y = b;
else if (sel == 2'b10) y = c;
end
When sel == 2'b11, y is not assigned, so it must keep its old value. A combinational block that has to remember a value becomes a latch. Synthesis warns about an inferred latch, and the design now has a level-sensitive storage element that STA and DFT handle badly.
Fix it by assigning y on every path: add a final else y = d;, or put a default at the top of the block (y = '0;) and let the if chain override it. The same applies to a case without a default, and to a block that assigns two outputs but only sets one of them in some branch.
18What is the difference between wire and reg in Verilog, and what does logic change in SystemVerilog?
A wire is a net. It has no storage, is driven continuously (by assign or a module output), and can have multiple drivers (resolved, for example, with tri-states).
A reg is a variable that holds its value between procedural assignments. It is what you assign inside always and initial blocks. Despite the name, a reg does not mean a flip-flop: a reg assigned in always @* synthesises to combinational logic.
SystemVerilog’s logic can be used in both places (continuous assign or procedural), as long as it has a single driver. That removes most wire/reg confusion. For nets with multiple drivers you still need wire (or tri).
19What is the difference between == and ===? What happens in if (x) when x is unknown?
== is logical equality. If either operand has an X or Z bit that matters, the result is X. === is case equality: it compares X and Z literally, so the result is always 0 or 1. === is for testbenches and is not synthesisable.
if (cond) treats an X condition as false and takes the else branch. That is why X bugs can hide in simulation: a block may look like it works because an unknown silently chose the else path. SystemVerilog assertions and X-propagation tools (and linting for if on uninitialised signals) catch this.
20What is a simulation-synthesis mismatch? Give two common causes.
It is when RTL simulation and the synthesised gate netlist behave differently, so your tests pass on code that is not the hardware you get.
Common causes:
- Incomplete sensitivity list in a combinational block, for example
always @(a or b)fory = a & b & c. Simulation updatesyonly whenaorbchanges; synthesis ignores the list and builds an AND3. Usealways @*oralways_comb. full_case/parallel_casepragmas, which tell synthesis something the simulator does not know.- Delays like
#5in RTL, which synthesis drops. - Initial values on registers (
reg q = 0;) that synthesis ignores for ASICs. - Reading a variable in a combinational block before it is assigned in the same block.
21What is the difference between case, casez and casex? Why is casex risky?
casecompares every bit exactly, including X and Z.caseztreats Z (or?) as a don’t-care, in both the case expression and the items.casextreats both X and Z as don’t-cares.
casex is risky because an X on the select in simulation matches the first item and hides the problem, while the real hardware does something else. Use casez with ? for wildcard decoding, or SystemVerilog case ... inside, which only treats the item’s wildcards as don’t-cares.
22Write a flip-flop with an asynchronous active-low reset, and one with a synchronous reset.
// Asynchronous reset: reset is in the sensitivity list
always @(posedge clk or negedge rst_n)
if (!rst_n) q <= 1'b0;
else q <= d;
// Synchronous reset: reset is just another input sampled at the clock edge
always @(posedge clk)
if (!rst_n) q <= 1'b0;
else q <= d;
For the async version, the if must test the reset first and the polarity must match the edge in the list (negedge rst_n with if (!rst_n)). Putting other signals in that list, or extra logic before the reset check, gives a model that synthesis cannot map to a flop.
23What is the difference between a task and a function?
| function | task | |
|---|---|---|
Time control (#, @, wait) |
Not allowed | Allowed |
| Return value | Returns one value | Uses output/inout arguments |
| Can call | Functions only | Tasks and functions |
| Synthesisable | Yes, as combinational logic | Only if it has no timing control |
In SystemVerilog, declare them automatic when they are recursive or called from parallel threads, so each call gets its own variables instead of sharing static storage.
24Which Verilog constructs are not synthesisable?
- Delays (
#10),wait, and event controls in the middle of a block. initialblocks (ignored for ASICs; some FPGA tools use them to set power-up values).- System tasks such as
$display,$random,$finishand file I/O. fork/join,force/release,realarithmetic.- Loops whose bound is not known at compile time.
===and!==.
Classes, mailboxes, queues and dynamic arrays from SystemVerilog are testbench-only too.
25How does a for loop synthesise? Write a population count (number of ones) with one.
A synthesisable for loop has a constant bound and is unrolled into parallel hardware. It is not a loop in time.
module popcount #(parameter N = 16) (
input logic [N-1:0] din,
output logic [$clog2(N+1)-1:0] ones);
always_comb begin
ones = '0;
for (int i = 0; i < N; i++)
ones = ones + din[i];
end
endmodule
This unrolls into a chain of N adders. A good synthesis tool rebalances it, but in a timing-critical path you would write an explicit adder tree (pairs, then nibbles, then bytes) to get log2 N levels.
26Why does this lose the carry, and how do you fix it?
logic [7:0] a, b, avg;
assign avg = (a + b) >> 1;
In Verilog an expression is sized to the largest operand, including the left side. Here everything is 8 bits, so a + b is computed in 8 bits, the carry is dropped, and then the shift happens. For a = b = 200 you get 72 instead of 200.
Fix: widen one operand inside the expression, for example assign avg = ({1'b0, a} + b) >> 1; or use a 9-bit intermediate logic [8:0] sum = a + b;.
A related trap: wrapping an expression in a concatenation, {a + b}, makes it self-determined, so the carry is lost even when the left side is 9 bits.
27What goes wrong when you mix signed and unsigned values in an expression?
If any operand in an expression is unsigned, Verilog evaluates the whole expression as unsigned. A negative value is then treated as a large positive number and is zero-extended instead of sign-extended.
logic signed [7:0] x = -8'sd4;
logic [7:0] y = 8'd2;
logic signed [9:0] z;
assign z = x + y; // x is treated as 252, result 254, not -2
Fix: make every operand signed ($signed(y) or $signed({1'b0, y}) if y must stay positive), and watch literals too: 8'd2 is unsigned, 8'sd2 is signed. Comparisons like if (x < 0) on an unsigned value are always false, which lint tools flag.
28What is the difference between packed and unpacked arrays in SystemVerilog?
logic [3:0][7:0] p; // packed: 4 bytes in one 32-bit vector
logic [7:0] u [4]; // unpacked: 4 separate bytes
Packed dimensions are written before the name. The whole thing is one contiguous vector: you can assign it to a 32-bit value, do arithmetic on it, or slice p[2] to get a byte. Only bit-level types (logic, bit) can be packed.
Unpacked dimensions are written after the name. Elements are separate variables; you index one element at a time and cannot treat the array as a single number. Memories are usually unpacked (logic [31:0] mem [1024]).
Ports carrying a bus of fields are usually packed; RAM models are unpacked.
29What do always_ff, always_comb and always_latch add over plain always?
They state your intent, and tools check it.
always_combinfers its own sensitivity list (including signals read inside called functions), runs once at time zero, and tools warn if it infers a latch or if a variable is driven from elsewhere.always_ff @(posedge clk ...)must describe flops: tools flag blocking timing controls inside it and multiple drivers.always_latchdocuments a deliberate latch so lint does not complain.
They also forbid a variable being written by more than one of these blocks, which catches a common multi-driver bug.
30What do unique case and priority case mean?
unique case: exactly one item matches for every value that occurs. Simulation warns if none or more than one match. Synthesis may build a parallel (one-hot style) mux with no priority.priority case: items are checked in order and at least one must match. Simulation warns if none match. Synthesis keeps the priority but may treat unlisted values as don’t-cares.
They replace the old full_case/parallel_case pragmas with checks the simulator actually enforces, so they are much safer. If the warning fires, you have found a real bug or a missing default.
31What is a race condition in Verilog? Show an example.
A race is when the result depends on the order in which the simulator runs blocks that are triggered at the same time. That order is not defined by the language.
always @(posedge clk) a = b;
always @(posedge clk) b = a;
Depending on which block runs first, both end up equal to the old b or the old a. Real hardware would swap them.
Using non-blocking assignments in clocked blocks removes this race. Other common races: a testbench driving inputs with blocking assignments on the same clock edge the DUT samples them (fix: drive on the opposite edge, use a clocking block, or use <=), and reading a variable in one block while another block writes it with = at the same time.
32How does parameterisation work? Explain parameter, localparam and generate.
parameteris a constant that the parent can override when it instantiates the module:fifo #(.DEPTH(32), .WIDTH(64)) u_fifo (...);.localparamis a constant that cannot be overridden. Use it for values derived from parameters, such aslocalparam AW = $clog2(DEPTH);.generate(afororifoutside procedural blocks) creates hardware at elaboration time, such as N copies of a module or optional logic.
genvar i;
generate for (i = 0; i < N; i++) begin : g_sync
sync2 u_sync (.clk(clk), .d(din[i]), .q(dout[i]));
end endgenerate
Avoid defparam; it changes parameters from far away in the hierarchy and is deprecated.
33How is a tri-state bus written in RTL, and why do chips rarely use one internally?
assign bus = drive_en ? data_out : 'z;
Only one driver may enable at a time. Inside a modern chip, tri-states are avoided: bus contention causes short-circuit current, a floating bus burns power and wrecks X-checking, and they complicate DFT and timing. Designers use a mux (or AND-OR) to select the driver instead. Tri-states are used at the chip’s I/O pads.
34Write the Verilog for a two-stage pipelined adder that adds four numbers.
Stage 1 adds pairs, stage 2 adds the two partial sums. Output is valid two cycles after the inputs.
module add4_pipe #(parameter W = 8) (
input logic clk, rst_n, in_vld,
input logic [W-1:0] a, b, c, d,
output logic [W+1:0] sum,
output logic out_vld);
logic [W:0] s_ab, s_cd;
logic vld1;
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin vld1 <= 0; out_vld <= 0; end
else begin
vld1 <= in_vld;
out_vld <= vld1;
end
always_ff @(posedge clk) begin // datapath needs no reset
s_ab <= a + b;
s_cd <= c + d;
sum <= s_ab + s_cd;
end
endmodule
Points interviewers look for: growing widths so nothing overflows, a valid bit that travels with the data, and no reset on wide datapath flops (it saves area and routing).
FSMs, counters and clock dividers
35How do you code an FSM in RTL? Write a small one in the recommended style.
Keep the state register in a clocked block and the next-state and output logic in a combinational block with defaults at the top. Name states with an enum (or localparams).
typedef enum logic [1:0] {IDLE, BUSY, DONE} state_t;
state_t state, nxt;
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= nxt;
always_comb begin
nxt = state; // default: stay
busy = 1'b0; // default outputs: no latches
case (state)
IDLE: if (start) nxt = BUSY;
BUSY: begin busy = 1'b1; if (last) nxt = DONE; end
DONE: nxt = IDLE;
default: nxt = IDLE; // recover from illegal encodings
endcase
end
Why interviewers like this style: the defaults prevent latches, the default branch makes the FSM safe, and the clocked block stays trivial. If an output must be glitch-free, register it in a third block (or decode it from the next state) instead of driving it straight from the combinational block.
36Design a Mealy FSM that detects the sequence 10110, with overlap.
Name each state by how much of the pattern has been seen: S0 (nothing), S1 (1), S2 (10), S3 (101), S4 (1011).
| State | in = 0 | in = 1 |
|---|---|---|
| S0 | S0 / 0 | S1 / 0 |
| S1 | S2 / 0 | S1 / 0 |
| S2 | S0 / 0 | S3 / 0 |
| S3 | S2 / 0 | S4 / 0 |
| S4 | S2 / 1 | S1 / 0 |
The key step for every wrong bit is to ask: what is the longest suffix of what I have seen that is still a prefix of 10110? For example, from S3 (101) a 0 gives 1010, whose suffix 10 is a prefix, so go to S2, not S0. After a match, 10110 ends in 10, so overlap continues from S2.
A Mealy machine needs 5 states. A Moore machine needs 6, because the output must be a state of its own.
Likely follow-up: How would you check it quickly without an FSM?
Shift the input into a 5-bit register and compare to 5’b10110. It uses 5 flops instead of 3, but it is trivially correct and overlap comes for free. Interviewers like hearing both options.
37What is the difference between Moore and Mealy machines in timing, not just definition?
A Moore output depends only on the state, so it changes only after a clock edge and is glitch-free if decoded from flops (or taken directly from a flop). A Mealy output depends on state and inputs, so it reacts in the same cycle as the input and usually needs one fewer state.
The cost of Mealy: the output has a combinational path from input to output, which can glitch and adds to the timing path of whatever the output drives. Many teams register Mealy outputs, which gives the same timing as Moore again. For outputs that leave a block or drive enables, a registered output is the safe default.
38Design a divide-by-3 clock with a 50% duty cycle.
With only rising edges you can get high for 1 cycle and low for 2 (33%) or the reverse. To get 1.5 cycles high you need the falling edge too.
logic [1:0] cnt;
logic a, b;
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin cnt <= 0; a <= 0; end
else begin
cnt <= (cnt == 2) ? 0 : cnt + 1;
a <= (cnt == 2); // high for one full cycle out of three
end
always_ff @(negedge clk or negedge rst_n)
if (!rst_n) b <= 0;
else b <= a; // same pulse, half a cycle later
assign clk_div3 = a | b; // 1.5 cycles high, 1.5 cycles low
a and b overlap, so the OR has no glitch. The duty cycle is exactly 50% only if the input clock is 50%. The same idea works for any odd N: make a pulse that is (N−1)/2 cycles wide, delay it by half a cycle on the falling edge, and OR the two.
Likely follow-up: Why is it bad to put logic like this OR gate on a clock in an ASIC?
Clock-tree tools and STA treat it as a generated clock through a logic cell, so you must define it with create_generated_clock and use a proper clock cell. Many teams prefer a counter-based enable at the original clock rate instead of a new clock.
39Design a divide-by-2 clock, and explain why a clock enable is often better than a divided clock.
A divide-by-2 is a flop whose D is its own inverted Q: always_ff @(posedge clk) q <= ~q;. The output has a 50% duty cycle regardless of the input duty cycle.
A divided clock creates a new clock domain: it needs its own clock tree, a generated-clock constraint, and care at every crossing back to the original clock. A clock enable keeps everything on the fast clock and lets logic update every second cycle:
always_ff @(posedge clk) en <= ~en;
always_ff @(posedge clk) if (en) slow_reg <= next;
Synthesis can then turn the enable into a clock gate, which saves the same power without a new domain. Paths that only update on enabled cycles can be constrained as multicycle paths.
40Detect a rising edge, a falling edge and any edge on a signal.
Register the signal and compare it with its previous value:
always_ff @(posedge clk) sig_d <= sig;
assign rise = sig & ~sig_d;
assign fall = ~sig & sig_d;
assign any = sig ^ sig_d;
Each output is a one-cycle pulse. If sig comes from another clock domain or a pin, pass it through a two-flop synchronizer first and run the edge detector on the synchronized version.
Interviewers sometimes ask how to detect the falling edge of the clock itself. You do not sample a clock with itself; you use a flop triggered on negedge clk, or treat the clock as data in a much faster clock domain.
41Design an FSM that tells whether a serial binary number (MSB first) is divisible by 3.
Track the remainder mod 3 of the number seen so far. Each new bit shifts the number left, so new = 2 · old + bit, and the remainder updates as r' = (2r + bit) mod 3.
| r | bit 0 | bit 1 |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 2 | 0 |
| 2 | 1 | 2 |
Three states, start in 0. The number is divisible by 3 whenever the state is 0. The same method works for any divisor k with k states.
Likely follow-up: What if the bits arrive LSB first?
Each new bit is worth 2^i, and 2^i mod 3 alternates 1, 2, 1, 2. Track the remainder plus one extra bit for whether the current weight is 1 or 2, so 6 states.
42Design a vending machine that sells an item for ₹15, accepts ₹5 and ₹10 coins, and returns change.
States are the amount inserted so far: S0 (₹0), S5, S10. Inputs are coin5 and coin10 (one coin per cycle). Outputs are dispense and change5.
| State | coin5 | coin10 |
|---|---|---|
| S0 | S5 | S10 |
| S5 | S10 | S0, dispense |
| S10 | S0, dispense | S0, dispense + change5 |
As a Mealy machine this needs 3 states. Say what happens with no coin (stay), and mention that coin inputs from a sensor must be synchronized and turned into single-cycle pulses with an edge detector before they reach the FSM.
43Write a Fibonacci sequence generator in Verilog.
Keep the last two values in registers and update both every cycle:
module fib #(parameter W = 16) (
input logic clk, rst_n, en,
output logic [W-1:0] f,
output logic ovf);
logic [W-1:0] a, b;
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin a <= 0; b <= 1; ovf <= 0; end
else if (en && !ovf) begin
a <= b;
b <= a + b;
ovf <= (a + b) < b; // carry out: next value does not fit
end
assign f = a;
endmodule
The output runs 0, 1, 1, 2, 3, 5, 8… One adder, two registers, one new term per cycle. The point interviewers check is overflow: a 16-bit register holds terms up to F(24) = 46368, and the adder wraps after that.
44What is an LFSR? What is its period, and which state must be avoided?
A linear feedback shift register is a shift register whose input is the XOR of selected bits (taps). With taps from a primitive polynomial, an n-bit LFSR goes through all 2^n − 1 non-zero states before repeating.
In the usual XOR form, the all-zeros state locks up: zeros XOR to zero forever. Reset the LFSR to a non-zero seed (or use XNOR feedback, where all-ones is the lock-up state).
Uses: pseudo-random test patterns, BIST, scramblers, CRC, and cheap counters where the count order does not matter (fewer gates than a binary counter, one XOR in the feedback path).
45How do you design a debouncer for a mechanical push button?
- Synchronize the button input with two flops, because it is asynchronous.
- Run a counter that resets whenever the synchronized input differs from the current stable output, and counts up while it stays the same.
- When the counter reaches a threshold (for example 10 to 20 ms worth of clock cycles), copy the input to the stable output.
- Add an edge detector on the stable output if the system wants one pulse per press.
At 50 MHz, 10 ms is 500,000 cycles, so the counter needs 19 bits.
46Binary, one-hot or Gray state encoding? When would you choose each?
- Binary: fewest flops (
log2 N), but next-state and output decoding take more logic. Good for large FSMs in area-sensitive ASICs. - One-hot: one flop per state. Decoding is a single bit, so it is fast, and it is the default for FPGAs where flops are cheap. Needs care with illegal states (more than one bit set).
- Gray: adjacent states differ by one bit, which reduces switching power when the FSM mostly steps through states in order, and helps when another clock domain reads the state.
Most synthesis tools can re-encode an FSM automatically. Interviewers want to hear the trade-off between speed, area, power and robustness.
47How do you make an FSM safe from illegal states?
An illegal state is a state encoding that is not in your design, for example two hot bits in a one-hot FSM, reached through an upset (SEU), a reset glitch or a bad power-up.
- Always include a
defaultthat sends the FSM to a known state (usually IDLE). - Make sure synthesis keeps that recovery logic. Some tools remove “unreachable” states, so use the tool’s safe-FSM option.
- For one-hot, check for invalid encodings and recover, or use Hamming-distance-3 encoding with error correction in safety-critical designs.
- Use a proper synchronous reset release so the FSM never starts in a half-reset state.
48Count the cars in a parking lot with an entry sensor and an exit sensor. Design the logic.
- Synchronize both sensor signals and turn each into a single-cycle pulse with a rising-edge detector, so a car held over the sensor counts once.
- Use an up/down counter sized for the capacity (for 200 spaces, 8 bits):
incon entry,decon exit. - Handle both pulses in the same cycle: the count does not change.
- Saturate: do not increment at capacity, do not decrement at 0, and raise
fullandemptyflags. Thefullflag drives the “Lot full” sign.
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) cnt <= '0;
else case ({in_p, out_p})
2'b10: if (cnt != CAP) cnt <= cnt + 1;
2'b01: if (cnt != 0) cnt <= cnt - 1;
default: ; // none or both
endcase
assign full = (cnt == CAP);
This kind of real-life counter question is common for freshers. What matters is the edge detection, the simultaneous case and the limits.
Timing for RTL designers
49What are setup time and hold time, and why does a flip-flop need them?
Setup time is how long D must be stable before the active clock edge. Hold time is how long it must stay stable after the edge.
Inside a master-slave flop, the master latch closes at the clock edge. Setup time is the time the data needs to travel through the master’s internal path and settle in its feedback loop before it closes. Hold time exists because the latch does not close instantly: the clock takes time to switch the transmission gates, so if D changes too soon after the edge, the new value can still leak in.
Violate either one and the flop can capture the wrong value or go metastable.
Likely follow-up: Can setup or hold time be negative?
Yes. If the clock path inside the flop is slower than the data path, the data can arrive slightly after the edge and still be captured (negative setup), or change slightly before the edge without harm (negative hold). The sum of setup and hold, the width of the window, is always positive.
50Write the setup and hold check equations for a register-to-register path.
With skew defined as capture clock arrival − launch clock arrival:
- Setup:
Tclk-q + Tcomb(max) + Tsetup ≤ Tclk + skew − uncertainty - Hold:
Tclk-q + Tcomb(min) ≥ Thold + skew + uncertainty
Setup checks the data arriving at the next edge, so the clock period appears in it. Hold checks that new data does not overwrite the data captured at the same edge, so the period does not appear. Slack is required time minus arrival time; negative slack is a violation.
51Tclk-q = 0.5 ns, combinational delay 1 to 3 ns, setup 0.3 ns, hold 0.2 ns, and the capture clock arrives 0.4 ns later than the launch clock. What is the maximum frequency? Is hold met?
Setup: Tclk ≥ Tclk-q + Tcomb(max) + Tsetup − skew = 0.5 + 3 + 0.3 − 0.4 = 3.4 ns. So fmax ≈ 294 MHz.
Hold: arrival = Tclk-q + Tcomb(min) = 0.5 + 1 = 1.5 ns; required = Thold + skew = 0.2 + 0.4 = 0.6 ns. Slack = 1.5 − 0.6 = +0.9 ns, so hold is met.
Note how the positive skew helped setup by 0.4 ns and ate 0.4 ns of hold margin. Interviewers often change the sign of the skew next; with −0.4 ns skew, fmax drops to 1/4.2 ns ≈ 238 MHz and hold slack rises to 1.7 ns.
52A divide-by-2 circuit is a flop with an inverter from Q back to D. Tclk-q = 60 ps, inverter delay = 20 ps, setup = 40 ps, hold = 30 ps. What is the maximum clock frequency, and is hold met?
The path starts and ends at the same flop, so skew is zero.
- Setup:
Tclk ≥ Tclk-q + Tinv + Tsetup = 60 + 20 + 40 = 120 ps, so fmax ≈ 8.3 GHz (in theory). - Hold: arrival
= 60 + 20 = 80 ps, which is more than the 30 ps hold time, so hold is met with 50 ps slack.
If the hold time were larger than 80 ps, the circuit would fail at every frequency, and you would add delay in the feedback path. This simplest-possible loop is a favourite warm-up because it tests both equations in one minute.
53Why can’t a hold violation be fixed by slowing down the clock?
The hold check compares the launch and capture of the same clock edge, so the clock period does not appear in the equation. Slowing the clock gives more time for setup but changes nothing for hold.
That is why a hold violation on silicon is fatal: the chip fails at every frequency. Hold is fixed by adding delay to the data path (buffers or delay cells in physical design) or by reducing skew.
54Your block misses timing by 200 ps at 1 GHz. What can you change in the RTL?
First look at the critical paths: where they start and end, how many logic levels they have, and whether they are real or should be false/multicycle paths. Then:
- Pipeline the path: add a register stage and adjust latency and valid signals.
- Restructure logic: balance trees, replace a long priority chain (if/else-if) with a parallel case, use one-hot encoding for an FSM on the path.
- Move late-arriving signals closer to the output. If
selarrives late, compute both results early and useselonly on the final mux (carry-select style precompute). - Duplicate high-fanout registers so each copy drives fewer loads.
- Retime: let synthesis move flops across logic, or move them yourself.
- Use faster arithmetic: a carry-lookahead or prefix adder instead of ripple carry, a Booth/Wallace multiplier.
Also ask whether 200 ps can come from synthesis or PD options (higher effort, low-Vt cells) before changing the micro-architecture.
55Optimise a logic path for timing assuming area is no concern. What would you do?
With area free, trade it for speed:
- Precompute every possible result in parallel and select at the end with the late signal (speculation / carry-select).
- Duplicate logic so each path has low fanout and short wires.
- Use parallel-prefix structures (Kogge-Stone adders, tree comparators) instead of chains: depth goes from O(n) to O(log n).
- Replace priority encoders with one-hot muxes (AND-OR).
- Flatten logic to fewer levels, even if it means more gates.
- Pipeline if latency is allowed.
End by saying what it costs: area, power and more wiring congestion, which can hurt timing in physical design.
56A 100 µm wire has 100 ps delay. You cut it at 20 µm and 50 µm and insert a buffer (30 ps delay) at each cut. What is the new delay?
Wire delay from distributed RC grows with length squared (R and C both grow with length). So each segment has delay 100 ps × (L / 100 µm)²:
- 20 µm: 100 × 0.04 = 4 ps
- 30 µm: 100 × 0.09 = 9 ps
- 50 µm: 100 × 0.25 = 25 ps
Wire total 38 ps, plus 2 buffers × 30 ps = 60 ps, so 98 ps. Only slightly better than 100 ps.
Lessons: repeaters make long-wire delay roughly linear in length, but each buffer has a cost, so there is an optimum spacing; equal segments work best (three 33.3 µm segments give about 33 ps of wire, 93 ps total). This simple model ignores buffer input capacitance and output resistance.
57What is clock skew? Is it always bad?
Skew is the difference in arrival time of the same clock at two flops. It is not always bad.
- Positive skew (capture clock later) gives the path more time for setup but makes hold harder.
- Negative skew helps hold and hurts setup.
Useful skew is used on purpose in physical design: delay the clock to the capture flop of a critical path to borrow time from the next stage, as long as the next path has slack. What is always bad is skew you did not plan for, plus jitter, which is the cycle-to-cycle variation of the clock edge itself and is only ever a loss.
58What is the difference between a false path and a multicycle path? Give an example of each.
- A false path is a timing path that can never be functionally exercised, or does not need to meet timing at all. Examples: a configuration register written once at boot and then static; paths between asynchronous clock domains that go through a synchronizer; test-mode-only paths in functional mode.
set_false_pathremoves them from analysis. - A multicycle path must meet timing, but in more than one cycle. Example: a datapath whose source and destination flops are only enabled every second cycle by the same enable.
For a 2-cycle path, set set_multicycle_path 2 -setup and set_multicycle_path 1 -hold (from the same start and end points). Without the hold adjustment, the hold check moves too and becomes far too strict.
A false path that is not really false is a silicon bug, so every exception needs a review and, ideally, a check in simulation or a formal tool.
59Pipeline a 4×4 multiplier. Then do the same with a single adder (serial multiply).
Array multiplier: form the 4 partial products pp[i] = (b[i] ? a : 0) << i, then add them. A combinational version is a tree of three adders. To pipeline it, register after the first adder level (s01 = pp0 + pp1, s23 = pp2 + pp3) and add s01 + s23 in the next stage. Throughput: one result per cycle; latency: 2 cycles.
Serial (shift-and-add): one adder and an 8-bit accumulator. Each cycle, look at one bit of b; if it is 1, add a << i (or add a and shift the accumulator right). After 4 cycles the product is ready. Throughput: one result every 4 cycles, with about a quarter of the adder hardware.
This is the core area-versus-throughput trade-off. A MAC unit (multiply-accumulate) reuses the same structure with the accumulator kept between operations.
60Why can’t you gate a clock with a plain AND gate? How does a clock gating cell fix it?
If the enable changes while the clock is high, clk & en cuts the high pulse short or creates a new short pulse, a glitch that can clock flops falsely.
An integrated clock gating (ICG) cell puts a latch in front of the AND gate. The latch is transparent while the clock is low and holds while it is high, so the enable seen by the AND gate can only change while the clock is low. The gated clock gets only full pulses.
In RTL you normally write an enable (if (en) q <= d;) and let synthesis insert ICGs automatically for groups of flops. The enable must meet a setup check to the ICG’s latch, which STA reports as a clock gating check.
61What is time borrowing in latch-based design?
With flops, every stage must finish in one clock period, and slack in one stage cannot help the next.
With latches on alternate phases, a latch is transparent for half a cycle. If the logic before it is late, the data simply passes through while the latch is open and the late part is taken from the next stage’s time. A slow stage borrows time from a fast one, up to the transparent window minus setup.
It is used in high-performance processor datapaths. STA tools support it, but it makes timing reports harder to read, and the borrowed time must be paid back within the loop.
62Which SDC constraints does an RTL designer usually write or review?
create_clockfor every primary clock, andcreate_generated_clockfor divided or muxed clocks.set_input_delayandset_output_delayon ports, which describe how much of the cycle the outside world uses.set_clock_groups -asynchronousbetween unrelated clocks.set_false_pathandset_multicycle_pathexceptions, with a reason for each.set_max_delay -datapath_onlyfor Gray-coded or bundled-data CDC paths.set_clock_uncertainty, sometimesset_case_analysisfor test or mode pins.
The designer knows the intent (which paths are static, which cross domains), so they own the exceptions even if the synthesis or STA team runs the tools.
Clock domain crossing and reset
63What problems can happen when a signal crosses from one clock domain to another?
Three different problems, each with its own fix:
- Metastability. The receiving flop samples a changing signal, inside its setup/hold window. Fix: a synchronizer (two or more flops).
- Data incoherence. A multi-bit value is synchronized bit by bit; bits resolve on different cycles, so the receiver sees a value that never existed. Fix: Gray code for counters, or a handshake/enable-based crossing or an async FIFO for data.
- Data loss. A pulse in a fast domain is shorter than the slow domain’s clock period, so it is never sampled. Fix: stretch it, a toggle synchronizer, or a handshake.
Naming the right problem before the fix is what separates a good answer from a memorised one.
64How does a two-flop synchronizer work, and what does it not do?
The first flop in the destination domain may go metastable. It then has almost a full destination clock period to resolve before the second flop samples it. The probability that it is still unresolved after that time falls exponentially, so the second flop’s output is reliably 0 or 1.
What it does not do:
- It does not guarantee you get the new value on a specific cycle. The output may change one cycle earlier or later.
- It does not make a multi-bit bus safe.
- It cannot catch a pulse shorter than the destination clock period.
Rules: register the signal in the source domain first (no combinational logic before the synchronizer, which could glitch), keep the two flops close together, and use three flops at very high frequencies or for very high reliability.
65What is MTBF for a synchronizer, and how do you increase it?
Mean time between failures is roughly
MTBF = e^(t_r / τ) / (T0 · f_clk · f_data)
where t_r is the time allowed for resolution (about one clock period minus the flop’s clock-to-q and setup), τ and T0 are flop parameters from the library, and f_clk, f_data are the clock frequency and data toggle rate.
Because t_r is in an exponent, adding time helps enormously: a third flop typically raises MTBF by many orders of magnitude. Other ways: use special synchronizer flops with small τ, lower the data toggle rate, or run the synchronizer on a slower clock.
66Why can’t you synchronize a multi-bit bus with a two-flop synchronizer on each bit?
Each bit’s synchronizer resolves independently. If several bits change together, some may be seen this cycle and some the next, so the receiver can see a value that never existed. For example 0111 → 1000 could be read as 1111 or 0000 for a cycle.
Fixes:
- Gray code, if the value is a counter that changes by one step at a time (async FIFO pointers).
- Enable/MUX synchronization (bundled data): hold the bus stable, synchronize a single valid or toggle signal, and sample the whole bus when that arrives.
- Request/acknowledge handshake.
- Asynchronous FIFO for streaming data.
67How do you pass a single-cycle pulse from a fast clock domain to a slow one?
A plain two-flop synchronizer can miss it completely, because the pulse can start and end between two slow clock edges.
Toggle synchronizer: in the source domain, each pulse flips a toggle flop, turning the pulse into a level change that lasts until the next pulse. Synchronize that level with two flops in the destination domain, then detect any edge (XOR of the last two synchronized samples) to recreate a one-cycle pulse.
Limit: pulses must be spaced far enough apart (about two to three destination clock periods) for each toggle to be seen. If they can come faster, use a handshake that blocks the source until the destination acknowledges, or count the pulses and cross the count through an async FIFO or Gray counter.
68Explain a 4-phase request/acknowledge handshake across clock domains.
- Source puts data on the bus and holds it, then raises
req. - Destination synchronizes
req, sees it high, captures the data (which has been stable for several cycles), and raisesack. - Source synchronizes
ack, sees it high, and lowersreq. - Destination sees
reqlow and lowersack. Source seesacklow and may send the next item.
Only req and ack are synchronized; the data bus is safe because it does not change while the handshake is in progress. It is robust and works for any clock ratio, but slow: each transfer costs several synchronizer delays in both directions. A 2-phase (toggle) version halves the round trips by treating each transition of req and ack as an event.
69How does an asynchronous FIFO work, and why are its pointers Gray coded?
Writes happen in the write clock domain and reads in the read clock domain, through a dual-port RAM. Each side keeps its own pointer. To decide full, the write side needs the read pointer; to decide empty, the read side needs the write pointer. Those pointers cross domains through two-flop synchronizers.
A binary pointer changing from 0111 to 1000 flips four bits, and a synchronizer could see any mix. A Gray-coded pointer changes one bit per increment, so the synchronized value is always either the old pointer or the new one. Either is safe: a stale pointer can only make the FIFO look more full or more empty than it really is, never the opposite. That is why the flags are called pessimistic.
Pointers are one bit wider than the address so that full and empty can be told apart when the addresses are equal.
70How are full and empty generated in an asynchronous FIFO?
With N+1-bit Gray pointers (N address bits):
// read domain
assign empty = (rptr_gray_next == wptr_gray_sync);
// write domain: top two bits inverted, rest equal
assign full = (wptr_gray_next ==
{~rptr_gray_sync[N:N-1], rptr_gray_sync[N-2:0]});
Empty: the read pointer has caught up with the write pointer, so all bits are equal. Full: the write pointer is exactly one lap ahead. In binary that means the MSB differs and the rest match; in Gray code the reflection means the top two bits differ and the rest match.
Flags are usually registered (computed from the next pointer values) so they are clean for the logic that uses them.
Likely follow-up: Can an async FIFO have a depth that is not a power of two?
Not with a plain Gray counter, because the wrap from the last value back to 0 then changes more than one bit. You need a special Gray sequence that is symmetric around the wrap, or a different scheme.
71Why do we use asynchronous assert and synchronous de-assert for reset?
Asynchronous assert puts the design into reset immediately, even if the clock is not running, which matters at power-up.
Synchronous de-assert matters because the release edge is what goes wrong: if reset releases close to a clock edge, it violates the flops’ recovery/removal timing. Some flops come out of reset this cycle and others the next, so an FSM can start in an illegal state.
The reset synchronizer: two flops with their async clear driven by the external reset, D of the first tied to 1. On assert, both clear at once. On release, the 1 shifts through over two clock edges, so the reset seen by the design always releases in step with the clock. Each clock domain needs its own synchronizer.
72Synchronous reset or asynchronous reset? Give the trade-offs.
| Synchronous reset | Asynchronous reset | |
|---|---|---|
| Needs a running clock | Yes | No |
| Flop type | Normal flop + logic on D | Flop with a reset pin |
| Glitches on reset | Filtered (only sampled at the edge) | Can reset the design falsely |
| Timing | Reset is on the data path, adds logic | Needs recovery/removal checks and a synchronizer |
| Reset width | Must last at least one clock cycle | Can be short |
Common practice in ASICs: asynchronous assert with synchronous de-assert for control logic, and no reset on wide datapath registers that are always written before they are read. FPGAs often prefer synchronous reset. What interviewers want is that you know why, not that you pick a side.
73What are recovery time and removal time?
They are the setup and hold checks for an asynchronous reset pin when the reset is released.
- Recovery time: how long before the clock edge the reset must be de-asserted for the flop to respond normally to that edge.
- Removal time: how long after the clock edge the reset must stay asserted.
STA checks them on the reset network from the reset synchronizer. They only apply to the release of reset; assertion is asynchronous by design.
74How do you design a glitch-free clock multiplexer?
Switching a plain mux while both clocks run can create a runt pulse. The glitch-free version uses two cross-coupled enable paths:
- Each clock has its own enable flop (or two-flop synchronizer if the clocks are asynchronous), clocked on the falling edge of that clock.
- Each clock’s enable input is
select condition AND NOT (the other clock's enable). - The output is
(clk0 & en0) | (clk1 & en1).
When the select changes, the active clock’s enable drops first, on its own falling edge, while its clock is low. Only then can the other enable rise, again on its own falling edge. The output is low during the handover, so no partial pulse appears. Both clocks must be running for the switch to complete. In practice teams use a library clock-mux cell or a verified IP block.
75Can static timing analysis verify a clock domain crossing?
No. STA assumes it knows the phase relationship between launch and capture clocks. For asynchronous clocks there is none, so the paths are declared false (set_clock_groups -asynchronous) and STA stops checking them.
CDC is verified structurally with CDC tools such as Synopsys SpyGlass CDC, Siemens Questa CDC or Cadence Conformal/JasperGold CDC. They find unsynchronized crossings, multi-bit buses synchronized bit by bit, reconvergence of separately synchronized signals, and glitchy logic before a synchronizer. STA is still used for the synchronizer flops themselves and for set_max_delay limits on Gray-coded buses.
76What is reset domain crossing (RDC)?
An RDC path is one where the launching flop and the capturing flop are in the same clock domain but different reset domains. If the source flop is reset asynchronously while the destination is not, the source output changes at an arbitrary moment, and the destination can go metastable even though both are on one clock.
Fixes: make sure the destination is also in reset (or held) when the source resets, gate the crossing with an isolation enable during reset, or put a synchronizer on the path. RDC tools check this the same way CDC tools check clock crossings.
FIFOs and arbiters
77How do you calculate the depth of a FIFO? Explain the method.
The FIFO must absorb the data written during the worst-case burst that the reader cannot drain at the same time.
- Find the longest possible burst: the maximum number of writes back-to-back. Watch for “X writes in Y cycles”, where the worst case puts one window’s writes at the end and the next window’s at the start.
- Find the time that burst takes:
t = burst / write rate. - Find how many items the reader removes in that time at its slowest rate:
reads = t × read rate. - Depth =
burst − reads. Add margin for synchronizer latency in async FIFOs, and round up to a power of two if the design needs one.
If the average write rate is higher than the average read rate, no finite depth works. Say so; interviewers sometimes test this.
78Write clock 80 MHz, read clock 50 MHz. The writer sends a burst of 120 words with no idle cycles; the reader reads one word every cycle. What FIFO depth is needed?
Time to write 120 words: 120 / 80 MHz = 1.5 µs.
Words read in 1.5 µs: 1.5 µs × 50 MHz = 75.
Depth = 120 − 75 = 45. In an asynchronous FIFO add a few entries for the pointer synchronization delay (the writer sees reads 2 to 3 read clocks late), and many designs round up to 64.
The reader needs 120 / 50 MHz = 2.4 µs to drain the burst, so the writer must stay idle for at least 2.4 − 1.5 = 0.9 µs before the next burst.
79Same clock for both sides. The writer sends 80 words in every 100 cycles (at any position); the reader reads 8 words in every 10 cycles. What depth?
Worst case for the writer: the 80 writes of one 100-cycle window are at its end and the 80 writes of the next window at its start, giving 160 writes in 160 consecutive cycles.
Over those 160 cycles the reader manages 160 × 8 / 10 = 128 reads.
Depth = 160 − 128 = 32.
Check the averages first: writes average 0.8 per cycle and reads 0.8 per cycle, so a finite FIFO works. If the reader averaged less than 0.8 per cycle, the FIFO would eventually overflow at any depth.
80Writer: 100 MHz, sends bursts of 100 words, one word every 2 cycles. Reader: 50 MHz, reads one word every 4 cycles. What depth is needed?
Idle cycles change the rates, not the method.
- Write rate: 100 MHz / 2 = 50 M words/s. Time for the burst:
100 / 50 M = 2 µs. - Read rate: 50 MHz / 4 = 12.5 M words/s. Reads in 2 µs:
2 µs × 12.5 M = 25. - Depth =
100 − 25 =75.
Before answering, say the assumption: the read pattern is steady (one read exactly every 4 cycles). If the reader may bunch its idle cycles, use the worst case: the fewest reads it can possibly make in 2 µs.
81Design a synchronous FIFO. How do you generate full and empty?
Use pointers one bit wider than the address. Empty when they are equal; full when the address bits match but the extra MSB differs.
module sync_fifo #(parameter W = 8, D = 16, AW = $clog2(D)) (
input logic clk, rst_n, wr_en, rd_en,
input logic [W-1:0] wdata,
output logic [W-1:0] rdata,
output logic full, empty);
logic [W-1:0] mem [D];
logic [AW:0] wptr, rptr;
assign empty = (wptr == rptr);
assign full = (wptr[AW] != rptr[AW]) && (wptr[AW-1:0] == rptr[AW-1:0]);
wire do_wr = wr_en && !full;
wire do_rd = rd_en && !empty;
always_ff @(posedge clk or negedge rst_n) // pointers: reset
if (!rst_n) begin wptr <= '0; rptr <= '0; end
else begin
if (do_wr) wptr <= wptr + 1'b1;
if (do_rd) rptr <= rptr + 1'b1;
end
always_ff @(posedge clk) begin // storage: no reset
if (do_wr) mem[wptr[AW-1:0]] <= wdata;
if (do_rd) rdata <= mem[rptr[AW-1:0]];
end
endmodule
Another way is a counter of stored items (full when count == D). Be ready to explain what happens on a simultaneous read and write when full or empty: here a write when full is blocked even if a read happens in the same cycle; some designs allow it.
Likely follow-up: The data comes out one cycle after rd_en. How do you make it available in the same cycle?
That is a first-word fall-through (FWFT) or show-ahead FIFO. Either read the RAM combinationally (only for small flop-based FIFOs), or prefetch the head entry into an output register as soon as the FIFO is not empty, so rdata is already valid when rd_en is asserted.
82Can you build a FIFO from a single-port SRAM if you need a read and a write in the same cycle?
A single-port SRAM does one access per cycle, so not directly. Options:
- Two banks (ping-pong): split even and odd addresses into two single-port SRAMs. Reads and writes usually hit different banks; when they collide, a small flop buffer absorbs the write for a cycle.
- Double-width SRAM: collect two words before each write and read two words at a time, so each side needs the RAM only every other cycle.
- Run the SRAM at twice the clock, if timing allows.
- Use a two-port (one read, one write) or dual-port SRAM, at more area.
The point of the question is that you know why the single-port case is a problem and can trade area against complexity.
83How would you verify a FIFO? Which corner cases matter?
Designers are expected to know how their block is tested. For a FIFO, check:
- Reset: empty is 1, full is 0, and no stale data comes out.
- Fill to full: full asserts at exactly the depth, further writes are blocked, and no data is overwritten.
- Drain to empty: empty asserts after the last word, extra reads are blocked, and the output does not change.
- Simultaneous read and write when empty, when full and in between: count stays the same and data order is kept.
- Pointer wrap-around: run many times the depth through it, so both pointers wrap several times.
- Back-to-back and random traffic with a scoreboard (a reference queue) comparing every word.
- For an async FIFO, different clock ratios in both directions, and very slow and very fast reads.
Assertions that never fire: no write when full, no read when empty, full and empty never both high.
84Why do FIFOs have almost-full and almost-empty flags?
Flow control takes time. If the producer sees full only after it happens, and its stall signal takes a few cycles to reach the logic that writes (pipeline stages, registered outputs, a clock crossing), it will write a few more words and overflow.
almost_full asserts when the free space drops to the number of cycles of that latency, so the producer stops in time. almost_empty lets a consumer that reads in bursts wait until there is enough data. The thresholds are often programmable.
85Design a fixed-priority arbiter for N requesters.
Grant the lowest-numbered active request. The neat trick: req & -req (two’s complement) keeps only the lowest set bit.
assign gnt = req & (~req + 1'b1);
Example: req = 0110 gives ~req + 1 = 1010, and 0110 & 1010 = 0010. Requester 1 wins.
The loop version, which some interviewers prefer to see:
always_comb begin
gnt = '0;
for (int i = N-1; i >= 0; i--)
if (req[i]) begin gnt = '0; gnt[i] = 1'b1; end // lowest i is assigned last, so it wins
end
The weakness of fixed priority is starvation: requester 0 can block all others forever.
86How does a round-robin arbiter work? How would you build one?
A round-robin arbiter rotates priority so that the requester just served gets the lowest priority next time. Every requester is served within N grants, so nobody starves.
A common implementation uses two fixed-priority arbiters and a mask:
- Keep a mask that has 1s for all positions above the last granted one.
- Arbiter A works on
req & mask. Arbiter B works on plainreq. - If any masked request exists, use A’s grant; otherwise use B’s (wrap around).
- After a grant, update the mask to the positions above the new winner.
For N = 4 with grants last given to 1 and requests 1011: mask = 1100, masked request = 1000, so requester 3 wins. Next time the mask is 0000, so B picks requester 0.
Variants: weighted round robin (some requesters get several turns), and arbiters that only move the pointer when the grant is actually used.
87What are the rules of a valid/ready handshake, and what is a skid buffer?
In a valid/ready (AXI-style) interface, a transfer happens on a cycle where both valid and ready are high.
- Once the source raises
valid, it must keepvalidhigh and data stable until the transfer happens. - The source must not wait for
readybefore raisingvalid(to avoid deadlock); the sink may wait forvalidbefore raisingready.
In a pipeline, ready travels backwards and becomes a long combinational path. Registering ready breaks that path, but then the stage has already accepted data in the cycle that ready dropped. A skid buffer is a one-entry spare register that catches that extra item, so the stage can register ready and still never lose data. It is a two-entry FIFO in practice.
88What is credit-based flow control?
The receiver tells the sender how many buffer slots it has (the credits). The sender keeps a counter: it decrements on each send and stops at zero. When the receiver frees a slot, it returns a credit and the sender increments.
Unlike valid/ready, the sender never needs a same-cycle ready, so it works across long wires, pipelines and links with many cycles of latency (PCIe, on-chip networks). To run at full rate, the receiver’s buffer must hold at least the round-trip latency in credits.
Datapath and micro-architecture
89Multiply a number by 63 without a multiplier. What about by 7.5?
63·x = 64·x − x = (x << 6) − x. One shift (free wiring) and one subtractor. The result needs 6 more bits than x.
Constant multiplication is always shifts and adds. Using subtraction (Canonical Signed Digit form) keeps the number of adders low: 63 = 111111 in binary would need 5 adders, but 64 − 1 needs only 1.
7.5·x = 8x − x/2 = (x << 3) − (x >> 1), with care for the bit lost by the right shift (keep one fractional bit or round).
90Generate the squares 1, 4, 9, 16, 25… every cycle without a multiplier.
Use the difference between consecutive squares: (n+1)² = n² + 2n + 1. The difference is the odd numbers 3, 5, 7, 9…
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) begin sq <= 1; odd <= 3; end
else begin
sq <= sq + odd; // 1, 4, 9, 16, 25 ...
odd <= odd + 2;
end
Two adders and two registers instead of a multiplier. The same forward-difference trick generates any polynomial sequence, for example cubes with three accumulators.
91How do you check in hardware whether a number is a power of two?
A power of two has exactly one bit set. Subtracting 1 clears that bit and sets all the bits below it, so x & (x − 1) is zero only for powers of two (and for zero itself):
assign is_pow2 = (x != 0) && ((x & (x - 1)) == 0);
It is one decrementer, an AND and a zero detect. Alternatives interviewers accept: popcount equal to 1, or a one-hot check.
92Compare ripple-carry, carry-lookahead and carry-select adders.
| Adder | Delay | Area | Idea |
|---|---|---|---|
| Ripple carry | O(n) | Smallest | Carry passes through every full adder |
| Carry lookahead | O(log n) with a tree | Larger | Compute generate g = a·b and propagate p = a ⊕ b, then all carries in parallel |
| Carry select | About O(√n) | Roughly 2× in the upper blocks | Compute each upper block for carry-in 0 and 1, then pick with the real carry |
| Parallel prefix (Kogge-Stone, Brent-Kung) | O(log n) | Large, many wires | Tree of (g, p) combine operators |
In practice synthesis picks the adder architecture from the timing constraint (DesignWare in Synopsys flows), but interviewers want you to explain why lookahead is faster.
93Accumulate data per address: every cycle a new (address, value) arrives and you must add value to a counter stored in RAM. The RAM has 1-cycle read latency. What goes wrong and how do you fix it?
Each update is a read-modify-write: read the old count, add, write back. With a 1-cycle read and a 1-cycle write, the write of update N lands a cycle or two after update N+1 has already read the same address, so N+1 reads a stale value and one addition is lost.
Fix with forwarding (bypass): keep the address and new value of the updates still in flight in the pipeline. When a new request’s address matches one in flight, use the in-flight value instead of the RAM output. It is the same read-after-write hazard as in a CPU pipeline.
Other options: stall when addresses match (simple, loses throughput), or merge consecutive updates to the same address before they reach the RAM.
94What are pipeline hazards, and how are they handled?
- Structural hazard: two instructions need the same resource in the same cycle (one memory port for instruction fetch and data access). Fix: duplicate the resource or stall.
- Data hazard: an instruction needs a result that an earlier instruction has not written yet (read after write). Fix: forwarding from later pipeline stages, or stall (interlock) when forwarding is not enough, such as a load followed by its use.
- Control hazard: the next instruction address is unknown until a branch resolves. Fix: branch prediction, flush on mispredict, delay slots in old ISAs.
Many hardware datapaths, not only CPUs, face the same issues; the read-modify-write accumulator above is a data hazard.
95A cache is 32 KB, 4-way set associative, with 64-byte lines and 32-bit addresses. How many bits are tag, index and offset?
- Offset: 64-byte lines need
log2 64 =6 bits. - Number of lines:
32 KB / 64 B = 512. Sets:512 / 4 ways = 128, so index is 7 bits. - Tag:
32 − 7 − 6 =19 bits.
Each line also stores a valid bit, often a dirty bit (write-back caches) and replacement state (for LRU in 4 ways, a few bits per set). Computer architecture basics like this come up at processor, GPU and SoC companies even for RTL roles.
96Which RTL techniques reduce dynamic power?
Dynamic power is roughly α · C · V² · f. RTL can cut the activity α and the switched capacitance C:
- Clock gating: stop the clock to registers that are not being updated. The clock tree is often 30 to 40% of dynamic power, so this is the biggest lever. Write clean enables so synthesis can infer gates.
- Operand isolation: hold the inputs of a large arithmetic block steady (AND them with the enable) when its output is not used.
- Avoid needless toggling: do not reset or update wide datapath registers when idle, use Gray or one-hot encoding where buses toggle a lot, and avoid glitchy logic deep in a cone.
- Memory access: read RAMs only when the data is needed, and gate their chip-select.
Larger savings come from architecture: power gating idle blocks (needs isolation cells, retention registers and a UPF power intent file) and dynamic voltage and frequency scaling.
Flow, scripting and projects
97Walk through the front-end design flow. Where do lint and CDC checks fit?
- Specification and micro-architecture: block diagram, interfaces, pipelines, FIFOs, clocking and reset plan.
- RTL coding in Verilog or SystemVerilog.
- Lint (SpyGlass, Ascent, HAL): coding-rule checks, run on every change before simulation. It finds latches, width mismatches, multiple drivers, combinational loops and undriven signals.
- Functional verification: simulation with a testbench (often UVM), assertions and coverage; formal checks for some blocks.
- CDC and RDC checks on the full block with its clocks defined.
- Synthesis with SDC constraints, to a gate netlist; check timing, area and power.
- Logical equivalence check (RTL vs netlist), then hand off to DFT and physical design, and iterate on timing.
Freshers who can say where each tool fits, and what it catches, stand out.
98Write a Python script that counts errors and warnings per module in a simulation log.
Assume lines like UVM_ERROR ... [MODULE_NAME] message or Error: (mod_a) .... Scripting rounds care more about clean parsing than the exact format, so state your assumption first.
import re, sys
from collections import Counter
pat = re.compile(r'\b(error|warning)\b.*?[\[(](\w+)[\])]', re.I)
counts = Counter()
with open(sys.argv[1]) as f:
for line in f:
m = pat.search(line)
if m:
counts[(m.group(2), m.group(1).lower())] += 1
for (mod, kind), n in sorted(counts.items()):
print(f"{mod:20s} {kind:8s} {n}")
Points to mention: read line by line (logs can be gigabytes), compile the regex once, handle case, and print sorted results. Product companies often ask a CSV or string-parsing task like this alongside RTL.
99How should you answer “Explain your project”?
This question takes the most time in almost every RTL interview report. A structure that works:
- One sentence on what the design does and why (for example, “an AXI-lite UART with a 16-deep FIFO”).
- Block diagram you can draw in a minute: interfaces, clocks, main blocks.
- Your decisions and the reason for each: why a FIFO of that depth, why that FSM encoding, how you handled reset and any clock crossing.
- How you verified it: testbench, directed or random tests, corner cases, any assertions or coverage.
- Results: frequency, area or utilisation, what worked on the board.
- One problem you hit and how you debugged it, and what you would do differently.
Expect the interviewer to dig into anything you mention. If you mention CDC, they will ask how you synchronized it; if you mention 100 MHz, they will ask about the critical path. Do not list anything you cannot explain.
100Open-ended design: split a stream of 32-bit words (one per cycle) into four 8-bit output streams. How do you approach it?
Open-ended micro-architecture questions are graded on the process, not one answer. Work through it out loud:
- Clarify the spec. Does each byte go to a fixed output, or round-robin? Can outputs stall (backpressure)? What happens when one output is slow?
- Throughput. 32 bits in per cycle and 4 × 8 bits out per cycle balance exactly, so there is no slack: any stall on one output must stall the input, or you need per-output buffering.
- Structure. Register the input word, split it into 4 bytes, give each output a small FIFO, and stall the input when any FIFO is almost full.
- Interfaces. Valid/ready on every port, and say what happens on reset.
- Verification. Corner cases: one output stalled for a long time, all outputs stalled, back-to-back words.
Saying the assumptions out loud, and checking the throughput maths before drawing, is what interviewers mark highly.