X
RSS YouTube LinkedIn Twitter XCore IRC

Search




Post new topic Reply to topic   [ 3 posts ] 
Author Message
PostPosted: Thu Mar 08, 2012 3:23 pm 
Joined: Wed Jan 05, 2011 2:15 pm
Posts: 33
Hi All,

Simple question...I hope. How do I access a function local variable with the inline assembler using ldw?

Example of the code below:

Code:
long nGlobalVar ;
void MyFunction (int a)
{
    int b ;
    // This is global access
    asm("ldw r0, dp[nGlobalVar]") ;
   
    // How do I correctly do local access?
    // This will not compile correctly
    asm("ldw r0, sp[a]") ;
   
    // I can get the following to work, and avoid
    // the clobber registers, but I really want to simply
    // use a syntax similar to the line above
    asm("add r0, %0, 0" : : "r"(a) : "r0","r1","r2") ;
    // The above code will expand to
    //     ldw r11, sp[1]
    //     add r0, r11, 0
    // I want tight code    : (
}


Top
Offline Profile View all posts by this user  
 
PostPosted: Thu Mar 08, 2012 8:25 pm 
User avatar
XCore Expert
Joined: Sun Jul 11, 2010 1:31 am
Posts: 675
You would write something like
Code:
unsigned x, y;
asm("ldw %0,%1" : "=r"(x) : "m"(y));

but with the current tools that results in
Code:
Could not match memory address.  Inline asm failure!


Another option is to pass the address of the var instead, like
Code:
unsigned x, y;
asm("ldw %0,%1" : "=r"(x) : "p"(&y));

but that results in
Code:
xcc2: /build/swnb/autobuild/Linux/sb_20110630_1915_02_1981/tools_llvm/src/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp:5326: void llvm::SelectionDAGLowering::visitInlineAsm(llvm::CallSite): Assertion `(OpInfo.ConstraintType == TargetLowering::C_RegisterClass || OpInfo.ConstraintType == TargetLowering::C_Register) && "Unknown constraint type!"' failed.
debug.c:189: internal compiler error: Aborted


Anyway, in general, it is best to pass things in registers, since XS1 is
a load-store architecture (that is, all instructions that access memory
do not compute things as well). It seems what you really want to do
is force things into the r0 register? If you can explain why, perhaps
there is a good solution.


Top
Offline Profile View all posts by this user  
 
PostPosted: Tue Apr 10, 2012 5:40 pm 
Joined: Tue Dec 15, 2009 10:23 pm
Posts: 108
Hi!

Is there any specific reason you want to inline code? It's really easy to setup an external .S (capitalized, so it gets pre-processed) file and call that directly from XC.

Just wondering..

-Yvo


Top
Offline Profile View all posts by this user  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic   [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest



Search for:
Jump to: