# Writing safe Verilog

DevFeed: [Writing safe Verilog](<https://devfeed.tech/articles/writing-safe-verilog-77734.md>)

Original publisher: [Read original article](<https://danluu.com/pl-troll/>)

Published: 2013-09-15T00:00:00Z

Content type: article

Language: en

Sources: [Danluu](<https://devfeed.tech/sources/danluu.md>)

Topics: [Verilog](<https://devfeed.tech/topics/verilog.md>), [synchronization](<https://devfeed.tech/topics/synchronization.md>)

Tags: [hardware](<https://devfeed.tech/tags/hardware.md>), [linter](<https://devfeed.tech/tags/linter.md>), [verilog](<https://devfeed.tech/tags/verilog.md>)

## AI overview

The article explains how naming conventions enable lightweight static checks in Verilog for pipeline stages, clock domains, and module boundaries. These checks can catch errors before costly simulation and timing analysis. The author reports building a checker in half an hour that found seven bugs with two false positives.

## Source excerpt

Troll? That's how people write Verilog1. At my old company, we had a team of formal methods PhD's who wrote a linter that typechecked our code, based on our naming convention. For our chip (which was small for a CPU), building a model (compiling) took about five minutes, running a single short test took ten to fifteen minutes, and long tests took CPU months. The value of a linter that can run in seconds should be obvious, not even considering the fact that it can take hours of tracing through waveforms to find out why a test failed2. Lets look at some of the most commonly used naming conventions. Pipeline stage When you pipeline hardware, you end up with many versions of the same signal, one for each stage of the pipeline the signal traverses. Even without static checks, you'll want some simple way to differentiate between these, so you might name them foo_s1, foo_s2, and foo_s3, indicating that they originate in the first, second, and third stages, respectively. In any particular stage, a signal is most likely to interact with other signals in the same stage; it's often a mistake when logic from other stages is accessed. There are reasons to access signals from other stages, like bypass paths and control logic that looks at multiple stages, but logic that stays contained within a stage is common enough that it's not too tedious to either "cast" or add a comment that disables the check, when looking at signals from other stages. Clock domain Accessing a signal in a different clock domain without synchronization is like accessing a data structure from multiple threads without synchronization. Sort of. But worse. Much worse. Driving combinational logic from a metastable state (where the signal is sitting between a 0 and 1) can burn a massive amount of power3. Here, I'm not just talking about being inefficient. If you took a high-power chip from the late 90s and removed the heat sink, it would melt itself into the socket, even under normal operation. Modern chips have