C Compiler MACCS

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

C Compiler MACCS

Postby Andy » Thu Mar 11, 2010 2:09 am

I noticed that the C compiler can target a MACCS instruction using

Code: Select all

sum += (long long int)x * (long long int)y;
but it generates other unnecessary instructions - are there any plans to fix this? I'm trying to optimise a critical filter section of an MP3 decoder written in C.

Does anyone know a way of handling 64 bit ints in assembly so I can write an inline assembly function that can be called from C?

I want to define a function that uses inline assembly

Code: Select all

static __inline long long int MY_MACCS(long long int sum, int x, int y)
that can take the long long int sum and split it into two 32 bit registers so I can pass it to the macs instructions. Really what I'd like to know is if it can be done without doing extra shifts/masks to split the long long int.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Postby Woody » Thu Mar 11, 2010 10:34 am

Do you really need to multiply two 64 bit numbers or just keep the accumulated result of multiplying two 32 bit numbers in 64 bits?
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Postby Andy » Thu Mar 11, 2010 11:20 am

Woody wrote:Do you really need to multiply two 64 bit numbers or just keep the accumulated result of multiplying two 32 bit numbers in 64 bits?
Sorry, maybe I didn't make it clear. I want the accumulated result of multiplying two 32 bit numbers in 64 bits.
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Postby richard » Thu Mar 11, 2010 2:47 pm

Andy wrote:but it generates other unnecessary instructions - are there any plans to fix this?
Yes, we hope to improve the C compiler's code generation for 64bit operations in the next release.
Really what I'd like to know is if it can be done without doing extra shifts/masks to split the long long int.
Don't worry about leaving the shifts in, they should be optimised away. The following example:

Code: Select all

long long maccs(long long sum, int x, int y)
{
  unsigned sum_lo = (unsigned)sum;
  int sum_hi = (int)(sum >> 32);
  unsigned result_lo;
  int result_hi;
  asm("maccs %1, %0, %4, %5" :
      "=r"(result_lo), "=r"(result_hi) :
      "0"(sum_lo), "1"(sum_hi), "r"(x), "r"(y));
  return result_lo | ((long long)result_hi << 32);
}
Compiles to (9.9.2 tools):

Code: Select all

maccs:
  maccs r1, r0, r2, r3
  retsp 0
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Postby Andy » Thu Mar 11, 2010 3:40 pm

Thanks Richard, that's exactly what I needed.

Who is online

Users browsing this forum: No registered users and 0 guests