public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [DOC Patch] Add sample for @cc constraint
@ 2016-03-13  4:01 David Wohlferd
  2016-03-23  7:02 ` David Wohlferd
  2016-03-24 15:21 ` Bernd Schmidt
  0 siblings, 2 replies; 12+ messages in thread
From: David Wohlferd @ 2016-03-13  4:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Henderson, Sandra Loosemore, David Wohlferd

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ccA.patch --]
[-- Type: text/x-patch; name="ccA.patch", Size: 1824 bytes --]

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-04-26  0:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-13  4:01 [DOC Patch] Add sample for @cc constraint David Wohlferd
2016-03-23  7:02 ` David Wohlferd
2016-03-24 15:21 ` Bernd Schmidt
2016-03-24 17:59   ` Sandra Loosemore
2016-03-27 22:34   ` David Wohlferd
2016-03-29 12:10     ` Bernd Schmidt
2016-04-01 23:39       ` David Wohlferd
2016-04-11 22:49         ` David Wohlferd
2016-04-12 13:06           ` Bernd Schmidt
2016-04-15 23:13             ` David Wohlferd
2016-04-25  9:51               ` Bernd Schmidt
2016-04-26  0:16                 ` David Wohlferd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).