1 fractional operation mode, Fractional operation mode -7, Section 4.3.1.1, “rounding – Freescale Semiconductor ColdFire MCF52210 User Manual

Page 83

Advertising
background image

Multiply-Accumulate Unit (MAC)

MCF52211 ColdFire® Integrated Microcontroller Reference Manual, Rev. 2

Freescale Semiconductor

4-7

4.3.1

Fractional Operation Mode

This section describes behavior when the fractional mode is used (MACSR[F/I] is set).

4.3.1.1

Rounding

When the processor is in fractional mode, there are two operations during which rounding can occur:

1. The 32-bit accumulator is moved into a general purpose register. If MACSR[S/U] is cleared, the

accumulator is stored as is in the destination register; if it is set, the 32-bit value is rounded to a
16-bit value using the round-to-nearest (even) method. The resulting 16-bit number is stored in the
lower word of the destination register. The upper word is zero-filled. The accumulator value is
unaffected by this rounding procedure.

2. Execution of a MAC (or MSAC) instruction with 32-bit operands. If MACSR[R/T] is zero,

multiplying two 32-bit numbers creates a 64-bit product truncated to the upper 32 bits; otherwise,
it is rounded using round-to-nearest (even) method.

To understand the round-to-nearest-even method, consider the following example involving the rounding
of a 32-bit number, R0, to a 16-bit number. Using this method, the 32-bit number is rounded to the closest
16-bit number possible. Let the high-order 16 bits of R0 be named R0.U and the low-order 16 bits be R0.L.

If R0.L is less than 0x8000, the result is truncated to the value of R0.U.

If R0.L is greater than 0x8000, the upper word is incremented (rounded up).

If R0.L is 0x8000, R0 is half-way between two 16-bit numbers. In this case, rounding is based on
the lsb of R0.U, so the result is always even (lsb = 0).

— If the lsb of R0.U equals 1 and R0.L equals 0x8000, the number is rounded up.

— If the lsb of R0.U equals 0 and R0.L equals 0x8000, the number is rounded down.

This method minimizes rounding bias and creates as statistically correct an answer as possible.

The rounding algorithm is summarized in the following pseudocode:

if R0.L < 0x8000

then Result = R0.U

else if R0.L > 0x8000

then Result = R0.U + 1

else if lsb of R0.U = 0

/* R0.L = 0x8000 */

then Result = R0.U

else Result = R0.U + 1

The round-to-nearest-even technique is also known as convergent rounding.

4.3.1.2

Saving and Restoring the MAC Programming Model

The presence of rounding logic in the MAC output datapath requires that special care during the MAC’s
save/restore process. In particular, any result rounding modes must be disabled during the save/restore
process so the exact bit-wise contents of the MAC registers are accessed. Consider the memory structure
containing the MAC programming model:

struct macState

{

int acc;

int mask;

Advertising
This manual is related to the following products: