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.

Registers used by the compiler

Hi,

I am porting a small operating system to the C6748, and am right now in the process of implementing support for interrupts. Its pretty straightforward, but unfortunately also prone for being very slow because of the amount of registers in the C6748.

I will ofcourse have to save all registers that are used by the interrupt routine, and as I would like to write some of these routines in C, then I will have to push all the registers that C uses.

Since the cpu has 64 registers, I will have to push A1-A9, A16-31m, B1-B9, B16-B31. I am pretty sure the compiler never would use this many registers for normal code, but if I don't know for sure, then I cannot count on it.

The optimizer seems to be pretty good and if I create a function and marks it with the "interrupt" keyword, then it may generate code that saves fewer registers, however, I cannot use the "interrupt" keyword because the compiler also generates a return from interrupt (B IRP) instruction when it is used, and I want the code to return to my own assembler code that called the C function..

 

So now for the questions:

- Is there a way to tell the c compiler to generate a function saving all necessary registers but NOT generate the B IRP instruction. It should generate the normal B B3 instead.

- Is there a way to tell the c-compiler to limit its own use to a certain register range?

 If that was possible, I probably could limit the c code to use registers 0-15 and reserve 16-31 for special purpose assembler code. In this case I would only have to save A1-A9 and B1-B9.

- Any other suggestions? I am pretty uncomfortable with having to push about 52 registers on each interrupt.

 

Helge

 

 

  • Helge Rasmussen said:
    - Is there a way to tell the c compiler to generate a function saving all necessary registers but NOT generate the B IRP instruction. It should generate the normal B B3 instead.

    No.

    Helge Rasmussen said:
    - Is there a way to tell the c-compiler to limit its own use to a certain register range?

    No.

    Helge Rasmussen said:
    - Any other suggestions? I am pretty uncomfortable with having to push about 52 registers on each interrupt.

    If your assembly coded interrupt service routine (ISR) must call C code, then no, I don't have any great ideas.

    The case where a C coded "interrupt" keyword function preserves fewer registers is when that ISR calls no other functions.  Try writing a C ISR that calls other functions.  Then the compiler will have the same problem you are experiencing now.  And you will see the compiler generate all the register save/restore code you are trying to avoid.

    Your best bet is to not call any C functions.  Then you only have to preserve the registers which are directly used.

    BTW ... Consider writing your ISR in linear assembly.  Let the tools deal with that 8-way parallelism and 5 stage pipeline.

    Thanks and regards,

    -George

     

  • Thanks for the answer, I had feared that it would be as you wrote.

     

    I would have thought it a reasonable feature for a compiler for embedded code to have the ability to limit its use of registers, so I thought I'd better ask.

    You are right that the compiler tends to generate code that saves all registers, but the optimizer seems to be able to leave out some of the push/pops when it can see that not all registers are in use. I had placed all relevant c code in the same file in the hope of using this, but I guess no luck there either.

    The reason for c interrupt routines was just for ease of the users of the OS .  I guess I will have to limit them to use assembler, or if they want to use c, then to write their own register saver.

    The compiler and linear assembler seems to do a very good job at optimizing code, so I thought , why not use it.

    Helge

     

     

  • Helge Rasmussen said:

    Since the cpu has 64 registers, I will have to push A1-A9, A16-31m, B1-B9, B16-B31. I am pretty sure the compiler never would use this many registers for normal code, but if I don't know for sure, then I cannot count on it.

    The compiler can and does use all of those registers, particularly in code with loops that get software pipelined.