VERILOG : 7. User Defined Primitives (UDPs)
🔹 What are User Defined Primitives (UDPs)?
In Verilog, User Defined Primitives (UDPs) are a way to create custom logic primitives beyond the limited set of built-in primitives. They allow designers to define combinational logic or sequential logic using truth tables.
👉 In simple words, UDPs are custom truth tables written in Verilog.
For example:
Combinational UDP → Works like a simple gate (AND, OR, XOR, etc.) but defined by the user.
-
Sequential UDP → Models latches, flip-flops, and other memory elements.
These are particularly useful when modeling ASIC libraries or verifying custom-designed hardware components.
🔹 Syntax of a UDP
Every UDP in Verilog follows a strict syntax:
Example UDP Skeleton:
Here:
-
primitive→ Keyword to define UDP. -
a→ Output port (must always come first). -
b, c, d→ Input ports. -
table ... endtable→ Defines functionality.
🔹 Rules for UDP Ports
When defining UDPs, some strict rules apply:
-
✅ A UDP can only have one output but up to 10 inputs.
-
✅ The output port must be the first port in the list.
-
✅ All ports are scalar (vectors are not allowed).
-
✅ UDPs cannot have bidirectional ports (
inout). -
✅ For sequential UDPs, the output must be declared as a
reg. -
❌ Declaring
regfor combinational UDP outputs is illegal.
🔹 Combinational UDP Example
Let’s define a simple OR gate using UDP:
Explanation:
-
?means “don’t care” (0, 1, or x). -
If
cis1, output is1. -
If
bis1, output is1. -
If both are
0, output is0.
This behaves just like a logical OR gate.
🔹 Testbench for Combinational UDP
To test the above UDP, we can write a simple testbench:
Sample Output:
🔹 Sequential UDP Example
Sequential UDPs behave like flip-flops or latches.
Example: A UDP with an initial state:
Here, reg a; is necessary since it stores state.
🔹 UDP Symbols Used in Tables
Verilog UDPs use special symbols in truth tables:
|
Symbol |
Meaning |
Example |
|
? |
Don’t care (0, 1, or x) |
? 1 : 1; |
|
b |
0 or 1 (not x) |
b ? : 1; |
|
r |
Rising edge (0 → 1) |
(01) |
|
f |
Falling edge (1 → 0) |
(10) |
|
p |
Positive edge (including x and z cases) |
(0x), (x1) |
|
n |
Negative edge (including x and z cases) |
(1x), (x0) |
|
* |
Any transition |
(??) |
|
- |
No change in output |
Used in sequential UDPs |
⚠️ Note: z is not allowed in UDP input tables.
🔹 Why Use UDPs?
UDPs are useful when:
-
You want to model custom primitives for ASIC libraries.
-
You need a simplified abstraction of a logic function.
-
You’re building sequential elements without writing long
alwaysblocks. -
You want to simulate and verify custom hardware more efficiently.
🔹 Final Thoughts
User Defined Primitives (UDPs) in Verilog give hardware designers the ability to go beyond built-in gates and model custom logic with ease. With the help of tables, you can define combinational and sequential behaviors concisely.
By mastering UDPs, you can:
-
Build accurate ASIC models
-
Simplify simulation code
-
Improve testbench readability
👉 Whether you’re a beginner or an advanced designer, UDPs are an essential part of mastering Verilog HDL.

Comments
Post a Comment