advanced digital design with the verilog hdl · • review of combinational and sequential logic...

76
Copyright 2001, 2003 MD Ciletti 1 Advanced Digital Design with the Verilog HDL M. D. Ciletti Department of Electrical and Computer Engineering University of Colorado Colorado Springs, Colorado [email protected] Draft: Chap 6a: Synthesis of Combinational and Sequential Logic Copyright 2001, 2003. These notes are solely for classroom use by the instructor. No part of these notes may be copied, reproduced, or distributed to a third party, including students, in any form without the written permission of the author.

Upload: others

Post on 22-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 1

Advanced Digital Design with the Verilog HDL

M. D. Ciletti

Department

of Electrical and Computer Engineering

University of Colorado Colorado Springs, Colorado

[email protected]

Draft: Chap 6a: Synthesis of Combinational and Sequential Logic

Copyright 2001, 2003. These notes are solely for classroom use by the instructor. No part of these notes may be copied, reproduced, or distributed to a third party, including students, in any form without the written permission of the author.

Page 2: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 2

Note to the instructor: These slides are provided solely for classroom use in academic institutions by the instructor using the text, Advance Digital Design with the Verilog HDL by Michael Ciletti, published by Prentice Hall. This material may not be used in off-campus instruction, resold, reproduced or generally distributed in the original or modified format for any purpose without the permission of the Author. This material may not be placed on any server or network, and is protected under all copyright laws, as they currently exist. I am providing these slides to you subject to your agreeing that you will not provide them to your students in hardcopy or electronic format or use them for off-campus instruction of any kind. Please email to me your agreement to these conditions. I will greatly appreciate your assisting me by calling to my attention any errors or any other revisions that would enhance the utility of these slides for classroom use.

Page 3: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 3

COURSE OVERVIEW

• Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction to synthesis with HDLs • Programmable logic devices • State machines, datapath controllers, RISC CPU • Architectures and algorithms for computation and signal processing • Synchronization across clock domains • Timing analysis • Fault simulation and testing, JTAG, BIST

Page 4: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 4

Synthesis of Combinational and Sequential Logic Tasks for synthesis tools:

• detect and eliminate redundant logic • detect combinational feedback loops • exploit don't-care conditions • detect unused states • detect and collapse equivalent states • make state assignments • synthesize optimal, multilevel realizations of logic

subject to constraints on area and/or speed physical technology.

Page 5: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 5

Tasks for the Designer

Understand how to synthesize combinational logic

Understand how to synthesize sequential logic

Understand how language constructs synthesize

Anticipate the results of synthesis

Adhere to style conventions

Page 6: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 6

Introduction to Synthesis Three common levels of abstraction:

architectural: sequence of operation

transform input sequence to output sequence

no schedule for clock cycles

logical: variables and Boolean functions

Fixed architecture of registers, datapaths, and functional units

Synthesize an optimized netlist of gates and registers

physical: geometric detail

mask sets for transistor fabrication

Page 7: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 7

Three Common Views

• behavioral: algorithm spec for data transformations (see Chapter 9)

• structural: datapath elements that implement the algorithm

• physical: mask set

Synthesis creates a sequence of transformations between views of a circuit, from a higher

level of abstraction to a lower one, with each step leading to a more detailed description of

the physical reality.

Page 8: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 8

Modified Y-Chart (Fig. 6-1)

• Behavioral synthesis transforms an algorithm to an architecture and a schedule of

operations (clock cycles)

• Architecture is represented as an RTL model

• Synthesize RTL model is a netlist of gates and registers

BehavioralDescription

StructuralDescription

PhysicalDescription

Cell Geometry

PhotomaskLayoutDatabase

Boolean algebra

Data flow/RTL

Algorithm

Logic netlist,schematic

Registers,ALUs, etc

ProcessorMemoryPeripheral interface

Continuousassignment

Proceduralassignment

Non-blockingassignment

