0% found this document useful (0 votes)
9 views61 pages

Computer Org Chapter - 03 J

Uploaded by

sakthivel.jd05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views61 pages

Computer Org Chapter - 03 J

Uploaded by

sakthivel.jd05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 61

COMPUTER ORGANIZATION AND DESIGN

5
Edition
th

The Hardware/Software Interface

Chapter 3
Arithmetic for Computers
§3.1 Introduction
Arithmetic for Computers
 Operations on integers
 Addition and subtraction
 Multiplication and division
 Dealing with overflow
 Floating-point real numbers
 Representation and operations

Chapter 3 — Arithmetic for Computers — 2


Possible Representations

Chapter 3 — Arithmetic for Computers — 3


MIPS: 32-bit signed integers

Chapter 3 — Arithmetic for Computers — 4


Addition and Subtraction

Chapter 3 — Arithmetic for Computers — 5


Add and Subtract

Chapter 3 — Arithmetic for Computers — 6


§3.2 Addition and Subtraction
Integer Addition
 Example: 7 + 6

 Overflow if result out of range



Adding +ve and –ve operands, no overflow

The result will be less than one of the operands

Adding two +ve operands

Overflow if result sign is 1

Adding two –ve operands

Overflow if result sign is 0
Chapter 3 — Arithmetic for Computers — 7
Integer Subtraction
 Add negation of second operand
 Example: 7 – 6 = 7 + (–6)
+7: 0000 0000 … 0000 0111
–6: 1111 1111 … 1111 1010
+1: 0000 0000 … 0000 0001
 Overflow if result out of range
 Subtracting two +ve or two –ve operands, no overflow
 Subtracting +ve from –ve operand

Overflow if result sign is 0
 Subtracting –ve from +ve operand

Overflow if result sign is 1

Chapter 3 — Arithmetic for Computers — 8


Overflow in unsigned addition

Chapter 3 — Arithmetic for Computers — 9


Overflow in unsigned subtraction

Chapter 3 — Arithmetic for Computers — 10


Overflow in signed addition

Chapter 3 — Arithmetic for Computers — 11


Overflow in signed subtraction

Chapter 3 — Arithmetic for Computers — 12


Overflow with Unsigned

Chapter 3 — Arithmetic for Computers — 13


Dealing with Overflow

Chapter 3 — Arithmetic for Computers — 14


Arithmetic for Multimedia

Chapter 3 — Arithmetic for Computers — 15


§3.3 Multiplication
Multiplication
 Start with long-multiplication approach
multiplicand
1000
multiplier
× 1001
1000
0000
0000
1000
product 1001000

Length of product is
the sum of operand
lengths

Chapter 3 — Arithmetic for Computers — 16


Multiplication Hardware

Initially 0

Chapter 3 — Arithmetic for Computers — 17


Example : 2 x 3

Chapter 3 — Arithmetic for Computers — 18


Optimized Multiplier
 Perform steps in parallel: add/shift

 One cycle per partial-product addition


 That’s ok, if frequency of multiplications is low
Chapter 3 — Arithmetic for Computers — 19
Faster Multiplier
 Uses multiple adders
 Cost/performance tradeoff

 Can be pipelined
 Several multiplication performed in parallel
Chapter 3 — Arithmetic for Computers — 20
MIPS Multiplication

Chapter 3 — Arithmetic for Computers — 21


§3.4 Division
Division

quotient

dividend
1001
1000 1001010
-1000
divisor
10
101
1010
-1000
remainder 10

n-bit operands yield n-bit


quotient and remainder

Chapter 3 — Arithmetic for Computers — 22


Example

Chapter 3 — Arithmetic for Computers — 23


Division Reminder register 
Dividend
initially

Chapter 3 — Arithmetic for Computers — 24


Division: 7 by 2

Chapter 3 — Arithmetic for Computers — 25


Division: 7 by 2

Chapter 3 — Arithmetic for Computers — 26


Division Hardware
Initially divisor
in left half

Initially dividend

Chapter 3 — Arithmetic for Computers — 27


Optimized Divider

Chapter 3 — Arithmetic for Computers — 28


MIPS Division

Chapter 3 — Arithmetic for Computers — 29


§3.5 Floating Point
Floating Point

normalized

not normalized

Chapter 3 — Arithmetic for Computers — 30


Floating Point Standard
 Defined by IEEE Std 754-1985
 Developed in response to divergence of
representations
 Portability issues for scientific code
 Now almost universally adopted
 Two representations
 Single precision (32-bit)
 Double precision (64-bit)

Chapter 3 — Arithmetic for Computers — 31


Floating Point
In general, the floating point numbers are of the form,

Single Precision

Double Precision

Chapter 3 — Arithmetic for Computers — 32


Example

Chapter 3 — Arithmetic for Computers — 33


Example

Chapter 3 — Arithmetic for Computers — 34


