diff options
author | Hans-Peter Nilsson <hp@bitrange.com> | 2004-10-19 23:17:06 +0000 |
---|---|---|
committer | Hans-Peter Nilsson <hp@gcc.gnu.org> | 2004-10-19 23:17:06 +0000 |
commit | b55d57460298a5e0f675b1e7a2af84690cb14f4d (patch) | |
tree | b89f428228dd43542bbe4d2d1d9acc39948b054c /gcc/doc | |
parent | 9a7ac511547ff9cf0692eaffea7a21dc15ae30eb (diff) | |
download | gcc-b55d57460298a5e0f675b1e7a2af84690cb14f4d.zip gcc-b55d57460298a5e0f675b1e7a2af84690cb14f4d.tar.gz gcc-b55d57460298a5e0f675b1e7a2af84690cb14f4d.tar.bz2 |
extend.texi (Extended Asm): Warn and provide example solution for using a call-clobbered asm register.
* doc/extend.texi (Extended Asm): Warn and provide example
solution for using a call-clobbered asm register.
(Local Reg Vars): Similar. Cross-reference example.
From-SVN: r89299
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index eef64f1..0667540 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -3585,6 +3585,23 @@ register int *result asm ("r0"); asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); @end smallexample +@anchor{Example of asm with clobbered asm reg} +In the above example, beware that a register that is call-clobbered by +the target ABI will be overwritten by any function call in the +assignment, including library calls for arithmetic operators. +Assuming it is a call-clobbered register, this may happen to @code{r0} +above by the assignment to @code{p2}. If you have to use such a +register, use temporary variables for expressions between the register +assignment and use: + +@smallexample +int t1 = @dots{}; +register int *p1 asm ("r0") = @dots{}; +register int *p2 asm ("r1") = t1; +register int *result asm ("r0"); +asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); +@end smallexample + Some instructions clobber specific hard registers. To describe this, write a third colon after the input operands, followed by the names of the clobbered hard registers (given as strings). Here is a realistic @@ -4141,6 +4158,20 @@ Stores into local register variables may be deleted when they appear to be dead according to dataflow analysis. References to local register variables may be deleted or moved or simplified. +As for global register variables, it's recommended that you choose a +register which is normally saved and restored by function calls on +your machine, so that library routines will not clobber it. A common +pitfall is to initialize multiple call-clobbered registers with +arbitrary expressions, where a function call or library call for an +arithmetic operator will overwrite a register value from a previous +assignment, for example @code{r0} below: +@smallexample +register int *p1 asm ("r0") = @dots{}; +register int *p2 asm ("r1") = @dots{}; +@end smallexample +In those cases, a solution is to use a temporary variable for +each arbitrary expression. @xref{Example of asm with clobbered asm reg}. + @node Alternate Keywords @section Alternate Keywords @cindex alternate keywords |