[Cbe-oss-dev] spu-gcc inline asm

Ulrich Weigand Ulrich.Weigand at de.ibm.com
Sat Jul 18 01:36:45 EST 2009


Phil Pratt-Szeliga wrote:

> I am doing something for google summer of code (I am working on opencl
> for gcc) and I am having trouble jumping
> to a function that is downloaded at runtime.
> 
> The first step is to jump to a function with arguments.  It works
> using inline assembly using no arguments, but I can't
> figure out how to make it work with an argument.  Is the spu-gcc
> inline assembly syntax different?

Your sample code contains multiple issues:

>   unsigned long long arg1 = 20;
>   asm("andbi $3,$3,20;\
>        brsl $0, function1;");

The assembler code is clobbering the contents of registers
3 and 0 without telling the compiler about it.  (Similar with 
the other inline asm statements.)  In fact, if it were to actually
execute the brsl statement, all call-clobbered registers are
potentially clobbered at this point.

Also, the semicolon after the andbi $3,$3,20 acts as a
start-of-comment character to the assembler, which means
everything beyond it, in particular the brsl, is ignored as
comment.  You should use \n instead of ;.

>   /* gives me the compiler error #1 */
>   asm ("andbi $3,$3,%0"
>       : /* no output args */
>       : "r" (arg1)
>       );

As the error you're seeing below says, the third operand to
andbi must be an immediate integer, but you are using the "r"
constraint to instruct GCC to place a *register* name as the %0
operand.  The only way the assembler can treat "$2" as an
appropriate immediate operand is by considering it as symbol
(which of course is nowhere defined).

You need to either use an actual immediate operand (using
the "i" instead of the "r" constraint, or else use an assembler
instruction that accepts a register operand.

>   asm("brsl $0, function1");

You shouldn't use two separate asm statements.  There is
no guarantee the compiler won't generate additional code
in between the two (which might clobber the registers you've
just set up).


The more fundamental question would be why you're trying
to use an inline asm in the first place.  If you simply want to
call a function, why can't you just set a function pointer 
variable to the target address and then call it?


Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

-- 
  Dr. Ulrich Weigand | Phone: +49-7031/16-3727
  STSM, GNU compiler and toolchain for Linux on System z and Cell/B.E.
  IBM Deutschland Research & Development GmbH
  Vorsitzender des Aufsichtsrats: Martin Jetter | Geschäftsführung: Erich 
Baier
  Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht 
Stuttgart, HRB 243294



More information about the cbe-oss-dev mailing list