37. Barrel Shifter

Complete the missing connections in the supplied 4-bit two-stage barrel shifter. The circuit must support logical left shift, logical right shift, arithmetic right shift, and rotate right for shift/rotate amounts from 0 to 3.

Constraints

  • Inputs: Data[3:0], Amount[1:0], Operation[1:0].
  • Output: Y[3:0].
  • The circuit is fully combinational.
  • Stage 1 performs an optional shift/rotate by 1; Stage 2 performs an optional shift/rotate by 2.
  • Complete only the open connections. Do not add, remove, replace, or reconfigure the provided components or existing wiring.

Behavioral Reference

Operation[1:0]FunctionRequired Behavior
00Logical Shift Left (LSL)Shift left and fill vacated LSB positions with 0.
01Logical Shift Right (LSR)Shift right and fill vacated MSB positions with 0.
10Arithmetic Shift Right (ASR)Shift right and replicate the current sign bit into vacated MSB positions.
11Rotate Right (ROR)Rotate right and wrap shifted-out LSB bits back to the MSB side.

Amount[1:0] = 00, 01, 10, 11 represents shift/rotate by 0, 1, 2, 3 positions respectively.

Need Help? Refer to the Quick Guide below

Advanced arithmetic circuits use specialized structures to optimize and trade off speed, area, throughput, numerical range, and precision in processor, DSP, accelerator, and semiconductor datapaths.

1. Advanced Addition and Subtraction

Carry-Lookahead Adder

In a Ripple-Carry Adder, each stage waits for the previous carry, so delay increases as the adder width grows. A Carry-Lookahead Adder (CLA) reduces this delay by calculating carry conditions directly from the input bits.

For each bit i:

Gi = Ai · Bi      Generate
Pi = Ai ⊕ Bi      Propagate

Gi = 1 means bit i generates a carry, while Pi = 1 means an incoming carry can propagate through that bit.

Generate and propagate circuit

The next carry is:

Ci+1 = Gi + Pi·Ci

For a 4-bit CLA with C0 = Cin:

C1 = G0 + P0·C0
C2 = G1 + P1·G0 + P1·P0·C0
C3 = G2 + P2·G1 + P2·P1·G0 + P2·P1·P0·C0
C4 = G3 + P3·G2 + P3·P2·G1 + P3·P2·P1·G0 + P3·P2·P1·P0·C0

Because C1 to C4 are derived directly from P, G, and Cin, the carry does not need to ripple through all four adder stages.

The sum and final carry are:

Si = Pi ⊕ Ci,  i = 0...3
Cout = C4

The basic CLA architecture is:

A[3:0],B[3:0],Cin -> P/G Logic -> Lookahead Carry Logic -> Sum Logic -> Sum[3:0],Cout

For wider adders, each 4-bit CLA block can also generate Group Propagate and Group Generate signals:

PG = P3·P2·P1·P0
GG = G3 + P3·G2 + P3·P2·G1 + P3·P2·P1·G0

The block carry is:

Cout = GG + PG·Cin

This allows carry lookahead to be applied between multiple CLA blocks:

4-bit CLA Blocks -> Group P/G -> Higher-Level Lookahead -> Carry Between CLA Blocks

A CLA therefore uses additional carry-generation logic to reduce carry-propagation delay, making it suitable for faster arithmetic datapaths.

4-bit Carry Lookahead Adder

Carry-Select Adder

A Carry-Select Adder (CSLA) reduces carry waiting by calculating the next block twice: once with assumed Cin = 0 and once with assumed Cin = 1.

For an upper block:

{S0,Cout0} = Ablock + Bblock + 0
{S1,Cout1} = Ablock + Bblock + 1

When the real carry Csel arrives from the lower block, MUXes select the correct precomputed result:

Si = Csel'·S0i + Csel·S1i
Cout = Csel'·Cout0 + Csel·Cout1
Ablock,Bblock -> Add(Cin=0) --\
                               -> MUX(Csel) -> Selected Sum,Cout
Ablock,Bblock -> Add(Cin=1) --/

The arithmetic is completed before Csel arrives, so only the MUX selection remains on the final carry-dependent path. The trade-off is duplicated adder hardware.

4-bit Carry Select Adder

Parallel-Prefix Carry

