This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[DOC Patch] Add sample for @cc constraint


The docs for the new(-ish) @cc constraint need an example. Attached.

ChangeLog:

2016-03-12  David Wohlferd  <dw@LimeGreenSocks.com>

    * doc/extend.texi: Add sample for @cc constraint

Note that while I have a release on file with FSF, I don't have write access to SVN.

dw
Index: extend.texi
===================================================================
--- extend.texi	(revision 234163)
+++ extend.texi	(working copy)
@@ -8047,6 +8047,7 @@
 
 Because of the special nature of the flag output operands, the constraint
 may not include alternatives.
+Do not clobber flags if they are being used as outputs.
 
 Most often, the target has only one flags register, and thus is an implied
 operand of many instructions.  In this case, the operand should not be
@@ -8105,6 +8106,43 @@
 ``not'' @var{flag}, or inverted versions of those above
 @end table
 
+For builds that don't support flag output operands, this example generates
+code to convert the flags to a byte (@code{setc}), then converts the
+byte back to flags (@code{if (a)} would generate a @code{testb}):
+
+@example
+char a;
+
+#ifndef __GCC_ASM_FLAG_OUTPUTS__
+
+/* If outputting flags is not supported.  */
+asm ("bt $0, %1\n\t"
+     "setc %0"
+  : "=q" (a)
+  : "r" (b)
+  : "cc");
+
+#else
+
+/* Avoid the redundant setc/testb and use the carry flag directly.  */
+asm ("bt $0, %1"
+  : "=@@ccc" (a)
+  : "r" (b));
+
+#endif
+
+if (a)
+  printf ("odd\n");
+else
+  printf ("even\n");
+@end example
+
+To see the improvement in the generated output, make sure optimizations
+are enabled.
+
+Note: On the x86 platform, flags are normally considered clobbered by
+extended asm whether the @code{"cc"} clobber is specified or not.
+
 @end table
 
 @anchor{InputOperands}
@@ -8260,6 +8298,8 @@
 On other machines, condition code handling is different, 
 and specifying @code{"cc"} has no effect. But 
 it is valid no matter what the target.
+For platform-specific uses of flags, see also
+@ref{FlagOutputOperands,Flag Output Operands}.
 
 @item "memory"
 The @code{"memory"} clobber tells the compiler that the assembly code

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