Arithmetic For Computers: The Hardware/Software Interface
Arithmetic For Computers: The Hardware/Software Interface
Arithmetic For Computers: The Hardware/Software Interface
ARM
ARITHMETIC FOR
COMPUTERS
“There are 10 types of people in the
world, the ones who understand binary
and the ones who don’t.”
- Whatsapp Forward
§3.1 Introduction
Arithmetic for Computers
• Operations on integers
• Addition and subtraction
• Multiplication and division
• Dealing with overflow
• Saturating operations
• On overflow, result is largest representable value
• c.f. 2s-complement modulo arithmetic
• E.g., clipping in audio, saturation in video
multiplicand
1000
multiplier
× 1001
1000
0000
0000
1000
product 1001000
Length of the
product is the sum of
operand lengths
Initially 0
64
Can be pipelined
Several multiplication performed in parallel
Chapter 3 — Arithmetic for Computers — 11
LEGv8 Multiplication
• Three multiply instructions:
• MUL: multiply
• Gives the lower 64 bits of the product
1000 1001010
Initially dividend
Chapter 3 — Arithmetic for Computers — 16
Optimized Divider
•In binary
• ±1.xxxxxxx2 × 2yyyy
• Largest value
• exponent: 11111110
actual exponent = 254 – 127 = +127
• Fraction: 111…11 significand ≈ 2.0
• ±2.0 × 2+127 ≈ ±3.4 × 10+38
• Largest value
• Exponent: 11111111110
actual exponent = 2046 – 1023 = +1023
• Fraction: 111…11 significand ≈ 2.0
• ±2.0 × 2+1023 ≈ ±1.8 × 10+308
0 0 0 0 0
•Single: 1011111101000…00
•Double: 1011111111101000…00
• 2. Add significands
• 9.999 × 101 + 0.016 × 101 = 10.015 × 101
• 2. Add significands
• 1.0002 × 2–1 + –0.1112 × 2–1 = 0.0012 × 2–1
Step 1
Step 2
Step 3
Step 4
• 1. Add exponents
• For biased exponents, subtract bias from sum
• New exponent = 10 + –5 = 5
• 2. Multiply significands
• 1.110 × 9.200 = 10.212 10.212 × 105
• 1. Add exponents
• Unbiased: –1 + –2 = –3
• Biased: (–1 + 127) + (–2 + 127) = –3 + 254 – 127 = –3 + 127
• 2. Multiply significands
• 1.0002 × 1.1102 = 1.110 1.1102 × 2–3
• 3. Normalize result & check for over/underflow
• 1.1102 × 2–3 (no change) with no over/underflow
• Underflow
• Examples:
• 16 8-bit integer adds:
• ADD V1.16B, V2.16B, V3.16B
• 4 32-bit FP adds:
• FADD V1.4S, V2.4S, V3.4S