Parallel-prefix adders use the same bit propagate and generate signals as CLA:

Gi = Ai·Bi
Pi = Ai ⊕ Bi

A prefix node combines two adjacent groups. If (Gu,Pu) is the upper group and (Gl,Pl) is the lower group:

Gcombined = Gu + Pu·Gl
Pcombined = Pu·Pl

Repeated prefix stages build the generate/propagate pair for wider bit ranges. A compact 4-bit Kogge-Stone-style prefix tree is:

Parallel Prefix Carry

Stage 1 forms the 1:0, 2:1, and 3:2 groups. Stage 2 extends the required groups to 2:0 and 3:0. Cin is then combined with each group pair to generate the actual carries.

Once the prefix pair for bits i:0 is available:

Ci+1 = G(i:0) + P(i:0)·Cin
Si = Pi ⊕ Ci

The same combine equations are implemented repeatedly as a tree, giving approximately logarithmic carry-distribution depth.

ArchitectureMain StrengthMain Cost
Kogge-StoneLow logic depthMore prefix nodes and dense routing
Brent-KungFewer nodes and simpler routingGreater logic depth

Kogge-Stone is attractive when timing dominates, while Brent-Kung reduces routing and node count when area/interconnect matter more.

4-bit Kogge-Stone Adder
4-bit Brent-Kung Paralllel Prefix Adder

Shared Add/Subtract

Addition and subtraction can share the same arithmetic path using two's-complement subtraction:

Result = A + (B ⊕ SUB) + SUB
B -> XOR(SUB) --\
                 -> Adder -> Result
A --------------/
SUB ------------> Cin

SUB = 0 leaves B unchanged with Cin = 0. SUB = 1 inverts B and sets Cin = 1:

A - B = A + B' + 1

At each bit:

Xi = Bi ⊕ SUB
Si = Ai ⊕ Xi ⊕ Ci
Ci+1 = Ai·Xi + Ai·Ci + Xi·Ci

Thus, one adder performs both operations.

4-bit Shared Add/Subtract Circuit

Arithmetic Status

Arithmetic status signals describe how the result should be interpreted.

Carry = CN
Borrow = SUB · Cout'
Overflow = C(N-1) ⊕ CN
Zero = (S0 + S1 + ... + S(N-1))'
Negative = S(N-1)
  • Carry is mainly used for unsigned addition.
  • Borrow is asserted only during subtraction when the final carry-out is 0.
  • Overflow indicates a signed result exceeded the representable range.
  • Zero is asserted when all result bits are 0.
  • Negative is the result MSB for signed two's-complement data.

Carry and signed overflow are different. For example, adding two positive signed values can produce a negative result even when the carry signal alone does not indicate the signed error.

Fast-Adder Selection

ArchitectureTiming CharacteristicMain CostTypical Fit
CLADirect carry lookaheadExtra carry-generation logicSmall/medium timing-critical adders
Carry-SelectPrecomputation followed by final MUX selectionDuplicated arithmetic blocksDesigns that can trade area for shorter carry-dependent delay
Kogge-StoneLow prefix depthMore prefix nodes and dense routingAggressive timing targets
Brent-KungGreater prefix depthFewer nodes and lighter routingArea/routing-sensitive designs

The suitable architecture depends on width, timing target, area, and routing constraints rather than one adder being universally best.

2. Multiplication and MAC

Multiplier Architecture

Most hardware multipliers can be viewed as three stages:

Operands -> Partial-Product Generation -> Reduction -> Final Addition -> Product

For an unsigned multiplier, each partial-product bit is:

PP(i,j) = Ai · Bj

For a 4-bit multiplier, each multiplier bit either selects a shifted copy of A or contributes zero:

B0=1 -> PP0 = A<<0    B0=0 -> PP0 = 0
B1=1 -> PP1 = A<<1    B1=0 -> PP1 = 0
B2=1 -> PP2 = A<<2    B2=0 -> PP2 = 0
B3=1 -> PP3 = A<<3    B3=0 -> PP3 = 0

Different multiplier architectures mainly change how the partial products are generated and reduced.

Iterative Shift-and-Add Multiplier

An iterative multiplier reuses one adder across several clock cycles, reducing hardware at the cost of latency.

One common unsigned implementation uses a 2N-bit shifted multiplicand register M, an N-bit multiplier register Q, and a 2N-bit accumulator ACC.

