From patchwork Mon Jun 13 23:37:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 634949 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 3rT8Mv0WPMz9t0R for ; Tue, 14 Jun 2016 09:37:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=EXub5Zb2; 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=LAhCKg9ekZBca4R CwO3XrfEQMZQatmX7LTf5JjNpn+up+xKY8zwY23od1Rx2CNqUAK/d6CrXGwQfP1Y IclM2xeBlMGmf6u+BjCi581rXdYMpvdmLWIOLy5wJT9aFIPaP2nGstekN0g1zKOs SiQpuzUcr4w/KDG3EAf1Htoa603U= 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=NMbsoe8Q74QWyqjPtDP4g c6hJpo=; b=EXub5Zb2wLupOI8YhS6udVGfdvi9vQGrN+Mx/AtcK4aUe0jV+P9Wk OGekfk8jVfYQtWcLJyQ7xUCf4znMKw073e4/K5xDst2lxA6FEs2E3vmlD3hLbrms IXbybPlLPoQbVyrrwT6awvp50gWff4feJXd2Ok7P7cRp4xSwhaM6M0= Received: (qmail 66342 invoked by alias); 13 Jun 2016 23:37:37 -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 66216 invoked by uid 89); 13 Jun 2016 23:37:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=set_attr, match_operand, define_expand, 1.2q X-HELO: mail-vk0-f53.google.com Received: from mail-vk0-f53.google.com (HELO mail-vk0-f53.google.com) (209.85.213.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 13 Jun 2016 23:37:26 +0000 Received: by mail-vk0-f53.google.com with SMTP id t129so71903590vka.1 for ; Mon, 13 Jun 2016 16:37:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5kt3jcqKPKNpGyz9PEVP04GAn7DcdAXeE+QOHdA9wEQ=; b=YU8SMZ0DB5QM1RstV/jAHNoU7k1LEop/pnGq69kl1Vl980qwgar96104F6CqGQlKNl a7dwBxAJ4bXsxtM3Oj++/sU50fMsq+ETJYVPFuAc6zOwh8BUkQa5qoyw4Xqlnklpb/Wg 4NqkYzCHyh8LxYOiTFJfFJZcYitppqRqDOSmhEHSubWson8Mezo4Z6lsFtSeMJXDSibq vGrO2YdD+H6fbIA2xvza/PAU0szAq3bn6uCXHtnKZ/ErPlYrwuANkdXVGCyPTlnyEAQ/ ziknpCztoT9yTPrdEAi3g7egpFEvbR9X+lB1x35qBkKDWut8GQQL+rcvuDWNKK7eh9XL xxtQ== X-Gm-Message-State: ALyK8tKZATOIhM3PhoNJw3a+fFVSDBlEjJ3HRHs/ciwHcQ34dvKN8+k6XzRKNCiEV+UKTG44iIabPye5lLZE3w== X-Received: by 10.31.164.129 with SMTP id n123mr7912148vke.21.1465861043936; Mon, 13 Jun 2016 16:37:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.19.198 with HTTP; Mon, 13 Jun 2016 16:37:23 -0700 (PDT) In-Reply-To: References: From: Uros Bizjak Date: Tue, 14 Jun 2016 01:37:23 +0200 Message-ID: Subject: Re: [PATCH, i386]: Introduce __builtin_signbitq to use SSE4.1 PTEST insn To: Joseph Myers Cc: "gcc-patches@gcc.gnu.org" On Tue, Jun 14, 2016 at 12:50 AM, Uros Bizjak wrote: > On Mon, Jun 13, 2016 at 11:54 PM, Joseph Myers wrote: > >>> Attached patch intriduces __builtin_signbitq built-in function, so the >>> compiler will be able to use SSE4.1 PTEST instruction to determine >>> sign bit of __float128 value. >> >> The __builtin_signbit function is type-generic from GCC 6 onwards, so I >> don't see any need for this type-specific function. (The .md pattern may >> still be useful, of course, for better expansion of type-generic >> __builtin_signbit on float128 arguments.) >> >>> The patch introduces complete infrastructure, including fallback to >>> __signbittf2 libgcc function for non-SSE4.1 targets. >> >> I don't see any need for a libgcc fallback either. Generic code in GCC >> should always be able to implement signbit using bit-manipulation, without >> needing any library fallback. After some more head scratching, I have reverted my v1 patch and committed the following revision. It works like magic, without any libgcc fallbacks. Thanks for guiding me to the right direction, and sorry for the troubles! 2016-06-13 Uros Bizjak * config/i386/i386.md (signbittf2): New expander. * config/i386/sse.md (ptesttf2): New insn pattern. testsuite/ChangeLog: 2016-06-13 Uros Bizjak * gcc.target/i386/float128-3.c: New test. * gcc.target/i386/quad-sse4.c: Ditto. * gcc.target/i386/quad-sse.c: Use -msse instead of -msse2. Update scan strings. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline SVN. Uros. Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 237382) +++ config/i386/i386.md (working copy) @@ -16198,6 +16198,22 @@ DONE; }) +(define_expand "signbittf2" + [(use (match_operand:SI 0 "register_operand")) + (use (match_operand:TF 1 "register_operand"))] + "TARGET_SSE4_1" +{ + rtx mask = ix86_build_signbit_mask (TFmode, 0, 0); + rtx scratch = gen_reg_rtx (QImode); + + emit_insn (gen_ptesttf2 (operands[1], mask)); + ix86_expand_setcc (scratch, NE, + gen_rtx_REG (CCZmode, FLAGS_REG), const0_rtx); + + emit_insn (gen_zero_extendqisi2 (operands[0], scratch)); + DONE; +}) + (define_expand "signbitxf2" [(use (match_operand:SI 0 "register_operand")) (use (match_operand:XF 1 "register_operand"))] Index: config/i386/sse.md =================================================================== --- config/i386/sse.md (revision 237380) +++ config/i386/sse.md (working copy) @@ -15212,6 +15212,19 @@ (const_string "*"))) (set_attr "mode" "")]) +(define_insn "ptesttf2" + [(set (reg:CC FLAGS_REG) + (unspec:CC [(match_operand:TF 0 "register_operand" "Yr, *x, x") + (match_operand:TF 1 "vector_operand" "YrBm, *xBm, xm")] + UNSPEC_PTEST))] + "TARGET_SSE4_1" + "%vptest\t{%1, %0|%0, %1}" + [(set_attr "isa" "noavx,noavx,avx") + (set_attr "type" "ssecomi") + (set_attr "prefix_extra" "1") + (set_attr "prefix" "orig,orig,vex") + (set_attr "mode" "TI")]) + (define_insn "_round" [(set (match_operand:VF_128_256 0 "register_operand" "=Yr,*x,x") (unspec:VF_128_256 Index: testsuite/gcc.target/i386/float128-3.c =================================================================== --- testsuite/gcc.target/i386/float128-3.c (nonexistent) +++ testsuite/gcc.target/i386/float128-3.c (working copy) @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -msse4.1" } */ +/* { dg-require-effective-target sse4 } */ + +#include "sse4_1-check.h" + +int signbit (__float128); + +extern void abort (void); + +static void +sse4_1_test (void) +{ + static volatile __float128 a; + + a = -1.2q; + if (!signbit (a)) + abort (); + + a = 1.2q; + if (signbit (a)) + abort (); +} Index: gcc/testsuite/gcc.target/i386/quad-sse.c =================================================================== --- gcc/testsuite/gcc.target/i386/quad-sse.c (revision 237380) +++ gcc/testsuite/gcc.target/i386/quad-sse.c (working copy) @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -msse2" } */ +/* { dg-options "-O2 -msse" } */ __float128 x, y; @@ -18,4 +18,4 @@ __float128 test_3(void) return __builtin_copysignq (x, y); } -/* { dg-final { scan-assembler-not "call.*(neg|fabs|copysign)" } } */ +/* { dg-final { scan-assembler-not "neg|fabs|copysign" } } */ Index: testsuite/gcc.target/i386/quad-sse4.c =================================================================== --- testsuite/gcc.target/i386/quad-sse4.c (nonexistent) +++ testsuite/gcc.target/i386/quad-sse4.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -msse4.1" } */ + +int signbit (__float128); + +__float128 x; + +int __test_1(void) +{ + return signbit (x); +} + +/* { dg-final { scan-assembler-not "signbit" } } */