
MPY32 Operation
Given the separation in processing of 16-bit operations (32-bit results) and 32-bit operations (64-bit
results) by the module, it is important to understand the implications when using MAC/MACS operations
and mixing 16-bit operands or results with 32-bit operands or results. User software must address these
points during use when mixing these operations. The following code illustrates the issue.
; Mixing 32x24 multiplication with 16x16 MACS operation
MOV
#MPYSAT,&MPY32CTL0
; Saturation mode
MOV
#052C5h,&MPY32L
; Load low word of 1st operand
MOV
#06153h,&MPY32H
; Load high word of 1st operand
MOV
#001ABh,&OP2L
; Load low word of 2nd operand
MOV.B
#023h,&OP2H_B
; Load high word of 2nd operand
;... 5 NOPs required
MOV
&RES0,R6
; R6 = 00E97h
MOV
&RES1,R7
; R7 = 0A6EAh
MOV
&RES2,R8
; R8 = 04F06h
MOV
&RES3,R9
; R9 = 0000Dh
; Note that MPYC = 0!
MOV
#0CCC3h,&MACS
; Signed MAC operation
MOV
#0FFB6h,&OP2
; 16x16 bit operation
MOV
&RESLO,R6
; R6 = 0FFFFh
MOV
&RESHI,R7
; R7 = 07FFFh
The second operation gives a saturated result because the 32-bit value used for the 16×16-bit MACS
operation was already saturated when the operation was started; the carry bit MPYC was 0 from the
previous operation, but the MSB in result register RES1 is set. As one can see in the flow chart, the
content of the result registers are saturated for multiply-and-accumulate operations after starting a new
operation based on the previous results, but depending on the size of the result (32 bit or 64 bit) of the
newly initiated operation.
The saturation before the multiplication can cause issues if the MPYC bit is not properly set as the
following code shows.
;Pre-load result registers to demonstrate overflow
MOV
#0,&RES3
;
MOV
#0,&RES2
;
MOV
#0,&RES1
;
MOV
#0,&RES0
;
; Saturation mode and set MPYC:
MOV
#MPYC,&MPY32CTL0
MOV.B
#082h,&MACS_B
; 8-bit signed MAC operation
MOV.B
#04Fh,&OP2_B
; Start 16x16 bit operation
MOV
&RES0,R6
; R6 = 00000h
MOV
&RES1,R7
; R7 = 08000h
Even though the result registers were loaded with all zeros, the final result is saturated. This is because
the MPYC bit was set, causing the result used for the multiply-and-accumulate to be saturated to
08000 0000h. Adding a negative number to it would again cause an underflow, thus, the final result is also
saturated to 08000 0000h.
421
SLAU272C – May 2011 – Revised November 2013
32-Bit Hardware Multiplier (MPY32)
Copyright © 2011–2013, Texas Instruments Incorporated