At load:

ACC = 0
M = ZeroExtend(A,2N)
Q = B
Count = 0

During each iteration, Q0 controls a MUX in front of the shared adder:

ADDEND = M when Q0=1, otherwise 0
ACCnext = ACC + ADDEND
Mnext = M << 1
Qnext = Q >> 1
Countnext = Count + 1
Q0 -> ADDEND MUX -> Shared Adder -> ACC
M  -> Shift Left ------------------^
Q  -> Shift Right -> Next Q0

After N iterations:

Product = ACC

Start loads the registers. During operation:

Busy = 1 while iterations remain
Done = 1 when the final iteration completes

The circuit therefore trades multiple cycles for one reused adder.

Radix-4 Modified Booth Multiplier

Radix-4 Modified Booth reduces the number of partial-product rows by examining overlapping groups of three multiplier bits.

Use:

Q[-1] = 0

For a 4-bit multiplier:

Q3 Q2 Q1 Q0 Q[-1] -> {Q1,Q0,Q[-1]} , {Q3,Q2,Q1}

For one Booth group {y2,y1,y0}, the recoder selects one multiple of M:

Booth GroupSelected Multiple
000, 1110
001, 010+M
011+2M
100-2M
101, 110-M

The recoder can be viewed as one-hot select logic:

SEL_0   = y2'·y1'·y0' + y2·y1·y0
SEL_+M  = y2'·(y1 ⊕ y0)
SEL_-M  = y2 ·(y1 ⊕ y0)
SEL_+2M = y2'·y1·y0
SEL_-2M = y2 ·y1'·y0'

For signed 4-bit operands, first sign-extend the multiplicand to the 6-bit internal multiple path:

Mw = SignExtend(M,6)
+M = Mw
+2M = Mw << 1
-M = Mw' + 1
-2M = (Mw << 1)' + 1

Each Booth group selects one of these values. The selected signed multiple is sign-extended to the partial-product/reduction width and group k is then shifted by 2k bit positions:

Booth Group -> Recoder -> Multiple MUX -> Shift by 2k -> Partial Product

The widened path is important for the most-negative operand because values such as -(-8) and 2×(-8) cannot be safely formed in only four signed bits.

Radix-4 Booth therefore reduces the number of partial-product rows while adding recoding and multiple-selection logic.

Carry-Save Compression and Wallace Reduction

When several partial-product bits have the same weight, propagating carry after every addition would create a long delay.

A 3:2 compressor uses the full-adder equations in each weight column k:

Sk = Xk ⊕ Yk ⊕ Zk
Ck+1 = Xk·Yk + Xk·Zk + Yk·Zk

Sk remains in column k, while Ck+1 moves to the next higher-weight column.

3 Same-Weight Bits -> 3:2 Compressor -> Sum[k] + Carry[k+1]

A Wallace tree applies these compressors in parallel according to the height of each bit-weight column. The exact number of compression levels depends on the column heights.

Conceptual Wallace reduction tree:

Conceptual Wallace Tree

The final product is:

Product = SumRow + CarryRow

The compressor stages avoid global carry propagation; only the final two-row addition requires a normal carry-propagate adder.

Multiply-Accumulate

A Multiply-Accumulate (MAC) combines multiplication with accumulator feedback:

P = A × B
ACCnext = ACC + P
A,B -> Multiplier -> Adder -> ACC Register -> Feedback

A practical MAC often selects the next accumulator input with a control MUX:

Clear      -> ACC_D = 0
Load       -> ACC_D = P
Accumulate -> ACC_D = ACC + P
Hold       -> ACC_D = ACC
0, P, ACC+P, ACC -> Control MUX -> ACC Register

Assume one MAC operation is selected at a time. The selected value is loaded on the active clock edge.

Repeated accumulation can exceed the width of one product, so the accumulator is often wider than the multiplier output. These extra guard bits reduce overflow risk before the final result is narrowed.

Pipelined MAC

Pipeline registers divide multiplication and accumulation into shorter timing stages so new transactions can enter before older ones have completed.

For the 2-cycle reference latency, input-capture registers define the transaction acceptance edge. The two compute stages are multiplication and accumulation.

Pipelined MAC

The register updates are:

