From patchwork Thu Jul 30 21:10:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 51728 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 7EBD822D9C for ; Thu, 30 Jul 2015 21:10:43 +0000 (UTC) Received: by wicmm11 with SMTP id mm11sf1825154wic.3 for ; Thu, 30 Jul 2015 14:10:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:mime-version:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-original-sender :x-original-authentication-results; bh=/aeHiSO4muMAcLwP/U4Ll57x+2oyN7hM+twYH7kiw4M=; b=UW7M6rTZ2F2pSVKr6fG8NHXkilFsCMCqr/xG9Q7j+erao79CFTaq9yXYZn50ZF4z9U raukupsVSIYr5En4uGveUTIVIzfYzWORqSXAiGeyP0vsuPpZKFIl9qWoUke2IhAlNte2 +J0+st1VK2589DNq6uT+rK2oCLZaADz70NnzERhLTvp/y5uRIdGwXJkYIVdLNXo1jUXy hiNZ6K8iPn0ooSOklMSib4SqCjzB63cYYoiXjm4mERC2KNR7+8YLXwJHhFtYW6x8UyNN vSxCJmyOZ3nnhGdGSTdy70kO3xMKCajoe1H1fb/dFc2nLlsaf7H2W+5k2OTnElxuPY1e Zlxg== X-Gm-Message-State: ALoCoQms3ZXFsKQszyhYxQ4TWbmwXwcxs8GAI1aNphVdrwgsVPNMVYh/glrPDD03OvykrCqdm/FT X-Received: by 10.112.181.37 with SMTP id dt5mr18479835lbc.10.1438290642798; Thu, 30 Jul 2015 14:10:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.196 with SMTP id d4ls257917laa.91.gmail; Thu, 30 Jul 2015 14:10:42 -0700 (PDT) X-Received: by 10.112.139.131 with SMTP id qy3mr46028033lbb.4.1438290642640; Thu, 30 Jul 2015 14:10:42 -0700 (PDT) Received: from mail-lb0-x231.google.com (mail-lb0-x231.google.com. [2a00:1450:4010:c04::231]) by mx.google.com with ESMTPS id lk12si1753030lac.139.2015.07.30.14.10.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2015 14:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::231 as permitted sender) client-ip=2a00:1450:4010:c04::231; Received: by lbbud7 with SMTP id ud7so30996419lbb.3 for ; Thu, 30 Jul 2015 14:10:42 -0700 (PDT) X-Received: by 10.152.18.162 with SMTP id x2mr46640087lad.73.1438290641928; Thu, 30 Jul 2015 14:10:41 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp848295lba; Thu, 30 Jul 2015 14:10:40 -0700 (PDT) X-Received: by 10.70.50.3 with SMTP id y3mr109927637pdn.90.1438290639462; Thu, 30 Jul 2015 14:10:39 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ei6si4948312pdb.74.2015.07.30.14.10.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2015 14:10:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-404342-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 52725 invoked by alias); 30 Jul 2015 21:10:24 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 52652 invoked by uid 89); 30 Jul 2015 21:10:20 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, ZIP_ATTACHED autolearn=no version=3.3.2 X-HELO: mail-yk0-f180.google.com Received: from mail-yk0-f180.google.com (HELO mail-yk0-f180.google.com) (209.85.160.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 30 Jul 2015 21:10:18 +0000 Received: by ykax123 with SMTP id x123so44479699yka.1 for ; Thu, 30 Jul 2015 14:10:16 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.13.248.68 with SMTP id i65mr51513048ywf.151.1438290616749; Thu, 30 Jul 2015 14:10:16 -0700 (PDT) Received: by 10.37.88.137 with HTTP; Thu, 30 Jul 2015 14:10:16 -0700 (PDT) In-Reply-To: <55B8AC02.9050301@arm.com> References: <55B8AC02.9050301@arm.com> Date: Fri, 31 Jul 2015 02:40:16 +0530 Message-ID: Subject: Re: [ARM] implement division using vrecpe/vrecps with -funsafe-math-optimizations From: Prathamesh Kulkarni To: Kyrill Tkachov Cc: gcc Patches , Charles Baylis X-IsSubscribed: yes X-Original-Sender: prathamesh.kulkarni@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::231 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 On 29 July 2015 at 16:03, Kyrill Tkachov wrote: > Hi Prathamesh, > > This is probably not appropriate for -Os optimisation. > And for speed optimisation I imagine it can vary a lot on the target the > code is run. > Do you have any benchmark results for this patch? Hi Kyrill, Thanks for the review. I have attempted to address your comments in the attached patch. Does it look OK from correctness perspective ? Unfortunately I haven't done benchmarking yet. I ran a test-case (attached) prepared by Charles for target arm-linux-gnueabihf (on APM Mustang), and it appeared to run faster with the patch: Options passed: -O3 -mfpu=neon -mfloat-abi=hard -funsafe-math-optimizations Before: t8a, len = 32, took 2593977 ticks t8a, len = 128, took 2408907 ticks t8a, len = 1024, took 2354950 ticks t8a, len = 65536, took 2365041 ticks t8a, len = 1048576, took 2692928 ticks After: t8a, len = 32, took 2027323 ticks t8a, len = 128, took 1920595 ticks t8a, len = 1024, took 1827250 ticks t8a, len = 65536, took 1797924 ticks t8a, len = 1048576, took 2026274 ticks I will get back to you soon with benchmarking results. Thanks, Prathamesh > > Thanks, > Kyrill > > > On 29/07/15 11:09, Prathamesh Kulkarni wrote: >> >> Hi, >> This patch tries to implement division with multiplication by >> reciprocal using vrecpe/vrecps >> with -funsafe-math-optimizations and -freciprocal-math enabled. >> Tested on arm-none-linux-gnueabihf using qemu. >> OK for trunk ? >> >> Thank you, >> Prathamesh > > + /* Perform 2 iterations of Newton-Raphson method for better accuracy */ > + for (int i = 0; i < 2; i++) > + { > + emit_insn (gen_neon_vrecps (vrecps_temp, rec, operands[2])); > + emit_insn (gen_mul3 (rec, rec, vrecps_temp)); > + } > + > + /* We now have reciprocal in rec, perform operands[0] = operands[1] * > rec */ > + emit_insn (gen_mul3 (operands[0], operands[1], rec)); > + DONE; > + } > +) > + > > Full stop and two spaces at the end of the comments. > 2015-07-28 Prathamesh Kulkarni Charles Baylis * config/arm/neon.md (div3): New pattern. testsuite/ * gcc.target/arm/vect-div-1.c: New test-case. * gcc.target/arm/vect-div-2.c: Likewise. diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md index 654d9d5..f2dbcc4 100644 --- a/gcc/config/arm/neon.md +++ b/gcc/config/arm/neon.md @@ -548,6 +548,33 @@ (const_string "neon_mul_")))] ) +(define_expand "div3" + [(set (match_operand:VCVTF 0 "s_register_operand" "=w") + (div:VCVTF (match_operand:VCVTF 1 "s_register_operand" "w") + (match_operand:VCVTF 2 "s_register_operand" "w")))] + "TARGET_NEON && !optimize_size + && flag_unsafe_math_optimizations && flag_reciprocal_math" + { + rtx rec = gen_reg_rtx (mode); + rtx vrecps_temp = gen_reg_rtx (mode); + + /* Reciprocal estimate. */ + emit_insn (gen_neon_vrecpe (rec, operands[2])); + + /* Perform 2 iterations of newton-raphson method. */ + for (int i = 0; i < 2; i++) + { + emit_insn (gen_neon_vrecps (vrecps_temp, rec, operands[2])); + emit_insn (gen_mul3 (rec, rec, vrecps_temp)); + } + + /* We now have reciprocal in rec, perform operands[0] = operands[1] * rec. */ + emit_insn (gen_mul3 (operands[0], operands[1], rec)); + DONE; + } +) + + (define_insn "mul3add_neon" [(set (match_operand:VDQW 0 "s_register_operand" "=w") (plus:VDQW (mult:VDQW (match_operand:VDQW 2 "s_register_operand" "w") diff --git a/gcc/testsuite/gcc.target/arm/vect-div-1.c b/gcc/testsuite/gcc.target/arm/vect-div-1.c new file mode 100644 index 0000000..e562ef3 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/vect-div-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target arm_v8_neon_ok } */ +/* { dg-options "-O2 -funsafe-math-optimizations -ftree-vectorize -fdump-tree-vect-all" } */ +/* { dg-add-options arm_v8_neon } */ + +void +foo (int len, float * __restrict p, float *__restrict x) +{ + len = len & ~31; + for (int i = 0; i < len; i++) + p[i] = p[i] / x[i]; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ diff --git a/gcc/testsuite/gcc.target/arm/vect-div-2.c b/gcc/testsuite/gcc.target/arm/vect-div-2.c new file mode 100644 index 0000000..8e15d0a --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/vect-div-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target arm_v8_neon_ok } */ +/* { dg-options "-O2 -funsafe-math-optimizations -fno-reciprocal-math -ftree-vectorize -fdump-tree-vect-all" } */ +/* { dg-add-options arm_v8_neon } */ + +void +foo (int len, float * __restrict p, float *__restrict x) +{ + len = len & ~31; + for (int i = 0; i < len; i++) + p[i] = p[i] / x[i]; +} + +/* { dg-final { scan-tree-dump-times "vectorized 0 loops" 1 "vect" } } */