From patchwork Fri Apr 1 23:39:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wohlferd X-Patchwork-Id: 605079 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 3qcHt51mg9z9sRB for ; Sat, 2 Apr 2016 10:39:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ODM40heq; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=aiaEqb4WNWJRG/lcM n5+UQ+9dhlY/BLdm8w+8De8gAHfcVdgNQDC3zkWqWdvVv75BbXTpo6TGP2Y4L2Wf ZmwhbqCqLvyp0NB96fhn9wcE6N3blgEFq2VmdsWBllG5MmPcaG2fmSnu5d7GyFXD yi8uBIO7w9jghCBDavn9TkYNDw= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=x8NTibv/aoR698bKNfMcKKQ wYsM=; b=ODM40heqG6J3a1vr8YprrkfNTYgYdYu145NVKsSLW2VngyDriBlPR3h Z7pRKFWB4VXvfQUIe7uYqUs+6gNh5gdegxAaKTsOcFYkc8ABQ09zJddOSE1fJMVj RIYB0HOKO0PDou93vONj3Y3SGFIr+RG1OgtOmSKB7QHfMllz9X0g= Received: (qmail 75510 invoked by alias); 1 Apr 2016 23:39:47 -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 75473 invoked by uid 89); 1 Apr 2016 23:39:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_20, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=stc, $128, H*RU:sk:bosmail, Hx-spam-relays-external:sk:bosmail X-HELO: bosmailout04.eigbox.net Received: from bosmailout04.eigbox.net (HELO bosmailout04.eigbox.net) (66.96.189.4) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 01 Apr 2016 23:39:45 +0000 Received: from bosmailscan14.eigbox.net ([10.20.15.14]) by bosmailout04.eigbox.net with esmtp (Exim) id 1am8fH-0001Q4-3x for gcc-patches@gcc.gnu.org; Fri, 01 Apr 2016 19:39:43 -0400 Received: from [10.115.3.33] (helo=bosimpout13) by bosmailscan14.eigbox.net with esmtp (Exim) id 1am8fF-00029Z-Hv for gcc-patches@gcc.gnu.org; Fri, 01 Apr 2016 19:39:41 -0400 Received: from bosauthsmtp03.yourhostingaccount.com ([10.20.18.3]) by bosimpout13 with id dBfc1s00703yW7601Bffg0; Fri, 01 Apr 2016 19:39:41 -0400 X-Authority-Analysis: v=2.1 cv=Abo/HhnG c=1 sm=1 tr=0 a=6uKCkKhFq2wXOH2GoQX8aA==:117 a=sZx1nW7oDdbgogxTPqu5Xw==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=88b2x-oFWvEA:10 a=kziv93cY1bsA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=gnoLx-BPWXYC7C6UM4MA:9 a=RDOGX4o61x_XIfnT:21 a=Bpn60UdhbwviuREJ:21 a=QEXdDO2ut3YA:10 a=4E0degvs8qDq7E2D7i8A:9 Received: from [207.118.20.56] (port=50901 helo=[192.168.1.160]) by bosauthsmtp03.eigbox.net with esmtpa (Exim) id 1am8f9-0006RJ-5H; Fri, 01 Apr 2016 19:39:35 -0400 Subject: Re: [DOC Patch] Add sample for @cc constraint To: Bernd Schmidt References: <56E4E5D6.4030500@LimeGreenSocks.com> <56F40103.8080600@redhat.com> <56F85899.4010201@LimeGreenSocks.com> <56FA6B82.9080308@redhat.com> Cc: "gcc-patches@gcc.gnu.org" , Richard Henderson , Sandra Loosemore , David Wohlferd From: David Wohlferd Message-ID: <56FF06A7.8040900@LimeGreenSocks.com> Date: Fri, 1 Apr 2016 16:39:19 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <56FA6B82.9080308@redhat.com> X-EN-UserInfo: 97390230d6758ac7ebdf93f8c6197d31:931c98230c6409dcc37fa7e93b490c27 X-EN-AuthUser: dw@limegreensocks.com X-EN-OrigIP: 207.118.20.56 X-EN-OrigHost: unknown > I would like executable code that verifies that this feature is indeed working as intended. First draft is attached. It tests all 28 (14 conditions plus 14 inverted). I wasn't sure what to set for optimization (O2? O3? O0?), so I left the default. It looks like even at O3 there are some missed optimizations here, but that's an issue for another day. > Is there any _actual_ problem here? Like, if you combine the output and the clobber you run into problems? Looks to me like an explicit "cc" clobber is just ignored on x86. We just need to make sure this stays working (testcases). Today? No. You can clobber or not clobber and both will produce the exact same output. But letting people program this two different ways guarantees that people *will* program it both ways. And just because there isn't any definable reason to limit this today doesn't mean that there won't ever be. But by then it will be 'too late' to change it because it "breaks existing code." >> 1) Leave this text in. >> 2) Remove the text and add the compiler check to v6. >> 3) Remove the text and add the compiler check to v7. >> 4) Leave the text in v6, then in v7: remove the text and add the compiler check. >> 5) (Reluctantly) remove the text and hope this never becomes a problem. So, I've made my pitch, but it sounds like you want #5? > My question would be, can this information ever be relevant to users? They may notice that their code still works if they omit the "cc", but that's not really a habit we want to encourage. People do this now without understanding how or why it works. > I think this is an internal implementation detail that doesn't necessarily even have to be documented. One time it would matter is if people want to move from basic asm (which doesn't clobber "cc") to any type of extended asm (which always does). It /probably/ won't matter in that case (and may even make things better). But it shouldn't be a secret. dw Index: gcc/testsuite/gcc.target/i386/asm-flag-6.c =================================================================== --- gcc/testsuite/gcc.target/i386/asm-flag-6.c (revision 0) +++ gcc/testsuite/gcc.target/i386/asm-flag-6.c (working copy) @@ -0,0 +1,276 @@ +/* Executable testcase for 'output flags.' */ +/* { dg-do run } */ + +char TestC () +{ + char r; + + __asm__ ("stc" : "=@ccc"(r)); + if (r) + { + __asm__ ("clc" : "=@ccnc"(r)); + if (r) + return 1; + } + return 0; +} + +char TestE () +{ + char r; + + /* 1 equals 1. */ + __asm__ ("cmp $1, %1" : "=@cce"(r) : "r" (1)); + if (r) + { + /* 1 not equals 2. */ + __asm__ ("cmp $2, %1" : "=@ccne"(r) : "r" (1)); + if (r) + return 1; + } + return 0; +} + +char TestZ () +{ + char r; + + /* 1 equals 1. */ + __asm__ ("cmp $1, %1" : "=@ccz"(r) : "r" (1)); + if (r) + { + /* 1 not equals 2. */ + __asm__ ("cmp $2, %1" : "=@ccnz"(r) : "r" (1)); + if (r) + return 1; + } + return 0; +} + +char TestA () +{ + char r; + + /* 1 a 0. */ + __asm__ ("cmp $0, %1" : "=@cca"(r) : "r" (1)); + if (r) + { + /* 1 na 2. */ + __asm__ ("cmp $2, %1" : "=@ccna"(r) : "r" (1)); + if (r) + { + /* 1 na 1. */ + __asm__ ("cmp $1, %1" : "=@ccna"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestAE () +{ + char r; + + /* 1 ae 0. */ + __asm__ ("cmp $0, %1" : "=@ccae"(r) : "r" (1)); + if (r) + { + /* 1 nae 2. */ + __asm__ ("cmp $2, %1" : "=@ccnae"(r) : "r" (1)); + if (r) + { + /* 1 ae 1. */ + __asm__ ("cmp $1, %1" : "=@ccae"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestB () +{ + char r; + + /* 1 b 2. */ + __asm__ ("cmp $2, %1" : "=@ccb"(r) : "r" (1)); + if (r) + { + /* 1 nb 0. */ + __asm__ ("cmp $0, %1" : "=@ccnb"(r) : "r" (1)); + if (r) + { + /* 1 nb 1. */ + __asm__ ("cmp $1, %1" : "=@ccnb"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestBE () +{ + char r; + + /* 1 be 2. */ + __asm__ ("cmp $2, %1" : "=@ccbe"(r) : "r" (1)); + if (r) + { + /* 1 nbe 0. */ + __asm__ ("cmp $0, %1" : "=@ccnbe"(r) : "r" (1)); + if (r) + { + /* 1 be 1. */ + __asm__ ("cmp $1, %1" : "=@ccbe"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestG () +{ + char r; + + /* 1 g 0. */ + __asm__ ("cmp $0, %1" : "=@ccg"(r) : "r" (1)); + if (r) + { + /* 1 ng 2. */ + __asm__ ("cmp $2, %1" : "=@ccng"(r) : "r" (1)); + if (r) + { + /* 1 ng 1. */ + __asm__ ("cmp $1, %1" : "=@ccng"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestGE () +{ + char r; + + /* 1 ge 0. */ + __asm__ ("cmp $0, %1" : "=@ccge"(r) : "r" (1)); + if (r) + { + /* 1 nge 2. */ + __asm__ ("cmp $2, %1" : "=@ccnge"(r) : "r" (1)); + if (r) + { + /* 1 ge 1. */ + __asm__ ("cmp $1, %1" : "=@ccge"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestL () +{ + char r; + + /* 1 l 2. */ + __asm__ ("cmp $2, %1" : "=@ccl"(r) : "r" (1)); + if (r) + { + /* 1 nl 0. */ + __asm__ ("cmp $0, %1" : "=@ccnl"(r) : "r" (1)); + if (r) + { + /* 1 nl 1. */ + __asm__ ("cmp $1, %1" : "=@ccnl"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestLE () +{ + char r; + + /* 1 le 2. */ + __asm__ ("cmp $2, %1" : "=@ccle"(r) : "r" (1)); + if (r) + { + /* 1 nle 0. */ + __asm__ ("cmp $0, %1" : "=@ccnle"(r) : "r" (1)); + if (r) + { + /* 1 le 1. */ + __asm__ ("cmp $1, %1" : "=@ccle"(r) : "r" (1)); + if (r) + return 1; + } + } + return 0; +} + +char TestO () +{ + char r; + unsigned char res = 128; + + /* overflow. */ + __asm__ ("addb $128, %1" : "=@cco"(r), "+r"(res)); + if (r) + { + /* not overflow. */ + __asm__ ("addb $1, %1" : "=@ccno"(r), "+r"(res)); + if (r) + return 1; + } + return 0; +} + +char TestP () +{ + char r, res = 1; + + /* even # bits. */ + __asm__ ("addb $2, %1" : "=@ccp"(r), "+r"(res)); + if (r) + { + /* odd # bits. */ + __asm__ ("addb $1, %1" : "=@ccnp"(r), "+r"(res)); + if (r) + return 1; + } + return 0; +} + +char TestS () +{ + char r, res = 1; + + /* sign bit set. */ + __asm__ ("addb $128, %1" : "=@ccs"(r), "+r"(res)); + if (r) + { + /* sign bit not set. */ + __asm__ ("subb $128, %1" : "=@ccns"(r), "+r"(res)); + if (r) + return 1; + } + return 0; +} + +/* dg-do treats exit code of 0 as success. */ +int main () +{ + if (TestC () && TestE () && TestZ () && TestA () + && TestAE () && TestB () && TestBE () && TestG () + && TestGE () && TestL () && TestLE () && TestO () + && TestP () && TestS ()) + return 0; + return 1; +}