Edge k   : A0 <= A, B0 <= B, C0 <= C, V0 <= Valid_in
Edge k+1 : P1 <= A0×B0, C1 <= C0, V1 <= V0
Edge k+2 : Result <= P1+C1, Valid_out <= V1

Therefore:

Latency = 2 cycles
II = 1 cycle

Latency is measured from the input acceptance edge to the corresponding result edge, while initiation interval (II) is the spacing between accepted transactions. II = 1 assumes the pipeline can accept a transaction every cycle with no stall or backpressure condition.

Because a new transaction may be captured every cycle, the delayed C and Valid paths must remain aligned with the matching product through both compute stages.

3. Advanced Division

Divider Datapath

An iterative divider repeatedly updates the partial remainder and quotient using one shared add/subtract path.

Dividend,Divisor -> Shift/Add-Subtract -> Partial Remainder,Quotient -> Counter/Control -> Next Iteration

The datapath normally includes:

  • partial-remainder register,
  • quotient register,
  • divisor register,
  • add/subtract logic,
  • iteration counter,
  • controller.

For 4-bit restoring and non-restoring division, EWskills uses a 5-bit signed partial remainder so negative intermediate values are representable.

Restoring Division

Restoring division performs a trial subtraction during each iteration.

For quotient Q, divisor D, and signed partial remainder R, extend the divisor to the partial-remainder width:

Dext = ZeroExtend(D, R_width)
Rshift = {R(R_width-2:0), Q(N-1)}
T = Rshift - Dext
Neg = T(MSB)
Qbit = Neg'
Rnext = T when Neg=0, otherwise Rshift
Qnext = {Q(N-2:0), Qbit}
Shift -> Subtract D -> Sign Test -> R MUX -> Rnext
                              \----> Qbit -> Qnext

A negative trial selects Rshift, effectively discarding the subtraction; a non-negative trial keeps T. This is the restore operation.

Non-Restoring Division

Non-restoring division avoids immediately restoring every negative partial remainder. The previous remainder sign selects the next arithmetic operation.

For each iteration, use the divisor extended to the partial-remainder width:

Dext = ZeroExtend(D, R_width)
Rshift = {R(R_width-2:0), Q(N-1)}
T = Rshift - Dext when R>=0, otherwise Rshift + Dext
Qbit = T(MSB)'
Qnext = {Q(N-2:0), Qbit}
Rnext = T
R Sign -> Add/Subtract Select -> Rshift ± D -> Sign Test -> Qbit

The same add/subtract datapath is reused: a non-negative remainder selects subtraction, while a negative remainder selects addition.

After the final iteration:

Rfinal = R + Dext when R<0, otherwise R
RestoringNon-Restoring
Negative trial is immediately discarded/restoredNegative remainder may continue
Restore decision occurs in the same iterationNext operation depends on remainder sign
Simpler conceptual flowFewer explicit restore operations

Signed Division

Signed division can reuse an unsigned magnitude divider by adding magnitude-conversion logic before it and sign-restoration logic after it.

For dividend A and divisor B:

Qsign = A(N-1) ⊕ B(N-1)
Rsign = A(N-1)
Amag = A when A(N-1)=0, otherwise A' + 1
Bmag = B when B(N-1)=0, otherwise B' + 1
Signed Inputs -> Magnitude Logic -> Unsigned Divider -> Sign Restore -> Signed Q,R

Amag and Bmag are interpreted as unsigned magnitudes during the core division. For example, 4-bit 1000 represents signed -8 before magnitude conversion but unsigned magnitude 8 inside the divider.

After magnitude division:

Q = Qmag when Qsign=0, otherwise Qmag' + 1
R = Rmag when Rsign=0, otherwise Rmag' + 1

EWskills uses:

Quotient -> truncate toward zero
Remainder -> same sign as dividend

Example:

-7 / 3 = -2 remainder -1

Divider Exceptions

Two important conditions are detected before normal iterations begin.

Divide-by-zero can be implemented with a zero detector on the divisor:

DivZero = (D0 + D1 + ... + D(N-1))'

Signed overflow occurs for the most-negative dividend divided by -1:

IsMIN = A(N-1)·A(N-2)'·...·A0'
IsMinus1 = B(N-1)·B(N-2)·...·B0
Overflow = IsMIN · IsMinus1

