![Freescale Semiconductor ColdFire MCF5211 Reference Manual Download Page 92](http://html1.mh-extra.com/html/freescale-semiconductor/coldfire-mcf5211/coldfire-mcf5211_reference-manual_2330619092.webp)
Multiply-Accumulate Unit (MAC)
MCF5213 ColdFire® Integrated Microcontroller Reference Manual, Rev. 3
4-6
Freescale Semiconductor
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.4.1.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;
int macsr;
} macState;
The following assembly language routine shows the proper sequence for a correct MAC state save. This
code assumes all Dn and An registers are available for use, and the memory location of the state save is
defined by A7.
MAC_state_save:
move.l macsr,d7
; save the macsr
clr.l d0
; zero the register to ...
move.l d0,macsr
; disable rounding in the macsr
move.l acc,d5; save the accumulator
move.l mask,d6
; save the address mask
movem.l #0x00e0,(a7); move the state to memory
This code performs the MAC state restore:
MAC_state_restore:
movem.l (a7),#0x00e0; restore the state from memory
move.l #0,macsr
; disable rounding in the macsr
move.l d5,acc; restore the accumulator
move.l d6,mask
; restore the address mask
move.l d7,macsr
; restore the macsr
Executing this sequence type can correctly save and restore the exact state of the MAC programming
model.
4.4.1.1.3
MULS/MULU
MULS and MULU are unaffected by fractional-mode operation; operands remain assumed to be integers.
4.4.1.1.4
Scale Factor in MAC or MSAC Instructions
The scale factor is ignored while the MAC is in fractional mode.