aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndreas Jaeger <aj@suse.de>2004-01-21 18:26:08 +0100
committerAndreas Jaeger <aj@gcc.gnu.org>2004-01-21 18:26:08 +0100
commitbbf5a54d985232333942f49ff89d35e6debd7e8c (patch)
tree057b9f125772c207a2ba0f4d03de52e7e037ea67 /gcc
parentbfccaa6f7006c6f1a56f6b8e4194583e8cddd2f4 (diff)
downloadgcc-bbf5a54d985232333942f49ff89d35e6debd7e8c.zip
gcc-bbf5a54d985232333942f49ff89d35e6debd7e8c.tar.gz
gcc-bbf5a54d985232333942f49ff89d35e6debd7e8c.tar.bz2
extend.texi (Extended Asm): Clarify memory clobber.
2004-01-21 Andreas Jaeger <aj@suse.de> Michael Matz <matz@suse.de> * doc/extend.texi (Extended Asm): Clarify memory clobber. Co-Authored-By: Michael Matz <matz@suse.de> From-SVN: r76288
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/doc/extend.texi34
2 files changed, 33 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 67a1f8e..2cdc83e1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-01-21 Andreas Jaeger <aj@suse.de>
+ Michael Matz <matz@suse.de>
+
+ * doc/extend.texi (Extended Asm): Clarify memory clobber.
+
2004-01-21 Jakub Jelinek <jakub@redhat.com>
* crtstuff.c (frame_dummy, __do_global_ctors_1): Call
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 0eed679..e2bfd93 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3917,13 +3917,35 @@ represents the condition codes as a specific hardware register;
condition code is handled differently, and specifying @samp{cc} has no
effect. But it is valid no matter what the machine.
-If your assembler instruction modifies memory in an unpredictable
+If your assembler instructions access memory in an unpredictable
fashion, add @samp{memory} to the list of clobbered registers. This
-will cause GCC to not keep memory values cached in registers across
-the assembler instruction. You will also want to add the
-@code{volatile} keyword if the memory affected is not listed in the
-inputs or outputs of the @code{asm}, as the @samp{memory} clobber does
-not count as a side-effect of the @code{asm}.
+will cause GCC to not keep memory values cached in registers across the
+assembler instruction and not optimize stores or loads to that memory.
+You will also want to add the @code{volatile} keyword if the memory
+affected is not listed in the inputs or outputs of the @code{asm}, as
+the @samp{memory} clobber does not count as a side-effect of the
+@code{asm}. If you know how large the accessed memory is, you can add
+it as input or output but if this is not known, you should add
+@samp{memory}. As an example, if you access ten bytes of a string, you
+can use a memory input like:
+
+@example
+@{"m"( (@{ struct @{ char x[10]; @} *p = (void *)ptr ; *p; @}) )@}.
+@end example
+
+Note that in the following example the memory input is necessary,
+otherwise GCC might optimize the store to @code{x} away:
+@example
+int foo ()
+@{
+ int x = 42;
+ int *y = &x;
+ int result;
+ asm ("magic stuff accessing an 'int' pointed to by '%1'"
+ "=&d" (r) : "a" (y), "m" (*y));
+ return result;
+@}
+@end example
You can put multiple assembler instructions together in a single
@code{asm} template, separated by the characters normally used in assembly