From patchwork Thu Oct 31 18:43:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 287586 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7196C2C03EB for ; Fri, 1 Nov 2013 05:43:35 +1100 (EST) 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:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=Oaw7uhkvDBUGB+OxVu BMHxtQH5y7Xytk0G1DevJwv+FENnNQ3ArvCdWeY0JiTcxCoC1EyDOlb7EIVFa/je 2fdYX8BkZCvhjXq/zimGQrbKqxxaiQo3KQ4L26zT1jw4jB/tsEoUd7NGHPK8SjM0 gT27I2+IbUKTtqI2XpQA6WvyY= 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:date:message-id:subject :from:to:cc:content-type; s=default; bh=3M40CZJzv3JvZJeioQuWKz3m cHM=; b=TQQSlk0C5OY/CxP3GuSLyYlHb4Ijrm+FRK7OoG1j9+0tPrIMC4NhUxc4 /LKPPTPhLuRDcQ7XTqSXWZAIq+e/laWLQQsnv2RGpAcw+V+8GJ45Pnc5/9bmDcbG 3ND23ICKzAZtdt/fmDmll12SW3YJtEv8SzjT1ZUVorhUbnyC08U= Received: (qmail 19132 invoked by alias); 31 Oct 2013 18:43:27 -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 19115 invoked by uid 89); 31 Oct 2013 18:43:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oa0-f53.google.com Received: from mail-oa0-f53.google.com (HELO mail-oa0-f53.google.com) (209.85.219.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 31 Oct 2013 18:43:26 +0000 Received: by mail-oa0-f53.google.com with SMTP id n12so3561160oag.12 for ; Thu, 31 Oct 2013 11:43:24 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.60.134.14 with SMTP id pg14mr2935165oeb.66.1383245004443; Thu, 31 Oct 2013 11:43:24 -0700 (PDT) Received: by 10.182.137.136 with HTTP; Thu, 31 Oct 2013 11:43:24 -0700 (PDT) In-Reply-To: References: Date: Thu, 31 Oct 2013 19:43:24 +0100 Message-ID: Subject: Re: [PATCH] Vectorizing abs(char/short/int) on x86. From: Uros Bizjak To: Cong Hou Cc: "gcc-patches@gcc.gnu.org" , Richard Biener , "Joseph S. Myers" On Wed, Oct 30, 2013 at 9:02 PM, Cong Hou wrote: > I have run check_GNU_style.sh on my patch. > > The patch is submitted. Thank you for your comments and help on this patch! I have committed a couple of fixes/improvements to your expander in i386.c. There is no need to check for the result of expand_simple_binop. Also, there is no guarantee that expand_simple_binop will expand to the target. It can return different RTX. Also, unhandled modes are now marked with gcc_unreachable. 2013-10-31 Uros Bizjak * config/i386/i386.c (ix86_expand_sse2_abs): Rename function arguments. Use gcc_unreachable for unhandled modes. Do not check results of expand_simple_binop. If not expanded to target, move the result. Tested on x86_64-pc-linux-gnu and committed. Uros. Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 204264) +++ config/i386/i386.c (working copy) @@ -42020,36 +42020,36 @@ return false; } +/* Calculate integer abs() using only SSE2 instructions. */ + void -ix86_expand_sse2_abs (rtx op0, rtx op1) +ix86_expand_sse2_abs (rtx target, rtx input) { enum machine_mode mode = GET_MODE (op0); - rtx tmp0, tmp1; + rtx tmp0, tmp1, x; switch (mode) { /* For 32-bit signed integer X, the best way to calculate the absolute value of X is (((signed) X >> (W-1)) ^ X) - ((signed) X >> (W-1)). */ case V4SImode: - tmp0 = expand_simple_binop (mode, ASHIFTRT, op1, + tmp0 = expand_simple_binop (mode, ASHIFTRT, input, GEN_INT (GET_MODE_BITSIZE - (GET_MODE_INNER (mode)) - 1), + (GET_MODE_INNER (mode)) - 1), NULL, 0, OPTAB_DIRECT); - if (tmp0) - tmp1 = expand_simple_binop (mode, XOR, op1, tmp0, - NULL, 0, OPTAB_DIRECT); - if (tmp0 && tmp1) - expand_simple_binop (mode, MINUS, tmp1, tmp0, - op0, 0, OPTAB_DIRECT); + tmp1 = expand_simple_binop (mode, XOR, tmp0, input, + NULL, 0, OPTAB_DIRECT); + x = expand_simple_binop (mode, MINUS, tmp1, tmp0, + output, 0, OPTAB_DIRECT); break; /* For 16-bit signed integer X, the best way to calculate the absolute value of X is max (X, -X), as SSE2 provides the PMAXSW insn. */ case V8HImode: tmp0 = expand_unop (mode, neg_optab, op1, NULL_RTX, 0); - if (tmp0) - expand_simple_binop (mode, SMAX, op1, tmp0, op0, 0, - OPTAB_DIRECT); + + x = expand_simple_binop (mode, SMAX, tmp0, input, + output, 0, OPTAB_DIRECT); break; /* For 8-bit signed integer X, the best way to calculate the absolute @@ -42057,14 +42057,17 @@ as SSE2 provides the PMINUB insn. */ case V16QImode: tmp0 = expand_unop (mode, neg_optab, op1, NULL_RTX, 0); - if (tmp0) - expand_simple_binop (V16QImode, UMIN, op1, tmp0, op0, 0, - OPTAB_DIRECT); + + x = expand_simple_binop (V16QImode, UMIN, tmp0, input, + output, 0, OPTAB_DIRECT); break; default: - break; + gcc_unreachable (); } + + if (x != output) + emit_move_insn (output, x); } /* Expand an insert into a vector register through pinsr insn.