User Defined Primitive

LRM §8.

User Defined Primitives define new primitives.


primitive UDP_name (output, input, ...);
  [ reg output; ]
  [ initial output = initial_value; ]


User Defined Primitives (UDP) define new primitives, small components, and are used exactly the same as the built-in primitives.

The width of the UDP ports is 1-bit. Only one output is allowed. This output is the first port in the port list. The number of inputs may be limited, but at least 9 inputs for a sequential UDP and 10 inputs for a combinational UDP is allowed.

The UDP is a sequential UDP if the UDP output is declared as a reg. The initial (power-up) state for sequential UDP's can be defined with the initial statement.

The behaviour of a UDP is defined in a truth table. The rows in the table define the output values for various input conditions. The truth table entry is:

input_values : output_value;                           // combinational UDP
input_values : previous_output_state : output_value;   // sequential UDP

The input values are separated by white spaces. The input values in the table must be listed in the same order as in the port list.

The truth table symbols are shown in the table below:




Logic 0


Logic 1

x or X



Don't care if input is 0, 1 or X

b or B

Don't care if input is 0 or 1


Output does not change (sequential UDP only)


Input transition from logic v to logic w

r or R

Rising input transition: (01)

f or F

Falling input transition: (10)

p or P

Positive input transition: (01), (0x) or (x1)

n or N

Negative input transition: (10), (1x) or (x0)


Any possible input transition: (??)

Any combination of input values not specified in the table will result in a X (unknown) value on the output.

The Z value is not supported in the table. Z's on inputs are treated as X. Z as output value is not allowed.

If an edge appears anywhere in the table, all possible edges on inputs must be considered, because the default is that an edge causes the output to be unknown for a sequential UDP.


primitive Mux (y, a, b, sel);       // combinational UDP
  output y;
  input a, b, sel;
    // a  b  sel  :  y
       0  ?   0   :  0;
       1  ?   0   :  1;
       ?  0   1   :  0;
       ?  1   1   :  1;

primitive Dff (q, d, clk, rst);    // sequential UDP
  output q;
  input clk, rst, d;
  reg q;
  initial q = 0;
    // d  clk  rst : old q : q
       ?   ?    0  :   ?   : 0;
       0   R    1  :   ?   : 0;
       1  (01)  1  :   ?   : 1;
       ?   N    1  :   ?   : -;
       *   ?    1  :   ?   : -;
       ?   ?   (0?):   ?   : -;

See also:

Built-in primtives, Instantiation, Module