Skip to content

Verilog · Chapter 16 · User-Defined Primitives

User-Defined Primitives (UDPs) in Verilog — Chapter 16 Overview

A user-defined primitive, or UDP, is a custom primitive you define with a truth table, much like the built-in gates but with behaviour you specify directly instead of choosing from the standard set. A UDP has exactly one output, which must be the first port, and is defined between primitive and endprimitive with a table that maps input and state combinations to that output. There are two kinds. A combinational UDP has an output that is a pure function of its inputs. A sequential UDP has an output that depends on its current state and input transitions, modeling a latch or flip-flop with edge and level sensitivity. UDPs are reference material, not synthesizable and not used to author RTL. Their niche is modeling library cells and legacy gate-level behaviour compactly. This overview frames both kinds and sets up the sub-topics.

Foundation12 min readVerilogUDPPrimitiveTruth TableCell Modeling

Chapter 16 · User-Defined Primitives (Overview)

1. The Engineering Problem

The built-in gate primitives (Chapter 11) cover the standard logic gates — but modeling a custom primitive (an ASIC standard cell's exact behaviour, including its handling of unknowns) sometimes calls for defining a primitive by its truth table directly. The question:

How do you define a custom primitive by its truth table — like the built-in gates but with your own behaviour — and when does that matter?

The answer is the user-defined primitive (UDP): a single-output primitive whose behaviour is given by a table. It is reference material — not synthesizable, not for RTL design — used to model library cells and legacy gate-level behaviour compactly.

2. Mental Model — A Custom Primitive Defined by a Truth Table

3. The Two Kinds of UDP

udp-glance.v
Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
   // COMBINATIONAL UDP — output is a function of inputs (a truth table):
   primitive mux_udp (out, a, b, sel);
       output out;
       input  a, b, sel;
       table
           // a b sel : out
              1 ? 0   : 1;     // sel=0 → out = a
              0 ? 0   : 0;
              ? 1 1   : 1;     // sel=1 → out = b
              ? 0 1   : 0;
       endtable
   endprimitive
 
   // SEQUENTIAL UDP — output depends on state + input transitions (a latch):
   primitive latch_udp (q, d, en);
       output q;  reg q;       // 'reg' → sequential (stateful)
       input  d, en;
       table
           // d en : q(state) : q(next)
              ? 0  :    ?      :   -;     // en=0 → hold (no change)
              0 1  :    ?      :   0;     // en=1 → q = d
              1 1  :    ?      :   1;
       endtable
   endprimitive
  • Combinational UDP — the table maps inputs to the output; ? is a don't-care. (Drilled in 16.1.)
  • Sequential UDP — the output is declared reg (stateful), and the table includes the current state and next state; - means "no change" (hold). (Drilled in 16.2.)

4. Why UDPs Are Reference, Not Design

The context that frames this chapter:

  • Not synthesizable — synthesis does not produce or accept UDPs as design logic; they are simulation models.
  • Cell-library modeling — a UDP can model an ASIC standard cell's exact behaviour (including precise unknown/x handling) more compactly than a gate network — their main real use.
  • Legacy gate-level — older gate-level models and some primitive libraries use UDPs.
  • You read, you don't author — new design is RTL; UDPs are encountered in cell libraries and legacy code, which is why this chapter is reference.

5. What This Chapter Covers

§Sub-topicCovers
16.1Combinational UDPstruth-table primitives; don't-cares; combinational cell models
16.2Sequential UDPsstateful UDPs; latches and flip-flops; edge/level tables
16.3UDPs Advanced Techniquesedge symbols, shorthand, don't-cares, limitations

6. Common Misconceptions

"UDPs are how you write custom logic in RTL." False. UDPs are not synthesizable and not for RTL design — they are simulation models for cells. Custom logic in RTL is written behaviourally (Chapter 14).

"A UDP can have multiple outputs." False. A UDP has exactly one output (the first port). For multiple outputs, use a module.

"UDPs are common in modern design." Misleading. They are legacy/reference — used mainly in cell-library modeling. Most engineers read them (in libraries) rather than write them.

7. Summary

A user-defined primitive (UDP) is a custom single-output primitive defined by a truth table:

  • Single output (first port), defined with primitive/endprimitive and a table/endtable.
  • Two kinds — combinational (truth table of inputs → output) and sequential (output depends on state + input transitions; output is reg).
  • Reference — not synthesizable; used for cell-library modeling and legacy gate-level.

The sub-topics drill each: Chapter 16.1 Combinational UDPs, 16.2 Sequential UDPs, and 16.3 UDPs Advanced Techniques. After UDPs, the remaining chapters cover delay and timing reference topics (17–19).