RTL Design #43 · 2026-11-05 · Wraparound compare · Medium · about 12 min

Sequence numbers that don't know the counter wraps

Packets carry a 16-bit sequence number that wraps from 65535 back to 0. seq_before says, combinationally, whether a was sent before b:

  • b is 1 to 32767 steps ahead of a (counting up, and wrapping): a_first is 1.
  • b is the same as a, or 32768 or more steps ahead (that is, b is behind a): a_first is 0.

For example, 65530 is before 3, because 3 is nine steps past it. Run tries eight pairs and some come out wrong. Fix seq_before.sv.

Write and run your answer in the browser. The hidden tests check it, and it’s free.