This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC asm register clobber


> Thanks. In this case a specific register is required. Is it sufficient
> to write:
> 
> 	"=c" (out)     "c" (in)

No, the second one is always "0" (the number zero) to tell gcc that
the two parameters are the same register, not two values that must
(paradoxically) simultaneously be in the same register.

> If the 'out' parameter is not marked volatile, but is unused, what
> stops the compiler from optimizing it away, and having done so,
> concluding mistakenly that 'in' remains live in that register?

Hence the "0", which tells gcc how to correlate the parameters so it
knows what's really going on.

If gcc determines that it doesn't need the result of the asm, it
doesn't keep the asm.  You can make the asm volatile to prevent that:

  asm volatile (...)

This is why it's important to get the asm right, so that gcc knows
when it's *really* unneeded, not *accidentally* unneeded.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]