0

I'm optimizing C code for OpenRISC and I want to manually prereserve some computed values in registers, the pseudocode looks like that:

external loop
    compute eight values (heavy calculations)
    internal loop
        use values computed above

When I looked at GCC ABI for OpenRISC I saw two groups of registers: callee-saved and temporary? Which registers I should use to store these eight values? I mean, which registers I can put on clobbered list in inline asm?

I need to hardoce registers, because we run executables on custom OpenRISC.

1 Answer 1

3

The answer is: whatever you like.

If you use callee-save registers then the compiler will save them for you (as long as you do mark them as clobbered).

If you use temporary registers (a.k.a. caller-save) then the compiler will be forced to save them if you make a function call. Beware that the compiler also prefers to use these for other variables, so if you use up the caller-save ones it'll have to use callee-save for other things, so it might end up being much the same difference.

At the end of the day, if you are doing heavy calculations then saving a few registers to stack before you start is not going to be a big deal.

There are some registers that contain important values (such as stack pointer) that you must not overwrite. Others, such as the GOT table pointer are less important, and the compiler will restore the value when you're done (just be sure you don't need it during the process.

Really though, you don't need to work it out for yourself: the compiler can select registers for you:

int a, b, c;

asm volatile ("whatever" : "=&w" (a), "=&w" (b), "=&w" (c));

The variables are not needed, but they must have registers assigned, so they effectively reserve a register for whatever you want. The & indicates an "early-clobber", which means that they can't share the same register as an input register (not that my example shows any).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.