This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: AW: Wonly-top-basic-asm
- From: David Wohlferd <dw at LimeGreenSocks dot com>
- To: Sandra Loosemore <sandra at codesourcery dot com>, Bernd Schmidt <bschmidt at redhat dot com>, Bernd Edlinger <bernd dot edlinger at hotmail dot de>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Richard Henderson <rth at redhat dot com>, "jason at redhat dot com" <jason at redhat dot com>
- Cc: "segher at kernel dot crashing dot org" <segher at kernel dot crashing dot org>, "Paul_Koning at Dell dot com" <Paul_Koning at Dell dot com>, Jeff Law <law at redhat dot com>, Andrew Haley <aph at redhat dot com>, hubicka at ucw dot cz
- Date: Fri, 19 Feb 2016 17:03:12 -0800
- Subject: Re: AW: Wonly-top-basic-asm
- Authentication-results: sourceware.org; auth=none
- References: <56A54EF9 dot 8060006 at LimeGreenSocks dot com> <56A61442 dot 3090803 at redhat dot com> <56A9C134 dot 1030500 at LimeGreenSocks dot com> <56B80F57 dot 9020606 at LimeGreenSocks dot com> <HE1PR07MB09059C5C9C060394C61A1232E4D50 at HE1PR07MB0905 dot eurprd07 dot prod dot outlook dot com> <56BBCC90 dot 9020001 at LimeGreenSocks dot com> <56BCAB73 dot 20506 at redhat dot com> <56BD8427 dot 4050405 at LimeGreenSocks dot com> <56BDD550 dot 3050908 at redhat dot com> <56BE80F4 dot 6060803 at codesourcery dot com> <56BFFBD9 dot 7010202 at LimeGreenSocks dot com>
On 2/13/2016 8:00 PM, David Wohlferd wrote:
Fair enough. Committing what we can right now sounds like a good plan.
Attached is the doc patch, minus the proposed warning.
ChangeLog:
2016-02-19 David Wohlferd <dw@LimeGreenSocks.com>
Bernd Schmidt <bschmidt@redhat.com>
* doc/extend.texi: Doc basic asm behavior re clobbers.
dw
Index: extend.texi
===================================================================
--- extend.texi (revision 233367)
+++ extend.texi (working copy)
@@ -7458,7 +7458,8 @@
@end table
@subsubheading Remarks
-Using extended @code{asm} typically produces smaller, safer, and more
+Using extended @code{asm} (@pxref{Extended Asm}) typically produces smaller,
+safer, and more
efficient code, and in most cases it is a better solution than basic
@code{asm}. However, there are two situations where only basic @code{asm}
can be used:
@@ -7498,10 +7499,25 @@
symbol errors during compilation if your assembly code defines symbols or
labels.
-Since GCC does not parse the @var{AssemblerInstructions}, it has no
-visibility of any symbols it references. This may result in GCC discarding
-those symbols as unreferenced.
+@strong{Warning:} The C standards do not specify semantics for @code{asm},
+making it a potential source of incompatibilities between compilers. These
+incompatibilities may not produce compiler warnings/errors.
+GCC does not parse basic @code{asm}'s @var{AssemblerInstructions}, which
+means there is no way to communicate to the compiler what is happening
+inside them. GCC has no visibility of symbols in the @code{asm} and may
+discard them as unreferenced. It also does not know about side effects of
+the assembler code, such as modifications to memory or registers. Unlike
+some compilers, GCC assumes that no changes to either memory or registers
+occur. This assumption may change in a future release.
+
+To avoid complications from future changes to the semantics and the
+compatibility issues between compilers, consider replacing basic @code{asm}
+with extended @code{asm}. See
+@uref{https://gcc.gnu.org/wiki/ConvertBasicAsmToExtended, How to convert
+from basic asm to extended asm} for information about how to perform this
+conversion.
+
The compiler copies the assembler instructions in a basic @code{asm}
verbatim to the assembly language output file, without
processing dialects or any of the @samp{%} operators that are available with
@@ -7516,11 +7532,25 @@
Basic @code{asm} provides no
mechanism to provide different assembler strings for different dialects.
-Here is an example of basic @code{asm} for i386:
+Here is an example of top-level basic @code{asm} for i386 that defines an
+asm macro. That macro is then invoked from within a function using
+extended @code{asm}:
@example
-/* Note that this code will not compile with -masm=intel */
-#define DebugBreak() asm("int $3")
+/* Define macro at file scope with basic asm. */
+/* Add macro parameter p to eax. */
+asm (".macro testme p\n\t"
+ "addl $\\p, %eax\n\t"
+ ".endm");
+
+/* Use macro in function using extended asm. It needs
+ the "cc" clobber since the flags are changed and uses
+ the "a" constraint since it modifies eax. */
+int DoAdd (int value)
+@{
+ asm ("testme 5" : "+a" (value) : : "cc");
+ return value;
+@}
@end example
@node Extended Asm