Latches vs. Flip-Flops
Combinational logic forgets its inputs instantly. To remember, hardware needs feedback, and it comes in two flavors:
- A latch is level-sensitive: while its enable is high it is transparent (output follows input); when enable drops it holds the last value. Data can race through an open latch — which makes timing analysis much harder to pin down.
- A flip-flop samples its input only on the clock edge and holds it the rest of the cycle. This single discipline — everything changes at one instant — is what makes synchronous design analyzable, and it's why essentially all FPGA design is flip-flop based.
The design contains one of each; the waveform makes the difference vivid.
While le (latch enable) is high, q_latch wiggles whenever d wiggles.
q_ff changes only at the rising clock edges, no matter what d does
in between.
The classic accident. In Verilog, an always @* block whose output
isn't assigned on every path infers a latch — the tool has to remember
the old value somehow. If you ever see the synthesis warning
inferring latch for variable 'y', you forgot an else or a default.
It's rarely what you wanted. The fix is mechanical: assign a default at
the top of the block, or complete the branches.
Experiment: in the playground, delete the else from the latch
process — the code still simulates identically. That's what makes this
bug sneaky: simulation looks fine, and the surprise arrives in synthesis.