Professional Documents
Culture Documents
A modeling technique whereby the user can virtually argument predefined gate
primitives by designing and specifying new primitive elements called user-defined
primitives (UDPs). These primitives are self-contained and do not instantiate other
primitives or modules.
Verilog provides a standard set of primitives, such as AND, NAND, NOT, OR, and NOR,
as a part of the language. These are also known as built-in primitives.
Instances of these new UDPs can be used in the same manner as the gate primitives to
represent the circuit being modeled. This technique can reduce the amount of memory
and improve simulation performance. The Verilog-XL algorithm accelerates the
evaluation of these UDPs.
Each UDP has exactly one output, which can be in one of these states: 0, 1, or x. The tri-
state value z is not supported. Any input that has the value Z will be treated as X.
1. Combinational UDP
2. Sequential UDP
A sequential UDP uses the value of its inputs and the current value of its output to
determine the next value of output.
Sequential UDPs provide an efficient and easy way to model sequential circuits such
as latches and flip-flops.
A sequential UDP can model both level-sensitive and edge-sensitive behavior. The
maximum number of inputs to a combinational UDP is 10. The maximum number of
inputs to a sequential UDP is limited to 9 because the internal state counts as an input.
Syntax
UDP begins with the reserved word primitive and ends with endprimitive.
Ports/terminals of primitive should follow. UDPs should be defined outside
the module and endmodule.
UDP Rules
Hardware behavior is described as a primitive state table that lists out a different
possible combination of inputs and their corresponding output within
the table and endtable. Values of input and output signals are indicated using the
following symbols.
Symbol Comments
0 Logic 0
1 Logic 1
Combinational UDP
In combinational UDPs, the output state is determined solely as a function of the current
input states. Whenever an input changes state, the UDP is evaluated, and one of the
state table rows is matched. The output state is set to the value indicated by that row.
The maximum number of inputs to a Combinational UDP is 10.
Consider the following example, which defines a multiplexer with two data inputs, a
control input. But there can only be a single output.
A ? indicates that the signal can be either 0, 1 or x and does not matter in deciding the
final output.
Example
Below is a testbench module that instantiates the UDP and applies input stimuli to it.
1. module tb;
2. reg sel, a, b;
3. reg [2:0] dly;
4. wire out;
5. integer i;
6.
7. // Instantiate the UDP
8. // UDPs cannot be instantiated with port name connection
9. mux u_mux ( out, sel, a, b);
10. initial begin
11. a <= 0;
12. b <= 0;
13.
14. $monitor("[T=%0t] a=%0b b=%0b sel=%0b out=%0b", $time, a, b, sel, out);
15.
16. // Drive a, b, and sel after different random delays
17. for (i = 0; i < 10; i = i + 1) begin
18. dly = $random;
19. #(dly) a <= $random;
20. dly = $random;
21. #(dly) b <= $random;
22. dly = $random;
23. #(dly) sel <= $random;
24. end
25. end
26. endmodule
Sequential UDP
Sequential UDP allows the mixing of the level-sensitive and edge-sensitive constructs in
the same description. The output port should also be declared as reg type within the
UDP definition and can be optionally initialized within an initial statement.
Sequential UDP takes the value of its inputs and the current value of its output to
determine the next value of its output. The value of the output is also the internal state
of the UDP.
Sequential UDPs have an additional field in between the input and output field, which is
delimited by a ":" representing the current state.
Sequential UDP provides an easy and efficient way to model sequential circuits such as
latches and flip-flops. The maximum number of inputs to a Sequential UDP is limited to
9 because the internal state counts as an input. There are two kinds of sequential UDPs.
1. Level-Sensitive UDPs
This new field represents the current state of the UDP. The output field in a sequential
UDP represents the next state.
In the above code, a hyphen "-" on the last row of the table indicates no change in value
for q+.
1. module tb;
2. reg clk, d;
3. reg [1:0] dly;
4. wire q;
5. integer i;
6. d_latch u_latch (q, clk, d);
7. always #10 clk = ~clk;
8. initial begin
9. clk = 0;
10.
11. $monitor ("[T=%0t] clk=%0b d=%0b q=%0b", $time, clk, d, q);
12. #10; // To see the effect of X
13. for (i = 0; i < 50; i = i+1) begin
14. dly = $random;
15. #(dly) d <= $random;
16. end
17.
18. #20 $finish;
19. end
20. endmodule
2. Edge-Sensitive UDPs
In level-sensitive behavior, the inputs and the current state's values are sufficient to
determine the output value.
Edge sensitive behavior differs in that changes in the output are triggered by specific
transitions of the inputs.
The UDP is instantiated and driven with random d input values in the testbench after a
random number of clocks.
1. module tb;
2. reg clk, d;
3. reg [1:0] dly;
4. wire q;
5. integer i;
6. d_flop u_flop (q, clk, d);
7. always #10 clk = ~clk;
8. initial begin
9. clk = 0;
10. $monitor ("[T=%0t] clk=%0b d=%0b q=%0b", $time, clk, d, q);
11. #10; // To see the effect of X
12. for (i = 0; i < 20; i = i+1) begin
13. dly = $random;
14. repeat(dly) @(posedge clk);
15. d <= $random;
16. end
17. #20 $finish;
18. end
19. endmodule
The output q follows the input d after 1 clock delay, which is the D flip-flop's desired
behavior.