From patchwork Sun Mar 13 04:00:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wohlferd X-Patchwork-Id: 596711 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qN6cp24nnz9s36 for ; Sun, 13 Mar 2016 15:01:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bhiTEOMw; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=oZQ2XYOM73gIGdXZQO1crSwCSfgRjhJaDDrpdiOZELxCKsA2IF DdgEO3VClLqs5Jcqz4ZqoBDvXjeXURlwZgXZF8/5Hg6iqHD148K76Zz4iKC5mhXv apASi9dCLD5tfMBEj0ksARus9byQELf9lAydaylg2cW9D/5FKDotBwhOs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=Dia98PzsAtssx8LM2XfiRxx4Nxw=; b=bhiTEOMwM8EBvtgmlkhq rn8VrB/H+Ni4rGrlSj3p+2cmpkZA3awL7rdYlIL4XA3/qHB14jNw/OvY/QQecXFM b/RDdfUFzeZmKSCBq/nvwgZ2Rg4n4hN1GeHafprogGhAu+n4aCmzZqEPfg+pCOsa Mu45N1eqtnvWG4F4SZ8fDeA= Received: (qmail 70465 invoked by alias); 13 Mar 2016 04:01:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 70285 invoked by uid 89); 13 Mar 2016 04:00:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=ccc, converts, U*@, ish X-HELO: bosmailout09.eigbox.net Received: from bosmailout09.eigbox.net (HELO bosmailout09.eigbox.net) (66.96.184.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sun, 13 Mar 2016 04:00:47 +0000 Received: from bosmailscan02.eigbox.net ([10.20.15.2]) by bosmailout09.eigbox.net with esmtp (Exim) id 1aexCv-00017d-Oi for gcc-patches@gcc.gnu.org; Sat, 12 Mar 2016 23:00:45 -0500 Received: from [10.115.3.32] (helo=bosimpout12) by bosmailscan02.eigbox.net with esmtp (Exim) id 1aexCu-0005ky-6h for gcc-patches@gcc.gnu.org; Sat, 12 Mar 2016 23:00:44 -0500 Received: from bosauthsmtp02.yourhostingaccount.com ([10.20.18.2]) by bosimpout12 with id VG0g1s00602gpmq01G0jru; Sat, 12 Mar 2016 23:00:44 -0500 X-Authority-Analysis: v=2.1 cv=HK1NF+dv c=1 sm=1 tr=0 a=9MP9vxlQrmnoeofDS6o88g==:117 a=sZx1nW7oDdbgogxTPqu5Xw==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=88b2x-oFWvEA:10 a=7OsogOcEt9IA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=C8F9KGFtAAAA:8 a=dCO5kVAFl5Nz8PTUXgwA:9 a=QEXdDO2ut3YA:10 a=WxJSNdLZNtQA:10 a=gBCWZrJL1UzskLwCxOMA:9 Received: from [207.118.20.56] (port=50224 helo=[192.168.1.160]) by bosauthsmtp02.eigbox.net with esmtpa (Exim) id 1aexCp-0003V6-TT; Sat, 12 Mar 2016 23:00:40 -0500 From: David Wohlferd Subject: [DOC Patch] Add sample for @cc constraint To: "gcc-patches@gcc.gnu.org" Cc: Richard Henderson , Sandra Loosemore , David Wohlferd Message-ID: <56E4E5D6.4030500@LimeGreenSocks.com> Date: Sat, 12 Mar 2016 20:00:22 -0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 X-EN-UserInfo: 97390230d6758ac7ebdf93f8c6197d31:931c98230c6409dcc37fa7e93b490c27 X-EN-AuthUser: dw@limegreensocks.com X-EN-OrigIP: 207.118.20.56 X-EN-OrigHost: unknown The docs for the new(-ish) @cc constraint need an example. Attached. ChangeLog: 2016-03-12 David Wohlferd * 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