Digital Logic Design: a rigorous approach c

Similar documents
Chapter 5: Selectors, Shifters, Priority Encoders & Half-Decoders

Chapter 3: Trees. Goals

Combinational Logic Design Combinational Functions and Circuits

Combinational Logic. By : Ali Mustafa

Logic and Computer Design Fundamentals. Chapter 8 Sequencing and Control

Combinational Logic. Mantıksal Tasarım BBM231. section instructor: Ufuk Çelikcan

Hardware Design I Chap. 4 Representative combinational logic

COMP 382: Reasoning about algorithms

Lecture 6: Introducing Complexity

Chapter 4. Combinational: Circuits with logic gates whose outputs depend on the present combination of the inputs. elements. Dr.

COMBINATIONAL LOGIC FUNCTIONS

Digital Logic. CS211 Computer Architecture. l Topics. l Transistors (Design & Types) l Logic Gates. l Combinational Circuits.

The goal differs from prime factorization. Prime factorization would initialize all divisors to be prime numbers instead of integers*

Logic. Combinational. inputs. outputs. the result. system can

XI STANDARD [ COMPUTER SCIENCE ] 5 MARKS STUDY MATERIAL.

Sorting algorithms. Sorting algorithms

Chapter 5 Arithmetic Circuits

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary

CHAPTER1: Digital Logic Circuits Combination Circuits

data structures and algorithms lecture 2

CDM. Recurrences and Fibonacci. 20-fibonacci 2017/12/15 23:16. Terminology 4. Recurrence Equations 3. Solution and Asymptotics 6.

IT T35 Digital system desigm y - ii /s - iii

Chapter 5. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 5 <1>

Design of Sequential Circuits

Propositional Logic. Logical Expressions. Logic Minimization. CNF and DNF. Algebraic Laws for Logical Expressions CSC 173

Omega notation. Transitivity etc.

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Digital Logic

Exclusive OR/ Exclusive NOR

Computational Complexity - Pseudocode and Recursions

I. Motivation & Examples

Review: Additional Boolean operations

Spiral 2-1. Datapath Components: Counters Adders Design Example: Crosswalk Controller

Module 1: Analyzing the Efficiency of Algorithms

Algorithms (II) Yu Yu. Shanghai Jiaotong University

CS 310 Advanced Data Structures and Algorithms

CDM. Recurrences and Fibonacci

CS/EE 181a 2008/09 Lecture 4

Binary addition example worked out

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

COMP2611: Computer Organization. Introduction to Digital Logic

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Computer Science. 19. Combinational Circuits. Computer Science COMPUTER SCIENCE. Section 6.1.

Tecniche di Verifica. Introduction to Propositional Logic

EECS Components and Design Techniques for Digital Systems. FSMs 9/11/2007

Department of Electrical & Electronics EE-333 DIGITAL SYSTEMS

211: Computer Architecture Summer 2016

Lecture 18: P & NP. Revised, May 1, CLRS, pp

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

Lecture 22 Chapters 3 Logic Circuits Part 1

Digital Logic Design: a rigorous approach c

CprE 281: Digital Logic

Data Structures and Algorithms Running time and growth functions January 18, 2018

Latches. October 13, 2003 Latches 1

Digital Logic: Boolean Algebra and Gates. Textbook Chapter 3

I. Motivation & Examples

Every time has a value associated with it, not just some times. A variable can take on any value within a range

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CPE100: Digital Logic Design I

Majority is incompressible by AC 0 [p] circuits

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Discrete Mathematics. CS204: Spring, Jong C. Park Computer Science Department KAIST

CPE100: Digital Logic Design I

ENGIN 112 Intro to Electrical and Computer Engineering

CSE140: Components and Design Techniques for Digital Systems. Decoders, adders, comparators, multipliers and other ALU elements. Tajana Simunic Rosing

Enrico Nardelli Logic Circuits and Computer Architecture

CMP 334: Seventh Class

Physical Layer and Coding

Lecture 3: AC 0, the switching lemma

P, NP, NP-Complete, and NPhard

Chapter 3 Ctd: Combinational Functions and Circuits

EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

WORKBOOK. Try Yourself Questions. Electrical Engineering Digital Electronics. Detailed Explanations of

Digital Logic Design: a rigorous approach c

Analysis of Algorithms - Using Asymptotic Bounds -

( c) Give logic symbol, Truth table and circuit diagram for a clocked SR flip-flop. A combinational circuit is defined by the function

Galois Field Algebra and RAID6. By David Jacob

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

