Coding for the MAC (Multiply-Accumulate Unit)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Coding for the MAC (Multiply-Accumulate Unit)

2,404 Views
CleverScreenNam
Contributor I
Hi, I'm using CodeWarrior V7.0, IDE version 5.9.0, targetting the MCF52211 on the M52211EVB.  I'm looking at doing 32-bit multiplication for a project I'm working in, so I've been looking at using the MAC assembly instructions.  Specifically, the "mac.l" instruction.
 
Here is part of the code I put together to try this out:
 
  long data = 0x2000000;
  long mult = 0x2000000;   
  long product = 0;
  
  asm {
    move.l  #0,acc
    move.l  data,d0
    move.l  mult,d1
    mac.l    d0,d1
    move.l  acc, d1
    move.l  d1,product
  }   
  
  
When I execute this, I get a zero as the result.  MACSR is 0x06, indicating both zero and overflow.  (When I use numbers that produce a result that is less than 32 bits, I get the correct result.) 
 
In section 4.3.1.1 of the MCF52211 ColdFire Integrated Microcontroller Reference Manual, Rev.2, it says that rounding can occur when "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."
 
Why doesn't my result get truncated to a 32-bit value?
 
I also noted that in Chapter 5 of the ColdFire Family Programmer's Reference Manual, Rev.3, it says that the product, shifted as defined by the scale factor, to the the accumulator.  Do I need to do this in order to truncate the 64-bit result?
How do I specify the scale factor to make the 32-bit shift?  
 
I tried changing the mac instruction to the following:
 
mac.l d0,d1,11
mac.l d0,d1 11
mac.l d0,d111
mac.l d0,d1 L
mac.l d0,d1L
 
but all produced assembly errors.
 
 
Labels (1)
0 Kudos
1 Reply

293 Views
CleverScreenNam
Contributor I
Okay, I figured it out myself. In order to do the shift, you use the symbol ">>" or "<<", and can only shift one bit.  So, it should look like:
 
mac.l    d0,d1>>
 
Taking the most signficant 32 bits of a 64-bit result requires the selection of fractional mode in the MACSR.
0 Kudos