diff mbox

[DOC] Add sample for @cc constraint

Message ID 245ed05c-e585-e8e8-c177-a548d7e19921@LimeGreenSocks.com
State New
Headers show

Commit Message

David Wohlferd April 26, 2016, 12:16 a.m. UTC
On 4/25/2016 2:51 AM, Bernd Schmidt wrote:
> On 04/16/2016 01:12 AM, David Wohlferd wrote:
>> There were  basically 3 changes I was trying for in that doc patch. Are
>> any of them worth keeping?  Or are we done?
>>
>> 1) "Do not clobber flags if they are being used as outputs."
>> 2) Output flags sample (with #if removed).
>> 3) "On the x86 platform, flags are always treated as clobbered by
>> extended asm whether @code{"cc"} is specified or not."
>>
>> I'm prepared to send an updated patch if there's anything here that
>> might get approved.
>
> I think the updated flags sample would be nice to have.

Attached.

dw
diff mbox

Patch

Index: extend.texi
===================================================================
--- extend.texi	(revision 235054)
+++ extend.texi	(working copy)
@@ -8135,6 +8135,26 @@ 
 ``not'' @var{flag}, or inverted versions of those above
 @end table
 
+This example uses the @code{bt} instruction (which sets the carry flag) to
+see if bit 0 of an integer is set.  To see the improvement in the generated
+output, make sure optimizations are enabled.
+
+@example
+void TestEven (int value)
+@{
+  char CarryIsSet;
+
+  asm ("bt $0, %[value]"
+    : "=@@ccc" (CarryIsSet)
+    : [value] "rm" (value));
+
+  if (CarryIsSet)
+    printf ("odd\n");
+  else
+    printf ("even\n");
+@}
+@end example
+
 @end table
 
 @anchor{InputOperands}