33
םםםם םםםםם – םםםם םםםםםםם םםםםםםםFoundations of Combinational Circuits םםםםם םםםם3

מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

  • View
    234

  • Download
    10

Embed Size (px)

Citation preview

Page 1: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

מבנה המחשב – מבוא למחשבים ספרתיים

Foundations of

Combinational Circuits

3תרגול מספר

Page 2: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Checking a CircuitMapping the circuit into a directed graph G(V,E).

Each gate is a vertex

Each output terminal defines a net

Each net is transformed into edges from the output terminal to each of the input terminals.

OR

AND

NOT XOR OUT

IN

IN

Single net

Page 3: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Graph Representationby List of Neighbors

6

7

8

3

4

5

2

1 3 5 86

7 5 6

2 8

Page 4: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Graph Representationby Matrix

v

v

v

1 2 3 4 5

1

2

3

4

5

Page 5: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Checking a Circuit

• If a terminal has two incoming edges, then it is fed by two nets, which is illegal. In that case we stop and return FALSE.

OR

AND

NOT XOR OUT

IN

IN

Two inputs to

one terminal !

Page 6: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Testing for Circles

• In order to test for circles we need to run a Depth-First-Search (DFS) algorithm on the graph, and check for any backwards edges during the execution of the algorithm.

Page 7: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

DFS Example

1

2

4

5

3

Stack

Page 8: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

DFS

1

1

2

4

5

3

Stack

= Currently in the stack

Page 9: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

DFS

1

2

1

2

4

5

3

Stack

Page 10: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

DFS

1

2

3

1

2

4

5

3

Stack

Page 11: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

DFS

1

2

3

1

2

4

5

3

4

Stack

Backwards Edge

This graph has a cycle!

Page 12: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Elements of the Proof

• The algorithm terminates regardless of the structure of the input graph.

• If there is a cycle in the graph, the algorithm will find it (return FALSE).

• If there is no cycle in the graph, the algorithm will return TRUE.

Page 13: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

The Algorithm Terminates

• The algorithm passes through every vertex only once, therefore it will always terminate after visiting all of the vertices regardless of the edges.

Page 14: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

The Proof

• Assume there is a cycle in the graph. At some point a first vertex that belongs to the cycle will be reached. All other vertices of the cycle have not been reached yet.

• Before that first vertex is popped out of the stack, the DFS procedure guarantees that an edge closing the cycle and entering that vertex will be tested.

• It is a backwards edge.

Page 15: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

The Proof

• Immediate, but nevertheless:

• Assume there are no cycles in the graph.

• Backwards edges cannot exist since they require a path from a successor to a predecessor, which means there is a cycle.

Page 16: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort

• Works only on Directed Acyclic Graphs (DAG).

• The Algorithm:

– Form a set of all independent vertices - those that have no incoming edges. There must be at least one!

– While the set is empty: Pick any vertex v from the set. If any of its successors have no other predecessors – add them to the set of independent vertices. Erase all of the edges originating at v.

Page 17: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

= Independent Vertex

Page 18: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN

Page 19: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN IN

Page 20: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN IN OR

Page 21: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN IN OR AND

Page 22: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN IN OR AND NOT

Page 23: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN IN OR AND NOT XOR

Page 24: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Topological Sort Example

OR

AND

NOT XOR OUT

IN

IN

The Topological Sort:

IN IN OR AND NOT XOR OUT

Page 25: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Testing for Cycles duringTopological Sort

OR

AND

NOT XOR OUT

IN

IN

There are nodes left, but none are independent Cycle!

Page 26: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Propagation Delay

}{

pdpathsallpd

tMaxT

There is always at least one “critical path”.

What is the propagation delay of a circuit that is not acyclic?

Page 27: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Finding the Propagation Delay

)}'()'({)()( '

vtvtMaxvt pd

readyinputsvrpredecessov

readyinputs

Now, using the fact that it is an acyclic graph, we go through the topological order from start to beginning, each time updating the “inputs ready” time of the successors.

The total propagation delay is the maximal “inputs ready” time (assuming that we used output nodes).

Page 28: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

Finding the Maximum Delay

0 0 OR AND NOT XOR OUT

Page 29: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

A circuit with 2n/2 paths

2 options 2 options

n/2 stages with 2 options each, resulting in 2n/2 paths.

How are we computing the delay of an exponential number of circuits in linear time? Let’s go to the previous slide.

Page 30: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

A circuit with 2n paths• …cannot be built!

• Why? A combinational circuit is a DAG, therefore we cannot reorder the gates to create different paths. Our only option is to include or exclude gates to create different paths.

• But, having n gates, we only have 2n such paths. Each gate can be included or excluded, therefore 2n.

• We cannot build this circuit since we will require an unbounded in-degree of the gates.

Page 31: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

XOR is Associative – part I

cbaabcbaabcbaXORXOR )''(')''()),,((

)''(),( baabbaXOR

cbaabcbaab )''(')''(

cbabacbaab )')('(')''(

cbbbabaaacbaab )''''(')''(

cbaabcbaab )''(')''(

cbaabcbcacab ''''''

Definition

1st Expanded definition

De Morgan

De Morgan

Distributive

Complement

Distributive

Page 32: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

XOR is Associative – part 2

)''(')''()),(,( cbbcacbbcacbXORaXOR

)''(),( baabbaXOR

)''(')''( cbbcacbbca

)''(')')('( cbbcacbcba

)''(')''''( cbbcacccbcbbba

)''(')''( cbbcacbcba

cbabcacabacb ''''''

Definition

2nd Expanded definition

De Morgan

De Morgan

Distributive

Complement

Distributive

Page 33: מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3

THE END