DOC PREVIEW
UCLA COMSCI M151B - Lecture6

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Week 4 - Monday3_4Multiplication Start with long-multiplication approach Multiplicand: 1000 Multiplier: 1001 x ------------------ 1000 0000 0000 1000 + ------------------ 1001000 Length of product is the sum of operand lengths Shifting to the left is raising it by a power -> multiplying by 2 Potentially dealing with 64-bit products Multiplying 2 32-bit numbers We have to use 64-bit ALUMultiplication Hardware Product is going to be initially 0 Start 1. Test Multiplier0 (Least significant bit of the multiplier.) Goes to control test If 1 Add multiplicand to product and place the result in product register 2. Shift the multiplicand register left 1 bit 3. Shift the multiplier register right 1 bit 4. Has it repeated 32 times? If yes Done Else Repeat from #1Optimized Multiplier Perform steps in parallel: add/shift One cycle per partial-product addition It's okay if frequency of multiplications is low Multiplicand is not shifted at all Product register will be shifted insteadMIPS 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 -> rd3_5Signed Multiplication Make both positive Remember whether to complement product when done Apply definition of 2's complement Need to sign-extend partial products and subtract at the end Booth's Algorithm Elegant way to multiply signed numbers Using same hardware as before and save cyclesMotivation for Booth's Algorithm Example 2 x 6 = 0010 x 0110: 0010 x 0110 ------------ + 0000 shift (0 in multiplier) + 0010 add (1 in multiplier) + 0010 add (1 in multiplier) + 0000 shift (0 in multiplier) ------------ 00001100 ALU with add or subtract gets same result in more than one way: 14 = 2+4+8 14 = -2+16 001110 = -000010+010000 = 111110+010000 0010 x 0110 ------------ 0000 shift (0 in multiplier) - 0010 sub (first 1 in multiplier) 0000 shift (mid string of 1s) + 0010 add (prior step had last 1) ------------ 0001100 This example is not a very good example because we only have 2 consecutive 1's. But let's say we have 4 1's. Conventional: 0010 x 011110 ------------ 0000 + 0010 + 0010 + 0010 + 0010 + 0000 ------------ 000111100 0010 x 011110 ------------ 0000 - 0010 0000 0000 0000 + 0010 ------------ 000111100 We're saving more time because we're adding once and subtracting once instead of adding 5 times.Booth's Algorithm End of run -> most-significant bit Middle of run -> bunch of 1's in the middle Beginning of run -> least-significant bitCurrent Bit Bit to the right Explanation Example Op 1 0 Begins run of 1s 000111*10*00 Sub 1 1 Middle of run of 1s 00011*11*000 None 0 1 End of run of 1s 00*01*111000 Add 0 0 Middle of run of 0s 0*00*1111000 None Originally for Speed (when shift was faster than add) Replace a string of 1s in multiplier with an initial subtract when we first see one and then later add for the bit after the last one3_6IEEE Floating-Point Format S | Exponent | Fraction Exponent: Single: 8 bits Double: 11 bits Fraction: Single: 23 bits Double: 52 bits x = (-1)^S*(1+Fraction)*2^(Exponent-Bias) S: sign bit (0 => non-negative, 1 => negative) Normalized significand: 1.0 <= |Signficand| <= 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 = 1203Floating-Point Addition Consider a 4-digit decimal example 9.999*10^1+1.610*10^-1 1. Align decimal points Shift number with smaller exponennt 9.999*10^1+0.016*10^1 2. Add significands 10.015*10^1 3. Normalize result & check for over/underflow 1.0015*10^2 4. Round and renormalize if necessary


View Full Document

UCLA COMSCI M151B - Lecture6

Download Lecture6
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture6 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture6 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?