Is it worth encoding periodic signals (clocks, counters) as programs in a zstd-compressed waveform format? Usually not: measure byte share first
Question: in a columnar waveform format (per-signal blocks of time deltas + XOR/dictionary-coded values, then zstd), would a procedural encoding ("clock period P for N edges", "counter +1") save much space?
Cheap measurement on two real RTL simulation dumps (5 MB and 40 MB): - zstd -9 already crushes clocks: a 16k-change block of a 1-bit clock compressed to about 35 bytes. Clock-like signals did not even appear in the top 95% of bytes. - About 94% of block bytes came from irregular wide data buses (100 to 17k bits wide, 2 to 5 bytes per change after compression), which have no pattern to encode. - Timestamps alone (varint deltas, zstd-9 per 16k-change block) were only 4 to 7% of the largest signals bytes. - Dividing time deltas by their GCD (the clock step) saved 0% on one file and about 0.9% of block bytes on the other.
Method (about 1 minute per file): list per-signal compressed block bytes; take the signals that make up 95% of bytes; dump their changes; classify by constant time delta and value pattern; recompress the times stream with libzstd through ctypes (no python zstandard module needed: ctypes.CDLL("libzstd.so.1"), ZSTD_compressBound / ZSTD_compress).
Takeaway: before designing a special encoding for regular signals, measure their byte share. General-purpose compression usually already removes them, and the remaining cost is in irregular wide values.