From patchwork Fri Aug 20 15:23:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1519079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=A4yt0av0; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Grlm662Mxz9sWd for ; Sat, 21 Aug 2021 01:24:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71E503896C2A for ; Fri, 20 Aug 2021 15:24:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71E503896C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1629473042; bh=WxlHYlfpIEN8btNlFkXTJSjnvmeeGAU5bC9GYiesYLM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A4yt0av0cgLc0ZScRyKI6hNlNzXEJTpRgi5sgHIojV4ZJ+PwEXm7kPAhBv4JHqYDm 8Y8ZPRbaTcCzkFx2ekMiqraTTqMMFdFDVN9r2/sW8/ep+55sP+g9eDbPHCIqDSRQpd rEHRqFc14RrCRM1966vXj69nd8Lpe8pjjJ6tp7ho= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id AB4DA385DC15 for ; Fri, 20 Aug 2021 15:23:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AB4DA385DC15 Received: by mail-pj1-x1036.google.com with SMTP id mq3so7502565pjb.5 for ; Fri, 20 Aug 2021 08:23:41 -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:subject:message-id:date:user-agent :mime-version:content-language; bh=WxlHYlfpIEN8btNlFkXTJSjnvmeeGAU5bC9GYiesYLM=; b=rzV0TojHF6INlWfDJEYu/6dkAjJx/3gn7b0o/gL6e9EsPtBff+KPJtGWgygQEQlV/J Sv/07UrCGD7I2EPngtcApy+Yz9EVw0G9g75wbgvVFbx0uVYtJJUhjLJZWOlX25NHAc4H W+WBQw5Micx+2NzN/Ps04JVeejDGJnSEymeafe6lR4VpcEbMOaw5f1G9BtV4OqSNdOin egdaLgLSwJtAIPUbzq041JnDFHjOfDg9bAkwCrb0cdNXevrPnoiJqMlgsk1n0nNCHIqT 57ZPrfaJf2lvRd0I/Z3OGB4OHltB4AtmOVrahx8bteHLKpKCseSc31aU6MYy5e4rZmx7 i1Xg== X-Gm-Message-State: AOAM533znzpkGkkg/Q3ve3dObginwVac8Xy9rf9uEagXuVbqX40fFUGP 2vHsWiPgk8uFE5yJE7GcKwPeYGxTJYlSBw== X-Google-Smtp-Source: ABdhPJxnaVT2VS0OD5m50EMkV+OiYj+VKZ7vVxT+dV6HyqOCncIt9Sv7+ve26tsT2Z0X54WqZv4j8g== X-Received: by 2002:a17:90b:1a85:: with SMTP id ng5mr5152075pjb.62.1629473020404; Fri, 20 Aug 2021 08:23:40 -0700 (PDT) Received: from [172.31.0.175] (c-98-202-48-222.hsd1.ut.comcast.net. [98.202.48.222]) by smtp.gmail.com with ESMTPSA id a4sm7582398pfk.0.2021.08.20.08.23.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Aug 2021 08:23:39 -0700 (PDT) To: GCC Patches Subject: [committed] Further improvements to constant shifts on H8 Message-ID: <8ecb119a-3d6a-61b9-8a58-27a90f719b9d@gmail.com> Date: Fri, 20 Aug 2021 09:23:39 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jeff Law via Gcc-patches From: Jeff Law Reply-To: Jeff Law Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" A few more shift-by-constant improvements on the H8. For H8/300H arithmetic right shift 15 bits, we'd conceptually like to use the shift-by-16 idiom where we move half-words around.  Of course that loses a bit.  But we can save away that bit into C, shift-by-16, sign-extend, then rotate through the carry one bit the other way.  That saves nearly 100 cycles and is the same size.  We were already using this concept elsewhere. For H8/300H SImode arithmetic rightshift by 28, 29 or 30 bits we use the shift-by-16 + shift-by-8 sequences, sign extend, then handle the residuals inline.  This saves on the order of 200 cycles vs a loop.  THe sequences are larger, but we're stil talking about burning at most 10 bytes of instruction space to save 200 cycles.  Obviously with -Os we revert to the loop sequence. For H8/S HImode logical shift by 12 (right or left) we switch from using a shift-by-8 idiom, clear bits, shift-by-2, shift-by-2 to a 2 rotate by 2 positions + masking sequence which is the same size/speed on the hardware, but should simulate faster as it's one less instruction. For H8/S SImode arithmetic right by 15 bits, we use the same trick as on the H8/300H. For H8/S SImode logical shifts by 27 bits we can shave off 2 more bytes and 2 cycles by using a rotation based sequence over shift-by-16, shift-by-8, shift-by-2, shift-by-1 style sequence. This has gone through the usual simulator testing without regressions. Jeff commit 5f80c6270de6ac79d819de50048b32351a6b97c3 Author: Jeff Law Date: Fri Aug 20 11:19:05 2021 -0400 Further improvements to constant shifts for the H8 gcc/ * config/h8300/h8300.c (shift_alg_hi): Improve arithmetic shift right by 15 bits for H8/300H and H8/S. Improve logical shifts by 12 bits for H8/S. (shift_alg_si): Improve arithmetic right shift by 28-30 bits for H8/300H. Improve arithmetic shift right by 15 bits for H8/S. Improve logical shifts by 27 bits for H8/S. (get_shift_alg): Corresponding changes. (h8300_option_override): Revert to loops for -Os when profitable. diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c index 0c4e5089791..8ccacecba79 100644 --- a/gcc/config/h8300/h8300.c +++ b/gcc/config/h8300/h8300.c @@ -213,9 +213,9 @@ static enum shift_alg shift_alg_hi[2][3][16] = { /* 0 1 2 3 4 5 6 7 */ /* 8 9 10 11 12 13 14 15 */ { INL, INL, INL, INL, INL, INL, INL, INL, - SPC, SPC, SPC, SPC, SPC, ROT, ROT, ROT }, /* SHIFT_ASHIFT */ + SPC, SPC, SPC, SPC, ROT, ROT, ROT, ROT }, /* SHIFT_ASHIFT */ { INL, INL, INL, INL, INL, INL, INL, INL, - SPC, SPC, SPC, SPC, SPC, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */ + SPC, SPC, SPC, SPC, ROT, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */ { INL, INL, INL, INL, INL, INL, INL, INL, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFTRT */ } @@ -237,9 +237,9 @@ static enum shift_alg shift_alg_si[2][3][32] = { SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_LSHIFTRT */ { INL, INL, INL, INL, INL, INL, INL, LOP, - SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP, + SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, - SPC, SPC, SPC, SPC, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */ + SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFTRT */ }, { /* TARGET_H8300S */ @@ -256,7 +256,7 @@ static enum shift_alg shift_alg_si[2][3][32] = { SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_LSHIFTRT */ { INL, INL, INL, INL, INL, INL, INL, INL, - INL, INL, INL, INL, INL, INL, INL, LOP, + INL, INL, INL, INL, INL, INL, INL, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFTRT */ } @@ -372,6 +372,9 @@ h8300_option_override (void) shift_alg_si[H8_300H][SHIFT_ASHIFTRT][25] = SHIFT_LOOP; shift_alg_si[H8_300H][SHIFT_ASHIFTRT][26] = SHIFT_LOOP; shift_alg_si[H8_300H][SHIFT_ASHIFTRT][27] = SHIFT_LOOP; + shift_alg_si[H8_300H][SHIFT_ASHIFTRT][28] = SHIFT_LOOP; + shift_alg_si[H8_300H][SHIFT_ASHIFTRT][29] = SHIFT_LOOP; + shift_alg_si[H8_300H][SHIFT_ASHIFTRT][30] = SHIFT_LOOP; /* H8S */ shift_alg_hi[H8_S][SHIFT_ASHIFTRT][14] = SHIFT_LOOP; @@ -3830,6 +3833,10 @@ get_shift_alg (enum shift_type shift_type, enum shift_mode shift_mode, } else if (count == 15) { + /* The basic idea here is to use the shift-by-16 idiom to make things + small and efficient. Of course, that loses one bit that we need, + so we stuff the bit into C, shift by 16, then rotate the bit + back in. */ switch (shift_type) { case SHIFT_ASHIFT: @@ -3841,7 +3848,9 @@ get_shift_alg (enum shift_type shift_type, enum shift_mode shift_mode, info->cc_special = OLD_CC_SET_ZNV; goto end; case SHIFT_ASHIFTRT: - gcc_unreachable (); + info->special = "shll.w\t%f0\n\tmov.w\t%e0,%f0\n\texts.l\t%S0\n\trotxl.l\t%S0"; + info->cc_special = OLD_CC_SET_ZNV; + goto end; } } else if (count >= 16 && count <= 23) @@ -3863,6 +3872,23 @@ get_shift_alg (enum shift_type shift_type, enum shift_mode shift_mode, goto end; } } + else if (TARGET_H8300S && count == 27) + { + switch (shift_type) + { + case SHIFT_ASHIFT: + info->special = "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t#2,%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0"; + goto end; + case SHIFT_LSHIFTRT: + info->special = "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t#2,%S0\n\trotl.l\t%S0\n\textu.l\t%S0"; + goto end; + case SHIFT_ASHIFTRT: + info->remainder = count - 24; + info->special = "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0"; + info->cc_special = OLD_CC_SET_ZNV; + goto end; + } + } else if (count >= 24 && count <= 27) { info->remainder = count - 24;