VHDL stands for VHSIC Hardware Description Language. It is a hardware description language for modelling, simulating and implementing digital circuits. Since its standardization as IEEE 1076, VHDL has been used for RTL design, verification, documentation and communication between engineers and EDA tools.
A style guide does not make a design correct by itself. It makes correctness easier to achieve. Digital designs often live for many years, pass through several hands and are reused in derivative products. Consistent source code reduces review effort, shortens onboarding time, makes bugs easier to locate and keeps synthesis, simulation and lint results reproducible.
This article collects practical VHDL coding rules for project teams. The rules are intentionally conservative: they favour readability, portability and maintainability over cleverness.
Why VHDL code needs style rules
VHDL is read more often than it is written. A naming convention, indentation style and reset strategy are therefore engineering decisions, not cosmetic details. Good style helps in several concrete situations:
-
during code review, because reviewers can concentrate on behaviour instead of formatting;
-
during simulation debugging, because signal names remain meaningful in waveforms;
-
during FPGA or ASIC bring-up, because clock domains, resets and interfaces are easy to identify;
-
during reuse, because module boundaries and generic parameters are self-explanatory;
-
during maintenance, because old design intent can still be reconstructed from the code.
The most important rule is consistency. A small, documented convention that is applied everywhere is more valuable than a large rule set that is ignored under schedule pressure.
Scope of the guide
The following rules are primarily intended for synthesizable RTL. Testbenches may use more expressive constructs, file I/O, randomization or higher-level abstractions. Even there, naming and formatting conventions should remain compatible with the project style.
When a rule has to be broken, make the exception explicit in a comment or design note. Silent exceptions are hard to distinguish from mistakes.
Formatting and layout
Keep formatting mechanical and boring. The reader should not have to infer structure from taste.
Line length
Limit line length to a project-defined value, for example 100 characters. A strict 80-character limit is still useful when code is reviewed in terminals, printed documentation or side-by-side diffs. Long lines can usually be split without loss of clarity.
Prefer one VHDL statement per line:
-- Good
ready_o <= valid_i and not busy_s;
-- Avoid
ready_o <= valid_i and not busy_s; count_v := count_v + 1;
Indentation
Indent every nested region consistently. Use spaces, not tabs, unless the project explicitly defines tabs. A common choice is two or four spaces per indentation level.
p_registers : process (clk_i, rst_i) is
begin
if rst_i = '1' then
counter_s <= (others => '0');
elsif rising_edge(clk_i) then
if enable_i = '1' then
counter_s <= counter_s + 1;
end if;
end if;
end process p_registers;
The indentation should show the hierarchy of entity, architecture, process, if, case, loop, block and generate statements.
Case
VHDL is case-insensitive. Mixed-case identifiers may look readable in the editor but can be normalized by some tools in reports or waveforms. For portable readability, use lowercase identifiers with underscores:
signal write_enable_s : std_logic;
constant c_fifo_depth : positive := 1024;
Choose one keyword style and apply it consistently. Many teams use lowercase for keywords and identifiers because it avoids visual noise.
Naming conventions
A good name tells the reader what an object represents and how it should be used. Avoid abbreviations unless they are standard in the project domain.
Object prefixes
Use prefixes where they add information that the type declaration is not immediately showing:
| Object | Convention | Example |
|---|---|---|
Variable |
|
|
Constant |
|
|
Generic |
|
|
Alias |
|
|
Type |
|
|
Subtype |
|
|
Prefixes are most useful in long processes, packages and generic maps. Do not overuse them for local names that are already obvious.
Labels and design units
Labels should describe the role of a concurrent statement or process:
| Element | Convention | Example |
|---|---|---|
Process |
|
|
Block |
|
|
Loop |
|
|
Generate statement |
|
|
Function |
|
|
Component instance |
|
|
Instance labels such as u_ are common because they read naturally as "unit". If an existing project uses cmp_, keep it; do not mix both styles in one code base.
Ports and internal signals
Port direction should be visible at the module boundary. A simple convention is:
| Direction | Suffix | Example |
|---|---|---|
Input |
|
|
Output |
|
|
Bidirectional |
|
|
Use one bidirectional suffix project-wide. For internal signals, many teams use _s:
signal request_s : std_logic;
signal response_s : std_logic_vector(g_data_width - 1 downto 0);
Keep the same base signal name across hierarchy whenever possible. This makes port maps and waveforms easier to follow:
u_fifo : entity work.fifo(rtl)
port map (
clk_i => clk_i,
rst_i => rst_i,
valid_i => write_valid_s,
ready_o => write_ready_s,
data_i => write_data_s
);
Clock signals should start with clk_ or be named clk_i at a single-clock module boundary. Reset signals should make polarity explicit: rst_i for active-high reset, rst_n_i for active-low reset.
Comments and documentation
Comments should explain intent, assumptions and non-obvious design decisions. They should not repeat the syntax.
-- Good: explains why the limit exists.
-- The counter saturates because downstream firmware polls the value at 1 kHz.
if error_count_s /= c_error_count_max then
error_count_s <= error_count_s + 1;
end if;
-- Avoid: repeats the assignment without adding information.
-- Increment error_count_s by one.
error_count_s <= error_count_s + 1;
Use a short file header for ownership, purpose and important constraints. For reusable IP, document the clocking, reset behaviour, generics, port semantics and legal parameter ranges.
Clocks and resets
Clock and reset style affects synthesis, timing closure, CDC analysis and silicon or FPGA bring-up. Define these rules before the project grows.
Clock domains
Use the minimum practical number of clock domains. Every additional clock domain creates verification and timing obligations.
Do not gate clocks with ordinary RTL logic unless the project has a verified clock-gating methodology and technology-specific cells. In FPGA designs, prefer clock enables:
if rising_edge(clk_i) then
if enable_i = '1' then
data_s <= data_i;
end if;
end if;
Do not use data signals as clocks. Do not use clocks or resets as data or enables.
Clock-domain crossings
Signals that cross between unrelated clock domains need explicit synchronization. For a single-bit control signal, use a two-flop synchronizer in the receiving clock domain. For pulses, multi-bit buses or data streams, use a handshake, asynchronous FIFO or another CDC-safe protocol. A two-flop synchronizer is not sufficient for an arbitrary bus.
Name CDC signals clearly and keep synchronizers close to the receiving logic.
Reset strategy
Choose one reset strategy for the project. Active-high resets are easy to read, but active-low resets are common when they come from board-level or IP-level interfaces. The name must show the polarity.
If an asynchronous reset is used, its assertion can be asynchronous, but its release should be synchronized to the target clock domain. Avoid mixing reset styles inside one module unless there is a documented reason.
Hierarchy and module boundaries
A complex core should be decomposed into small modules with clear responsibilities. The top-level entity should primarily connect submodules. If glue logic is necessary, consider putting it in a small named adapter module rather than hiding it in the top level.
Good hierarchy has these properties:
-
module names describe function, not implementation accidents;
-
interfaces use stable names and types;
-
signal names remain recognizable across hierarchy;
-
clock and reset distribution is explicit;
-
optional features are controlled by generics, not by commented-out code.
Use direct entity instantiation where supported:
u_timer : entity work.timer(rtl)
generic map (
g_counter_width => 32
)
port map (
clk_i => clk_i,
rst_i => rst_i,
enable_i => timer_enable_s,
expired_o => timer_expired_s
);
Component declarations are still useful in some flows, but they are not required for every module when direct instantiation is available.
Packages
Packages should contain shared types, constants, functions and, where needed, component declarations. Name a package after the design area or entity and use the _pkg suffix:
package uart_pkg is
constant c_uart_data_bits : positive := 8;
type t_uart_parity is (
parity_none,
parity_even,
parity_odd
);
end package uart_pkg;
Avoid dumping unrelated declarations into one global package. Large catch-all packages create hidden dependencies and slow down reuse.
State machines
Always draw or document the state transition diagram for a non-trivial finite state machine. The diagram is not bureaucratic overhead; it is the fastest way to validate the designer’s understanding and to support later maintenance.
Use enumerated types for states:
type t_rx_state is (
rx_idle,
rx_start,
rx_data,
rx_stop
);
signal rx_state_s : t_rx_state;
signal rx_next_state_s : t_rx_state;
Choose one FSM coding style for the project: one-process, two-process or three-process. Each can be correct. The important points are to define reset behaviour, assign safe defaults in combinational logic and handle illegal or unused states deliberately.
p_next_state : process (all) is
begin
rx_next_state_s <= rx_state_s;
case rx_state_s is
when rx_idle =>
if start_detected_s = '1' then
rx_next_state_s <= rx_start;
end if;
when rx_start =>
rx_next_state_s <= rx_data;
when rx_data =>
if bit_done_s = '1' then
rx_next_state_s <= rx_stop;
end if;
when rx_stop =>
rx_next_state_s <= rx_idle;
end case;
end process p_next_state;
Types, arithmetic and libraries
Use ieee.numeric_std for arithmetic. Avoid non-standard packages such as std_logic_arith and std_logic_unsigned in new code.
Use unsigned and signed for numeric values and std_logic_vector for bit fields. This keeps arithmetic intent visible and prevents accidental type conversions.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
signal byte_count_s : unsigned(7 downto 0);
Constrain integer ranges when the value has a natural bound:
signal byte_index_s : integer range 0 to g_data_width / 8 - 1;
Review checklist
Before code is merged, check the following points:
-
Is the module purpose clear from its name, header and interface?
-
Are clock and reset names, polarities and domains unambiguous?
-
Are port directions visible in the names?
-
Are generics documented and constrained?
-
Are CDC paths explicitly handled?
-
Are combinational processes free of unintended latches?
-
Are FSM states typed, reset and documented?
-
Are packages cohesive rather than global dumping grounds?
-
Does the code use
numeric_stdfor arithmetic? -
Is formatting consistent enough that diffs show functional changes?
Automating the style guide
A written style guide is useful. An automated style check is better. Formatting, capitalization, naming and spacing rules can be checked by linters or style tools and integrated into continuous integration. Automated checks keep reviews focused on architecture and behaviour instead of whitespace.
Start with non-controversial rules such as indentation, line length, trailing whitespace and keyword case. Then add naming and structural checks once the team has agreed on the conventions.
Summary
VHDL style is not about making code look pretty. It is about reducing ambiguity in hardware descriptions. A good style guide makes signal direction, clocking, reset behaviour, hierarchy and design intent visible before the reader has to simulate or synthesize the design.
The best convention is the one that the whole project follows consistently.