For 4-bit signed data:

MIN = -8
-8 / -1 = +8

+8 is outside the 4-bit signed range -8...+7, so normal division must not begin as though the result were representable.

High-Radix Division

Higher-radix dividers determine more quotient information per iteration and therefore require fewer iterations.

More Quotient Bits per Iteration -> Fewer Iterations -> More Complex Selection Logic

SRT-style division is one example. Detailed quotient-selection mathematics is outside this Quick Guide.

4. Barrel Shifters

Barrel-Shifter Principle

A barrel shifter performs a variable shift in one combinational operation using cascaded MUX stages.

For 4-bit data, two stages are enough:

X[3:0] -> Shift-by-1 Stage[S0] -> Shift-by-2 Stage[S1] -> Y[3:0]
SHAMT[1:0]Total Shift
000
011
102
113
S0 = SHAMT[0]
S1 = SHAMT[1]

Each output of a stage is a 2:1 MUX:

MUX(S,D0,D1) = S'·D0 + S·D1

Using vector notation:

Y1[i] = S0'·X[i] + S0·SRC1[i]
Y[i]  = S1'·Y1[i] + S1·SRC2[i]

SRC1 defines where each bit comes from for a shift by 1, while SRC2 defines the source for an additional shift by 2. The operation type changes these source connections; the two-stage MUX structure remains the same.

An N-bit barrel shifter therefore needs approximately log2(N) controlled shift stages.

Logical Shifts

Logical shifts fill newly opened positions with 0.

For a 4-bit logical-right shifter:

SRC1[3:0] = {0, X3, X2, X1}
SRC2[3:0] = {0, 0, Y1[3], Y1[2]}

Using the stage equations defined above, these sources directly form the shift-by-1 and shift-by-2 MUX network.

For a 4-bit logical-left shifter:

SRC1[3:0] = {X2, X1, X0, 0}
SRC2[3:0] = {Y1[1], Y1[0], 0, 0}

Example:

1011 << 1 -> 0110    1011 >> 1 -> 0101

Arithmetic Right Shift

Arithmetic right shift uses the same MUX stages as logical right shift, but the newly opened MSB positions are filled with the original sign.

For 4-bit input X[3:0]:

SRC1[3:0] = {X3, X3, X2, X1}
SRC2[3:0] = {Y1[3], Y1[3], Y1[3], Y1[2]}

Using the same stage equations, Y1[3] remains equal to the original sign bit, so the second stage also replicates the correct sign.

1010 (-6) -> ASR 1 -> 1101 (-3)

Rotate

Rotate operations wrap shifted-out bits to the opposite side instead of replacing them with zeros.

For a 4-bit rotate-right network:

SRC1[3:0] = {X0, X3, X2, X1}
SRC2[3:0] = {Y1[1], Y1[0], Y1[3], Y1[2]}

The same two-stage equations are used; only the wrapped source connections change.

Example:

1011 -> ROR 1 -> 1101

Logical, arithmetic, and rotate operations can therefore share the same staged-MUX idea; the main difference is the source selected for the shifted-in positions. Rotate-left uses the same stages with the wrapped source connections reversed.

Barrel shifters are used for ALU shifting, scaling, bit manipulation, address operations, fixed-point rescaling, and floating-point alignment/normalization.

5. Fixed-Point Arithmetic

Fixed-Point and Q-Format

A fixed-point number stores an integer while assuming a fixed binary-point position.

If a stored integer uses F fractional bits:

Value = Stored Integer × 2^-F

Example:

Stored = 0110
F = 2
Value = 6 × 2^-2 = 1.5

A common notation is Qm.n, where n indicates the number of fractional bits and m identifies the integer-side width.

Qm.n -> m integer-side bits, n fractional bits

Because conventions differ on whether the sign bit is included in m, a design should explicitly state:

Total Width + Signedness + Fractional-Bit Count

This avoids ambiguity about the implied binary-point position.

Range and Resolution

The fractional-bit count determines the smallest representable step:

Resolution = 2^-F

For a signed N-bit value with F fractional bits:

Minimum = -2^(N-F-1)
Maximum = 2^(N-F-1) - 2^-F

Increasing F improves resolution but leaves fewer bits for integer range.

For example:

F=2 -> Resolution = 0.25

