lecture6-2
lecture6-2
Start
Start
value the sum 2n + 2n-1 + … + 2m = 2n+1 – 2m • Modify Step 2 of Multiply Version 3 to sign extend when the product is
shifted right (arithmetic right shift, rather than logical right shift) because
• Replace a string of 1s in multiplier with an initial subtract when we first the product is a signed number
see a one and then later add after the last one • Multiply Version 3 and Booth share the same hardware, except Booth
– What if the string of 1’s started from the left of the (2’s complement) number, requires one extra flipflop to remember the bit to the right of the current
e.g., 11110001 – would the formula above have to be modified?! bit in the product register – which is the bit pushed out by the preceding
right shift
1c. 0010 1110 0111 0 shift P (sign ext) 1c. 0010 1110 1101 0 shift P (sign ext)
2. 0010 1111 0011 1 11 -> nop 2. 0010 1111 0110 1 01 -> add P = P + M
1d. 0010 1111 0011 1 shift P (sign ext) 1b. 0010 0001 0110 1 shift P (sign ext)
2. 0010 1111 1001 1 11 -> nop 2. 0010 0000 1011 0 10 -> sub P = P - M
1d. 0010 1111 1001 1 shift P (sign ext) 1c. 0010 1110 1011 0 shift P
2. 0010 1111 1100 1 01 -> add P = P + M 2. 0010 1111 0101 1 11 -> nop
1b. 0010 0001 1100 1 shift P (sign ext) 1d. 0010 1111 0101 1 shift P
Start
Algorithm
MIPS Notes
Observations
• div (signed), divu (unsigned), with two 32-bit register operands,
divide the contents of the operands and put remainder in Hi register
• Half the bits in divisor always 0
and quotient in Lo; overflow is ignored in both cases
– ⇒ 1/2 of 64-bit adder is wasted
– ⇒ 1/2 of divisor register is wasted
• Intuition: instead of shifting divisor to right, shift remainder to left…
• Sign bit is 0 for positive numbers, 1 for negative numbers Example : Represent –0.75ten in IEEE 754 single precision
– decimal: –0.75 = –3/4 = –3/22
• Number is assumed normalized and leading 1 bit of significand left of
binary point (for non-zero numbers) is assumed and not shown – binary: –11/100 = –.11 = –1.1 x 2-1
– e.g., significand 1.1001… is represented as 1001…, – IEEE single precision floating point exponent = bias + exponent
– exception is number 0 which is represented as all 0s (see next slide) value
– for other numbers: = 127 + (-1) = 126ten = 01111110two
value = (–1)sign * (1 + significand) * 2exponent value
– IEEE single precision: 10111111010000000000000000000000
exponent significand
• Exponent is biased to make sorting easier sign
– all 0s is smallest exponent, all 1s is largest
– bias of 127 for single precision and 1023 for double precision
equals exponent value
– therefore, for non-0 numbers:
value = (–1) * (1 + significand) * 2(exponent – bias)
sign
Start
0 1 0 1 0 1
Shift smaller
Overflow or Yes Control Shift right
number right
underflow?
No
Exception Add
Big ALU
4. Round the significand to the appropriate
number of bits
0 1 0 1
Increment or
decrement Shift left or right Normalize
No
Still normalized?
Done
Summary
• Computer arithmetic is constrained by limited precision
• Bit patterns have no inherent meaning but standards do exist:
– two’s complement
– IEEE 754 floating point
• Computer instructions determine meaning of the bit patterns.
• Performance and accuracy are important so there are many
complexities in real machines (i.e., algorithms and implementation)