What if 2’s Comp. used for E?

Chapter 3 — Arithmetic for Computers — 35


IEEE Floating-Point Format

S Exponent Fraction

x (  1)S (1 Fraction) 2(Exponent Bias)


 S: sign bit (0  non-negative, 1  negative)
 Normalize significand: 1.0 ≤ |significand| < 2.0

Always has a leading pre-binary-point 1 bit, so no need to
represent it explicitly (hidden bit)

Significand is Fraction with the “1.” restored
 Exponent: excess representation: actual exponent + Bias

Ensures exponent is unsigned

Single: Bias = 127; Double: Bias = 1203

Chapter 3 — Arithmetic for Computers — 36


IEEE 754 format
Single-Precision Range

Chapter 3 — Arithmetic for Computers — 38


Double-Precision Range

Chapter 3 — Arithmetic for Computers — 39


Floating Point Example

Chapter 3 — Arithmetic for Computers — 40eeeeeeeeeeee


Zero, Infinity and NaN

Chapter 3 — Arithmetic for Computers — 41


Denormalized Numbers
• Numbers represented in Unnormalized form

Chapter 3 — Arithmetic for Computers — 42


IEEE 754 Encoding Summary

Chapter 3 — Arithmetic for Computers — 43


Example

Chapter 3 — Arithmetic for Computers — 44


Example

Chapter 3 — Arithmetic for Computers — 45


Example

Chapter 3 — Arithmetic for Computers — 46


Floating-Point Addition
 Consider a 4-digit decimal example
 9.999 × 101 + 1.610 × 10–1
 1. Align decimal points
 Shift number with smaller exponent
 9.999 × 101 + 0.016 × 101
 2. Add significands
 9.999 × 101 + 0.016 × 101 = 10.015 × 101
 3. Normalize result & check for over/underflow
 1.0015 × 102
 4. Round and renormalize if necessary
 1.002 × 102

Chapter 3 — Arithmetic for Computers — 47


Floating-Point Addition
 Now consider a 4-digit binary example

1.0002 × 2–1 + –1.1102 × 2–2 (0.5 + –0.4375)
 1. Align binary points
 Shift number with smaller exponent

1.0002 × 2–1 + –0.1112 × 2–1
 2. Add significands

1.0002 × 2–1 + –0.1112 × 2–1 = 0.0012 × 2–1
 3. Normalize result & check for over/underflow

1.0002 × 2–4, with no over/underflow
 4. Round and renormalize if necessary

1.0002 × 2–4 (no change) = 0.0625

Chapter 3 — Arithmetic for Computers — 48


FP Adder Hardware

Chapter 3 — Arithmetic for Computers — 49


FP Arithmetic Hardware

Chapter 3 — Arithmetic for Computers — 52


Co-processors in MIPS

Chapter 3 — Arithmetic for Computers — 53


FP Instructions in MIPS
 FP hardware is coprocessor 1

Adjunct processor that extends the ISA
 Separate FP registers

32 single-precision: $f0, $f1, … $f31

Paired for double-precision: $f0/$f1, $f2/$f3, …
 FP instructions operate only on FP registers
 FP load and store instructions

lwc1, ldc1, swc1, sdc1

e.g., ldc1 $f8, 32($sp)

Chapter 3 — Arithmetic for Computers — 54


FP Instructions in MIPS

Chapter 3 — Arithmetic for Computers — 55


Associativity
 Parallel programs may interleave
operations in unexpected orders
 Assumptions of associativity may fail
(x+y)+z x+(y+z)
x -1.50E+38 -1.50E+38
y 1.50E+38 0.00E+00
z 1.0 1.0 1.50E+38
1.00E+00 0.00E+00
 Need to validate parallel programs under
varying degrees of parallelism
Chapter 3 — Arithmetic for Computers — 56
Who Cares About FP Accuracy?

Chapter 3 — Arithmetic for Computers — 57


Intel Pentium FDIV Bug

Chapter 3 — Arithmetic for Computers — 58


Rounding off the result

Chapter 3 — Arithmetic for Computers — 59


Accuracy

Chapter 3 — Arithmetic for Computers — 60


Guard, Round and Sticky bits
 The sticky bit allows the computer to see
the difference between 0.50 … 00 and
0.50 … 01 when rounding.

Chapter 3 — Arithmetic for Computers — 61


§3.9 Concluding Remarks
Concluding Remarks
 Bits have no inherent meaning
 Interpretation depends on the instructions
applied
 Computer representations of numbers
 Finite range and precision
 Need to account for this in programs

Chapter 3 — Arithmetic for Computers — 62


References
 Lecture -16 Floating Point Arithmetic
 https://www.youtube.com/watch?
v=03fhijH6e2w&list=PL59E5B57A04EAE09C
&index=16

Chapter 3 — Arithmetic for Computers — 63

You might also like