Ch 7. Finite State Machines. VII - Finite State Machines Contemporary Logic Design 1

ECE/CS 250 Computer Architecture

CSC9R6 Computer Design. Practical Digital Logic

Why digital? Overview. Number Systems. Binary to Decimal conversion

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

Analysis of Algorithms [Reading: CLRS 2.2, 3] Laura Toma, csci2200, Bowdoin College

Boolean Algebra and Digital Logic 2009, University of Colombo School of Computing

CSEE 3827: Fundamentals of Computer Systems. Combinational Circuits

CprE 281: Digital Logic

Numbers and Arithmetic

Simple Neural Nets for Pattern Classification: McCulloch-Pitts Threshold Logic CS 5870

COMPUTATIONAL COMPLEXITY

Extended Superposed Quantum State Initialization Using Disjoint Prime Implicants

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Outline. policies for the first part. with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014

DE58/DC58 LOGIC DESIGN DEC 2014

ALU A functional unit

ELCT201: DIGITAL LOGIC DESIGN

Quantum algorithms (CO 781/CS 867/QIC 823, Winter 2013) Andrew Childs, University of Waterloo LECTURE 13: Query complexity and the polynomial method

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Contents. Chapter 2 Digital Circuits Page 1 of 30

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Transcription:

Digital Logic Design: a rigorous approach c Chapter 13: Decoders and Encoders Guy Even Moti Medina School of Electrical Engineering Tel-Aviv Univ. May 17, 2018 Book Homepage: http://www.eng.tau.ac.il/~guy/even-medina 1/43

Buses Example an adder and a register (a memory device). The output of the adder should be stored by the register. Different name to each bit?! Definition A bus is a set of wires that are connected to the same modules. The width of a bus is the number of wires in the bus. Example PCI bus is used to connect hardware devices (e.g., network cards, sound cards, USB adapters) to the main memory. In our settings, we consider wires instead of nets. 2/43

Indexing conventions 1 Connection of terminals is done by assignment statements: The statement b[0 : 3] a[0 : 3] means connect a[i] to b[i]. 2 Reversing of indexes does not take place unless explicitly stated: b[i : j] a[i : j] and b[i : j] a[j : i], have the same meaning, i.e., b[i] a[i],...,b[j] a[j]. 3 Shifting is done by default: a[0 : 3] b[4 : 7], meaning that a[0] b[4],a[1] b[5], etc. We refer to such an implied re-assignment of indexes as hardwired shifting. 3/43

Example - 1 a 0 b 0 a 1 b 1 a n 1 b n 1 a[0 : n 1] b[0 : n 1] n n G 0 G 1 G n 1 G(n) n z 0 z 1 z n 1 z[0 : n 1] (A) (B) Figure: Vector notation: multiple instances of the same gate. 4/43

a 0 a 1 a n 1 b a[0 : n 1] b n 1 G 0 G 1 G n 1 G(n) n z 0 z 1 z n 1 z[0 : n 1] (A) (B) Figure: Vector notation: b feeds all the gates. 5/43

Reminder: Binary Representation Recall that a[n 1 : 0] n denotes the binary number represented by an n-bit vector a. n 1 a[n 1 : 0] n = a i 2 i. i=0 Definition Binary representation using n-bits is a function bin n : {0,1,...,2 n 1} {0,1} n that is the inverse function of. Namely, for every a[n 1 : 0] {0,1} n, bin n ( a[n 1 : 0] n ) = a[n 1 : 0]. 6/43

Division in Binary Representation r = (a mod b): a = q b +r, where 0 r < b. Claim Let s = x[n 1 : 0] n, and 0 k n 1. Let q and r denote the quotient and remainder obtained by dividing s by 2 k. Define the binary strings x R [k 1 : 0] and x L [n 1 : n k 1] as follows. Then, x R [k 1 : 0] = x[k 1 : 0] x L [n k 1 : 0] = x[n 1 : k]. q = x L [n k 1 : 0] r = x R [k 1 : 0]. 7/43

