From patchwork Fri May 25 08:42:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 136818 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3302925lji; Fri, 25 May 2018 01:48:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrQei4k1sNKOg59m/bM7JBaHN7tWM1XtB9L0gzPTjOy/gDtPCm5etUMzzMm3SuRO50LnOuO X-Received: by 2002:a17:902:76c4:: with SMTP id j4-v6mr1674908plt.257.1527238106148; Fri, 25 May 2018 01:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527238106; cv=none; d=google.com; s=arc-20160816; b=R1Of+xQsxF3YxI8sKclxAaIrKVH4AgDzMaki2HREsy5Pqcv+oPtRc9a/dp4oyq1egL C+Gh//yhYFH+82qxujiKOjzWyeG9xcCypWJVIHXHZccl8VJBNnBiJ9eBd/U52pgzvOTf CmKERLEewyvSixm55DRWXRK0cKCF5YunUZ7lwQrFXSmYPC2laE6irQEUi4U/qoVQ7XMN kMKlXOvBFRM3iEWda78TmRYcG8chqCC3F1URiz0E5/BiY+zksnBz3vAZftm4s40ByENZ u5dTNWr5E5270XZEtAlQ2nyuRDOHBwYwkcVVjS+jPAwuDRLXs7bKQEG5ydB1McBDg9vz 4xPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=co0mkVBb5CbaFQSJfSGsrbZVVMjGkfBGwyb0vv29a24=; b=kj+C5PHma+RQAs1Cz3MRa9Apk6jXJaO6NCMy9UhVYWlac8hMgcsYg7LIzgaSXIE1UH N2EG5h3O2nuTYBDbwhbZqHkv1cEoGtXJsAuLjK2zZn6QukBK2NIvx5iFQWtaSNhu2jdc x7GFznIjaxfuPXHawvPOwPKXIAxw/Hh/1e/zrCl2VxicE2BAnSwe93toCU1r3IBMdwdH nNf+QZ0lnYQf91f9XzIR7qvspEowlxL8ocdVygIqqmfF7t2nk8ziQAphf4vdiZMPXu9M zacI+MHUgn4p88PKUtS2dkFiHmEECL/9AbYSytoq+iU3uFzXQEdSUMenKQa45DcxXALV U5YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VudBngj4; spf=pass (google.com: domain of gcc-patches-return-478486-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478486-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id n4-v6si23463095pfa.66.2018.05.25.01.48.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 01:48:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478486-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VudBngj4; spf=pass (google.com: domain of gcc-patches-return-478486-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478486-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=YFoG+YjW9enGVwKc9m92a+MmTcxiqHro3ySBYjLPN1HiIHAZtV99/ UaVstyQJ/FZSCzKlE4rbP6qESQ0G3MUIpmNh3vZMKJrfbA1DF8IyL/l3ROe+SOvp y7OLtUnyKsYmXdZfVF2whLQAWueCflZUmVkj/8ilJ6zB73lVDvyoY8= 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 :to:subject:date:message-id:mime-version:content-type; s= default; bh=jVAFDzipRk1Si4AvLLEwlQXNZlw=; b=VudBngj4UhkzwZlxruBk h1bZYRKr/JtVCL0iA0C++Cl+FgCHDnIYHJxnOzGoBrlq3TPWikLPTV+oQnozlKVO J9LCGx90FVuHGXAEKATu0BxUClcSIv2t5fq83MZLJ6pn59jMhp83gVfFV6rHg3ce yrbTbBe193gM4X7rv7eVtgk= Received: (qmail 31164 invoked by alias); 25 May 2018 08:43:14 -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 30749 invoked by uid 89); 25 May 2018 08:43:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=save-temps, savetemps X-HELO: mail-wm0-f45.google.com Received: from mail-wm0-f45.google.com (HELO mail-wm0-f45.google.com) (74.125.82.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 May 2018 08:42:59 +0000 Received: by mail-wm0-f45.google.com with SMTP id a67-v6so12144507wmf.3 for ; Fri, 25 May 2018 01:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=co0mkVBb5CbaFQSJfSGsrbZVVMjGkfBGwyb0vv29a24=; b=kgkKUmcH4Rg9bKEKDGB3KPIp+bHes2d5l2CL+M63a+Udvq7HRgUwKLhRKKIyOXVdp7 HXWegS+BAxP+p4B4obg+TdgiEytmHfzi+QDt1gqMeYsiSoHSza8ZjME02YAwZ/5FR0dl LCLflmY450VVN2OVTMH8eK72KMIgzwOjbrwYt91IFko9aF+p6C16JiaUu5g15u/UUxfr qPlc3hWjX6oQlNyI962A0f+kKi0aPlVDmxzcl69+mZmwUrgna2jJHJon+q4SZVBggCe2 +Jvo7kLDjNm+LdgfUXoJ0oZHe8dNBa79rk2aLM0qzZKi6XHNH0LozEfRwTTG8cLqJAqN tWpw== X-Gm-Message-State: ALKqPwe3f9CE0sMtgmoNOl4VmjKlXwZWvMmE8OQjtl7tVnZvxA1IZmeS 9wSfhoBebRAgbs6AOULrnofVdBgXypg= X-Received: by 2002:a1c:c355:: with SMTP id t82-v6mr988981wmf.129.1527237777140; Fri, 25 May 2018 01:42:57 -0700 (PDT) Received: from localhost (144.69.7.51.dyn.plus.net. [51.7.69.144]) by smtp.gmail.com with ESMTPSA id b204-v6sm648546wmh.22.2018.05.25.01.42.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 May 2018 01:42:56 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [committed][AArch64] Add SVE support for integer division Date: Fri, 25 May 2018 09:42:55 +0100 Message-ID: <874liwcei8.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 After the previous patch to prevent pessimisation of divisions by constants, this patch adds support for the SVE integer division instructions. Tested on aarch64-linux-gnu (with and without SVE) and aarch64_be-elf. Committed as r260712. Richard 2018-05-25 Richard Sandiford gcc/ * config/aarch64/iterators.md (SVE_INT_BINARY_SD): New code iterator. (optab, sve_int_op): Handle div and udiv. * config/aarch64/aarch64-sve.md (3): New expander for SVE_INT_BINARY_SD. (*3): New insn for the same. gcc/testsuite/ * gcc.target/aarch64/sve/div_1.c: New test. * gcc.target/aarch64/sve/div_1_run.c: Likewise. * gcc.target/aarch64/sve/mul_highpart_2.c: Likewise. * gcc.target/aarch64/sve/mul_highpart_2_run.c: Likewise. Index: gcc/config/aarch64/iterators.md =================================================================== --- gcc/config/aarch64/iterators.md 2018-05-25 09:08:34.079950643 +0100 +++ gcc/config/aarch64/iterators.md 2018-05-25 09:28:55.825421996 +0100 @@ -1207,6 +1207,8 @@ (define_code_iterator SVE_INT_BINARY [pl (define_code_iterator SVE_INT_BINARY_REV [minus]) +(define_code_iterator SVE_INT_BINARY_SD [div udiv]) + ;; SVE integer comparisons. (define_code_iterator SVE_INT_CMP [lt le eq ne ge gt ltu leu geu gtu]) @@ -1237,6 +1239,8 @@ (define_code_attr optab [(ashift "ashl") (neg "neg") (plus "add") (minus "sub") + (div "div") + (udiv "udiv") (ss_plus "qadd") (us_plus "qadd") (ss_minus "qsub") @@ -1378,6 +1382,8 @@ (define_mode_attr lconst_atomic [(QI "K" ;; The integer SVE instruction that implements an rtx code. (define_code_attr sve_int_op [(plus "add") (minus "sub") + (div "sdiv") + (udiv "udiv") (neg "neg") (smin "smin") (smax "smax") Index: gcc/config/aarch64/aarch64-sve.md =================================================================== --- gcc/config/aarch64/aarch64-sve.md 2018-05-25 09:08:34.077950721 +0100 +++ gcc/config/aarch64/aarch64-sve.md 2018-05-25 09:28:55.825421996 +0100 @@ -1008,6 +1008,36 @@ (define_insn "*mul3_highpart" "mulh\t%0., %1/m, %0., %3." ) +;; Unpredicated division. +(define_expand "3" + [(set (match_operand:SVE_SDI 0 "register_operand") + (unspec:SVE_SDI + [(match_dup 3) + (SVE_INT_BINARY_SD:SVE_SDI + (match_operand:SVE_SDI 1 "register_operand") + (match_operand:SVE_SDI 2 "register_operand"))] + UNSPEC_MERGE_PTRUE))] + "TARGET_SVE" + { + operands[3] = force_reg (mode, CONSTM1_RTX (mode)); + } +) + +;; Division predicated with a PTRUE. +(define_insn "*3" + [(set (match_operand:SVE_SDI 0 "register_operand" "=w, w") + (unspec:SVE_SDI + [(match_operand: 1 "register_operand" "Upl, Upl") + (SVE_INT_BINARY_SD:SVE_SDI + (match_operand:SVE_SDI 2 "register_operand" "0, w") + (match_operand:SVE_SDI 3 "aarch64_sve_mul_operand" "w, 0"))] + UNSPEC_MERGE_PTRUE))] + "TARGET_SVE" + "@ + \t%0., %1/m, %0., %3. + r\t%0., %1/m, %0., %2." +) + ;; Unpredicated NEG, NOT and POPCOUNT. (define_expand "2" [(set (match_operand:SVE_I 0 "register_operand") Index: gcc/testsuite/gcc.target/aarch64/sve/div_1.c =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/div_1.c 2018-05-25 09:28:55.826421957 +0100 @@ -0,0 +1,26 @@ +/* { dg-do assemble { target aarch64_asm_sve_ok } } */ +/* { dg-options "-O2 -ftree-vectorize -fno-vect-cost-model --save-temps" } */ + +#include + +#define DEF_LOOP(TYPE) \ +void __attribute__ ((noipa)) \ +mod_##TYPE (TYPE *restrict dst, TYPE *restrict src1, \ + TYPE *restrict src2, int count) \ +{ \ + for (int i = 0; i < count; ++i) \ + dst[i] = src1[i] / src2[i]; \ +} + +#define TEST_ALL(T) \ + T (int32_t) \ + T (uint32_t) \ + T (int64_t) \ + T (uint64_t) + +TEST_ALL (DEF_LOOP) + +/* { dg-final { scan-assembler-times {\tsdiv\tz[0-9]+\.s, p[0-7]/m, z[0-9]+\.s, z[0-9]+\.s\n} 1 } } */ +/* { dg-final { scan-assembler-times {\tudiv\tz[0-9]+\.s, p[0-7]/m, z[0-9]+\.s, z[0-9]+\.s\n} 1 } } */ +/* { dg-final { scan-assembler-times {\tsdiv\tz[0-9]+\.d, p[0-7]/m, z[0-9]+\.d, z[0-9]+\.d\n} 1 } } */ +/* { dg-final { scan-assembler-times {\tudiv\tz[0-9]+\.d, p[0-7]/m, z[0-9]+\.d, z[0-9]+\.d\n} 1 } } */ Index: gcc/testsuite/gcc.target/aarch64/sve/div_1_run.c =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/div_1_run.c 2018-05-25 09:28:55.826421957 +0100 @@ -0,0 +1,30 @@ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-O2 -ftree-vectorize -fno-vect-cost-model --save-temps" } */ + +#include "div_1.c" + +#define N 79 + +#define TEST_LOOP(TYPE) \ + { \ + TYPE dst[N], src1[N], src2[N]; \ + for (int i = 0; i < N; ++i) \ + { \ + src1[i] = i * 7 + i % 3; \ + if (i % 11 > 7) \ + src1[i] = -src1[i]; \ + src2[i] = 5 + (i % 5); \ + asm volatile ("" ::: "memory"); \ + } \ + mod_##TYPE (dst, src1, src2, N); \ + for (int i = 0; i < N; ++i) \ + if (dst[i] != src1[i] / src2[i]) \ + __builtin_abort (); \ + } + +int +main (void) +{ + TEST_ALL (TEST_LOOP); + return 0; +} Index: gcc/testsuite/gcc.target/aarch64/sve/mul_highpart_2.c =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/mul_highpart_2.c 2018-05-25 09:28:55.826421957 +0100 @@ -0,0 +1,25 @@ +/* { dg-do assemble { target aarch64_asm_sve_ok } } */ +/* { dg-options "-O2 -ftree-vectorize -fno-vect-cost-model --save-temps" } */ + +#include + +#define DEF_LOOP(TYPE) \ +void __attribute__ ((noipa)) \ +mod_##TYPE (TYPE *dst, TYPE *src, int count) \ +{ \ + for (int i = 0; i < count; ++i) \ + dst[i] = src[i] / 17; \ +} + +#define TEST_ALL(T) \ + T (int32_t) \ + T (uint32_t) \ + T (int64_t) \ + T (uint64_t) + +TEST_ALL (DEF_LOOP) + +/* { dg-final { scan-assembler-times {\tsmulh\tz[0-9]+\.s, p[0-7]/m, z[0-9]+\.s, z[0-9]+\.s\n} 1 } } */ +/* { dg-final { scan-assembler-times {\tumulh\tz[0-9]+\.s, p[0-7]/m, z[0-9]+\.s, z[0-9]+\.s\n} 1 } } */ +/* { dg-final { scan-assembler-times {\tsmulh\tz[0-9]+\.d, p[0-7]/m, z[0-9]+\.d, z[0-9]+\.d\n} 1 } } */ +/* { dg-final { scan-assembler-times {\tumulh\tz[0-9]+\.d, p[0-7]/m, z[0-9]+\.d, z[0-9]+\.d\n} 1 } } */ Index: gcc/testsuite/gcc.target/aarch64/sve/mul_highpart_2_run.c =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/mul_highpart_2_run.c 2018-05-25 09:28:55.826421957 +0100 @@ -0,0 +1,29 @@ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-O2 -ftree-vectorize -fno-vect-cost-model --save-temps" } */ + +#include "mul_highpart_2.c" + +#define N 79 + +#define TEST_LOOP(TYPE) \ + { \ + TYPE dst[N], src[N]; \ + for (int i = 0; i < N; ++i) \ + { \ + src[i] = i * 7 + i % 3; \ + if (i % 11 > 7) \ + src[i] = -src[i]; \ + asm volatile ("" ::: "memory"); \ + } \ + mod_##TYPE (dst, src, N); \ + for (int i = 0; i < N; ++i) \ + if (dst[i] != src[i] / 17) \ + __builtin_abort (); \ + } + +int +main (void) +{ + TEST_ALL (TEST_LOOP); + return 0; +}