CSE 246: Computer Arithmetic Algorithms and Hardware Design Prof Chung-Kuan Cheng Lecture 3.

Slides:



Advertisements
Similar presentations
1 ECE 4436ECE 5367 Computer Arithmetic I-II. 2 ECE 4436ECE 5367 Addition concepts 1 bit adder –2 inputs for the operands. –Third input – carry in from.
Advertisements

1 Lecture 12: Hardware for Arithmetic Today’s topics:  Designing an ALU  Carry-lookahead adder Reminder: Assignment 5 will be posted in a couple of days.
Comparator.
Lecture Adders Half adder.
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Lecture 4: Adders.
1 Lecture 4: Arithmetic for Computers (Part 3) CS 447 Jason Bakos.
Chapter 6 Arithmetic. Addition Carry in Carry out
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Chapter # 5: Arithmetic Circuits Contemporary Logic Design Randy H
Lecture 8 Arithmetic Logic Circuits
ECE 301 – Digital Electronics
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
CSE 246: Computer Arithmetic Algorithms and Hardware Design Numbers: RNS, DBNS, Montgomory Prof Chung-Kuan Cheng Lecture 3.
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Chapter 5 Arithmetic Logic Functions. Page 2 This Chapter..  We will be looking at multi-valued arithmetic and logic functions  Bitwise AND, OR, EXOR,
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Basic Arithmetic (adding and subtracting)
Digital Arithmetic and Arithmetic Circuits
IKI a-Combinatorial Components Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes.
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter # 5: Arithmetic Circuits
Chapter 6-1 ALU, Adder and Subtractor
5-1 Programmable and Steering Logic Chapter # 5: Arithmetic Circuits.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Basic Arithmetic (adding and subtracting)
Computing Systems Designing a basic ALU.
درس مدارهای منطقی دانشگاه قم مدارهای منطقی محاسباتی تهیه شده توسط حسین امیرخانی مبتنی بر اسلایدهای درس مدارهای منطقی دانشگاه.
1 Lecture 12 Time/space trade offs Adders. 2 Time vs. speed: Linear chain 8-input OR function with 2-input gates Gates: 7 Max delay: 7.
CPS3340 Computer Architecture Fall Semester, 2013
ECE 331 – Digital System Design Multi-bit Adder Circuits, Adder/Subtractor Circuit, and Multiplier Circuit (Lecture #12)
1 Carry Lookahead Logic Carry Generate Gi = Ai Bi must generate carry when A = B = 1 Carry Propagate Pi = Ai xor Bi carry in will equal carry out here.
C-H1 Lecture Adders Half adder. C-H2 Full Adder si is the modulo- 2 sum of ci, xi, yi.
Addition and multiplication Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
1 Lecture 14 Binary Adders and Subtractors. 2 Overview °Addition and subtraction of binary data is fundamental Need to determine hardware implementation.
1 Lecture 11: Hardware for Arithmetic Today’s topics:  Logic for common operations  Designing an ALU  Carry-lookahead adder.
Lecture #23: Arithmetic Circuits-1 Arithmetic Circuits (Part I) Randy H. Katz University of California, Berkeley Fall 2005.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
Addition and multiplication1 Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
1 Arithmetic Building Blocks Today: Signed ArithmeticFirst Hour: Signed Arithmetic –Section 5.1 of Katz’s Textbook –In-class Activity #1 Second Hour: Adder.
CDA3101 Recitation Section 5
Carry-Lookahead & Carry-Select Adders
Lecture Adders Half adder.
Addition and multiplication
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
Basic Adders and Counters
Topics Number representation. Shifters. Adders and ALUs.
Combinational Circuits
CSE Winter 2001 – Arithmetic Unit - 1
Lecture 14 Logistics Last lecture Today
King Fahd University of Petroleum and Minerals
Unconventional Fixed-Radix Number Systems
Arithmetic Circuits (Part I) Randy H
Instructor: Prof. Chung-Kuan Cheng
UNIVERSITY OF MASSACHUSETTS Dept
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
CS 140 Lecture 14 Standard Combinational Modules
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
CSE 140 Lecture 14 Standard Combinational Modules
Addition and multiplication
Lecture 14 Logistics Last lecture Today
Addition and multiplication
Lecture 9 Digital VLSI System Design Laboratory
Arithmetic Circuits.
Lecture 2 Adders Half adder.
Presentation transcript:

CSE 246: Computer Arithmetic Algorithms and Hardware Design Prof Chung-Kuan Cheng Lecture 3

How to compare two RNS numbers We can approximate the magnitude of a RNS number by the following formula where

An Example Suppose, x = (6|3|0) RNS (7|5|3) y = (3|0|1) RNS (7|5|3) Then we have x/105 = [6(1/7) + 3(1/5) + 0(2/3)] mod 1 ≈ y/105 = [3(1/7) + 0(1/5) + 1(2/3)] mod 1 ≈ Clearly, x (48) is greater than y (10).

Double Base Number System (DBNS) DBNS is a new kind of number system, where there are two bases, p and q. Any number x is represented by the equation Also, this number system could be redundant, e.g. 54 = =

Double Base Number System (DBNS) We can represent DBNS numbers in a two-dimensional table. For example we can express 54 by this tabular representation xx 3x 9xx For each entry in the table, we multiply the corresponding row-value and column-value. Then we add up all such entries to get the value of the number represented by the table.

Double Base Number System (DBNS) DBMS can be of practical use too in some scenarios.  In binary number representation, each bit has approximately 0.5 probability of being 1.  But in DBNS, the number of bits that are logic 1 in the tabular representation could be much less.  Effectively, we can reduce the number of 0  1 and 1  0 transitions, thus saving power.

Double Base Number System (DBNS) A greedy approach to minimize the number of TRUE bits in the tabular representation of any integer : GREEDY (x) { if (x > 0) then do{ find the largest 2-integer w such that w ≤ x; write(w); x = x-w; greedy(x); }

Double Base Number System (DBNS) It can be shown that expected number of bits that are ‘turned on’ in a DBNS representation of integer is O[lg x/(lg lg x)], which is significantly lower than the corresponding number in the positional binary system, O(lg x). As an example, consider the integer In binary system, number of ‘1’s ≈ 100 In DBNS, number of ‘1’s ≈ 30 In the next few slides we shall discuss how we can implement ADDITION operation on two DBNS numbers.

DBNS Numbers: Addition Consider the integers 14 and 20. In DBNS system, 14 = [We represent this number by a green cross] 20 = [We represent this number by a red cross] The addition operation is performed by representation the numbers in tabular form, and then ‘merging’ the tables x 3x 9x

DBNS System: Addition The final merged table is : And the sum of 14 and 20 is = 34, which is indeed correct

DBNS System: Addition Few rules for ‘shifting’ values in the merged table  We can always use algebraic manipulations to minimize number of entries in a DBNS table, e.g. 2 i 3 j + 2 i 3 j+1 = 2 i+2 3 j 2 i 3 j + 2 i+1 3 j = 2 i 3 j+1 A variant of 2-integers are represented by using only single digit. They are of the form 2 s 3 t, and might be useful in logarithmic operations.

Chapter 2: ADDERS Half Adders  Half adders can add two 1-bit binary numbers when there is no carry in.  If the inputs are x i and y i, the sum and carry-out is given by the formula s i = x i ^ y i c i+1 = x i. y i  We use the following notations throughout the slides. means logical AND + means logical OR ^ means logical XOR ‘ means complementation

Full Adder The inputs are x[i], y[i] (operand bits) and c[i] (carry in) The outputs are s[i] (result bit) and c[i+1] (carry out) Inputs and outputs are related by these relations  s[i] = x[i] ^ y[i] ^ c[i]  c[i+1] = x[i].y[i] + c[i].(x[i] + y[i]) = x[i].y[i] + c[i].(x[i] ^ y[i])

Full Adder If carry-in bit is zero, then full adder becomes half adder If carry-in bit is one, then  s[i] = (x[i] ^ y[i])’  c[i+1] = x[i] + y[i] To add two n-bit numbers, we can chain n full adders to build a ripple carry adder

Ripple Carry Adder x[0] y[0] cin/c[0] s[0]... x[1] y[1] c[1] x[n-1] y[n-1] c[n-1] s[1] c[2] s[n-1] cout Overflow happen when operands are of same sign, and the result is of different sign. If we use 2’s complement to represent negative numbers, overflow occurs when (cout ^ c[n-1]) is 1

Ripple Carry Adder For sake of brevity, we use the following notations:  g[i] = x[i].y[i]  p[i] = x[i] + y[i] In terms of these notations, we can rewrite carry equations as  c[1] = g[0] + p[0].c[0]  c[2] = g[1] + p[1].c[1]  and so on…  We shall use these notations afterwards while discussing the design of other kind of adders It has been observed that expected length of carry chain is 2, while expected maximal length of carry chain is lg n. Hence, ripple carry adders are in general fast.

Ripple Carry Adder How do know that an adder has completed the operation?  Worst case scenario: Wait for the longest chain in the carry propagation network  We might inspect c[i+1] and its complement b[i+1] to determine the status of the adder c[i+1]b[i+1]Remark 00Not complete 10Complete 01 11Don’t care

Improvement to Ripple Carry Adder: Manchester Adders By intelligently using our device properties, we can reduce the complexity of the circuit used to compute carries in a ripple carry adder. Define: a[i] = (x[i])’.(y[i])’ Next we observe that c[i+1] is 1 in exactly these scenarios:  g[i] is 1, i.e. both x[i] & y[i] are 1  c[i] is 1 and it is propagated because p[i] is 1 c[i+1] is ‘pulled down’ to logic 0 irrespective of the value of c[i], when a[i] is 1, i.e. both x[i] and y[i] are 0 From these conditions, and keeping in mind the general characteristics of transistor devices we can design simplified circuits for computing carries – as shown in the next slide

Improvement to Ripple Carry Adder: Manchester Adders

Implementation of Manchester Adder using MOS transistors This is essentially the same circuit for computing carry, but implemented with MOS devices

Manchester Adder: Alternate design We divide the computation cycle into two distinct half-cycle : ‘precharge’ and ‘evaluate’. In the precharge half-cycle, g[i] and c[i+1] are assigned a tentative value of logic 1. This is evaluated in the next half-cycle with actual value of a[i]. The actual circuit for computing carries is shown in the next slide.

Manchester Adder: Alternate design Time  Q precharge evaluation

Carry Look-ahead Adder In a ripple-carry adder m-full adders are grouped together (m is usually equal to 4). Once the carry-in to the group is known, all the internal carries and the output carry is calculated simultaneously. We can use some algebraic manipulations to minimize hardware complexity. Consider the carry out of the group  c[i] = g[i-1] + p[i-1].c[i-1]  Putting the value of c[i-1], we can rewrite as c[i] = g[i-1] + p[i-1].g[i-2] + p[i-1].p[i-2].c[i-2]  Proceeding in this manner we get c[i] = g[i-1] + p[i-1].g[i-2] + p[i-1].p[i-2].g[i-3] + p[i-1].p[i-2].p[i-3].g[i-4] + p[i- 1].p[i-2].p[i-3].p[i-4].c[i-4]  To further simplify the equation, we note that g[i-1] = g[i-1].p[i-1], and p[i-1] can be factored out

Ling’s Adder c[i] = g[i-1] + p[i-1].g[i-2] + p[i-1].p[i-2].g[i-3] + p[i-1].p[i- 2].p[i-3].g[i-4] + p[i-1].p[i-2].p[i-3].p[i-4].c[i-4] We replace p[i]=x[i]^y[i] with t[i]=x[i]+y[i]. Because g[i]=g[i]t[i], we have c[i] = g[i-1]t[i-1] + t[i-1]g[i-2] + t[i-1].t[i-2].g[i-3] + t[i-1].t[i- 2].t[i-3].g[i-4] + t[i-1].t[i-2].t[i-3].t[i-4].c[i-4] Let h[i] = g[i-1] + g[i-2] + t[i-2].g[i-3] + t[i-2].t[i-3].g[i-4] + t[i- 2].t[i-3].t[i-4].t[i-5] h[i-4] C[i]= h[i]t[i-1]

Generalized Design for Adders: Prefix Adder Prefix computation  Given n inputs x 1, x 2, x 3 …x n and an associative operator ×. We want to compute yi = x i × x i-1 × x i-2 …× x 2 × x 1 for all i, 1≤ i ≤n  x can be a scalar/vector/matrix  For design of adders, we define the operator × in the following manner (g, p) = (g’, p’) × (g’’, p’’) g = g’’ + p’’.g’ p = p’.p’’

Alternate modeling of Prefix Computer: Finite State Machine A finite state machine has a set of states, and it ‘moves’ from one state to another according to input. Mathematically,  s k = f (s k-1, a k-1 ) The problem is to determine final state s n in O(lg n) operations, given initial state s 0 and sequence of inputs (a 0, a 1, …a n-1 ) This problem can be formulated in terms of prefix computation

Alternate modeling of Prefix Computer: Finite State Machine We assume that number of states are small and finite. Let s k = f a k-1 (s k-1 ), f a k-1 can be represented by matrix M a k-1 Now we are ready to represent our problem in terms of prefix computation.

Alternate Modeling of Prefix Computer: Finite State Machine The algorithm 1. Compute M a i in parallel 2. Compute N 1 = M a 1 N 2 = M a 2.M a 1 … N n = M a n.M a n-1 …M a 1 3. Compute S i+1 = N i (S 0 )