A value that does not fall exactly on a representable step must be approximated. This loss of precision is quantization.

Width Growth

Intermediate arithmetic may require more bits than the destination format.

For signed addition, one extra internal range bit can preserve the full mathematical result:

SumWide = SignExtend(A,N+1) + SignExtend(B,N+1)

For multiplication:

Wproduct = WA + WB
Fproduct = FA + FB

A multiply-accumulate path therefore commonly uses:

A,B -> Full-Width Product -> Fraction Align -> Wider ACC -> Round/Saturate -> Destination

Addition requires both operands to use the same binary-point position. If the product and accumulator use different fractional-bit counts:

ProductAligned = Rescale(Product, Fproduct -> FACC)
ACCnext = ACC + SignExtend(ProductAligned)

The wider internal path prevents range or precision from being discarded before the final narrowing stage.

Fixed-Point Multiplication and Rescaling

If operand A has FA fractional bits and B has FB fractional bits, and the destination uses Fdest fractional bits:

RawProduct = A × B
Fraw = FA + FB
Shift = Fraw - Fdest

Shift > 0 -> Rescaled = RawProduct >>> Shift
Shift = 0 -> Rescaled = RawProduct
Shift < 0 -> Rescaled = RawProduct << (-Shift)

The full product is kept before conversion to the destination format:

A,B -> Wide Multiply -> RawProduct -> Rescale -> Round/Saturate -> Output

For example, multiplying two values that each have 2 fractional bits produces a raw product with 4 fractional bits. Returning to a format with 2 fractional bits requires a right shift by 2.

Truncation and Rounding

Truncation discards the low-order fractional bits during rescaling. Here, truncation refers to fixed-point bit reduction; it is not the signed-division truncation-toward-zero rule:

Truncated = X >>> Shift

For EWskills fixed-point arithmetic, rounding uses round-to-nearest, ties away from zero. For Shift > 0, a compact implementation works on the magnitude:

Half = 1 << (Shift-1)
MagRounded = (|X| + Half) >> Shift
Rounded = MagRounded when X>=0, otherwise -MagRounded

Form |X| in a sufficiently wide internal path so the most-negative signed value remains representable. Adding Half before shifting makes an exact half-way value increase in magnitude, implementing ties away from zero.

Example for a destination step of 0.25:

+1.375 -> +1.50
-1.375 -> -1.50

Rounding logic is normally placed before final width narrowing, so the decision can use the discarded bits.

Overflow, Saturation, and Guard Bits

If a narrowed result exceeds the destination range, the output may either wrap or saturate.

After the value has been rescaled to the destination binary-point position, compare its stored integer representation against the signed destination code limits:

MAXcode = 2^(N-1)-1
MINcode = -2^(N-1)

Y = MAXcode when X>MAXcode
Y = MINcode when X<MINcode
Y = X       otherwise
Wide Result -> Compare with MIN/MAX -> Output MUX -> N-bit Result

A MAC or accumulator often keeps additional guard bits internally:

Products -> Wide Accumulator -> Round -> Saturate -> Output

These bits provide extra range and allow rounding/saturation to occur only when the final destination width is required.

Fixed-Point Format Selection

A fixed-point format should be selected from the required range and resolution:

Required Range -> Integer Bits    Required Resolution -> Fractional Bits

For a fixed total width, increasing one reduces the available bits for the other. The design therefore balances range, precision, overflow margin, and hardware width.

6. Floating-Point Arithmetic

FP32 Representation

IEEE-style FP32 uses three fields:

| Sign:1 | Exponent:8 | Fraction:23 |

For a normal value:

Value = (-1)^S × 1.Fraction × 2^(Exponent-127)

The exponent is stored with a bias of 127, and normal values use an implicit leading 1 in the significand.

FP32 Number Classes

Exponent and fraction patterns identify the FP32 number class.

A classifier can first generate three detectors:

ExpZero = (E7 + E6 + ... + E0)'
ExpOnes = E7·E6·...·E0
FracZero = (F22 + F21 + ... + F0)'

The class outputs then follow directly:

IsZero = ExpZero·FracZero
IsSubnormal = ExpZero·FracZero'
IsInfinity = ExpOnes·FracZero
IsNaN = ExpOnes·FracZero'
IsNormal = ExpZero'·ExpOnes'
ExponentFractionClass
00Zero
0nonzeroSubnormal
1...254anyNormal
2550Infinity
255nonzeroNaN

