Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimizing used registers when using inline ARM assembly in GCC

I want to write some inline ARM assembly in my C code. For this code, I need to use a register or two more than just the ones declared as inputs and outputs to the function. I know how to use the clobber list to tell GCC that I will be using some extra registers to do my computation.

However, I am sure that GCC enjoys the freedom to shuffle around which registers are used for what when optimizing. That is, I get the feeling it is a bad idea to use a fixed register for my computations.

What is the best way to use some extra register that is neither input nor output of my inline assembly, without using a fixed register?

P.S. I was thinking that using a dummy output variable might do the trick, but I'm not sure what kind of weird other effects that will have...

like image 207
Madcowswe Avatar asked Jan 04 '12 00:01

Madcowswe


1 Answers

Ok, I've found a source that backs up the idea of using dummy outputs instead of hard registers:

4.8 Temporary registers: People also sometimes erroneously use clobbers for temporary registers. The right way is to make up a dummy output, and use “=r” or “=&r” depending on the permitted overlap with the inputs. GCC allocates a register for the dummy value. The difference is that GCC can pick a convenient register, so it has more flexibility.

from page 20 of this pdf.

For anyone who is interested in more info on inline assembly with GCC this website turned out to be very instructive.

like image 185
Madcowswe Avatar answered Sep 22 '22 13:09

Madcowswe