Hierarchicalmodules and

primitiveinstantiations

View

1

2

3

Page 9: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 9

Synthesis Tool Organization

VerilogDescription

TechnologyImplementation

TRANSLATIONENGINE

Two-levelLogic Functions

OptimizedMulti-level Logic

Functions

OPTIMIZATIONENGINE

MAPPINGENGINE

TechnologyLibraries

Design Goals: Functionality, area, timing, testability

Page 10: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 10

Multi-Level Logic Optimization

Duplicate logic

Page 11: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 11

Logic Transformation: Decomposition

• Decompose a function into new nodes

• Re-use the new nodes in fanout paths

F = abc + abd + a'b'c' + b'c'd' Two-level logic!

a b c d

F

Page 12: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 12

F = XY + X' Y' X = ab Y = c + d

a b c d

X

Y

F

Page 13: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 13

Logic Transformation: Extraction

• Expresses a set of functions in terms of intermediate nodes

• Express each function in terms of its factors

• Detect which factors are shared among functions.

Page 14: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 14

F = (a + b)cd + e Multi-level logic! G = (a + b) e' H = cde

X = a + b Y = cd

a

b

c

d

G

H

F

+

e

+

e'

Page 15: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 15

a

b

c

d

G

H

F

+

e

+

e'

Y

X

Page 16: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 16

Logic Transformation: Factoring

• Produce a set of functions in products of sum form • Find a set of intermediate nodes to optimize the circuit’s delay and area • Share logic to reduce silicon area • Create multi-level structure from two-level structure • Sacrifice speed for area • Key: minimize the number of literals in factored form

Page 17: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 17

F = ac + ad + bc + bd + e

a

+

b c d e

F

Page 18: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 18

F = (a + b)(c + d) + e

a

+

b c d e

+

+

(a+b)

(c+d)

F

Page 19: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 19

Logic Transformation: Substitution

• Express a Boolean function in terms of its inputs and another function

• Reduce replicated logic

Page 20: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 20

G = a + b F = a + b + c

After substitution:

F = G + c New DAG:

a

+

b c

G

F+

a

+

b c

G

F+

Page 21: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 21

Logic Transformation: Elimination (Flattening)

• Undoes decomposition • Removes (collapses) a node in a function • Reduces the structure of the circuit. • Collapses levels of the circuit • Sacrifices area to get speed

Page 22: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 22

F = Ga + G' b G = c + d

After elimination:

F = ac + ad + bc'd' Revised DAG:

a b c

F+

da

+

b c

G

F+

dTwo-level

Page 23: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 23

RTL Synthesis

Given an architecture, an allocation of resources, and a schedule of clock cycles

• Convert language based RTL statements into Boolean equations

• Optimize the Boolean equations

• Synthesize an optimal realization in target technology

Synthesis tools (Synopsis Design Compiler) work in this domain.

Page 24: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 24

High-Level Synthesis

Also called behavioral synthesis or architectural synthesis

• Find an architecture whose resources can be scheduled and allocated to implement

an algorithm

• Difficulty: many architectures (Datapath elements, control unit, memory) may realize

the same algorithm

• Resource allocation:

• Identify functional operators/units

• Infer memory

• Bind operators to functional units

• Resource scheduling: Assign operations to clock cycles

Page 25: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 25

Parse Trees and data Flow Graphs

A = B + C;D = A * E;M = D - A

Fetch B Fetch C

+

Store A

Fetch A Fetch E

Store D

*

Fetch D Fetch A

-

Store M

Fetch B Fetch C

+

*

Fetch E

-

STORE M

A

D

y

Page 26: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 26

Synthesis of Combinational Logic

Options:

• Netlist of primitives

• User-defined primitive

• Continuous assignments

• Level-sensitive cyclic behavior

• Procedural continuous assignment (assign ... deassign )

Page 27: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 27

Synthesis: Netlist of Primitives

Value: remove redundant logic

