Verilog 2 - Design Examples: 6.375 Complex Digital Systems Arvind February 9, 2009
Verilog 2 - Design Examples: 6.375 Complex Digital Systems Arvind February 9, 2009
Register Transfer Level automatic tools to synthesize a low-level gate-level model Gate Level
February 9, 2009
L03-2
always blocks allow more expressive control structures, though not all will synthesize default
L03-3
L03-4
An example
wire A_in, B_in, C_in; reg A_out, B_out, C_out; always @( posedge clk ) begin A_out <= A_in; B_out <= A_out + 1; C_out <= B_out + 1; end
+1
+1
The order of non-blocking assignments does not matter! The effect of non-blocking assignments is not visible until the end of the simulation tick
February 9, 2009
L03-5
Another way
wire A_in, B_in, C_in; reg A_out, B_out, C_out; always @( posedge clk ) begin A_out <= A_in; B_out <= B_in; C_out <= C_in; end assign B_in = A_out + 1; assign C_in = B_out + 1;
+1
+1
February 9, 2009
L03-6
+1
+1
Syntactically illegal
February 9, 2009
L03-7
+1
+1
Does it have the same functionality? Yes. But why? Need to understand something about Verilog execution semantics
L03-8
February 9, 2009
+1
+1
+1
+1
February 9, 2009
L03-9
February 9, 2009
L03-10
A 1 B 2 C
C B A
On clock edge all those events which are sensitive to the clock are added to the active event queue in any order!
L03-11
February 9, 2009
A 1 B 2 C
C C A 1 B B
February 9, 2009
L03-12
A 1 B 2 C
2 1 B 1 C C
Event queue is emptied B evaluates and as a consequence 2 to added before we go is next to the event queue clock cycle
February 9, 2009
L03-13
Non-blocking assignment
Within a simulation tick all RHS
variables are read first and all the LHS variables are updated together at the end of the tick
to be maintained one keeps the computations to be performed while the other keeps the variables to be updated
Courtesy of Arvind http:// csg.csail.mit.edu/6.375/ L03-14
February 9, 2009
A 1 B 2
2 1
C B A R R R
Non-Blocking Queue C B A L L L
February 9, 2009
Variables in RHS of always C blocks are not updated until all inputs (e.g. LHS + dependencies) are Courtesy of Arvind http:// evaluated
csg.csail.mit.edu/6.375/
L03-15
February 9, 2009
L03-16
GCD in C
int GCD( int inA, int inB) { int done = 0; int A = inA; Such a GCD description can be int B = inB; easily written in Behavioral while ( !done ) Verilog { if ( A < B ) { swap = A; A = B; It can be simulated but it will B = swap; have nothing to do with } hardware, i.e. it wont else if ( B != 0 ) synthesize. A = A - B; else done = 1; } return A; }
February 9, 2009 Courtesy of Arvind http:// csg.csail.mit.edu/6.375/ L03-17
February 9, 2009
L03-18
February 9, 2009
L03-19
clk
reset
February 9, 2009
L03-20
zero? A
lt sub
A = inA; B = inB; while ( !done ) begin if ( A < B ) swap = A; A = B; B = swap; else if (B != 0) A = A - B; else done = 1; End Y = A; L03-21
February 9, 2009
Step 3: Add the control unit Control unit to sequence the datapath should be
A A sel en B B sel en B=0 A<B
designed to be either busy or waiting for input or waiting for output to be picked up
zero? A
lt sub
A = inA; B = inB; while ( !done ) begin if ( A < B ) swap = A; A = B; B = swap; else if (B != 0) A = A - B; else done = 1; End Y = A; L03-22
February 9, 2009
zero? A B
lt sub
);
L03-23
zero? A
lt sub
L03-24
Using explicit state helps vcMux2#(W) B_mux eliminate issues ( .in0 (operand_B), with non-blocking .in1 (A), assignments
wire [W-1:0] B_out; .sel (B_sel), .out (B_out) );
vcEDFF_pf#(W) B_pf Continuous ( .clk (clk), assignment .en_p (B_en), combinational .d_p (B_out), logic is fine .q_np (B) ); assign B_zero = (B==0); assign A_lt_B = (A < B); assign sub_out = A - B; assign result_data = A; Courtesy of Arvind http://
csg.csail.mit.edu/6.375/
L03-25
input_availble CALC Swapping and subtracting (B=0) result_taken DONE Waiting for consumer to take the result
February 9, 2009
L03-26
Localparams are not really parameters at all. They are scoped constants.
February 9, 2009
L03-27
February 9, 2009
L03-28
result_taken
DONE
L03-29
B=0
A<B
zero? A B
lt sub
February 9, 2009
L03-30