1 fractional operation mode, 1 rounding, Fractional operation mode -8 – Freescale Semiconductor MCF5480 User Manual

Page 156: Section 4.2.1.1.1, “rounding, Table 4-2, Summar

Advertising
background image

MCF548x Reference Manual, Rev. 3

4-8

Freescale Semiconductor

4.2.1.1

Fractional Operation Mode

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

4.2.1.1.1

Rounding

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

Execution of a store accumulator instruction (MOV.L ACCx,Rx). The lsbs of the 48-bit

accumulator logic are used to round the resulting 16- or 32-bit value. If MACSR[S/U] is cleared,

the low-order 8 bits are used to round the resulting 32-bit fraction. If MACSR[S/U] is set, the

low-order 24 bits are used to round the resulting 16-bit fraction.

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 that is truncated to the upper 40 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 = 1 and R0.L = 0x8000, the number is rounded up.
— If the lsb of R0.U = 0 and R0.L =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

Table 4-2. Summary of S/U, F/I, and R/T Control Bits

S/U

F/I

R/T

Operational Modes

0

0

x

Signed, integer

0

1

0

Signed, fractional
Truncate on MAC.L and MSAC.L
No round on accumulator stores

0

1

1

Signed, fractional
Round on MAC.L and MSAC.L
Round-to-32-bits on accumulator stores

1

0

x

Unsigned, integer

1

1

0

Signed, fractional
Truncate on MAC.L and MSAC.L
Round-to-16-bits on accumulator stores

1

1

1

Signed, fractional
Round on MAC.L and MSAC.L
Round-to-16-bits on accumulator stores

Advertising
This manual is related to the following products: