From patchwork Mon May 20 18:55:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Bolton X-Patchwork-Id: 245091 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 45FCD2C00C9 for ; Tue, 21 May 2013 04:56:23 +1000 (EST) 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:references:in-reply-to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=WeLZQ/2wBhz/qBke5oOF/Cxlt/D95 yqGFrYu0WlI4FLQWE+4Jn1pEkkEI4NcalKiYHGh8xLkLwWl7ffvI0LynTJHi9SoT U+AKz4e5/oMX9Z0KsHl7iv7H3x9NBK8UIzbkZfo0aM1WXUtms8RuId0q/rPiEg9z C9+fb/F3Ru9NVo= 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:references:in-reply-to:subject:date:message-id:mime-version :content-type; s=default; bh=Nvyx+0EW0XmNBaO36a/qJZb+198=; b=NSg r1UaP2WgD0K8lDYKJxViCyTa6InD992DftIcHQcUMslMXcO0txqGuFpVID4DPiZz FjD6llzOPK5LTA0I39SfSvRGFqzp9+9rTj7RWXYMzFQgML5+gELDSXm8hsOTWEgB irAPsMoDl/aDfubVx4Hq595dfQ7o8ZO3Rk+2F/rA= Received: (qmail 6656 invoked by alias); 20 May 2013 18:56:15 -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 6642 invoked by uid 89); 20 May 2013 18:56:14 -0000 X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, MSGID_MULTIPLE_AT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 20 May 2013 18:56:13 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 20 May 2013 19:56:10 +0100 Received: from E102352xp ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 20 May 2013 19:56:08 +0100 From: "Ian Bolton" To: References: <000101ce4bd2$6f17d010$4d477030$@bolton@arm.com> In-Reply-To: <000101ce4bd2$6f17d010$4d477030$@bolton@arm.com> Subject: RE: [PATCH, AArch64] Support BFI instruction and insv standard pattern Date: Mon, 20 May 2013 19:55:31 +0100 Message-ID: <000401ce558b$9a28bfe0$ce7a3fa0$@bolton@arm.com> MIME-Version: 1.0 X-MC-Unique: 113052019561001701 X-Virus-Found: No > Hi, > > This patch implements the BFI variant of BFM. In doing so, it also > implements the insv standard pattern. > > I've regression tested on bare-metal and linux. > > It comes complete with its own compilation and execution testcase. > > OK for trunk? > > Cheers, > Ian > > > 2013-05-08 Ian Bolton > > gcc/ > * config/aarch64/aarch64.md (insv): New define_expand. > (*insv_reg): New define_insn. > > testsuite/ > * gcc.target/aarch64/bfm_1.c: New test. (This patch did not yet get commit approval.) I improved this patch during the work I did on the recent insv_imm patch (http://gcc.gnu.org/ml/gcc-patches/2013-05/msg01007.html). I also renamed the testcase. Regression testing completed successfully. OK for trunk? Cheers, Ian 2013-05-20 Ian Bolton gcc/ * config/aarch64/aarch64.md (insv): New define_expand. (*insv_reg): New define_insn. testsuite/ * gcc.target/aarch64/insv_1.c: New test. diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index b27bcda..e5d6950 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -3164,6 +3164,52 @@ (set_attr "mode" "")] ) +;; Bitfield Insert (insv) +(define_expand "insv" + [(set (zero_extract:GPI (match_operand:GPI 0 "register_operand") + (match_operand 1 "const_int_operand") + (match_operand 2 "const_int_operand")) + (match_operand:GPI 3 "general_operand"))] + "" +{ + unsigned HOST_WIDE_INT width = UINTVAL (operands[1]); + unsigned HOST_WIDE_INT pos = UINTVAL (operands[2]); + rtx value = operands[3]; + + if (width == 0 || (pos + width) > GET_MODE_BITSIZE (mode)) + FAIL; + + if (CONST_INT_P (value)) + { + unsigned HOST_WIDE_INT mask = ((unsigned HOST_WIDE_INT)1 << width) - 1; + + /* Prefer AND/OR for inserting all zeros or all ones. */ + if ((UINTVAL (value) & mask) == 0 + || (UINTVAL (value) & mask) == mask) + FAIL; + + /* Force the constant into a register, unless this is a 16-bit aligned + 16-bit wide insert, which is handled by insv_imm. */ + if (width != 16 || (pos % 16) != 0) + operands[3] = force_reg (mode, value); + } + else if (!register_operand (value, mode)) + operands[3] = force_reg (mode, value); +}) + +(define_insn "*insv_reg" + [(set (zero_extract:GPI (match_operand:GPI 0 "register_operand" "+r") + (match_operand 1 "const_int_operand" "n") + (match_operand 2 "const_int_operand" "n")) + (match_operand:GPI 3 "register_operand" "r"))] + "!(UINTVAL (operands[1]) == 0 + || (UINTVAL (operands[2]) + UINTVAL (operands[1]) + > GET_MODE_BITSIZE (mode)))" + "bfi\\t%0, %3, %2, %1" + [(set_attr "v8type" "bfm") + (set_attr "mode" "")] +) + (define_insn "*_shft_" [(set (match_operand:GPI 0 "register_operand" "=r") (ashift:GPI (ANY_EXTEND:GPI diff --git a/gcc/testsuite/gcc.target/aarch64/insv_1.c b/gcc/testsuite/gcc.target/aarch64/insv_1.c new file mode 100644 index 0000000..0977e15 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/insv_1.c @@ -0,0 +1,84 @@ +/* { dg-do run } */ +/* { dg-options "-O2 --save-temps -fno-inline" } */ + +extern void abort (void); + +typedef struct bitfield +{ + unsigned short eight: 8; + unsigned short four: 4; + unsigned short five: 5; + unsigned short seven: 7; + unsigned int sixteen: 16; +} bitfield; + +bitfield +bfi1 (bitfield a) +{ + /* { dg-final { scan-assembler "bfi\tx\[0-9\]+, x\[0-9\]+, 0, 8" } } */ + a.eight = 3; + return a; +} + +bitfield +bfi2 (bitfield a) +{ + /* { dg-final { scan-assembler "bfi\tx\[0-9\]+, x\[0-9\]+, 16, 5" } } */ + a.five = 7; + return a; +} + +bitfield +movk (bitfield a) +{ + /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0x1d6b, lsl 32" } } */ + a.sixteen = 7531; + return a; +} + +bitfield +set1 (bitfield a) +{ + /* { dg-final { scan-assembler "orr\tx\[0-9\]+, x\[0-9\]+, 2031616" } } */ + a.five = 0x1f; + return a; +} + +bitfield +set0 (bitfield a) +{ + /* { dg-final { scan-assembler "and\tx\[0-9\]+, x\[0-9\]+, -2031617" } } */ + a.five = 0; + return a; +} + + +int +main (int argc, char** argv) +{ + static bitfield a; + bitfield b = bfi1 (a); + bitfield c = bfi2 (b); + bitfield d = movk (c); + + if (d.eight != 3) + abort (); + + if (d.five != 7) + abort (); + + if (d.sixteen != 7531) + abort (); + + d = set1 (d); + if (d.five != 0x1f) + abort (); + + d = set0 (d); + if (d.five != 0) + abort (); + + return 0; +} + +/* { dg-final { cleanup-saved-temps } } */