From patchwork Wed Jul 29 10:09:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 51625 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id A84FA22DB5 for ; Wed, 29 Jul 2015 10:09:59 +0000 (UTC) Received: by wicmv11 with SMTP id mv11sf5243349wic.1 for ; Wed, 29 Jul 2015 03:09:59 -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:date:message-id:subject:from:to :content-type:x-original-sender:x-original-authentication-results; bh=MHcGPPA2yULAFA9sn2HMETVVyw0RA58e4BRu1zamQHc=; b=MNWI8pLBq/559+3EtYM/BKAtr59nytWlfC7F8qM5iBD0adDE6MWHwaufwyaSf4dLrG aVXzbPDCRHdgijPbWmYbBI4mOfENvVL2Lxw9zd0+F3D0pmoc3aULtK6DEZkJ2j++WiLs /G0QciAVGn3TrUPQiLKUrGep1sB8j/y3qY8+vWbXccgxcuAloHQA13as4KurhjykkmfE 0rqFp/fKqT2aDrT5qDYwm4vaxSvf/FRKH7Lf43OYqgNpVcbxZuoiG5ZMsMzoMwe+Qbrb LD/LHPtI8NG3OhE4jmy9UD69ZVQhI8kv4pQlyg5QUiVCWgDSiYOly3CPJjjtHrh5f8kn HEZg== X-Gm-Message-State: ALoCoQlTEyphrujN5ri5ZFWbzDJyAV4BRAhX/tEnBE210AElINAQFissfNIG/DexA6R4gNa+ixS6 X-Received: by 10.194.184.6 with SMTP id eq6mr15718339wjc.4.1438164599017; Wed, 29 Jul 2015 03:09:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.227 with SMTP id n3ls24179lan.0.gmail; Wed, 29 Jul 2015 03:09:58 -0700 (PDT) X-Received: by 10.112.221.9 with SMTP id qa9mr37614927lbc.23.1438164598343; Wed, 29 Jul 2015 03:09:58 -0700 (PDT) Received: from mail-lb0-x235.google.com (mail-lb0-x235.google.com. [2a00:1450:4010:c04::235]) by mx.google.com with ESMTPS id e14si21097182lbo.160.2015.07.29.03.09.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 03:09:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::235 as permitted sender) client-ip=2a00:1450:4010:c04::235; Received: by lbbqi7 with SMTP id qi7so3561816lbb.3 for ; Wed, 29 Jul 2015 03:09:58 -0700 (PDT) X-Received: by 10.152.9.66 with SMTP id x2mr34291586laa.76.1438164598009; Wed, 29 Jul 2015 03:09:58 -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 l6csp2652392lba; Wed, 29 Jul 2015 03:09:56 -0700 (PDT) X-Received: by 10.70.59.41 with SMTP id w9mr90910484pdq.5.1438164595746; Wed, 29 Jul 2015 03:09:55 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id w10si8511173pas.189.2015.07.29.03.09.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 03:09:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-404184-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 55810 invoked by alias); 29 Jul 2015 10:09:43 -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 55799 invoked by uid 89); 29 Jul 2015 10:09:42 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f181.google.com Received: from mail-yk0-f181.google.com (HELO mail-yk0-f181.google.com) (209.85.160.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 29 Jul 2015 10:09:41 +0000 Received: by ykdu72 with SMTP id u72so3503217ykd.2 for ; Wed, 29 Jul 2015 03:09:39 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.129.44.136 with SMTP id s130mr41263950yws.80.1438164579660; Wed, 29 Jul 2015 03:09:39 -0700 (PDT) Received: by 10.37.88.137 with HTTP; Wed, 29 Jul 2015 03:09:39 -0700 (PDT) Date: Wed, 29 Jul 2015 15:39:39 +0530 Message-ID: Subject: [ARM] implement division using vrecpe/vrecps with -funsafe-math-optimizations From: Prathamesh Kulkarni To: 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::235 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 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 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..28c2e2a 100644 --- a/gcc/config/arm/neon.md +++ b/gcc/config/arm/neon.md @@ -548,6 +548,32 @@ (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 && 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 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; + } +) + + (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" } } */