CA Chap3 Arithmetics
CA Chap3 Arithmetics
❑ Using 32 bits
–2,147,483,648 to +2,147,483,647
❑ Subtraction
Negate the second operand then add to the first operand
12 + 8 =
122 + 8 =
122 + 80 =
CarryOut3
➔ Performance is low
IT3283E Fall 2022 15
Making addition faster: infinite hardware
❑ Parallelize the adder with the cost of hardware
❑ Given the addition:
𝑎𝑛 − 1𝑎𝑛 − 2 … 𝑎1𝑎0 + 𝑏𝑛 − 1𝑏𝑛 − 2 … 𝑏1𝑏0
❑ Let 𝑐𝑖 is the carry at bit 𝑖
c2 = (b1 . c1) + (a1 . c1) + (a1 . b1)
c1 = (b0 . C0) + (a0 . c0) + (a0 . b0)
❑ Then
Find c2 = (a1 . a0 . b0)
c2 from a0, b0, a1, b1?
❑ At bit 𝑖
❑ Denote
❑ Then
C1
C2
C3
C4
IT3283E Fall 2022 19
Carry lookahead
❑ Denote
multiplicand
multiplier
partial
can be formed in parallel
n product
and added in parallel for
array
faster multiplication
double precision product
2n
add
32-bit ALU
shift
right
product
multiplier Control
0 0 0 0 0 1 0 1 = 5
add 0 1 1 0 0 1 0 1 LSB=1 → add multiplicand
0 0 1 1 0 0 1 0 shift right
0 0 0 1 1 0 0 1 shift right
0 0 0 1 1 1 1 0 shift right = 30
IT3283E Fall 2022 28
Fast multiplier – Design for Moore
❑ Why is this fast?
0 16 17 0 0 0x18
n quotient
0 0 0 dividend
divisor
0
partial
0 remainder
array
0
remainder
n
0000 0110 =6
0000 1100
sub 1110 1 1 0 0 rem neg, so ‘ient bit = 0
0000 1100 restore remainder
0001 1000
sub 1111 1 0 0 0 rem neg, so ‘ient bit = 0
0001 1000 restore remainder
0011 0000
sub 0001 0 0 0 1 rem pos, so ‘ient bit = 1
0010 0010
sub 0000 0 0 1 1 rem pos, so ‘ient bit = 1
= 3 with 0 remainder
IT3283E Fall 2022 34
S Divide Instruction
❑ Divide (div and divu) generates the reminder in hi
and the quotient in lo
div $s0, $s1 # lo = $s0 / $s1
# hi = $s0 mod $s1
0 16 17 0 0 0x1A
❑ Division:
Dividend and divisor of the same sign:
- Keep quotient
- Keep/negate remainder so it is of the same sign with dividend
Dividend and divisor of different sign:
- Negate quotient
- Keep/negate remainder so it is of the same sign with dividend
➔1 x 103
➔ 0.1 x 104
s E (exponent) F (fraction)
sign = 1 → X is negative
E = 1000 0010 = 130
F = 10101100...00
→ X = (-1)1 x 1.101011000..00 x 2130-127
= -1.101011 x 23 = -1101.011
= -13.375
sign = 0
e = 0111 1111 = 127
m = 000…0000 (23 bit 0)
X = (-1)0 x 1.00…000 x 2127-127 = 1.0
➔ 9.687510 = 1001.10112
Finally
X = 0100 0001 0001 1011 0000 0000 0000 0000
s E (exponent) F (fraction)
❑ Add
(0.5 = 1.0000 2-1) + (-0.4375 = -1.1100 2-2)
Step 0:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
❑ Multiplication
(F1 2E1) x (F2 2E2) = F3 2E3
Step 0: Restore the hidden bit in F1 and in F2
Step 1: Add the two (biased) exponents and subtract the
bias from the sum, so E1 + E2 – 127 = E3
also determine the sign of the product (which depends on
the sign of the operands (most significant bits))
Step 2: Multiply F1 by F2 to form a double precision F3
Step 3: Normalize F3 (so it is in the form 1.XXXXX …)
- Since F1 and F2 come in normalized → F3 [1,4) → 1 bit right shift F3 and
increment E3
- Check for overflow/underflow
❑ Multiply
(0.5 = 1.0000 2-1) x (-0.4375 = -1.1100 2-2)
Step 0:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
❑ Multiply
(0.5 = 1.0000 2-1) x (-0.4375 = -1.1100 2-2)
Step 0: Hidden bits restored in the representation above
Step 1: Add the exponents (not in bias would be -1 + (-2) = -
3 and in bias would be (-1+127) + (-2+127) – 127 =
(-1 -2) + (127+127-127) = -3 + 127 = 124
http://pages.cs.wisc.edu/~markhill/cs354/Fall2008/notes/flpt.apprec.html
IT3283E Fall 2022 55
Example
❑ Calculate:
0.2 x 5 = ?
0.333 x 3 = ?
(1.0/3) x 3 = ?