// This function takes two arrays and multiplies them pairwise.
// The second array arrives in reverse order.
// Some computations are then performed on the product.

#include <fxp.h>

void demo (
   const Fix<8,7> A[8],
   const Fix<8,7> B[8],
   Fix<8,7>& overall_result,
   Uint<4>& position)
{
   #pragma OUT overall_result position
   
   static Fix<8,7> result = 0;
   Fix<8,7> current_result = 0;
   Uint<4> max= "0bu1111";
   
   for (Uint<4> i = 0; i < 8; i++)
   {
      Fix<8,7> product = A[i] * B[7-i];
      if (product > current_result) 
      {
         current_result = -product;
         position = max+1;
      } // end if
      else 
      {
         current_result = product<<2;
         position = max-1;
      } // end else
   }  // end for
   result = result + current_result;
   overall_result = result;
}
       

