/*
 *  mactest.c
 *
 *  This program demonstrates using the ColdFire MAC instructions
 *  within a normal C program.
 *
 *  Author:
 *    David Fiddes, D.J@fiddes.net
 *    http://fiddes.net/coldfire/
 *
 *  This code has no copyright and may freely be used in whatever 
 *  manner you see fit.
 *
 *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 
 *  OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT    
 *  LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR    
 *  FITNESS FOR A PARTICULAR PURPOSE.                              
 */
#include <stdio.h>

/* We substitute iprintf for printf to avoid bringing in the floating point library */
/* The functions are otherwise equivalent */
#define printf iprintf

unsigned int
calc_using_mac ( unsigned short a, unsigned short b )
{
  unsigned int result;

  __asm__ __volatile__ ( "  move.l #3,%%acc    \n\t" 
                         "  mac.w  %1l,%2l     \n\t"  
                         "  mac.w  %1l,%2l,#1  \n\t"  
                         "  move.l %%acc,%0    \n\t"
                         : "=d" (result)
                         : "d" (a), "d" (b) );
  return result;
}


unsigned int
calc_normally ( unsigned short a, unsigned short b )
{
  unsigned int result;

  result = 3;
  result = result + (a * b);
  result = result + ((a * b) << 1);

  return result;
}
                         
 


int main()
{
  printf( "Mactest - 5307/5206e MAC test program\n" );


  printf("calc_using_mac returns %i\n", calc_using_mac( 2, 3 ) ); 
  printf("calc_normally returns %i\n",  calc_normally( 2, 3 ) ); 
  
  return 0;
}
