Part 2 of the HDL coding guidelines series covers VHDL: how to compile it, how to partition and store it, how to name things, which data types to use, the design rules that keep RTL synthesizable and safe, and how to write testbenches and readable code. The rules below are a checklist you can adopt for a team, with the reasons behind the important ones in the deep dive.
See also Part 1 and Part 3 of the series.
Why coding guidelines matter
A chip project can have dozens of engineers writing VHDL over several years. Without shared rules, every block looks different, reviews take longer, synthesis and simulation disagree in subtle ways, and reusing a block on the next project means rewriting it. Good guidelines do three things: they keep the code synthesizable and free of known hazards, they make anyone's code readable by everyone else, and they make the flow (compiling, checking in, building the chip) predictable. Most of the rules below are simple; their value comes from everyone following them.
When compiling
- A configuration declaration is needed for each architecture in the design.
- Design-internal references must use library work.
- Use selected names in binding indications and use clauses only.
- Testbench and DUT should be compiled into the same library.
- Avoid more package references than needed.
Partitioning VHDL code
- VHDL units should take later floorplanning into account.
- Asynchronous parts should be placed into separate entities.
- Keep all objects and subprograms in the nearest possible scope.
- Keep local objects invisible outside a package.
- Transfer stable component declarations into component packages.
- Reuse the functionality of standard packages as much as possible.
- The size of VHDL units should be reasonable for synthesis.
- A VHDL unit should not exceed 500 lines of code.
- A process or subprogram should not exceed 100 lines of code.
- Component instantiations should not exceed 4 levels of hierarchy.
- An architecture should not contain more than 10 processes.
- Structural and behavioral code should not be mixed.
- Define project packages early in the project.
Storing VHDL code
- Configurations must be in a separate file, except at the lowest level of hierarchy.
- Only verified VHDL code is allowed for check-in.
- Store each VHDL unit in a separate file, except a package header and body.
- Hide old VHDL files.
Naming conventions
- All primary unit names must be unique in the project library.
- Identifier casing should be uniform in all VHDL code.
- Keyword casing should be uniform in all VHDL code.
- The length of entity names should not exceed 32 characters.
- An instance name must not contain the substring 'pfiller'.
- An instance name must not start with 'bondpad'.
- Identifier naming must be based on the English language.
- Use meaningful identifier names.
- Separate identifier components using underscores.
- Signal assignments for renaming purposes should be avoided.
- The names of clocks and resets should be unique in the whole design.
- Define naming conventions for VHDL units, files and objects, with examples and a list of standard abbreviations.
- Choose short instance names.
- Use the standard top levels xmpl, xmpl_top and xmpl_chip (where xmpl is the design name).
- Use an intermediate signal for reading from an output port.
Data types
- Use unresolved data types if possible.
- Hard and firm macros: data types at ports are std_(u)logic(_vector).
- Soft macros: data types at ports are std_(u)logic(_vector).
- Generics must have type integer for synthesis.
- Avoid custom data types (for example multidimensional arrays, records, enumeration types).
- Self-defined conversion functions must assert unmappable input values.
- Use complex data types inside architectures.
- Use a small number of self-defined global data types.
Design rules
- Asynchronous reset is mandatory for sequential processes.
- Do not use internal three-state buses.
- Use the predefined templates for component instantiation.
- Refer to one edge of the clock only.
- Do not use combinational feedback loops.
- Avoid feedthroughs.
- Strength stripping should be performed at chip level.
- Do not assign the value 'X'.
- Balance clock to delta accuracy.
- Pull-ups and pull-downs have to be modeled at chip level.
- Gate instantiation must be encapsulated in a separate unit.
- An FSM must be described in a separate entity/architecture pair.
- Instantiate the power pads for each power domain.
- Spend extensive effort on documenting interfaces.
- Spacer cells are needed between pads.
- Signals that cross clock domains must be synchronized by synchronization cells.
- Avoid gated clocks unless absolutely necessary.
- Avoid latches unless absolutely necessary.
- All outputs of synchronous modules should be registered.
- Process only one clock in RTL units.
- Do not use the value of type'left for initializing a signal or variable during reset.
- Avoid unused ports; buses must be split accordingly.
- Use case statements instead of if statements when the conditions are mutually exclusive.
- All signals and variables should be read at least once.
- Static ports should not exist.
- Avoid unnecessary computations within loops.
- Insert a test enable for scan test.
- Use vector operations instead of loops.
- Avoid unnecessary repetition of function calls.
- Use an efficient description for the wrap-around of counters.
- Build interface consistency checks into the model.
- For soft-core development use generics, not constants.
Testbenches
- Global signals may be used for testing purposes only.
- Variables of access types should be modified only in procedures defined in packages.
- A testbench has neither ports nor generics.
- Use an abstract, compact coding style in testbenches and simulation models.
- For accelerated simulation or emulation, the testbench must be synthesizable.
- Stop the simulation from within the testbench.
- Use assertion messages extensively.
Text I/O
- Binary file I/O may not be used.
- Use relative path names for files accessed through text I/O.
- Communication between modules using text I/O is forbidden.
- No characters with a lower rank than space may occur in text I/O.
- Check the success of every read operation.
- Use std.textio only where really necessary.
- Store file data in a VHDL variable if it is read multiple times.
Readability
- In association lists of generic maps and port maps, use named association.
- In association lists of subprogram calls, use named association.
- The language for comments and code documentation is English.
- Comments should relate to the lines of code below them.
- Trailing comments are only allowed for declarative lists.
- Comment each process, each subprogram and global aspects.
- Processes should be labeled.
- Aliases are not recommended.
- Do not define a subprogram for a subtype only.
- Use a separate library clause for each declared resource library.
- Use a separate use clause for each declared package.
- The maximum line length is 100 characters.
- The order of ports in entity, component and instance should be the same.
- Do not have unused signals.
- Indentation should be consistent in all VHDL code.
- Align comments, declaration lists and association lists vertically.
- Use closing labels for entity, architecture, process, loop, generate and similar constructs.
- Indicate the condition at the remote ends of control structures (if ... then, case).
- Use one statement per line.
- Group related constructs, and related port or signal declarations.
- Switch constructs should not be nested more than 4 levels deep.
- Order items the same way in package header and body.
- Use predefined attributes to make code generic and more reusable.
- Remove unnecessary code fragments; checked-in versions must not contain commented-out code.
Deep dive: the numbers and details
This part explains the reasoning behind the rules that cause the most debate, with code examples. Skip it if the checklist is all you need.
The numeric limits at a glance
| Rule | Limit |
|---|---|
| Lines per VHDL unit | 500 |
| Lines per process or subprogram | 100 |
| Instantiation depth | 4 levels |
| Processes per architecture | 10 |
| Entity name length | 32 characters |
| Line length | 100 characters |
| Nesting of switch constructs | 4 levels |
Limits like these are easy to check automatically with a lint tool or a short script, so they can be enforced at check-in rather than argued about in review.
One clock edge, one clock per unit
Mixing rising and falling edges in one block halves the time available for some paths and complicates scan insertion. Keeping one clock per RTL unit means clock domain crossings happen only in dedicated synchronizer cells, where they can be found and reviewed. A typical clocked process that follows the rules:
p_count : process (clk, rst_n)
begin
if rst_n = '0' then
count <= (others => '0');
elsif rising_edge(clk) then
if enable = '1' then
count <= count + 1;
end if;
end if;
end process p_count;
The process is labeled, uses one edge of one clock, and closes with its label.
Asynchronous or synchronous reset?
This guideline makes asynchronous reset mandatory. That is a project choice, not a universal rule. For FPGAs, AMD's UG1387 methodology guide recommends synchronous resets when a reset is needed, because they map onto more device resources, avoid limiting the clock frequency and are less likely to corrupt block RAM, LUT RAM and shift-register contents. Whichever style you choose, the release of an asynchronous reset must be synchronized to the clock to avoid recovery and removal violations.
Reading an output port
The rule "use an intermediate signal for reading from an output port" comes from VHDL-93, where reading a port of mode out was illegal. AMD's UG901 synthesis guide notes that VHDL-2008 lets you read output values. The intermediate signal is still good practice when code must compile with older tools:
signal count_i : unsigned(7 downto 0); ... count_i <= count_i + 1 when rising_edge(clk); count <= std_logic_vector(count_i); -- drive the port from the internal signal
Why not assign 'X'?
Assigning 'X' to mean "don't care" lets synthesis pick any value, but in simulation the 'X' propagates and can hide or create mismatches between RTL and gate-level results. Assign a real value and let synthesis optimize it, or use explicit don't-care handling that your tools document.
Case versus if
An if-elsif chain implies priority: the first true condition wins, and synthesis builds a priority structure. When the conditions are mutually exclusive, a case statement states that intent and produces a parallel multiplexer, which is usually smaller and faster.
Named association
u_fifo : entity work.fifo
generic map (DEPTH => 16, WIDTH => 32)
port map (
clk => clk,
rst_n => rst_n,
wr_en => wr_en,
din => wr_data,
rd_en => rd_en,
dout => rd_data,
full => fifo_full,
empty => fifo_empty
);
Positional association breaks silently when someone adds or reorders a port; named association fails to compile instead, which is what you want.
Chip-level rules
Several rules (pad spacer cells, power pads per domain, pull-ups at chip level, and the 'pfiller' and 'bondpad' instance name restrictions) concern the chip top level rather than block RTL. They are specific to the flow they were written for. If you adopt this checklist, replace them with the cell names and pad rules your own back-end flow uses.


Your comments will be moderated before it appears here.