Pre-Synthesis:

module boole_opt (y_out1, y_out2, a, b, c, d, e); output y_out1, y_out2; input a, b, c, d, e; and (y1, a, c); and (y2, a, d); and (y3, a, e); or (y4, y1, y2); or (y_out1, y3, y4); and (y5, b, c); and (y6, b, d); and (y7, b, e); or (y8, y5, y6); or (y_out2, y7, y8); endmodule

Page 28: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 28

Pre-Synthesis:

y_out1

y_out2

ea

b

c

d

Page 29: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 29

Synthesis Result

dcea

b

y_out1

y_out2

norf301 norf251

norf251

Page 30: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 30

Synthesis: Continuous Assignment

• Built-in operators have physical counterparts

• Continuous assignment statements are synthesizable

• Will produce (1) combinational logic, (2) latch, (3) three-state output Example 6.7

module or_nand (y, enable, x1, x2, x3, x4); output y; input enable, x1, x2, x3, x4; assign y = ~(enable & (x1 | x2) & (x3 | x4)); endmodule

Page 31: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 31

oai22_a

nand2i_a

x1x2x3x4

enable

y

Page 32: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 32

Synthesis: Level-Sensitive Cyclic Behavior

A level-sensitive cyclic behavior will synthesize to combinational logic if it assigns a value to

each output for every possible value of its inputs.

• The event control expression of the behavior must be sensitive to every input

• Every path of the activity flow must assign value to every output.

Page 33: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 33

Example 6.8 (Two-Bit Comparator Algorithm)

• The data words are identical if all of their bits match in each position • Otherwise, the most significant bit at which the words differ determines their relative

magnitude

Page 34: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 34

module comparator (a_gt_b, a_lt_b, a_eq_b, a, b); // Alternative algorithm parameter size = 2; output a_gt_b, a_lt_b, a_eq_b; input [size: 1] a, b; reg a_gt_b, a_lt_b, a_eq_b; integer k; always @ ( a or b) begin: compare_loop for (k = size; k > 0; k = k-1) begin if (a[k] != b[k]) begin a_gt_b = a[k]; a_lt_b = ~a[k]; a_eq_b = 0; disable compare_loop; end // if end // for loop a_gt_b = 0; a_lt_b = 0; a_eq_b = 1; end // compare_loop endmodule

Page 35: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 35

Synthesis Result:

mux

mux

a[2:1]

b[2:1]

a_eq_b

a_lt_b

a_gt_b

Page 36: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 36

Example 6.9 (Mux with selector logic)

module mux_logic (y, select, sig_G, sig_max, sig_a, sig_b); output y; input select, sig_G, sig_max, sig_a, sig_b; assign y = (select == 1) || (sig_G ==1) || (sig_max == 0) ? sig_a : sig_b; endmodule

Page 37: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 37

Synthesis Result

Page 38: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 38

Synthesis of Priority Structures

• A case statement implicitly attaches higher priority to the first item that it decodes than to the last one

• If the case items are mutually exclusive the synthesis tool will treat them as though they had equal priority and will synthesize a mux rather than a priority structure.

• Even when the list of case items is not mutually exclusive a synthesis tool might allow the user to direct that they be treated without priority (e.g., Synopsys parallel_case directive). This would be useful if only one case item could be selected at a time in actual operation.

• An if statement implies higher priority to the first branch than to the remaining branches.

• If branching is mutually exclusive, synthesis produces a mux structure • Otherwise create a priority structure

Page 39: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 39

Example 6.10

module mux_4pri (y, a, b, c, d, sel_a, sel_b, sel_c); output y; input a, b, c, d, sel_a, sel_b, sel_c; reg y; always @ (sel_a or sel_b or sel_c or a or b or c or d) begin if (sel_a == 1) y = a; else // highest priority if (sel_b == 0) y = b; else if (sel_c == 1) y = c; else y = d; // lowest priority end endmodule

