Computer Arithmetic. L. Liu Department of Computer Science, ETH Zürich Fall semester, Reconfigurable Computing Systems ( L) Fall 2012

Similar documents
Divide: Paper & Pencil

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

World Inside a Computer is Binary

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Floating Point Arithmetic

4.1 QUANTIZATION NOISE

Number Systems and Computer Arithmetic

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

CS & IT Conversions. Magnitude 10,000 1,

Representation of Numbers and Arithmetic in Signal Processors

CO212 Lecture 10: Arithmetic & Logical Unit

Floating Point Arithmetic

Number System. Introduction. Decimal Numbers


Introduction to Computers and Programming. Numeric Values

Chapter 10 Binary Arithmetics

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

CS 64 Week 1 Lecture 1. Kyle Dewey

Chapter 3: Arithmetic for Computers

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Floating Point Representation in Computers

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

ATAUL GHALIB ANALYSIS OF FIXED-POINT AND FLOATING-POINT QUANTIZATION IN FAST FOURIER TRANSFORM Master of Science Thesis

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Chapter 4. Operations on Data

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

CHW 261: Logic Design

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

COMP 122/L Lecture 2. Kyle Dewey

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Floating Point January 24, 2008

Giving credit where credit is due

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Module 2: Computer Arithmetic

The type of all data used in a C (or C++) program must be specified

Giving credit where credit is due

Number Systems CHAPTER Positional Number Systems

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Number Representations

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

System Programming CISC 360. Floating Point September 16, 2008

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Computer Architecture and Organization

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

02 - Numerical Representations

COMP Overview of Tutorial #2

Advanced Computer Architecture-CS501

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

CHAPTER 5: Representing Numerical Data

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

EE 109 Unit 6 Binary Arithmetic

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

Foundations of Computer Systems

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Floating Point. EE 109 Unit 20. Floating Point Representation. Fixed Point

unused unused unused unused unused unused

MC1601 Computer Organization

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

3.5 Floating Point: Overview

Organisasi Sistem Komputer

Lecture 2: Number Systems

Computer Organization: A Programmer's Perspective

COMP2611: Computer Organization. Data Representation

Floating Point Numbers

CS101 Lecture 04: Binary Arithmetic

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

EE 109 Unit 20. IEEE 754 Floating Point Representation Floating Point Arithmetic

The type of all data used in a C++ program must be specified

Chapter Three. Arithmetic

Number Systems (2.1.1)

Floating-point to Fixed-point Conversion. Digital Signal Processing Programs (Short Version for FPGA DSP)

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

MIPS Integer ALU Requirements

Today: Floating Point. Floating Point. Fractional Binary Numbers. Fractional binary numbers. bi bi 1 b2 b1 b0 b 1 b 2 b 3 b j

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Numbering systems. Dr Abu Arqoub

T02 Tutorial Slides for Week 2

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Floating Point Numbers

Floating Point Numbers

Numeric Encodings Prof. James L. Frankel Harvard University

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Floating Point Numbers. Lecture 9 CAP

SIGNED AND UNSIGNED SYSTEMS

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Inf2C - Computer Systems Lecture 2 Data Representation

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Data Representation Floating Point

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

Objectives. After completing this module, you will be able to:

Chapter 2. Data Representation in Computer Systems

Transcription:

Reconfigurable Computing Systems (252-2210-00L) all 2012 Computer Arithmetic L. Liu Department of Computer Science, ETH Zürich all semester, 2012 Source: ixed-point arithmetic slides come from Prof. Jarmo Takala, Tempere university of technology, inland 1

Number Representation Representation allows an exact value to be assigned to a binary number What is the decimal value of binary number 1011? Is 1011 negative or positive? 2

ixed-point Arithmetic Digital systems are finite bit systems Arithmetic operations are performed with finite-precision numbers Numbers are defined over a finite ring instead of a read field Overflow is possible Integers (integer arithmetic) Two s complement representation ractions 3

Unsigned Integer (b n-1 b n-2 b 0 ) Decimal Value x Quantization Step q n 1 10 = bn 1 + + 2 = 1 2 b + b 1111 0000 1 0 0 1110 15 14 1101 1100 13 12 1 0001 2 0010 0011 3 4 0100 Number Range [0,2 n x10 1] 11 5 1011 0101 10 6 1010 9 7 0110 8 1001 0111 1000 4

Signed Integer (b n-1 b n-2 b 0 ) Decimal Value x n 1 10 = bn 1 + + 2 Quantization Step q = 1 2 b + b 1 0 1110 1101-3 1100-4 1111-2 -1 0000 0 1 0001 2 0010 0011 3 4 0100 Number Range n 1 n 1 x10 [ 2,2 1] -5 5 1011 0101-6 6 1010-7 7 0110-8 1001 0111 1000 5

Properties Multiplication of two unsigned b-bit numbers yields a 2b-bit result law of conservation of bits multiplication of integers means high probability for overflow Multiplication of two signed b-bit numbers yields a 2b bit result only multiplication of 2 b-1 2 b-1 requires 2b-bits in this case, the dynamic range provided by the extra bit is wasted Addition of two b-bit numbers yields a (b+1)-bit result for N additions allocate log2(n) extra bits for result for avoiding overflow for example, addition of 256 numbers without overflow requires 8 extra bits 6

