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:
bis 1 to 32767 steps ahead ofa(counting up, and wrapping):a_firstis 1.bis the same asa, or 32768 or more steps ahead (that is,bis behinda):a_firstis 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.