Verilog
Verilog
endmodule a f1
nsel g1
g4
g3 f
b
g2
sel f2
endmodule a f1
nsel g1
g4
g3 f
b
g2
sel f2
endmodule a
f
b
sel
endmodule a
f
b
sel
endmodule
f
b
sel
Stimulus
Structure (Plumbing)
• Verilog program build from modules with I/O interfaces
• Modules may contain instances of other modules
• Modules contain local signals, etc.
• Module configuration is static and all run concurrently
0, 1
• Obvious
Z
• Output of an undriven tri-state driver
• Models case where nothing is setting a wire’s value
X
• Models when the simulator can’t decide the value
• Initial state of registers
• When a wire is being driven to 0 and 1 simultaneously
• Output of a gate with Z inputs
Copyright © 2001 Stephen A. Edwards All rights reserved
Four-valued Logic
Logical operators work on three-valued logic
0 1 X Z
look like
initial always
begin begin
… imperative statements … … imperative statements …
end end
initial begin
#10 a = 1; b = 0;
#10 a = 0; b = 1;
end
sum = a + b + cin;
case (op)
2’b00: y = a + b;
2’b01: y = a – b;
2’b10: y = a ^ b;
default: y = ‘hxxxx;
endcase
i = 0;
while (I <= 15) begin
output = i;
#10 i = i + 1;
end
reg q;
Fundamental problem:
• In a synchronous system, all flip-flops sample
simultaneously
• In Verilog, always @(posedge clk) blocks run in some
undefined sequence
a = 1; a <= 1;
b = a; b <= a;
c = b; c <= b;
a = 1;
b = a;
“ 1
a b c ”
c = b;
1 a
a <= 1;
b <= a; “ b ”
c <= b;
c
#42
• Schedule process to resume 42 time units from now
wait(cf & of)
• Resume when expression “cf & of” becomes true
@(a or b or y)
• Resume when a, b, or y changes
@(posedge clk)
• Resume when clk changes from 0 to 1
while (~ready)
count = count + 1;
Instead, use
wait(ready);
Major vendors
• Synopsys Design Compiler, FPGA Express
• Cadence BuildGates
• Synplicity (FPGAs)
• Exemplar (FPGAs)
Academic tools
• SIS (UC Berkeley)
Copyright © 2001 Stephen A. Edwards All rights reserved
Logic Synthesis
Takes place in two stages:
Typical operations
• Constant propagation
• Common subexpression elimination
• Function factoring
Time-consuming operation
• Can take hours for large chips
Sequential:
reg q;
always @(d or clk) q only assigned when
clk is 1
if (clk) q = d;
always @(a or b)
case ({a, b})
2’b00: f = 0; f is always assigned
2’b01: f = 1;
2’b10: f = 1;
default: f = 0;
endcase
Logic synthesis
• Translating Verilog (structural and behavioral) into
netlists
• Register inference: whether output is always updated
• Logic optimization for cleaning up the result
Delays
• Simulating circuits with delays does not improve
confidence enough
• Hard to get timing models accurate enough
• Never sure you’ve simulated the worst case
• Static timing analysis has taken its place