Chapter 5 - Dataflow Modeling
Chapter 5 - Dataflow Modeling
2
Verilog model for hardware
Verilog design
design
RTL Design
3
Content
Dataflow modeling
Continuous assignment
Expression, operator, operands
Design examples
4
Dataflow model
For complex design: number of gates is very large
-> need a more effective way to describe circuit
Dataflow model: Level of abstraction is higher than gate-
level, describe the design using expressions instead of
primitive gates
Circuit is designed in terms of dataflow between register,
how a design processes data rather than instantiation of
individual gates
RTL (register transfer level): is a combination of dataflow
and behavioral modeling
5
Continuous assignment
Drive a value onto a net
assign out = i1 & i2; //out is net; i1 and i2 are nets
Left-hand side Right-hand side
Net (vector or scalar) Net, register, function
Bit-select or part-select of a vetor net call (any expression that
Concatenation of any of the above gives a value)
Always active
Delay value: control time when the net is assigned value
assign #10 out = in1 & in2; //delay of performing computation,
//only used by simulator, not synthesis
6
Continuous assignment
Examples:
wire out = in1 & in2; //scalar net
//implicit continuous assignment, declared only once
assign addr[15:0] = addr1_bits[15:0] ^ addr2_bits[15:0]; //vector net
assign {c_out, sum[3:0]} = a[3:0] + b[3:0] + c_in; //concatenation
module adder (sum, carry_out, carry_in, ina, inb);
output [3:0] sum;
output carry_out;
input [3:0] ina, inb;
input carry_in;
wire carry_out, carry_in;
wire [3:0] sum, ina, inb;
assign {carry_out, sum} = ina + inb + carry_in;
endmodule
7
Continuous Assignment
Examples
Question: What shall be the result of the following assignment?
(1) wire [3:0] y;
assign y[3:0] = -3;
10
Continuous Assignment
Examples
A sample answer
12
Delay
Regular assignment delay
13
Expression: Operands
Constant number or string Constant
Parameter
Net
Variable (reg, integer, time, real, realtime)
Array element Data types
14
Expression: Operators
Arithmetic + - * / % **
Logical ! && ||
Logical equality == !=
Case equality === !===
Bitwise ~ & | ^ ^~ (or ~^)
Relational < > >= <= Operators not
allowed for real
Unary reduction & ~& | ~| ^ ^~ (or ~^) expression
Shift << >> <<< >>>
Concatenation {}
Replication {{}}
Condition ?: Ref. book for detail
of each operator!
Unary + - 15
Arithmetic Operators
16
Arithmetic Operators (cont.)
Example
17
Logical Operators
- Return a single bit 1 (true), 0 (false), x (unknown, if any operand has bits x).
- Treat all values that are nonzero as “1”
Example:
18
Logical and Case equality Operators
Example 1:
Example 2:
4'b1x00 == 4'b1x00 (x) 4'b1z00 == 4'b1x00 (x)
4'b1x00 === 4'b1x00 (1) 4'b1z00 == 4'b1z00 (x) 4'bxxx0 == 4'bzzz1 ( 0)
4'b1z00 == 4'b1x10 ( 0)
4'b1100 == 4'b1100 (1) 4'b1100 == 4'b1z10 ( 0)
4'b0000 == 4'b0000 (1) 4'b1100 == 4'b1x10 ( 0) 20
Relational Operators
21
Bit-wise Operators
• ~z = x
• (0,1, x, z) & z = x
• (0,1, x, z) | z = x
22
Bit-wise Operators (cont.)
Example:
23
Unary Reduction Operators
24
Unary Reduction Operators (cont.)
Example:
25
Shift Operators
Unsigned data type
26
Shift Operators (cont.)
Example:
27
Concatenation Operators
Example:
28
Replication Operators
Example:
29
Conditional Operator
Example:
30
Operators
Examples of basic operators
31
Operators
Examples of Equality operator
32
Operators
Logical, Bit-wise, Reduction operator
33
Operator precedence
34
Expression example
Bitwise operator
module xor3 (input a, b, c, output y);
assign y = a ^ b ^ c;
endmodule
Concatenation
module add_1bit (input a, b, ci, output s, co);
assign #(3, 4) {co, s} = {(a & b)|(b & ci)|(a & ci), a^b^ci};
endmodule
Conditional operator
module quad_mux2_1 (input [3:0] i0, i1, input s, output [3:0] y);
assign y = s ? i1 : i0;
endmodule
35
Expression example
Relational & Equality operator
module comp_4bit ( input [3:0] a, b, output a_gt_b, a_eq_b, a_lt_b);
assign a_gt_b = (a>b),
a_eq_b = (a==b),
a_lt_b = (a<b);
endmodule
Arithmetic operator
module add_4bit (input [3:0] a, b, input ci, output [3:0] s, output co);
assign { co, s } = a + b + ci;
endmodule
36
Combinational circuit
4 to 1 mux
module mux4_1(out, in1, in2, in3 ,in4, module mux4_1 (out, in1, in2, in3, in4,
cntrl1, cntrl2); cntrl) ;
output out; output out ;
input in1, in2, in3, in4, cntrl1, cntrl2; input in0,in1,in2,in3 ;
input [1:0] cntrl;
assign out = (in1 & ~cntrl1 & ~cntrl2) | assign out = (cntrl == 2'b00) ? in0 :
(in2 & ~cntrl1 & cntrl2) | (cntrl == 2'b01) ? in1 :
(in3 & cntrl1 & ~cntrl2) | (cntrl == 2'b10) ? in2 :
(in4 & cntrl1 & cntrl2); (cntrl == 2'b11) ? in3 :
endmodule 1'bx ;
endmodule
OR
// Use nested conditional operator
assign out = cntrl1 ? (cntrl2 ? in4 : in3) : (cntrl2 ? in2 : in1);
37
Combinational circuit
1 bit full adder
module fa (input a, b, cin,
output s, cout);
assign s = a^b^cin;
assign cout = (a & b) | (cin & (a^b));
endmodule
t1
t2
• Let’s design 8-bit adder
module adder(cout,s,a,b) ;
output cout;
output [7:0] s ;
input [7:0] a,b ;
assign {cout,s} = a + b ; t3
endmodule
38
Combinational circuit
Comparator
Comparator makes the comparison A ? B
Parameters that may be set “?” is determined by the input greaterNotLess
when the module is instantiated. and returns true(1) or false(0).
39
Sequential circuit
4-bit ripple carry counter
40
Sequential circuit
4-bit ripple carry counter
41
Summary
Continuous assignment: main construct in dataflow modeling,
always active
Left hand side of assignment must be a net
Using expression with operators & operands
Delays on a net can be defined in the assign statement,
implicit continuous assignment, or net declaration.
To describe much sophisticated logic easily, procedural
assignment is available in Verilog RTL programming (see later)
42