Definition of Decoder Definition A decoder with input length n is a combinational circuit specified as follows: Input: x[n 1 : 0] {0,1} n. Output: y[2 n 1 : 0] {0,1} 2n Functionality: y[i] = { 1 if x = i 0 otherwise. We denote a decoder with input length n by decoder(n). 8/43

Definition of Decoder Definition A decoder with input length n: Input: x[n 1 : 0] {0,1} n. Output: y[2 n 1 : 0] {0,1} 2n Functionality: y[i] = { 1 if x = i 0 otherwise. Number of outputs of a decoder is exponential in the number of inputs. Note also that exactly one bit of the output y is set to one. Such a representation of a number is often termed one-hot encoding or 1-out-of-k encoding. Example Consider a decoder decoder(3). On input x = 101, the output y equals 00100000. 9/43

Application of decoders An example of how a decoder is used is in decoding of controller instructions. Suppose that each instruction is coded by an 4-bit string. Our goal is to determine what instruction is to be executed. For this purpose, we feed the 4 bits to a decoder(4). There are 16 outputs, exactly one of which will equal 1. This output will activate a module that should be activated in this instruction. 10/43

Brute force design simplest way: build a separate circuit for every output bit y[i]. The circuit for y[i] is simply a product of n literals. Let v = bin n (i), i.e., v is the binary representation of the index i. define the minterm p v to be p v = (l v 1 lv 2 lv n), where: l v j = { x j if v j = 1 x j if v j = 0. Claim y[i] = p v. 11/43

analysis: brute force design The brute force decoder circuit consists of: n inverters used to compute inv( x), and a separate and(n)-tree for every output y[i]. The delay of the brute force design is t pd (inv)+t pd (and(n)-tree) = O(log 2 n). The cost of the brute force design is Θ(n 2 n ), since we have an and(n)-tree for each of the 2 n outputs. Wasteful because, if the binary representation of i and j differ in a single bit, then the and-trees of y[i] and y[j] share all but a single input. Hence the product of n 1 bits is computed twice. We present a systematic way to share hardware between different outputs. 12/43

An asymptotically optimal decoder design Base case decoder(1): The circuit decoder(1) is simply one inverter where: y[0] inv(x[0]) and y[1] x[0]. Reduction rule decoder(n): We assume that we know how to design decoders with input length less than n, and design a decoder with input length n. 13/43

x R[k 1 : 0] = x[k 1 : 0] k R[2 k 1 : 0] Decoder(k) 2 k R[r] xl[n k 1 : 0] = x[n 1 : k] n k Decoder(n k) 2 n k Q[2 n k 1 : 0] 2 n k 2 k array of and-gates Q[q] and q,r y[q 2 k + r] Figure: A recursive implementation of decoder(n). Claim (Correctness) y[i] = 1 x[n 1 : 0] = i.

Cost analysis We denote the cost and delay of decoder(n) by c(n) and d(n), respectively. The cost c(n) satisfies the following recurrence equation: { c(inv) if n=1 c(n) = c(k)+c(n k)+2 n c(and) otherwise. It follows that, up to constant factors { 1 if n = 1 c(n) = c(k)+c(n k)+2 n if n > 1. (1) Obviously, c(n) = Ω(2 n ) (regardless of the value of k). Claim c(n) = O(2 n ) if k = n/2. 15/43

Cost analysis (cont.) Claim c(n) = c(n) = O(2 n ) if k = n/2. Proof. { c(inv) if n=1 c(k)+c(n k)+2 n otherwise. c(n) 2 2 n by complete induction on n. basis: check for n {1,2,3}. step: c(n) = c( n/2 )+c( n/2 )+2 n 2 1+ n/2 +2 1+ n/2 +2 n = 2 2 n (2 n/2 +2 n/2 +1/2) 16/43

Delay analysis. The delay of decoder(n) satisfies the following recurrence equation: { d(inv) if n=1 d(n) = max{d(k), d(n k)} + d(and) otherwise. Set k = n/2. It follows that d(n) = Θ(logn). 17/43

Asymptotic Optimality Theorem For every decoder G of input length n: d(g) = Ω(logn) c(g) = Ω(2 n ). Proof. 1 lower bound on delay : use log delay lower bound theorem. 2 lower bound on cost? The proof is based on the following observations: Computing each output bit requires at least one nontrivial gate. No two output bits are identical. 18/43

Encoders An encoder implements the inverse Boolean function implemented by a decoder. the Boolean function implemented by a decoder is not surjective. the range of the Boolean function implemented by a decoder is the set of binary vectors in which exactly one bit equals 1. It follows that an encoder implements a partial Boolean function (i.e., a function that is not defined for every binary string). 19/43

Hamming Distance and Weight Definition The Hamming distance between two binary strings u,v {0,1} n is defined by dist(u,v) = {i u i v i }. Definition The Hamming weight of a binary string u {0,1} n equals dist(u,0 n ). Namely, the number of non-zero symbols in the string. We denote the Hamming weight of a binary string a by wt( a), namely, wt(a[n 1 : 0]) = {i : a[i] 0}. 20/43

Concatenation of strings Recall that the concatenation of the strings a and b is denoted by a b. Definition The binary string obtained by i concatenations of the string a is denoted by a i. Consider the following examples of string concatenation: If a = 01 and b = 10, then a b = 0110. If a = 1 and i = 5, then a i = 11111. If a = 01 and i = 3, then a i = 010101. We denote the zeros string of length n by 0 n (beware of confusion between exponentiation and concatenation of the binary string 0). 21/43

Definition of Encoder function We define the encoder partial function as follows. Definition The function encoder n : { y {0,1} 2n : wt( y) = 1} {0,1} n is defined as follows: encoder n ( y) equals the index of the bit of y[2 n 1 : 0] that equals one. Formally, Examples: wt(y) = 1 = y[ encoder n ( y) ] = 1. 1 encoder 2 (0001) = 00, encoder 2 (0010) = 01, encoder 2 (0100) = 10, encoder 2 (1000) = 11. 2 encoder n (0 2n k 1 1 0 k ) = bin n (k). 22/43

Encoder circuit - definition Definition An encoder with input length 2 n and output length n is a combinational circuit that implements the Boolean function encoder n. We denote an encoder with input length 2 n and output length n by encoder(n). An encoder(n) can be also specified as follows: Input: y[2 n 1 : 0] {0,1} 2n. Output: x[n 1 : 0] {0,1} n. Functionality: If wt( y) = 1, let i denote the index such that y[i] = 1. In this case x should satisfy x = i. Formally: wt( y) = 1 = y[ x ] = 1. 23/43

Encoder - remarks functionality is not specified for all inputs y. functionality is only specified for inputs whose Hamming weight equals one. Since an encoder is a combinational circuit, it implements a Boolean function. This means that it outputs a digital value even if wt(y) 1. Thus, two encoders must agree only with respect to inputs whose Hamming weight equals one. If y is output by a decoder, then wt( y) = 1, and hence an encoder implements the inverse function of a decoder. 24/43

Brute Force Implementation Recall that bin n (i)[j] denotes the jth bit in the binary representation of i. Let A j denote the set A j = {i [0 : 2 n 1] bin n (i)[j] = 1}. Claim If wt(y) = 1, then x[j] = i A j y[i]. 25/43

Brute Force Implementation - cont Claim If wt(y) = 1, then x[j] = i A j y[i]. Implementing an encoder(n): For each output x j, use a separate or-tree whose inputs are {y[i] i A j }. Each such or-tree has at most 2 n inputs. the cost of each or-tree is O(2 n ). total cost is O(n 2 n ). The delay of each or-tree is O(log2 n ) = O(n). 26/43

Can we do better? We will prove that the graphical cone of the first output is Ω(2 n ). So for every encoder C: c(c) = Ω(2 n ) and d(c) = Ω(n). The brute force design is not that bad. Can we reduce the cost? Let s try... 27/43

encoder (n) - a recursive design For n = 1, is simply x[0] y[1]. Reduction step: y L [2 n 1 1 : 0] = y[2 n 1 : 2 n 1 ] y R [2 n 1 1 : 0] = y[2 n 1 1 : 0]. Use two encoder (n 1) with inputs y L and y R. But, wt( y) = 1 (wt( y L ) = 0) (wt( y R ) = 0). What does an encoder output when input all-zeros? 28/43

Augmenting functionality Augment the definition of the encoder n function so that its domain also includes the all-zeros string 0 2n. We define encoder n (0 2n ) = 0 n. Note that encoder (1) (i.e., x[0] y[1]) also meets this new condition, so the induction basis of the correctness proof holds. 29/43

Reduction step for encoder (n) y L [2 n 1 1 : 0] y R [2 n 1 1 : 0] = y[2 n 1 : 2 n 1 ] 2 n 1 = y[2 n 1 1 : 0] 2 n 1 encoder (n 1) encoder (n 1) b[n 2 : 0] a[n 2 : 0] n 1 n 1 or-tree(2 n 1 ) or(n 1) 1 n 1 x[n 1] x[n 2 : 0] 30/43

Correctness Claim The circuit encoder (n) implements the Boolean function encoder n. y L [2 n 1 1 : 0] y R [2 n 1 1 : 0] = y[2 n 1 : 2 n 1 ] 2 n 1 = y[2 n 1 1 : 0] 2 n 1 encoder (n 1) encoder (n 1) b[n 2 : 0] n 1 a[n 2 : 0] n 1 or-tree(2 n 1 ) or(n 1) 1 n 1 x[n 1] x[n 2 : 0] 31/43

Cost Analysis 0 if n = 1 c(encoder 2 c(encoder (n 1)) (n)) = +c(or-tree(2 n 1 )) +(n 1) c(or) if n > 1. Let c(n) = c(encoder (n))/c(or). { 0 if n = 1 c(n) = 2 c(n 1)+(2 n 1 1+n 1) if n > 1. (2) Claim c(n) = Θ(n 2 n ). So c(encoder (n)) (asymptotically) equals the cost of the brute force design... 32/43

Reducing The Cost Claim If wt(y[2 n 1 : 0]) 1, then encoder n 1 (or( y L, y R )) = or(encoder n 1 ( y L ),encoder n 1 ( y R )). 33/43

y L [2 n 1 1 : 0] y R [2 n 1 1 : 0] = y[2 n 1 : 2 n 1 ] 2 n 1 = y[2 n 1 1 : 0] 2 n 1 encoder (n 1) encoder (n 1) b[n 2 : 0] a[n 2 : 0] n 1 n 1 or-tree(2 n 1 ) or(n 1) y L y R 1 n 1 2 n 1 2 n 1 x[n 1] x[n 2 : 0] or(2 n 1 ) 2 n 1 or-tree(2 n 1 ) encoder (n 1) 1 n 1 x[n 1] x[n 2 : 0]

Correctness? 2 n 1 y L 2 n 1 y R or(2 n 1 ) 2 n 1 or-tree(2 n 1 ) 1 x[n 1] encoder (n 1) n 1 x[n 2 : 0] 35/43

Functional Equivalence Definition Two combinational circuits are functionally equivalent if they implement the same Boolean function. Claim If wt(y[2 n 1 : 0]) 1, then encoder n 1 (or( y L, y R )) = or(encoder n 1 ( y L ),encoder n 1 ( y R )). Claim encoder (n) and encoder (n) are functionally equivalent. Corollary encoder (n) implements the encoder n function. 36/43

Cost analysis The cost of encoder (n) satisfies the following recurrence equation: { c(encoder 0 if n=1 (n)) = c(encoder (n 1))+(2 n 1) c(or) otherwis C(2 k ) = c(encoder (k))/c(or). Then, { C(2 k 0 if k=0 ) = C(2 k 1 )+(2 k 1) c(or) otherwise. we conclude that C(2 k ) = Θ(2 k ). Claim c(encoder (n)) = Θ(2 n ) c(or). 37/43

Delay analysis The delay of encoder (n) satisfies the following recurrence equation: 0 if n=1 d(encoder (n)) = max{d(or-tree(2 n 1 )), d(encoder (n 1)+d(or))} otherwise. Since d(or-tree(2 n 1 )) = (n 1) d(or), it follows that d(encoder (n)) = n d(or). 38/43

Asymptotic Optimality Theorem For every encoder G of input length n: d(g) = Ω(n) c(g) = Ω(2 n ). Proof. Focus on the output x[0] and the Boolean function f 0 that corresponds to x[0]. Tempting to claim that cone(f 0 ) 2 n 1, and hence the lower bounds follow. But, this is not a valid argument because the specification of f 0 is a partial function (domain consists only of inputs whose Hamming weight equals one)... must come up with a correct proof! 39/43

Asymptotic Optimality Theorem For every encoder G of input length n: Proof. d(g) = Ω(n) c(g) = Ω(2 n ). Consider the output x[0]. We claim that cone G (x[0]) 1 2 2n. Otherwise, there exists an even index i and an odd index j such that {i,j} cone G (x[0]) =. Now consider two inputs: e i (a unit vector with a one in position i) and e j. The output x[0] is the same for e i, 0 2n = flip i (e i ) = flip j (e j ) and e j. This implies that x[0] errs for at least of the inputs e i or e j. 40/43

Parametric Specification The specification of decoder(n) and encoder(n) uses the parameter n. The parameter n specifies the length of the input. This parameter is not an input. decoder(8) and decoder(16) are completely different circuits. {decoder(n)} n=1 is a family of circuits, one for each input length. 41/43

Summary - 1 We discussed: buses decoders encoders 42/43

Summary - 2 Three main techniques were used in this chapter. Divide & Conquer - a recursive design methodology. Extend specification to make problem easier. Adding restrictions to the specification made the task easier since we were able to add assumptions in our recursive designs. Evolution. Naive, correct, costly design. Improved while preserving functionality to obtain a cheaper design. 43/43