Accumulative Overflow Any chain of arithmetic operations whose final result is in the representable range can be calculated correctly even if overflow has occurred in some intermediate results Calculate 7+6-8=5 with 4-bit signed representation. + + 0111 +7 0110 +6 1101-3 overflow! 1000-8 0101 +5 7

ractional Representation Number field normalized into range [-1, 1) Overflow avoided in multiplication!! -1-1 = 1, 1 [-1, 1)!! As 1 cannot be represented, -1 is not allowed as a multiplier coefficient Also known as Q x representation x is the number of fraction bits or example, Q15 representation contains one bit for sign and 15 bits for fraction b 15 b 14 b 13 b 12 b 11 b 10 b 9 S b 8 b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0 binary point 8

ractional Representation Location of the radix-point is just a tool for programming Location is not necessarily fixed The bits of a fractional binary word can also be indexed starting from the MSB, which has an index 0, and continuing with negative indexes With this arrangement, the index of the bit readily tells the weight of that bit, and conversion to the decimal system is easy b 2 4 4 = = 0.0625 b -2 S b 0 b -1 b -3 b -4 b -5 b -6 b -7 b -8 b -9 b -10 b -11 b -12 b -13 b -14 b -15 binary point 9

ractional ixed-point (b n-1 b n-2 b 0 ) Decimal Value x 1 ( n 1) 10 = bn 1 + 2 bn 2 + + 2 b0 Quantization Step q Number Range x 10 = ( 1) 2 n [ 1,1 2 ( n 1) ] 1101 1100 1110 1111-0.125-0.25-0.375-0.5 0000 0001 0 0.125 0.25 0.375 0010 0.5 0011 0100-0.625 0.625 1011 0101-0.75 0.75 1010-0.875 0.875 0110-1 1001 0111 1000 10

ixed-point Overflow overflow characteristics of fixed-point fractional number Saturation arithmetic Source: Bhattacharyya, S.S.; Deprettere,E..; Leupers,R.; Takala,J., Handbook of Signal Processing System. 11

Example 4-Bit Integer Arithmetic Q3 ractional Arithmetic 1101 0011 11111101 1111101 000000 00000 = -3 10 = 3 10 Remember Sign Extension! 1.101 0.011 11.111101 11.11101 00.0000 00.000 = -0.375 10 = 0.375 10 11110111 = -9 10 11.110111 = -0.140625 10 11110111 -> 0111 = 7 10 11.110111 -> 1.110 = -0.250 10 INTEGER ULL PRECISION RACTIONAL 12

Guard Bits Extra bits, which are located to the right of the fraction at the arithmetic unit can be used to avoid the loss of precision during the normalization (left shift) as extra information for rounding 1.0011 b *2 2 1.00110 b *2 2 1.0001 b *2 1 0.10001 b *2 2 guard bit Loss of precision can be avoided by allocating extra bits (guard bits) to the right of fraction in the arithmetic unit 13

Arithmetic Operations ixed-point operations can be carried out precisely, if the result is representable with the given number of bits intermediate overflows produce no error to the final result Successive arithmetic operations increase the wordlength quantization is needed to reduce the number of bits can be implemented as truncation or rounding often, a few guard bits are used in the data path, and only the final result is quantized Arithmetic operations in all finite wordlength systems can introduce error 14

Quantization in ixed-point Quantization Curve Rounding-to-Nearest Q r [x] x Truncation of Two s Complement Q 2t [x] x Truncation of Magnitude Q mt [x] x Quantization Error e r (x) e 2t (x) e mt (x) Amplitude Distribution of Error ρ r (e r ) 1/q -q/2 q/2 x: 1.0110101 + 1 Q[x]: 1.0111 ρ 2t (e 2t ) ρ mt (e mt ) 1/q 1/(2q) e r -q q e 2t -q q e mt x: 1.0110101 Q[x]: 1.0110 x: 1.0110101 + 1 Q[x]: 1.0111 15

Shift-and-Add Multiplication Assume A is the multiplicant, B is the multiplier, this algorithm adds the multiplicant A to itself B times. Calculate 8 * 3 = 24 with two s complement representation. x 01000 011 multiplicant multiplier + 01000 01000 00000 0011000 product 16

Left-Shift Multiplicant Algorithm start A: multiplicant B: multiplier P: product X := A; Y := B; P:=0; N := WordLen(B) no Y0 = 1 yes Steps (N) Mulplicant (X) Multiplier (Y) Product (P) 3 01000 011 00000000 P := P+X 2 010000 01 +00001000 00001000 Shift X left Shift Y right 1 0100000 0 +00010000 00011000 0 01000000 _ +00000000 00011000 N := N-1 no N=0 yes Return P 17

Right-Shift Product Algorithm start A: multiplicant B: multiplier P: product X := A; Y := B; P:=0; N := WordLen(B) no Y0 = 1 yes Steps (N) Mulplicant (X) Multiplier (Y) Product (P) Shift P righ P := P+X 3 01000 011 00000000 2 01000 01 +01000000 01000000 00100000 no Shift Y right N := N-1 N=0 yes Return P 1 01000 0 +01000000 01100000 00110000 0 01000 _ +00000000 00110000 00011000 18

Unsigned Left-Shift Multiplier

Question Which shift-and-add multiplication algorithm is more resource efficient? 20