Page 40: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 40

Synthesis Result

mux_2mux_2

mux_2

sel_b

sel_c

d

c

b

a

sel_a

y

Page 41: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 41

Exploiting Don't-Care Conditions

SYNTHESIS TIP

An assignment to x in a case or an if statement will betreated as a don't care condition in synthesis.

Page 42: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 42

Example 6.11 (Latched Seven Segment Display)

ab

cd

e

f

g

4-BitCounter

Display_L

Blanking

Enable

clock

reset

ab

cd

e

f

g7

7

Display_R

(a)

Page 43: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 43

Page 44: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 44

module Latched_Seven_Seg_Display

(Display_L, Display_R, Blanking, Enable, clock, reset); output [6: 0] Display_L, Display_R; input Blanking, Enable, clock, reset; reg [6: 0] Display_L, Display_R; reg [3: 0] count; // abc_defg parameter BLANK = 7'b111_1111; parameter ZERO = 7'b000_0001; // h01 parameter ONE = 7'b100_1111; // h4f parameter TWO = 7'b001_0010; // h12 parameter THREE = 7'b000_0110; // h06 parameter FOUR = 7'b100_1100; // h4c parameter FIVE = 7'b010_0100; // h24 parameter SIX = 7'b010_0000; // h20 parameter SEVEN = 7'b000_1111; // h0f parameter EIGHT = 7'b000_0000; // h00 parameter NINE = 7'b000_0100; // h04 always @ (posedge clock) if (reset) count <= 0; else if (Enable) count <= count +1;

Page 45: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 45

always @ (count or Blanking) if (Blanking) begin Display_L = BLANK; Display_R = BLANK; end else case (count) 0: begin Display_L = ZERO; Display_R = ZERO; end 2: begin Display_L = ZERO; Display_R = TWO; end 4: begin Display_L = ZERO; Display_R = FOUR; end 6: begin Display_L = ZERO; Display_R = SIX; end 8: begin Display_L = ZERO; Display_R = EIGHT; end 10: begin Display_L = ONE; Display_R = ZERO; end 12: begin Display_L = ONE; Display_R = TWO; end 14: begin Display_L = ONE; Display_R = FOUR; end //default: begin Display_L = BLANK; Display_R = BLANK; end endcase endmodule

Page 46: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 46

SYNTHESIS TIP

If a conditional operator assigns the value z to the right-hand side expression of a continuous assignment in a level-sensitive behavior, the statement will synthesize to a three-state device driven by combinational logic.

Page 47: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 47

Example 6.12

module alu_with_z1 (alu_out, data_a, data_b, enable, opcode); input [2: 0] opcode; input [3: 0] data_a, data_b; input enable; output alu_out; // scalar for illustration reg [3: 0] alu_reg; assign alu_out = (enable == 1) ? alu_reg : 4’bz; always @ (opcode or data_a or data_b) case (opcode) 3'b001: alu_reg = data_a | data_b; 3'b010: alu_reg = data_a ^ data_b; 3'b110: alu_reg = ~data_b; default: alu_reg = 4'b0; // alu_with_z2 has default: alu_reg = 4'bx; endcase endmodule

Page 48: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 48

Synthesis Result: alu_with_z1

enable

data_b[3:0]

mux

opcode[2:0]

data_a[3:0]mux

alu_out

Page 49: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 49

