AnsweredAssumed Answered

Why cc21k does not use FEXT?

Question asked by canard on Mar 4, 2015
Latest reply on Apr 1, 2015 by MikeP

In this example I would like to extract 12 bits from the 16th bit. The fext function does what I want but it use an unwanted asm statement. I am surprised the compiler is not smart enough to use FEXT in the case of the extract function:

 

// Wanted solution

inline int extract(int x) {

  return (x & 0xFFF0000) >> 16;

}

 

// Ugly asm statement

inline int fext(int x) {

  int y;

  asm ("%0=fext %1 by 16:12 (SE);":"=d" (y):"d" (x));   

  return y;

}

 

// Another try

#define EXTRACT(x) (x & 0xFFF0000) >> 16

 

extern long a;

extern long x;

extern long y;

extern long z;

 

void main() {

  x = extract(a);

  y = fext(a);

  z = EXTRACT(a);

}

 

The compiler produce this output:

 

  r2=dm(_a);

  // ASM STATEMENT

  r1=fext r2 by 16:12 (SE);

  // END ASM STATEMENT

  dm(_y)=r1;

  r1=268369920;

  r2=r2 and r1;

  r2=lshift r2 by -16;

  dm(_x)=r2;

  dm(_z)=r2;

 

How can I tell the compiler to be smarter?

Outcomes