In g++, clobber lists for asm can be specified, for example:
asm ("somecode" : : "r1", "r2", "r3");
which means that the asm code changes register开发者_C百科s r1, r2, r3.
Now, my changed registers depend on a template parameter n
(the asm
block is inside of a template function), and registers r1, ..., rn will be changed. How can I express that?
How many different register constellations are you confronted with? If not too many, you could provide a specific implementation for each. (Template Specialization)
Because, I apprehend that there's no possibility to create "templated statements".
You can set all the register that you could use in the clobber list, so the compiler doesn't use them to store the value of a variable; I know this is a little bit slower, but if you don't need a very very high optimization, it will work.
精彩评论