Subnormal values do not use the implicit leading 1. This classifier logic is also the basis for bypassing the normal arithmetic path when a special value is detected.

Floating-Point Addition and Subtraction

Floating-point values with different exponents must first be aligned to the same scale.

Unpack -> Compare Exponents -> Align -> Add/Subtract -> Normalize -> Round -> Repack

For normal finite operands, first align the lower-exponent significand to the larger exponent:

Ework = max(EA,EB)
Shift = |EA - EB|
Maligned = MlowerExponent >> Shift

Bits shifted out during alignment are retained as Guard, Round, and Sticky (GRS) information for later rounding.

After alignment, compare the two aligned magnitudes when subtraction is required:

SameSign = (SA ⊕ SB)'
SameSign=1 -> Mraw = MA_aligned + MB_aligned
SameSign=0 -> Mraw = Mlarge - Msmall

For unlike signs, Mlarge and Msmall refer to the larger and smaller aligned magnitudes, and the result sign follows the operand with the larger magnitude.

Exponent Compare -> Align Smaller Significand + GRS -> Add/Subtract -> Normalize -> Round

The alignment barrel shifter, add/subtract unit, normalization logic, and rounding logic therefore form the main FP add/sub datapath.

Floating-Point Multiplication

Floating-point multiplication processes sign, exponent, and significand largely in parallel.

Unpack -> Sign/Exponent/Significand Operations -> Normalize -> Round -> Repack

For normal finite FP32 operands:

Sresult = SA ⊕ SB
Eraw = EA + EB - 127
Mraw = (1.FA) × (1.FB)
Mnorm = Mraw,      Enorm = Eraw       when Mraw < 2
Mnorm = Mraw >> 1, Enorm = Eraw + 1   when Mraw >= 2

The hardware therefore uses an XOR gate for the sign, exponent arithmetic for the biased exponent, a significand multiplier, and normalization selection for the significand path.

Special-value classification is handled separately from this normal finite datapath.

Normalization

A normal floating-point significand is represented in the form:

1.xxxxx × 2^E

Normalization shifts the significand and adjusts the exponent in the opposite direction so the numerical value is preserved.

Significand too large -> Shift Right -> Increment Exponent
Leading zeros         -> Shift Left  -> Decrement Exponent

Example:

10.10 × 2^3 -> 1.010 × 2^4

In hardware, a leading-one/leading-zero detector determines the required shift amount, a barrel shifter moves the significand, and exponent logic applies the matching correction.

Guard, Round, and Sticky Bits

Extra low-order information is retained before the final significand width is selected:

Retained Bits | Guard(G) | Round(R) | Remaining Bits -> OR -> Sticky(S)

For round-to-nearest, ties-to-even, let LSB be the least-significant retained bit. The rounding decision is:

RoundUp = G · (R + S + LSB)

Here, + inside (R + S + LSB) is Boolean OR. If RoundUp = 1, increment the retained significand by one unit in the last retained place (ULP).

This equation covers both cases:

  • more than half discarded -> increment,
  • exactly half discarded -> increment only when LSB = 1, making the retained result even.

If rounding generates a carry beyond the normalized significand width, the significand is shifted right and the exponent is incremented.

Floating-Point Exceptions

Important floating-point exception classes include:

ExceptionMeaning
InvalidOperation has no valid numeric result
Divide-by-ZeroFinite nonzero value divided by zero
OverflowResult magnitude is too large
UnderflowResult becomes extremely small
InexactRounded result differs from the exact mathematical value

A complete IEEE-754 FPU implementation is outside this Quick Guide; the focus is on the datapath flow and classification behavior.

Fixed Point vs Floating Point

Fixed PointFloating Point
Fixed binary-point positionExponent changes scale
Typically lower arithmetic hardware complexityTypically higher arithmetic hardware complexity
Limited dynamic rangeWide dynamic range
Predictable resolutionPrecision varies with magnitude
Suitable for known bounded rangesSuitable for values spanning a wide range

Fixed point is attractive when range and required resolution are known in advance and hardware efficiency matters. Floating point is useful when large dynamic range is more important than minimum arithmetic complexity.