Dmitry wrote:

could you please be more specific?
Are they eliminated during code generatin phase?
Have you tried to make one of them as input?

Only whole asm operator can be deleted by gcc. So, try to recombine params.
OK. Here is a specific example - a sqrt function from the 430 apps. book, turned into a C function. This version does not work. x and y get merged, and are no longer separate working variables inside the asm code.

int32_t isqrt32(register int32_t h)
{
   register int32_t x;
   register int32_t y;
   register int16_t i;

   x =
   y = 0;
   i = 32;
   __asm__ (
       "1: \n"
       " setc \n"
       " rlc    %A0 \n"
       " rlc     %B0 \n"
       " sub     %A0,%A1 \n"
       " subc    %B0,%B1 \n"
       " jhs    2f \n"
       " add    %A0,%A1 \n"
       " addc    %B0,%B1 \n"
       " sub    #2,%A0 \n"
       "2: \n"
       " inc    %A0 \n"
       " rla    %A2 \n"
       " rlc    %B2 \n"
       " rlc    %A1 \n"
       " rlc    %B1 \n"
       " rla    %A2 \n"
       " rlc    %B2 \n"
       " rlc    %A1 \n"
       " rlc    %B1 \n"
       " dec    %3 \n"
       " jne    1b \n"
       : "+r"(x), "+r"(y)
       : "r"(h), "r"(i));
   return  x;
}

The works. The values of x and y are now different as we enter the asm code, so GCC cannot coalesce them. It allocates two registers for x and another 2 for y. All is well, as setting the top bit of x happens to be harmless. It wastes code, though. It gets me around the immediate problem, but it obviously not the right way to do things.

int32_t isqrt32(register int32_t h)
{
   register int32_t x;
   register int32_t y;
   register int16_t i;

   x = 0x80000000;
   y = 0;
   i = 32;
   __asm__ (
       "1: \n"
       " setc \n"
       " rlc    %A0 \n"
       " rlc     %B0 \n"
       " sub     %A0,%A1 \n"
       " subc    %B0,%B1 \n"
       " jhs    2f \n"
       " add    %A0,%A1 \n"
       " addc    %B0,%B1 \n"
       " sub    #2,%A0 \n"
       "2: \n"
       " inc    %A0 \n"
       " rla    %A2 \n"
       " rlc    %B2 \n"
       " rlc    %A1 \n"
       " rlc    %B1 \n"
       " rla    %A2 \n"
       " rlc    %B2 \n"
       " rlc    %A1 \n"
       " rlc    %B1 \n"
       " dec    %3 \n"
       " jne    1b \n"
       : "+r"(x), "+r"(y)
       : "r"(h), "r"(i));
   return  x;
}


Regards,
Steve



Reply via email to