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.

Is there a way to access the C66x registers from C-level or do I have to write an asm function?

I would like to save the A and B registers into a structure from C level, is there an easy way of doing that? Is there an easy way of doing that from C-level by using intrinsics or other tricks? Anything like the gnu compiler supported asm-format which can process c-variables? Do I have to write a c-callable asm function ?

  • Hi,

    there's no way to do that from C. You need to write a C-callable (linear) assembly function.

    Kind regards,

    one and zero

  • On C55x, the ST and some other registers are all memory mapped so that I can access it directly. I could also use the asm in C to move data from registers to memory location directly. Is there a similar way to do that on C66x, as I am not so familiar with the C66x linear assembly?

    To do a automatic calling convention validation (I want to validate algorithm we buy including asm), what else do I have to check on C66x? From the compiler manual, I only saw those related to A0~A15, B0~B15, LC, IRP, NRP, RILC. I do not see any status registers as I used to have to maintain in C54x and C55x. Do I miss anything there? Do you know any existing code somewhere within TI or on the web for such thing?

    thanks

    Weichun

  • Hi,

    In C66x, you can also use "asm(" ");" statement to operate on registers in C code. Such as:

    asm(" STW A0,*B15--[1]");   // There must exist a space between the first double quotes and STW.

    asm(" STW A1,*B15--[1]");

    ……

    In this way, you can save all the registers to stack. And then copy out the entire data block to your structure in C.

    Why do you want to make the calling convention validation? It's clearly described by compiler user guide. The status register in C66x is defined in C66x CPU and Instruction Set.

    Allen

  • Allen,

    please be very careful with asm statements in your C-Code. The compiler rearranges code segments, uses registers freely, and can completely remove variables or
    expressions. Although the compiler never optimizes out an asm statement (except when it is unreachable), the surrounding environment where the assembly code is inserted can differ significantly from the original C/C++ source code.
    It is usually safe to use asm statements to manipulate hardware controls such as interrupt masks, but asm statements that attempt to interface with the C/C++ environment or access C/C++ variables can have unexpected results. After compilation, check the assembly output to make sure your asm statements are correct and maintain the integrity of the program.

    I would really recommend to write an assembly routine that is C-callable rather than using asm statements ...

    Kind regards,

    one and zero

  • Hi 1&0,

    Thanks for the advice, an assembly routine is definitely a better way. I'm just worrying about the calling of a routine will take effect on the runtime environment such as position of stack pointer or  registers' value. So I'm just trying on asm statement. 

    Anyway, learned a lot from your reply about the background info of asm, thanks.

    Allen

  • Hi Allen,

    how to interface between assembly and C is described in the Compiler User's Guide (SPRU 187).

    Chapter 7.5 Interfacing C and C++ With Assembly Language

    Please find an example from a previous post:

    http://e2e.ti.com/support/dsp/c6000_multi-core_dsps/f/639/p/159166/578164.aspx#578164

    Kind regards,

    one and zero