This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Question about asm called by C



Hi,

I know C program can solve most tasks excellently by careful programming and optimizations. My job needs some knowledge at assembly code. On page 198, spru187t.pdf, I am not clear about its item 4 (shown below). I do not understand especially this line:

 This step is needed only in assembly programs that were not compiled from C/C++ code.

In the simple small asm function, I do not see any stack operation in the asm and C file. I also write a same C function (add 4 to input parameter I) with that of asm. I do not see any difference in asm and C in disassembly lines.

I use CCS v5. CGT is 7.4.0B2

 

Thanks.

..................         

   .global asmfunc

   .global gvar

asmfunc:  .asmfunc

         LDW *+b14(gvar),A3

            NOP 4

            ADD a3, a4, a3

         STW a3, *b14(gvar)

         MV  a3, a4

         B   b3

         NOP 5

        .endasmfunc

............................

extern int asmfunc(int a); /* declare external as function */

int  gvar = 4; /* define global variable */

int

void main(void) {

int I = 5;

I = asmfunc(I);

}

 

 

4. Upon returning, the caller reclaims any stack space needed for arguments by adding to the stack

pointer. This step is needed only in assembly programs that were not compiled from C/C++ code. This

is because the C/C++ compiler allocates the stack space needed for all calls at the beginning of the

function and deallocates the space at the end of the function.

  • I get that when I relized that it applies to more parameters in function args.

    The line 00008574 is item 4 talking about? Am I right? Thanks.

     

     

     

  • Robert,

    The statement you quoted simply means that you do not have to worry about these stack manipulations if the assembly comes from original C from the compiler. This is one more reason to write it in C.

    So, write your routine in C, compile it with the Debug Configuration and study the code, then compile it with the Release Configuration and study the code. Optimize further from there, if needed. Or best, improve on the C code so the compiler will do a better job with it.

    Things that you think you need to write in assembly, instead write them in C and use intrinsics.

    You can learn a little about more in-depth optimizations by going to the Wiki and searching for "C6000 Optimization" (no quotes). You will find articles and a workshop that has been archived on the Wiki. You did not mention a specific DSP, but since this is in a C6000 forum thread, I assume that is the right place to point you.

    Also, search the forum, here and the Compiler Forum, for things like optimization to find other discussions. You will see a lot of times we recommend staying away from assembly. C6000 assembly is a great language for implementing C and for very high-performance code, but it is not a friendly language to write in. The unprotected pipeline means you will make mistakes that will be hard to figure out. But the compiler is very smart with how the pipeline works - that is its job. Your job is to build a great application in record time, and C is the way to do that, not assembly.

    If the simple function you show above is just a learning example, fine. The optimizer should be able to give you faster assembly from C for that.

    Regards,
    RandyP

  • Thanks for your message. The problem here is that the manager wants the code in assembly although I agree with you and other TI engineer more on that. My C code works in functionality, but the Release version code performance is still not as good as the expected. I check the list file and find that the Release code is really efficient but it has no SIMD feature yet. To manually read and improve it is difficult I understand. Do you have some opinions on the list code (I don't know whether a DSP expert can estimate something from this low level code.) ? It is obvious there are already some parallel instructions executing in this code.

     

    4212.acs_func_release.asm

    6678 has some SIMD instructions, which can be used in this project. This is also the direction the manager wants. This is the main advantage of DSP chip we want to use. I try with intrinsics first. Do you think we can get SIMD easily in C? In my previous posts, I did not make it clear. I intended to say linear assembly, not the pure assembly.

    Regards,

     

  • Robert,

    This thread started with a question about a statement in the C Compiler User's Guide, and that has been answered, I believe. I added unsolicited advice on how to proceed, which I stand behind. You can use the references in my previous post if you want to learn to take advantage of the more difficult programming methods.

    If you do not have time to learn from those references, then there are consultants in our TI Design Network who can help. Reading your assembly and re-writing it will be a good challenge for you. So I wish you and your manager good success.

    Regards,
    RandyP