Appendix A Gate-Level Details: Primitive Descriptions
Appendix A Gate-Level Details: Primitive Descriptions
Chapters 2 and 3 briefly introduced the built-in primitives. This appendix will
briefly describe each of the built-in primitives and the options when instantiating
them. The delay and strength options for primitive instances will be explained.
PRIMITIVE DESCRIPTIONS
Logic Gates
AND
The and primitive can have two or more inputs, and has one output. When all of the
inputs are “1” then the output is “1”.
0 1 x z
0 0 0 0 0
1 0 1 x x
x 0 x x x
z 0 x x x
NAND
The nand primitive can have two or more inputs, and has one output. When all of
the inputs are “1” then the output is “0”.
0 1 x z
0 1 1 1 1
1 1 0 x x
x l x x x
z l x x x
Gate-Level Details 283
OR
The or primitive can have two or more inputs, and has one output. When any of the
inputs is “1” then the output is “1”.
0 1 x z
0 0 1 x x
1 1 1 1 1
x x l x x
z x l x x
NOR
The nor primitive can have two or more inputs, and has one output. When any of
the inputs is “1” then the output is “0”.
0 1 x z
0 1 0 x x
1 0 0 0 0
x x 0 x x
z x 0 x x
284 Verilog Quickstart
XOR
The xor primitive can have two or more inputs, and has one output. When an odd
number of inputs is “1” then the output is “1”, unless any input is “x”. When any of
the inputs is “x” then the output is “x”.
0 1 x z
0 0 1 x x
1 1 0 x x
x x x x x
z x x x x
XNOR
The xnor primitive can have two or more inputs, and has one output. When an odd
number of inputs is “1” then the output is “0”, unless any input is “x”. When any of
the inputs is “x” then the output is “x”.
0 1 x z
0 1 0 x x
1 0 1 x x
x x x x x
z x x x x
Gate-Level Details 285
Buffers
BUF
The buf primitive has one input and can have one or more outputs. The output(s)
pass the same value as the input, except an input of “z” produces an output of “x”.
Input Output
0 0
1 1
x x
z x
NOT
The not primitive has one input and can have one or more outputs. The output(s)
pass the opposite value as the input, except an input of “x” or “z” produces an
output of “x”.
Input Output
0 1
1 0
x x
z x
286 Verilog Quickstart
BUFIF0
The bufif0 primitive has two inputs, (data and control) and one output. When the
control input is “0” the output passes the same value as the data input, except that
an input of “z’ produces an output of “x”. When the control input is “1” the output
is “z”. The port order of the primitive is output, input, control.
The remaining logic tables in the section show both strength and value. Verilog
uses a notation of three characters, two for the strength, and one for the value. Table
A-20 lists the two character codes used for the strength and the value is 0, 1, x, or z.
Data 0 1 x z
0 St0 HiZ StL StL
1 Stl HiZ StH StH
x StX HiZ StX StX
z StX HiZ StX StX
BUFlF1
The bufif1 primitive has two inputs, (data and control) and one output. When the
control input is “1” the output passes the same value as the data input, except that
an input of “z” produces an output of “x”. When the control input is “0” the output
is “z”. The port order of the primitive is output, input, control.
Gate-Level Details 287
Data 0 1 x z
1 HiZ St0 StL StL
1 HiZ St1 StH StH
x HiZ StX StX StX
z HiZ StX StX StX
NOTIF0
The notif0 primitive has two inputs, (data and control) and one output. When the
control input is “0” the output passes the opposite value as the data input, except
that an input of “z” produces an output of “x”. When the control input is “1” the
output is “z”. The port order of the primitive is output, input, control.
Data 0 1 x z
0 Stl HiZ StH StH
1 St0 HiZ StL StL
x StX HiZ StX StX
z StX HiZ StX StX
288 Verilog Quickstart
NOTlF1
The notif1 primitive has two inputs, data and control and one output. When the
control input is “1” the output passes the opposite value as the data input, except
that an input of “z” produces an output of “x”. When the control input is “0” the
output is “z”. The port order of the primitive is output, input, control.
Data 0 1 x z
0 HiZ Stl StH StH
1 HiZ St0 StL StL
x HiZ StX StX StX
Z HiZ StX StX StX
PULLDOWN
The pulldown primitive has only one terminal. It outputs a 0 of strength pull (pu0).
When nothing else is driving a net stronger than the pulldown, the pulldown will
drive the net to 0.
Gate-Level Details 289
PULLUP
The pullup primitive has only one terminal. It outputs a 1 of strength pull (pul).
When nothing else is driving a net stronger than the pullup, the pullup will drive
the net to 1.
Switches
The nmos and rnmos primitives are abstractions of unidirectional switches. When
the gate input is 1, this input is passed to the output, otherwise the output is high
impedance. The difference between the nmos and rnmos is the nmos passes the
input to the output with the strength unchanged, but the rnmos passes the value to
the output with a decreased strength. The port order of the primitive is output,
input, gate.
The output strength from any of the transistor primitives is dependent on the
strength of the input. The input strength for the following tables is strong, unless
otherwise noted.
Data 0 1 x z
0 HiZ St0 StL StL
1 HiZ Stl StH StH
x HiZ StX StX StX
z HiZ HiZ HiZ HiZ
Data 0 1 x z
0 HiZ Pu0 PuL PuL
1 HiZ Pul PuH PuH
x HiZ PuX PuX PuX
z HiZ HiZ HiZ HiZ
Gate-Level Details 291
The pmos and rpmos primitives are abstractions of unidirectional switches. When
the gate input is 0, this input is passed to the output, otherwise the output is high
impedance. The difference between the pmos and rpmos is the pmos passes the
input to the output with the strength unchanged, but the rpmos passes the value to
the output with a decreased strength. The port order of the primitive is output,
input, gate.
Data 0 1 x z
0 St0 HiZ StL StL
1 St1 HiZ StH StH
X StX HiZ StX StX
Z HiZ HiZ HiZ HiZ
Data 0 1 x z
0 Pu0 HiZ PuL PuL
1 Pul HiZ PuH PuH
x PuX HiZ PuX PuX
z HiZ HiZ HiZ HiZ
292 Verilog Quickstart
The cmos and rcmos primitives are the equivalent or nmos and pmos (or rnmos and
rpmos) primitives connected back to back. The primitive has four terminals. The
port order is output, input, ngate, pgate.
ngate pgate 0 1 x z
0 0 St0 Stl StX HiZ
0 1 HiZ HiZ HiZ HiZ
0 x StL StH StX HiZ
0 z StL StH StX HiZ
1 0 St0 St1 StX HiZ
1 1 St0 St1 StX HiZ
1 x St0 St1 StX HiZ
1 Z St0 St1 StX HiZ
x 0 St0 St1 StX HiZ
x 1 StL StH StX HiZ
x x StL StH StX HiZ
x z StL StH StX HiZ
z 0 St0 Stl StX HiZ
zz 1 StL StH StX HiZ
z x StL StH StX HiZ
z z StL StH StX HiZ
Gate-Level Details 293
The tran and rtran primitives are bidirectional pass gates. They have only two
terminals that are the bidirectional data pins. Delay specifications are not allowed
on these primitives. The rtran primitive is resistive, and the strength is reduced as
the value passes through.
The tranif0 and rtranif0 primitives are bidirectional pass gates. They have three
terminals. The first two are the bidirectional data pins, the third is the control input.
When the control input is 0, data passes between the two bidirectional data pins.
Delay specifications on these primitives are only turn on and turn off delays. The
rtranif0 primitive is resistive, and the strength is reduced as the value passes
through.
294 Verilog Quickstart
TRANlF1 andRTRANlF1
The tranif1 and rtranif1 primitives are bi-directional pass gates. They have three
terminals. The first two are the bi-directional data pins, the third is the control
input. When the control input is 1, data passes between the two bi-directional data
pins. Delay specifications on these primitives are only turn on and turn off delays.
The rtranif1 primitive is resistive, and the strength is reduced as the value passes
through.
INSTANCE DETAILS
When you create an instance of one of the built-in primitives, the instance name is
optional as you learned in chapter 3. There are other optional arguments you may
specify when creating primitive instances: delays and strengths.
Delays
A primitive may have from zero to nine delay specifications. If a primitive instance
has no delay specification the primitive is zero delay. A primitive may have separate
delays for both rise (to 1) and fall (to 0) time. A primitive that can output high
impedance (such as bufif1, bufif0, and the switches) has an optional turn off (to z)
delay. The delay to x is always the least of the delays specified. If a single delay is
specified, it is used for both rise and fall (and turn off if applicable).
Delays are declared with the # delay operator. The order of the delays is rise, fall,
and turnoff.
module delays ;
and a1 (y, a, b), a2 (w, d, e, f); // zero delay and gates
and #1 a3 (x, a, c, e), a4 (z, e, f); // unit delay and gates
and #(3,2) a5(c, w, z); // rise delay of 3, fall delay of 2
bufifl #(3,2,4) b1(x, a,b); // turn off time is 4
bufif0 #(2:3:4,1:2:3,3:4:5) b2 (f, e, d); // min:typ:max
endmodule
Example A-1 shows primitive instances with between zero and nine delays
specified. Notice that similar to reg and wire declarations where the range in the
specification applies to each declaration, the delay(s) affect each of the instances in
the declaration. The instances a3 and a4 are both unit delay, and that delay of 1 is
used for both rise and fall time. Instance a5 illustrates specifying separate rise and
Gate-Level Details 295
fall delays. When multiple delays are specified they are enclosed in parentheses.
Instance b1 shows adding the third delay specification of turn off time.
Delay Units
All the delays throughout the book were unitless. In behavioral modeling a delay of
one could mean anything. In the phone example in chapter 1 a delay unit was
interpreted as one minute. In gate-level modeling you might want to use delays with
units such as 1 nanosecond or 1 picosecond.
Verilog allows both the specification of a delay unit and a delay precision on a per-
module basis. The delay unit and precision are declared with the `timescale
compiler directive.
The main drawback to using delay units is that if you use them on one module you
must use them on all modules. When you declare a delay unit and precision, that
declaration applies to all following modules. You can declare the unit and precision
for just one module and have that declaration carry forward to all your other
modules: Just make sure that the file with the delay unit and precision declaration is
the first one compiled. If you compile a module before a `timescale directive and a
`timescale directive appears later in the source, Verilog will issue an error message
and abort compiling your files.
Table A-19 lists the units that can be used in a timescale declaration. The timescale
declaration goes outside a module, just before the module. The delay unit and
precision are a combination of 1, 10, or 100, and one of the unit codes in Table A-
19.
296 Verilog Quickstart
‘timescale 100ps / 1 ps
module mod2;
// #2 in this module = 200 ps
endmodule
Example A-2 shows two modules with their timescales. With the addition of the
time unit and precision, decimal delays are possible. Timescales and decimal delays
are usable for both behavioral and gate-level modeling, but most delays in
behavioral modeling are unitless. Behavioral modeling tends to be more abstract
and delays less important than delays in gate-level models.
The format code %t will print out the value of $time or $realtime including the
units.
Strengths
A primitive instance may optionally include the drive strengths from the drive0 and
drive1 columns of Table A-20 to indicate the drive strength of the gate.
Gate-Level Details 297
The drive strength of an instance is specified before the delay and the order of
strength declarations may be either strength1 or strength0 first. Example A-3 shows
declarations including strengths and delays.
module strength;
nand (strong0, highz1) oc1(z, a, b) oc2(w, d, e);
buf (weakl, weak0) #6 wimpo(out, in);
myudp (pull0, pull1) #(2:3:4,1:2:3) u1(q, c, d, r, s);
endmodule
Instances oc1 and oc2 in Example A-3 could be an example of a TTL open collector
NAND gate such as the 7401. As you may know, open collector drivers have strong
drive low, but no drive high, so they need a pullup resistor to achieve a value of 1.
The example buffer shows combining the syntax for specifying strengths with the
syntax of specifying a delay.
The format code %v provides more information than %b. The output produced by
%v is three characters, which describe in more detail the value and strength of a net.
The first two characters describe the strength as described in Table A-20. The third
character describes the value. Two new value codes are added to the 0, 1, X, Z set.
The two new codes are H and L. The value H represents either a 1 or a Z. The value
L represents either a 0 or a Z.
298 Verilog Quickstart
Nets in Verilog may be one of 120 possible values. All of these values can be
printed out with %v. Some of the values do not print out as nicely as the codes from
Table A-20. These values print out the strength portion of the value with a two-digit
numeric code. Values such as 65X and 241 can be printed out by %v. If the third
character in the value is X, the first number represents the zero strength and the
second number represents the one strength. If the third character in the value is 0 or
1, then the first two numbers represent a possible range of strength for the value.
Table A-21 shows the output strength for the switch primitives. The nmos, pmos,
cmos, tran, tranif0, and tranif1 primitives are considered to be ideal devices since
the strength is not reduced through them, except that supply strength is reduced to
strong. The rnmos, rpmos, rcmos, rtran, rtranif0, and rtranif1 primitives are
considered to be resistive devices since the strength is reduced through them.
All this detail with strengths is important for switch-level modeling, but is not used
in behavioral modeling.
Appendix B EXAMPLE SUMMARY
All the examples that are complete modules are syntactically correct. The CM
column of the table indicates the examples that are complete modules.
Examples that are not complete modules are marked synthesizable if the code in the
example is synthesizable in a complete module.
4-33 Events 64 n n
5-7 Concatenations 80 n y
6-25 Test Bench for the ALU 105 y n task and external data file
$cleartrace, 275
- $display, 47, 214
- subtraction, 72 for debug, 249
- no change, 137 specifying format, 48
See Command line option supressing spaces, 54
$dumpfile, 25 1
! $dumpvars, 251
!, 73 $fclose, 50
!=, 76, 77 $fdisplay, 51, 233
!==, 76,77 $finish, 131
$fmonitor, 51
" $fopen, 50
" and white space, 11 $fstrobe, 233
$fwrite, 51
$incpattern, 236
# $input, 266
#, 36 $key, 267
$list, 272
$ $monitor, 50, 214
$, 47 $monitoroff, 50
314 Verilog Quickstart
$monitoron, 50 *
$nokey, 267 *, 72
$random **, 72
example, 5
$readmemb, 226
$readmemh, 226 ’
$realtime, 62, 296 ,, 260
$restart, 275
$save, 275 .
$scope, 269 ., 260
$settrace, 275
$shmopen, 25 1 /
$shmprobe, 25 1 /, 72
$showscopes, 269 /*, 12
$showvars, 273 //, 12
$stop, 252
$strobe, 49,50 ?
$strobe_compare, 236 ?
$time, 62, 296 in case statement, 101
$write, 49 in udp table, 135
?:, 75, 168
% in testbench, 224
%, 72
%%, 54 @
%0b,54 @, 91
%0d, 54 memory address, 228
%0h,54
%0o, 54 ^
%b, 54 ^, 72
%c, 54
%d, 54 `
%e, 54
`defaultnettype, 59
%f, 54
`define, 13
%h, 54
`timescale, 62, 295
%m, 54
%o, 54
%s, 54 {
%t, 54,296 {{ }}, 79
%v, 54,297 { },79
& /
&, 72 |, 72
&&, 72 ||, 72
Index 315
~ address in file, 228
~, 73 alarm, 180
always, 34
+ combinatorial for synthesis, 170
+, 72 explained, 96
++, 110 sensitivity list, 92
sequential, 173
< synthesis, 173
<<, 72 synthesizable combinatorial logic,
<<<, 72 92
<= zero delay, 130
less than or equal to, 77 and
non blocking assignment, 69 bitwise, 72
synthesis, 211 built in gate, 20
when to use non blocking, 211 built in primitve, 282
logical, 73
= reduction, 74
= arithmetic operators, 72
arrays
synthesis, 21 1
of regs, 60
==, 77 two-dimensional, 185
===, 77 ascending range, 58
assign, 113
> improper use, 241
->, 94 assignement
> =, 77 conditional, 75
>>, 72 assignment
>>>, 72 blocking vs non blocking, 211
conditional, 88
0 continuous, 87
0 nonblocking, 69
value, 15 procedural, 65
quasi-continuous. See procedural
1 continuous assignment
1 with delays, 67
value, 15 assignments
procedural continuous, 111
A procedural for combinatorial
abstraction logic, 211
levels, 4 procedural for sequential logic,
active low signals, 10 211
adder, 171 asynchronous, 179
schematic, 28 asynchronous circuits, 178
simulation, 28
316 Verilog Quickstart
D display, 214
deassign, 113 for debug, 249
debug, 214 suppressing spaces, 54
decimal, 13 documentation, 3
declaration dump file, 251
array of reg, 60 dump task
bit index, 58 for memory, 146
bus, 58 dumpfile, 251
event, 63 dumpvars, 251
implicit net, 59
integer, 62 E
memory, 60 edge sensative
net, 58 udp, 136
edge sensitive
90 always, 91
parameter, 63 else, 98
range, 58 endcase, 99
real, 62 endfunction, 123
realtime, 62 endmodule, 14
reg, 60 endprimitive, 135
time, 62 endtable, 135
vector, 58 endtask, 116
declarations equal, 76
missing width, 239 equivalence, 77
declatation escaped identifiers, 10
string, 64 event, 91, 94
decompile, 272 example, 5
default net type, 59 using, 94
default value event list, 92
parameter override, 147 event-driven simulation, 4
define, 13 events, 63
defparam, 147 example, 5
delay, 36 expression
in primitive instance, 294 bit width of, 83
max, 295 truncation, 83
min, 295
proper use for synthesis, 212 F
turn off, 294 fall time, 294
typical, 295 fanin, 273
units, 295 fclose, 50
descending range, 58 fdisplay, 51, 233
design unit, 14 file
dff, 91 closing, 50
disable, 128 numbers, 51
318 Verilog Quickstart
opening, 50 H
printing to, 50 hexadecimal, 13
reading, 228 hierarchical names, 25
test vector, 234 hierarchy, 22
writing, 233 traversing interactively, 269
files high impedance
multiple, 51 continuous assignment buffer, 88
finish, 131 Highest level modules, 27
finishing simulation, 131 history, 260
flip-flop, 91
modified for speed, 201
I
with reset, 113
-i, 264
fmonitor, 51
Identifiers, 9
fopen, 50
escaped, 10
for, 110
IEEE standard, 8
for loop, 110
IEEE1364-1999, 65, 84, 92
force, 274
if, 97
forever, 107
illegal left hand side assignment, 238
forever loop, 108
illegal part select, 240
fork-join, 39
implicit net declaration, 59
disabling, 128
implicit state machine, 164
named, 128
incpattern, 236
nesting, 41
inferred latches, 243
frequently asked questions, 8
inferred registers, 243
fs, 295
initial, 34
fstrobe, 233
in UDP, 138
function, 123
inout, 21
and continuous assignment, 124
in testbench, 224
synthesis, 172
test bench, 225
with continuous assignment, 172
inout port
Functional Testing, 215
and task, 118
fwrite, 51
modeling with, 126
input, 21,266
G input port
gate and task, 118
instance, 22 instance, 21, 22
gate instance, 294 built in primitive, 294
with strength, 297 gate, 22
gate level modeling, 22 of module, 24
gates, 19, 20 primitive, 22
Gateway Design Automation, 2 user defined primitive, 139
Gray code, 161, 162 integer, 62
interactive simulation prompt, 253
internet
Index 319
Radix Specifiers, 13 S
RAM -s, 252
test bench, 225 s, 295
ram model, 146
save, 275
random
schematic, 19
example, 5 schematics, 19
range, 58
scope, 269
reverscd, 240 Self-Checking Test Benches, 215
remos, 292 semicolon, 14, 254
built in primitive, 20 sensitivity list, 92
readmemb, 226
sequential, 5
readmemh, 226
udp, 136
real, 62
sequential logic, 173
operators with, 82 settrace, 275
realtime, 296 shift operators, 72
reduction of strength, 298 shm, 251
reg, 60 shmopen, 251
and port declarations, 69 shmprobe, 251
initial value, 61
showscopes, 269
parameterized declaration, 144 showvars, 273
registers sign extension, 16
inferred, 243 signaling an event ->, 94
Regression Testing, 215 signed operations, 84
release, 274 signed constant, 84
repeat, 108, 171 signed values
repeat loop, 108 printing, 84
synthesis, 171 simulation, 2
repeat operator, 79 simulation performance, 199
response driven stimulus, 221 Simulation types
restart, 275
continuous, 4
results discrete, 4
log file, 47 single step, 255
print on change, 50 Sizing Expressions, 83
rise time, 294 sm, 297
rnmos, 290 small, 15
built in primitive, 20
small capacitor, 297
rpmos, 291 space
built in primitive, 20 suppressing, 54
rtran, 293 SPICE, 4
built in primitive, 20
st, 297
rtranif0, 293 start here at time 0, 34
rtranif1, 294 state, 15
built in primitive, 20 state machines
and synthesis, 160
Index 323
best style, 160 system tasks, 47
choosing a style, 166 system test, 221
default state, 163
encoding, 161 T
explicit, 155 table, 135
implicit, 164 talkverilog, 8
Mealy, 151 task, 116
Moore, 151 and sequential models, 176
stimulus in test bench, 218
response driven, 221 terminal, 21
stop, 252
ternary operator, 168
storage node, 57 test
strength, 15, 296 functional, 215
in primitive instance, 297
test vector
reduction, 290 capture, 236
strength reduction, 298
test vectors, 234
string
text macro, 13
printing, 47 then, 97
strings, 64, 82
three-state buffer, 76, 88, 286
operators with, 82 three-state inverter, 287, 288
strobe, 50 time, 62,296
strobe_compare, 236
timescale, 62, 295
strong, 15, 297 top level module, 27
strong0, 297
tracing, 39, 275
strong1, 297 tran, 293
Structural modeling, 19, 24
built in primitive, 20
su, 297
tranif0, 293
supply, 15, 297 built in primitive, 20
supply0, 57,297 tranif1 , 294
supply 1, 57, 297
built in primitive, 20
switches, 19, 289 traversing hierarchy, 269
syntax error, 241
tri, 57
synthesis, 3, 201 tri0, 57
<=, 211 tri1, 57
=, 211 triand, 57
asynchronous, 179 trior, 57
combinatorial always, 170
trireg, 57
combinatorial logic, 167
truncation, 83
continuous assignement, 168
truth table, 133
delays, 2 12
typical delay, 295
flowchart for checking, 203
functions, 172
repeat loop, 171
U
state machines, 160 UDP, 133
synthesizable, 202 combinatorial, 134
324 Verilog Quickstart