Professional Documents
Culture Documents
Chapter 3
Chapter 3
Chapter 3
1
§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
AND, OR,
ADD,
SLT
CarryIn0
A0 1-bit result0
B0 ALU
CarryOut0
CarryIn1
A1 1-bit result1
B1 ALU
CarryOut1
CarryIn2
A2 1-bit result2
B2 ALU
CarryOut2
CarryIn3
A3 1-bit result3
B3 ALU
CarryOut3
LS 283
n
multiplicand
multiplier
partial
can be formed in parallel
n product
and added in parallel for
array
faster multiplication
double precision product
2n
Rechnerstrukturen 182.092 3 — Arithmetic for Computers
13
§3.3 Multiplication
Long-multiplication Approach
multiplicand
1000
multiplier
× 1001
1000
0000
0000
1000
product 1001000
Length of product is
the sum of operand
lengths
Initially 0
Can be pipelined
Several multiplication performed in parallel
Rechnerstrukturen 182.092 3 — Arithmetic for Computers
18
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
remainder
n
Rechnerstrukturen 182.092 3 — Arithmetic for Computers
20
§3.4 Division
Division
Check for 0 divisor
Long division approach
quotient If divisor ≤ dividend bits
dividend 1 bit in quotient, subtract
1001 Otherwise
1000|1001010 0 bit in quotient, bring down next
-1000 dividend bit
divisor
10 Restoring division
101 Do the subtract, and if remainder
1010 goes < 0, add divisor back
-1000 Signed division
remainder 10
Divide using absolute values
Adjust sign of quotient and remainder
n-bit operands yield n-bit as required
quotient and remainder
Initially dividend
1 1
2. If E = 255 (max.) and M = 0, than X = ( −1) s ⋅ ∞ ⇒ ∞; ⇒ −∞
E = 255 M = 0 0 −0
0 11111111 000000000O0000000000000 = ∞
1 11111111 00000000000000000000000 = - ∞
http://754r.ucbtest.org/standards/754.pdf
(ANSI/IEEE Std 754–1985)
Rechnerstrukturen 182.092 3 — Arithmetic for Computers
39
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
Step 1
Step 2
Step 3
Step 4
Optional variations
I: integer operand
P: pop operand from stack
R: reverse operand order
But not all combinations allowed
Rechnerstrukturen 182.092 3 — Arithmetic for Computers
54
Streaming SIMD Extension 2 (SSE2)
Adds 4 × 128-bit registers
Extended to 8 registers in AMD64/EM64T
Can be used for multiple FP operands
2 × 64-bit double precision
4 × 32-bit double precision
Instructions operate on them simultaneously
Single-Instruction Multiple-Data