cps3340 computer architecture fall semester, 2013
DESCRIPTION
Lecture 15: Multiplication & Division Instructor: Ashraf Yaseen. CPS3340 Computer Architecture Fall Semester, 2013. Department of Math & Computer Science Central State University, Wilberforce, OH. 11/12/2013. Review. Last Class Second Exam Review This Class Multiplication Division - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/1.jpg)
CPS3340 COMPUTER
ARCHITECTURE Fall Semester, 2013
CPS3340 COMPUTER
ARCHITECTURE Fall Semester, 2013
11/12/2013
Lecture 15: Multiplication & Division
Instructor: Ashraf YaseenDEPARTMENT OF MATH & COMPUTER SCIENCECENTRAL STATE UNIVERSITY, WILBERFORCE, OH
1
![Page 2: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/2.jpg)
Review
Last Class Second Exam Review
This Class Multiplication Division
Next Class Floating Point Numbers
2
![Page 3: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/3.jpg)
Multiplication
Sequential Version of Multiplication Algorithm and Hardware Start with long-multiplication approach
1000× 1001 1000 0000 0000 1000 1001000
Length of product is the sum of operand lengths
multiplicand
multiplier
product
3
![Page 4: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/4.jpg)
Multiplication Hardware First version of Multiplication Hardware
32-bit multiplier 64-bit ALU 64-bit product (initialized to 0)
4
![Page 5: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/5.jpg)
Multiplication Hardware How many steps?
32 Each step has two operations
Shift Add
Initially 0
5
![Page 6: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/6.jpg)
Example
2*3
6
![Page 7: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/7.jpg)
Refined Multiplier Refined Multiplier
32-bit multiplicand and ALU Multiplier is placed in the right half of the product register 64-bit product register
7
![Page 8: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/8.jpg)
Refined Multiplier (cont)
Perform steps in parallel: add/shift
One cycle per partial-product addition That’s ok, if frequency of multiplications is low
8
![Page 9: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/9.jpg)
Faster Multiplier Uses multiple adders
Cost/performance tradeoff Done in 5 steps But needs 31 ALUs
Can be pipelined Several multiplication performed in parallel
9
![Page 10: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/10.jpg)
MIPS Multiplication
Two 32-bit registers for product HI: most-significant 32 bits LO: least-significant 32-bits
Instructions mult rs, rt / multu rs, rt
64-bit product in HI/LO mfhi rd / mflo rd
Move from HI/LO to rd Can test HI value to see if product overflows 32 bits
mul rd, rs, rt Least-significant 32 bits of product –> rd
10
![Page 11: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/11.jpg)
Back to the Example
A better way to do 2*3? 3 << 1 using SLL
Almost all compilers will perform a strength reduction optimization by replacing multiplication of power of 2 by shifting
11
![Page 12: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/12.jpg)
Division
Check for 0 divisor Long division approach
If divisor ≤ dividend bits 1 bit in quotient, subtract
Otherwise 0 bit in quotient, bring down next
dividend bit Restoring division
Do the subtraction, and if remainder goes < 0, add divisor back
Signed division Divide using absolute values Adjust sign of quotient and
remainder as required
10011000 1001010 -1000
1 10 101 1010 -1000 10
n-bit operands yield n-bitquotient and remainder
quotient
dividend
remainder
divisor
12
![Page 13: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/13.jpg)
Division Hardware
Initially dividend
Initially divisor in left half
First version of Division Hardware 32-bit quotient 64-bit ALU 64-bit remainder
13
![Page 14: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/14.jpg)
First Version Division Hardware
Initially dividend
Initially divisor in left half
14
![Page 15: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/15.jpg)
Example 7/2
15
![Page 16: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/16.jpg)
Optimized Divider
One cycle per partial-remainder subtraction Looks a lot like a multiplier!
Same hardware can be used for both
16
![Page 17: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/17.jpg)
Faster Division
Can’t use parallel hardware as in multiplier Subtraction is conditional on sign of
remainder Faster dividers (e.g. SRT devision)
generate multiple quotient bits per step Still require multiple steps
17
![Page 18: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/18.jpg)
MIPS Division
Use HI/LO registers for result HI: 32-bit remainder LO: 32-bit quotient
Instructions div rs, rt / divu rs, rt No overflow or divide-by-0 checking
Software must perform checks if required Use mfhi, mflo to access result
18
![Page 19: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/19.jpg)
Example Revisit
A better way to do 7/2? 7>>2 SRL
Most compiler will replace divide by power of 2 using right shift operations
19
![Page 20: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/20.jpg)
Summary
Multiplication First version of multiplication Optimized multiplication
Division First version of division Optimized division
20
![Page 21: CPS3340 Computer Architecture Fall Semester, 2013](https://reader030.vdocuments.us/reader030/viewer/2022033018/56814b39550346895db8424c/html5/thumbnails/21.jpg)
What I want you to do
Review Chapters 3.3 and 3.4
21