c - How to ask for a general purpose register in an asm inline statement? -


is there way ask gcc allocate register asm inline internal use only? here example (in pseudo-asm) r5 directly used in asm, general purpose register, internal use, neither input nor output :

asm("load_immediate_value %%r5,0;"     /* ... */     "add_immediate_value %%r5,%%r5,42"     /* ... */     :     :     : "r5"); 

in example, choose register r5 , tell gcc using through clobber list. if r5 abi register?! need way ask register without having name myself.

the way done is:

static __inline__ void set_archctrl0(unsigned long val) {     register unsigned long archctrl0 __asm__("archctrl0") = val;      __asm__ __volatile__("" : "+r"(archctrl0) : : "cc", "memory"); } 

the empty asm statement there force compiler not optimize whole thing out.

or, more practical example, reading stackpointer register can done like:

static __inline__ void * getsp(void) {     register void * sp asm("sp");     asm ("" : "=r"(sp));     return sp; } 

the method bind variables specific registers documented in explicit register variables section of gcc manual.

of course, if writing arch-specific register requires custom instruction (i.e. cannot done using whatever type of "move" or "load" cpu uses initialize register values), you'll rather require like:

static __inline__ void set_archctrl0(unsigned long val) {     __asm__ __volatile__("setarchctrl0 %0" : : "r"(val) : "cc", "memory"); } 

all of those, obviously, work registers not being used "normal" code (i.e. outside platform abi / explicitly reserved platform abi globals / regs not touched compiled code).

you cannot instruct compiler "keep hands off general-purpose register" way. knowledge, isn't possible in gcc.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -