Writing Synthesizable Verilog/System Verilog code

When writing synthesizable Verilog / System Verilog code, it is important to follow certain guidelines to ensure the code can be correctly synthesized into hardware using a synthesis tool. Here are some basic guidelines for writing synthesizable Verilog / System Verilog code:

  1. Clearly define modules and interfaces: To ensure clarity and consistency in your code, define modules and interfaces with proper ports and data types. Clearly state the purpose and functionality of each module and use descriptive names for signals and variables.

  2. Use non-blocking assignments for sequential logic: For accurate modeling of flip-flops, use non-blocking assignments (<=) inside always_ff or always_comb blocks for sequential logic. Non-blocking assignments ensure simultaneous updates in the next clock cycle.

  3. Use blocking assignments for combinational logic: In combinational logic, use blocking assignments (=) inside always_comb blocks for immediate updates. Blocking assignments ensure that updates occur immediately and in the order they are written.

  4. Avoid inferring latches: Unless explicitly required, avoid inferring latches. To prevent latch inference, cover all possible input combinations in your design and provide a default assignment for all variables in the always block.

  5. Specify edge-sensitive constructs for flip-flops: Specify the triggering conditions for flip-flop updates using posedge (positive edge) or negedge (negative edge). This ensures that flip-flops are updated only when the specified edge occurs on the clock signal.

  6. Limit the usage of always @(posedge clk): Enhance readability and synthesis efficiency by minimizing the use of clock-sensitive constructs outside the main sequential logic, such as always @(posedge clk). Use them only where necessary to avoid unnecessary updates and potential timing issues.

  7. Explicitly define sensitivity lists in procedural blocks: Ensure proper signal sensitivity by explicitly specifying sensitivity lists in always_comb, always_ff, or always_latch blocks. This helps avoid unintended synthesis issues and makes the code more robust.

  8. Use always_ff for synchronous logic: For synchronous logic, use always_ff blocks to maintain explicit control over clock and reset signals, ensuring proper synchronization.

  9. Avoid race conditions: Prevent race conditions where multiple signals drive the same output by using proper coding techniques, such as prioritization. Race conditions can lead to unpredictable results and should be avoided.

  10. Write portable code: To make your Verilog/SV code portable across different synthesis tools and FPGA vendors, avoid using vendor-specific or tool-specific constructs or pragmas unless explicitly required for your target platform. This ensures compatibility and facilitates ease of migration.

  11. Prefer the logic data type: For better compatibility and readability, use the logic data type instead of reg. Reserve the use of reg for variables with scheduling semantics.

  12. Utilize enumerated types (enum): Enhance clarity and maintainability by using enum to define state machines or control signals. Enumerated types provide a concise and organized way to represent a set of values.

  13. Follow coding style guidelines: Maintain consistent indentation, naming conventions, and comments throughout your code. Following coding style guidelines improves code readability and facilitates understanding and maintenance.

  14. Validate synthesis results: After synthesizing your code, validate the synthesized output using reports and physical design tools. This ensures that the hardware matches the intended design and meets performance requirements.

Popular Synthesis Tools: Here are some popular synthesis tools widely used in the industry:

  1. Cadence Design Systems – Genus Synthesis Solution
  2. Synopsys Inc – Design Compiler, DC NXT, Fusion Compiler
  3. Mentor Graphics – Precision RTL Synthesis
  4. Xilinx – Vivado Synthesis
  5. Intel Corporation – Intel Quartus Prime
  6. Open Source – Yosys Open Synthesis Suite

Following these guidelines will help you write synthesizable Verilog / SV code that can be correctly synthesized into hardware. This will save you time and effort in the long run and will help you to create reliable and efficient electronic systems.

I hope this blog post was helpful. If you have any questions, please feel free to leave a comment below.

Leave a Comment