Synthesis Result: alu_with_z2 (Exploit don't-cares)

enable

data_b[3:0]

mux

opcode[2:0]

data_a[3:0]

alu_out

Page 50: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 50

ASIC Cells and Resource Sharing

Example 6.13

module badd_4 (Sum, C_out, A, B, C_in); output [3: 0] Sum; output C_out; input [3: 0] A, B; input C_in; assign {C_out, Sum} = A + B + C_in; endmodule

Synthesis Result (With Library Cells)

Page 51: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 51

A1

B1

CIN2

SUM

CO

faf001A1

B1

CIN2

SUM

CO

faf001A1

B1

CIN2

SUM

CO

faf001A1

B1

CIN2

SUM

CO

faf001

A<0>

B<0>

C_in

Sum<3:0>

C_outC_out

Sum<3:0>

A<1>

B<1>

A<2>

B<2>

A<3>

B<3>

w000003<1>w000002<1>w000001<1>

mod00000 mod00002 mod00004 mod00006

B<3:0>A<3:0>

B<3:

0> A<3:

0>

A<3:0>B<3:0>

A<3:

0>

A<3:

0>

A<3:

0>

B<3:

0>

B<3:

0>

B<3:

0>Su

m<3

:0>

Sum

<3:0

>

Sum

<3:0

>

Sum<3:0>

Sum

<3:0

>

Sum<1> Sum<3>Sum<2>Sum<0>

Page 52: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 52

Synthesis Result (Without library cells)

+

+

esdpupd_

C_out

Sum[3:0]

5

5

5

5A[3:0]

B[3:0]

C_in

Page 53: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 53

SYNTHESIS TIP

Use parentheses to control operator grouping and reducethe size of a circuit.

assign y_out = sel ? data_a + accum : data_a + data_b;

Example 6.14 The use of parentheses in the description in res_share forces the synthesis tool to multiplex the datapaths and produce the circuit shown in Figure 6.21.

module res_share (y_out, sel, data_a, data_b, accum); output [4: 0] y_out; input [3: 0] data_a, data_b, accum; input sel; assign y_out = data_a + (sel ? accum : data_b); endmodule

Page 54: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 54

mux2_a

mux2_a

mux2_a

mux2_a

esdpupd_

esdpupd_

+

accum[3:0]

data_b[3:0]

data_a[3:0]

sel

y_out[4:0]

Page 55: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 55

Synthesis of Sequential Logic with Latches

SYNTHESIS TIP

A feedback-free netlist of combinational primitives willsynthesize into latch-free combinational logic.

Page 56: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 56

SYNTHESIS TIP

A continuous assignment with feedback in a conditionaloperator will synthesize into a latch.

Page 57: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 57

SYNTHESIS TIP

A set of feedback-free cont inuous assignments wi l lsynthesize into latch-free combinational logic.

Page 58: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 58

Example 6.15

assign data_out = (CS_b == 0) ? (WE_b == 0) ? data_in : data_out : 1'bz;

Page 59: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 59

Page 60: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 60

Accidental Synthesis of Latches

Example 6.16

module or4_behav (y, x_in);

parameter word_length = 4; output y; input [word_length - 1: 0] x_in; reg y; integer k; // Eliminated in synthesis always @ x_in begin: check_for_1 y = 0; for (k = 0; k <= word_length -1; k = k+1) if (x_in[k] == 1) begin y = 1; disable check_for_1; end end endmodule

Page 61: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 61

module or4_behav_latch (y, x_in);

parameter word_length = 4; output y; input [word_length - 1: 0] x_in; reg y; integer k; always @ (x_in[3:1]) // incomplete event control expression begin: check_for_1 y = 0; for (k = 0; k <= word_length -1; k = k+1) if (x_in[k] == 1) begin y = 1; disable check_for_1; end end endmodule

Page 62: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 62

y

x_in

y

x_in

D QEn

x_in[3]x_in[2]x_in[1]

x_in[3]x_in[2]

x_in[1]

x_in[0]

Page 63: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 63

Page 64: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 64

SYNTHESIS TIP

A Verilog description of combinational logic must assignvalue to the outputs for all possible values of the inputs.

Example 6.17

module mux_latch (y_out, sel_a, sel_b, data_a, data_b); output y_out;

input sel_a, sel_b, data_a, data_b; reg y_out;

always @ ( sel_a or sel_b or data_a or data_b) case ({sel_a, sel_b}) 2'b10: y_out = data_a; 2'b01: y_out = data_b; endcase

endmodule

Page 65: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 65

y_outsel_a

sel_b

data_b

data_a

LatchEn

Page 66: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 66

y_out

sel_asel_b

data_b

data_a

latrnb_a

mux2_a

xor2_a

esdpupd

Page 67: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 67

Intentional Synthesis of Latches

Example 6.18

module latch_if1(data_out, data_in, latch_enable); output [3: 0] data_out; input [3: 0] data_in; input latch_enable; reg [3: 0] data_out; always @ (latch_enable or data_in) if (latch_enable) data_out = data_in; else data_out = data_out; endmodule

Page 68: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 68

mux

mux

mux

mux

latch_enable

data_in[3:0]

data_out[3:0]

Page 69: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 69

SYNTHESIS TIP

An if statement in a level-sensitive behavior will synthesizeto a latch if the statement assigns value to a register variablein some, but not al l , branches, i .e., the statement isincomplete.

Example 6.19

module latch_if2 (data_out, data_in, latch_enable); output [3: 0] data_out; input [3: 0] data_in; input latch_enable; reg [3: 0] data_out; always @ (latch_enable or data_in) if (latch_enable) data_out = data_in; // Incompletely specified endmodule

Page 70: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 70

latch_enable

data_in[3:0]

data_out[3:0]latrnqb_a

esdpupd_

latrnqb_a

latrnqb_a

latrnqb_a

esdpupd_

esdpupd_

esdpupd_

Page 71: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 71

Example 6.20 (Register File)

module sn54170 (data_out, data_in, wr_sel, rd_sel, wr_enb, rd_enb); output [3: 0] data_out; input wr_enb, rd_enb; input [1: 0] wr_sel, rd_sel; input [3: 0] data_in; reg [3: 0] latched_data [3: 0]; always @ (wr_enb or wr_sel or data_in) begin if (!wr_enb) latched_data[wr_sel] = data_in; end assign data_out = (rd_enb) ? 4'b1111 : latched_data[rd_sel]; endmodule

Page 72: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 72

data

_out

[3:0

]

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

esdp

upd

wr_

enb

rd_e

nb

esdp

upd

esdp

upd

rd_s

el[1

:0]

data

_in[

3:0]

wr_

sel[1

:0]

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

latrp

qb_a

Page 73: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 73

Synthesis of Three-State Devices and Bus Interfaces

Example 6.21 (Uni-directional Bus Interface)

module Uni_dir_bus ( data_to_bus, bus_enable); input bus_enable; output [31: 0] data_to_bus; reg [31: 0] ckt_to_bus; assign data_to_bus = (bus_enable) ? ckt_to_bus : 32'bz; // Description of core circuit goes here to drive ckt_to_bus endmodule

Page 74: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 74

CoreCircuit ckt_to_bus

bus_enable

data_to_bus

32 32

Uni_dir_bus

Driver_1

Driver_2

Page 75: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 75

Example 6.22 (Bi-directional Bus Interface)

data_from_bus

ckt_to_bus

send_data

rcv_data

data_to_from_bus

32

32 32CoreCircuit

Bi_dir_bus

Driver_1

Driver_2

Figure 6.28 Bi-directional interface to a bi-directional bus.

Page 76: Advanced Digital Design with the Verilog HDL · • Review of combinational and sequential logic design • Modeling and verification with hardware description languages • Introduction

Copyright 2001, 2003 MD Ciletti 76

module Bi_dir_bus (data_to_from_bus, send_data, rcv_data);

inout [31: 0] data_to_from_bus; input send_data, rcv_data; wire [31: 0] ckt_to_bus; wire [31: 0] data_to_from_bus, data_from_bus; assign data_from_bus = (rcv_data) ? data_to_from_bus : 'bz; assign data_to_from_bus = (send_data) ? ckt_to_bus : 32'bz; // Behavior using data_from_bus and generating // ckt_to_bus goes here endmodule