π Lecture 35 β Multiplication and Division of Integers
π Overview: This lecture covers integer overflow, adder implementations (ripple carry and carry look ahead), unsigned and signed multiplication techniques, integer and fraction division algorithms, and branch architecture. Understanding these concepts is fundamental to designing efficient arithmetic logic units in computer processors.
ποΈ Topics Covered
The lecture covers overflow in fixed-point addition, ripple carry and carry look ahead adder implementations, complement adder/subtractor design for 2's complement, unsigned multiplication using parallel array and series-parallel multipliers, signed multiplication methods including 2's complement multiplication, Booth recoding, and bit-pair recoding, integer and fraction division algorithms, and branch architecture including condition codes and conditional branches.
π Lecture Summary
Overflow
When two m-bit numbers are added and the result exceeds the capacity of an m-bit destination, this situation is called an overflow. In the example, adding numbers that produce a result in the fifth bit position (when only four bits are allowed) causes overflow.
π Definition β Overflow: When the result of an arithmetic operation exceeds the storage capacity of the destination register.
π Example: Adding two 4-bit numbers that produce a 5-bit result (e.g., 1111 + 0001 = 10000) causes overflow because the fifth position is not allowed.
Different Implementations of the Adder
For a binary adder, the sum bit is obtained by:
sj = xj yj cj + xj yj cj + xj yj cj + xj yj cj
The carry bit equation is:
cj+1 = xj yj + xj cj + yj cj
where x and y are the input bits.
The two methods for computing the sum are:
- Ripple Carry Adder
- Carry Look ahead Adder
Ripple Carry Adder
In this adder circuit, we feed carry out from the previous stage to the next stage. For 64-bit addition, 126 logic levels are required between input and output bits. The logic levels can be reduced by using a higher base (Base 16). This is a relatively slow process.
π Definition β Ripple Carry Adder: An adder where the carry output of each stage becomes the carry input of the next stage, causing propagation delay through all stages.
Complement Adder/Subtractor
We can perform subtraction using an unsigned adder by complementing the second input and supplying overflow detection hardware.
2's Complement Adder/Subtractor
A combined adder/subtractor can be built using a mux to select the second adder input. The mux also determines the carry-in to the adder. The equation for mux output is:
qj = yj r + yj r
π Definition β Mux (Multiplexer): A combinational circuit that selects one of several input signals and forwards the selected input to a single output line.
Carry Look ahead Adder
The basic idea in carry look ahead is to speed up the ripple carry by determining whether the carry is generated at the j position after addition, regardless of the carry-in at that stage, or the carry is propagated from input to output in the digit. This results in faster addition and lesser propagation delay of the carry bits.
It divides the carry into two logical variables:
- Gj (Generate): Gj = xj yj
- Pj (Propagate): Pj = xj + yj
Hence the carry out will be: Cj+1 = Gj + Pj cj
Here G and P each require one gate, and the sum bit needs two more gates in the full adder. This results in less complexity i.e. log(m), much less compared to ripple carry adder where complexity is m (m is the number of bits). Ripple carry and look ahead schemes can be mixed by producing a carry-out at the left end of each look ahead module and using ripple carry to connect modules at any level of the look ahead tree.
π‘ Why this matters: Carry look ahead adders are essential for high-speed arithmetic in modern processors because they dramatically reduce propagation delay compared to ripple carry adders.
Unsigned Multiplication
The general schema for unsigned multiplication in base b is shown in Figure 6.5 of the textbook.
Parallel Array Multiplier: Each computational block consists of a full adder with an AND gate to form the product xiyj. In binary, mΒ² full adders are required and signals pass through almost 4m gates.
Series Parallel Multiplier: A combination of parallel and sequential hardware is used to build a multiplier, achieving good speed while saving hardware.
Signed Multiplication
The sign of a product is easily computed from the sign of the multiplier and the multiplicand. The product is positive if both have the same sign and negative if different. When two unsigned digits having m and n bits are multiplied, this results in a (m+n)-bit product, and (m+n+1)-bit product for signed digits.
Three methods for signed multiplication:
- 2's complement multiplier
- Booth recoding
- Bit-Pair recoding
2's complement Multiplication
If numbers are represented in 2's complement form, three modifications are required:
- Provision for sign extension
- Overflow prevention
- Subtraction as well as addition of the partial product
Booth Recoding
The Booth Algorithm makes multiplication simple to implement at hardware level and speeds up the procedure:
- Start with LSB; for each 0 of the original number, place a 0 in the recorded number until a 1 is indicated.
- Place a 1 for 1 in the recorded table and skip any succeeding 1's until a 0 is encountered.
- Place a 0 with 1 and repeat the procedure.
π Example: Recode the integer 485 according to Booth procedure.
Original number: 00111100101 = 256+128+64+32+4+1 = 485
Recoded Number: 01000101111 = +512-32+8-4+2-1 = 485
Bit-Pair Recoding
Booth recoding may increase the number of additions due to isolated 1s. To avoid this, bit-pair recoding is used where bits are encoded in pairs, resulting in only n/2 additions instead of n.
Division
Two types of division:
- Integer division
- Fraction division
Integer division
Steps for integer division:
- Clear upper half of dividend register, put dividend in lower half. Initialize quotient counter bit to 0.
- Shift dividend register left 1 bit.
- If difference is positive, put it into upper half of dividend and shift 1 into quotient. If negative, shift 0 into quotient.
- If quotient bits < m, go to step 2.
- m-bit quotient is in quotient register and m-bit remainder is in upper half of dividend register.
π Example: Divide 47ββ by 5ββ. [Detailed step-by-step solution with register operations is shown in the textbook pages 310-311]
Fraction Division
Steps for fractional division:
- Clear lower half of dividend register, put dividend in upper half. Initialize quotient counter bit to 0.
- If difference is positive, report overflow.
- Shift dividend register left 1 bit.
- If difference is positive, put it into upper half of dividend and shift 1 into quotient. If negative, shift 0 into quotient.
- If quotient bits < m, go to step 3.
- m-bit quotient has decimal at the left end and remainder is in upper half of dividend register.
Branch Architecture
The next important function performed by the ALU is branch. Branch architecture is based on:
- Condition Codes
- Conditional Branches
Condition Codes
Condition Codes are computed by the ALU and stored in the processor status register. The 'comparison' and 'branching' are treated as two separate operations. This approach is not used in the SRC. Table 6.6 of the textbook shows condition codes after subtraction for signed and unsigned x and y.
Implementation with flags is usually easier but requires status registers. In case of branch instructions, decision is based on the branch itself.
π‘ Why this matters: Branch architecture directly impacts processor performance through conditional execution and pipeline efficiency.
β Key Takeaways
The lecture emphasizes that overflow occurs when results exceed register capacity, requiring careful handling in arithmetic operations. Carry look ahead adders significantly outperform ripple carry adders by using generate (G) and propagate (P) signals to reduce propagation delay from O(m) to O(log m). For multiplication, Booth recoding and bit-pair recoding simplify hardware implementation by reducing the number of additions, while signed multiplication requires sign extension and overflow prevention. Division algorithms differ for integer and fraction operations, with fraction division requiring overflow checking before shifting. Branch architecture uses condition codes stored in processor status registers to enable conditional execution.
π§ Quick Revision Questions
- What is overflow and how does it occur in fixed-point addition?
- What are the equations for the sum bit (sj) and carry bit (cj+1) in a binary adder?
- What are the generate (Gj) and propagate (Pj) variables in carry look ahead addition, and how do they reduce propagation delay?
- What are the three modifications required for 2's complement multiplication compared to unsigned multiplication?
- What is the key difference between integer division and fraction division algorithms in terms of initial register setup and overflow checking?
π Lecture 36 β Floating-Point Arithmetic
π Overview: This lecture covers the design of barrel shifters and ALUs, then transitions into floating-point arithmetic representations and operations. Understanding these concepts is critical for computer architecture as they form the foundation for how computers handle real numbers and perform arithmetic operations efficiently.
ποΈ Topics Covered
The lecture begins with NxN crossbar design for barrel rotators and barrel shifter with logarithmic number of stages, followed by ALU design. It then covers floating-point representations, normalization, the IEEE floating-point standard, and concludes with detailed steps for floating-point addition/subtraction, multiplication, and division with worked examples.
π Lecture Summary
NxN Crossbar Design for Barrel Rotator
The NxN crossbar design for a barrel rotator uses a grid structure where inputs xβ,xβ,...,xβββ are applied to rows and outputs yβ,yβ,...yβββ come from vertical lines, creating NΓN cross points. Each input-output connection uses a tri-state buffer. A decoder at the input selects the shift count, with each decoder output connected diagonally to the tri-state buffers.
π Definition β Crossbar Rotator: A circuit that uses NΒ² gates arranged in a grid pattern to rotate an input word by any amount, where each input can connect to any output through tri-state buffers controlled by a decoder.
π Formula: Number of cross points = N Γ N β The total number of possible connections equals the square of the word size.
π Example: For an 8-bit word (N=8), the crossbar requires 8Γ8 = 64 cross points with 64 tri-state buffers and an 8-line decoder.
π‘ Why this matters: While simple in concept, the NΒ² gate count becomes impractical for large N, motivating more efficient designs.
Barrel Shifter with Logarithmic Number of Stages
The logarithmic barrel shifter represents a time-space trade-off compared to the NxN crossbar. For a shifter requiring 8 shifts, three stages are needed. Each stage has two possibilities: bypass (pass word unchanged) or shift (shift the word). The first stage provides 1-bit right shift, second stage 2-bit right shift, and so on. A shift count unit controls which stages activate.
π Definition β Shift/Bypass Cell: A combinational logic circuit that, controlled by a shift/bypass signal, either passes the input word unchanged or applies a shift of the stage's specified amount.
π Formula: Number of stages = logβ(N), Switch count = O(NlogN), Propagation delay = O(logN) β This design uses fewer switches but has higher propagation delay than the O(1) delay of the crossbar.
π Example: For a 3-bit shift (binary 011), signals sβ and sβ are 1, meaning stage 1 (1-bit shift) and stage 2 (2-bit shift) both activate, while sβ (4-bit shift) remains 0.
ALU Design
The ALU (Arithmetic Logic Unit) combines an arithmetic unit, logic unit, and shifter unit with multiplexers and a control unit. Two n-bit inputs (x and y) are simultaneously provided to all three units. The control unit accepts the op-code as input and generates control signals that activate the appropriate unit. Two multiplexers select the result: one mux chooses between arithmetic, logic, and shifter outputs for the final result z, while the other mux provides the status output corresponding to condition codes.
π Definition β ALU: A combinational circuit that performs arithmetic operations (add, subtract), logic operations (AND, OR, XOR), and shift/rotate operations on binary numbers based on the instruction's op-code.
Floating Point Representations
A floating-point number consists of three parts: sign, significand (also called mantissa), and exponent, with a fixed base. In computers, binary numbers encode these components into a single word.
π Definition β Floating-Point Number: A number represented as (-1)Λ’ Γ f Γ 2α΅ where s is the sign bit, f is the significand (mantissa), and e is the exponent with a biased representation.
π Example: -0.5 Γ 10β»Β³ has sign = -1, significand = 0.5, exponent = -3, base = 10.
π Formula: Floating-point form = (-1)Λ’ Γ f Γ 2α΅ β If s=1 the number is positive, if s=0 the number is negative. The exponent uses a biased representation where a constant (bias) is added to make the exponent always positive.
Normalization
A normalized floating-point number has a significand whose leftmost digit is non-zero and is a single digit. This ensures a unique representation for each number and maximizes precision.
π Definition β Normalization: The process of adjusting the significand and exponent so that the significand's most significant digit is non-zero and occupies exactly one digit position.
π Example: 0.56 Γ 10β»Β³ (not normalized) β 5.6 Γ 10β»Β³ (normalized form). Same principle applies to binary numbers.
IEEE Floating-Point Standard
The IEEE floating-point standard defines two main formats: single-precision and double-precision. Single-precision uses 1-bit sign, 8-bit exponent, 23-bit fraction, with a bias of 127. Double-precision uses 1-bit sign, 11-bit exponent, 52-bit fraction, with an exponent bias of 1023. Special values include NaN (Not-a-Number) and Β±β, represented when the exponent field eΜ=255 (for single precision).
π Definition β Overflow: A condition where a floating-point number's exponent is too large to be represented in the exponent field. For single precision, representable range is 1.2 Γ 10β»Β³βΈ β€ x β€ 3.4 Γ 10Β³βΈ.
π Formula: Actual exponent = stored exponent - bias β For single precision: exponent range = -126 to +127 (stored as 1 to 254, with 0 and 255 reserved)
Floating-Point Addition and Subtraction
The algorithm for floating-point addition/subtraction follows six steps: unpack sign, exponent and fraction fields; shift the significand to align decimal points; perform addition; normalize the sum; round off the result; check for overflow.
π Example 1: Add 0.5ββ and -0.4375ββ
- Step 1 - Convert to binary: 0.5ββ = 0.1β = 1.000 Γ 2β»ΒΉ, -0.4375ββ = -7/16ββ = -0.0111β = -1.110 Γ 2β»Β²
- Step 2 - Align exponents: -1.110 Γ 2β»Β² β -0.111 Γ 2β»ΒΉ
- Step 3 - Add significands: 1.000 Γ 2β»ΒΉ + (-0.111 Γ 2β»ΒΉ) = 0.001 Γ 2β»ΒΉ
- Step 4 - Normalize: 0.001β Γ 2β»ΒΉ = 0.010β Γ 2β»Β² = 1.000β Γ 2β»β΄
Floating-Point Multiplication
Floating-point multiplication follows five steps: unpack sign, exponent and significands; apply exclusive-or operation to signs (to determine result sign), add exponents, then multiply significands; normalize, round and shift the result; check for overflow; pack the result and report exceptions.
π Formula: Result sign = signβ XOR signβ, Result exponent = exponentβ + exponentβ, Result significand = significandβ Γ significandβ
Floating-Point Division
Floating-point division follows five steps: unpack sign, exponent and significands; apply exclusive-or to signs, subtract exponents, then divide significands; normalize, round and shift the result; check for overflow; pack the result and report exceptions.
π Formula: Result sign = signβ XOR signβ, Result exponent = exponentβ - exponentβ, Result significand = significandβ Γ· significandβ
β Key Takeaways
The most critical concepts from this lecture are the trade-off between NΓN crossbar and logarithmic barrel shifter designs, where crossbars use O(NΒ²) gates with O(1) delay while logarithmic shifters use O(NlogN) gates with O(logN) delay. The IEEE floating-point standard defines single-precision (32-bit: 1 sign, 8 exponent, 23 fraction with bias 127) and double-precision (64-bit: 1 sign, 11 exponent, 52 fraction with bias 1023) formats. For floating-point operations, addition/subtraction requires aligning exponents before adding significands, while multiplication uses XOR for sign, addition of exponents, and multiplication of significands, and division uses XOR for sign, subtraction of exponents, and division of significands. Normalization ensures unique representation by making the significand's most significant digit non-zero.
π§ Quick Revision Questions
- What are the two alternative designs for barrel rotators/shifters and what are their respective gate counts and propagation delays?
- In IEEE single-precision floating-point format, what is the bias value and how is it used to determine the actual exponent?
- What are the six steps required for floating-point addition and subtraction?
- How does the sign of the result get determined differently for floating-point multiplication versus division?
- What is normalization and why is it important in floating-point representation?