From patchwork Thu Jul 30 20:56:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1339049 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=LX5vNBcz; 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 4BHjPd1XNzz9sRN for ; Fri, 31 Jul 2020 06:56:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB0103858D37; Thu, 30 Jul 2020 20:56:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB0103858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596142576; bh=iserKeYoFEiXt9/FFFwhDgMos3hffT2AHW5wAG8VczM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LX5vNBczfrmz1SsqVpPUyhCG4lcNjSBkJF5UmtJqx7NDgjEgaxjs810l3z0VETT6k xyVtCaGuvQvF703TrIOHW3cskphlrFvIgaY0eYR9JvmdI9RVpJNgkM58q0CT0NXcjT sOYI6Z9VpZlz6vGFeE6TcxQvDgxhgb/VkRU3eHXw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by sourceware.org (Postfix) with ESMTPS id 3AFA43858D35 for ; Thu, 30 Jul 2020 20:56:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3AFA43858D35 IronPort-SDR: svttgAXZfU2FXSfLmlFuuWdz1VOu3z4heiloOAOjnscryG3Kkbdni6L2f5BKpGcXpTjhJA+wjv /8iENV3OcIZ9vZpzWNF3t0idFEO7zu50wCFyW9r1lt7aklHVtqR2G7gC2I53ctPbh1qQtUiXz9 VQcr7t9lwhnd0eMLmNQnJRm+GrO4McOGcrx7aYHyO3xax1nmeNF5k9UQBqCkkIP5JW/ygZmA0F TrhH2SXZmEtAvWCTd1habinipFjJwOstrvKgqQ32WOSigGqjedvMM5jZOIQN2qY6l9eRqDySD9 FKc= X-IronPort-AV: E=Sophos;i="5.75,415,1589212800"; d="scan'208";a="148097151" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 31 Jul 2020 04:56:14 +0800 IronPort-SDR: vNSI2ZB7ktbfy1SMRAELTQsqJM2pfsLLr7iqRhg8TrVKhNReuSH335UcgUMG69AoGRU4IzTycJ V4DjwSeHZzuICF78a295gWJDNBtkXfsj8= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2020 13:43:40 -0700 IronPort-SDR: M8uJVg6s1dVrXeF9bGGg8kqUqh7D1kwoB72hamki0c6OGQRnIruoQPORVXvJyVsAcNsun4yAbV p3GMY0zADFoQ== WDCIronportException: Internal Received: from unknown (HELO redsun52) ([10.149.66.28]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2020 13:56:12 -0700 Date: Thu, 30 Jul 2020 21:56:07 +0100 (BST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V/libgcc: Reduce the size of RV64 millicode by 6 bytes Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SCC_5_SHORT_WORD_LINES, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "Maciej W. Rozycki via Gcc-patches" From: "Maciej W. Rozycki" Reply-To: "Maciej W. Rozycki" Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Rewrite code sequences throughout the 64-bit RISC-V `__riscv_save_*' routines replacing `li t1, -48', `li t1, -64', and `li t1, -80', instructions, which do not have a compressed encoding, respectively with `li t1, 3', `li t1, 4', and `li t1, 4', which do, and then adjusting the remaining code accordingly observing that `sub sp, sp, t1' takes the same amount of space as an `slli t1, t1, 4'/`add sp, sp, t1' instruction pair does, again due to the use of compressed encodings, saving 6 bytes total. This change does increase code size by 4 bytes for RISC-V processors lacking the compressed instruction set, however their users couldn't care about the code size or they would have chosen an implementation that does have the compressed instructions, wouldn't they? libgcc/ * config/riscv/save-restore.S [__riscv_xlen == 64] (__riscv_save_10, __riscv_save_8, __riscv_save_6, __riscv_save_4) (__riscv_save_2): Replace negative immediates used for the final stack pointer adjustment with positive ones, right-shifted by 4. --- Hi, This is hopefully functionally obviously correct. There were also no regressions in `riscv64-linux-gnu' lp64d multilib testing across all our testsuites (with QEMU run in the Linux user emulation mode) where target libraries, including glibc, have been built with `-Os -msave-restore', that is with millicode enabled. OK to apply? Maciej --- libgcc/config/riscv/save-restore.S | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) gcc-riscv-libgcc-save-sll.diff Index: gcc/libgcc/config/riscv/save-restore.S =================================================================== --- gcc.orig/libgcc/config/riscv/save-restore.S +++ gcc/libgcc/config/riscv/save-restore.S @@ -45,7 +45,7 @@ FUNC_BEGIN (__riscv_save_10) .cfi_restore 27 addi sp, sp, -112 .cfi_def_cfa_offset 112 - li t1, -16 + li t1, 1 .Ls10: sd s10, 16(sp) .cfi_offset 26, -96 @@ -60,7 +60,7 @@ FUNC_BEGIN (__riscv_save_8) .cfi_restore 27 addi sp, sp, -112 .cfi_def_cfa_offset 112 - li t1, -32 + li t1, 2 .Ls8: sd s8, 32(sp) .cfi_offset 24, -80 @@ -77,7 +77,7 @@ FUNC_BEGIN (__riscv_save_6) .cfi_restore 27 addi sp, sp, -112 .cfi_def_cfa_offset 112 - li t1, -48 + li t1, 3 .Ls6: sd s6, 48(sp) .cfi_offset 22, -64 @@ -99,7 +99,7 @@ FUNC_BEGIN (__riscv_save_4) .cfi_restore 27 addi sp, sp, -112 .cfi_def_cfa_offset 112 - li t1, -64 + li t1, 4 .Ls4: sd s4, 64(sp) .cfi_offset 20, -48 @@ -123,7 +123,7 @@ FUNC_BEGIN (__riscv_save_2) .cfi_restore 27 addi sp, sp, -112 .cfi_def_cfa_offset 112 - li t1, -80 + li t1, 5 .Ls2: sd s2, 80(sp) .cfi_offset 18, -32 @@ -133,9 +133,10 @@ FUNC_BEGIN (__riscv_save_2) .cfi_offset 8, -16 sd ra, 104(sp) .cfi_offset 1, -8 + slli t1, t1, 4 # CFA info is not correct in next 2 instruction since t1's # value is depend on how may register really save. - sub sp, sp, t1 + add sp, sp, t1 jr t0 .cfi_endproc FUNC_END (__riscv_save_12)