Message ID | 20250409064701.3435-3-marlene.fally@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <newlib-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBDFD384F02D for <patchwork@sourceware.org>; Wed, 9 Apr 2025 06:55:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBDFD384F02D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XWDT57Lr X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 737A4384DED8 for <newlib@sourceware.org>; Wed, 9 Apr 2025 06:47:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 737A4384DED8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 737A4384DED8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744181231; cv=none; b=eD/oCNUqoCzxdC4XIfBHzgiGMrn41BbAh0LOsV9QKGxktd6d7Kob3DE+foCqtjA/txSW7sMGjgbo8EjNATdg42jD0zUFIYugfsGInJ0x363x/EANlHMGimkmPaJTW8KE00+PGqjkHltzGuoC8O28DRhwWLiIAq/Db/xwgAgPP9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744181231; c=relaxed/simple; bh=PzMKKbq9VQ6hfuv03HSl32Qqo6HPSJ/QL+PI4AWRV6w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jmFUChpZ4zs4glixwDlvdrKqViR0kfKUDT3+ex+nTkyE2bQZYH0D/kL1U5t5bkD4xLsOce1dHoBOJ0a70bZWr2QDO/elEZlYLG5/MsBcYoSQXzlxtaPXOuCvayDVqKVBR/CEivtPvY7N1d+RX264N6Cu9mjji5A+is6TfZYIr1E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 737A4384DED8 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5efe8d9ebdfso1382085a12.3 for <newlib@sourceware.org>; Tue, 08 Apr 2025 23:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744181230; x=1744786030; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wY7GCQu1BVch5XM7tCiBRkNvN+K/jwgfmanwxJg5rwQ=; b=XWDT57LrkQclDJ3ktvKkUirWsJldF0HpOikKqpRkYDsdoihRU6VnicpL+lutrZy4Lw uMi7XvvmF8qfTwWm7KmLRrJxZsI2RZt7VyPGorIvj9fK4St68g8CXAbN5GbkurZYVSNZ 5r2jglB6R2R22yj3S67XMd/B03U+Q7syk6O1cZ7EvIdowlq61OejnKfR2jH5BOPgIcfL 9+BjxkAcRX+1yN98ZrDsHdUjaDH8FkdY+UzL0ypQXg9lLuQf8wdQMaCOV702Bx6mHyxr DqGL/BN1ZyPYLU9HrdgBgr96999JhQTiS70iywIsnmS/WKGannebQBdcZJdwV0ghMfEL iY9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744181230; x=1744786030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wY7GCQu1BVch5XM7tCiBRkNvN+K/jwgfmanwxJg5rwQ=; b=tMv8RVFEUmTkBKBQU02KH2xCzjVi0Y+Ccdr0uVi/3Y9Lx5sv+QU7wVCCQ+qn9vFJ2d 68PNfY72bx/NpSNyYfI2Zvox5+JoojMbrNmGVWnTB6pFhhXEJGCYWGKS0kxIo38IC8WH vl201oLrDD4sB8z+OdRvNzhwmWLXW+0MF5t/dXiulZUpHq5swzKCiXmEWzCTsmoVodTt 5dGR0ft47fjfxTggt9h0fsXTrNsb6k5DC2EPg27UlHL5fAT5ePYcG4ueZPFolHuGSVOl u1N8HfQTuWR1qe6gFabZpHlGkP+AxPXtwXQXmzUbJUJ6kR20fGZ/85zbWvmSTQEKbkVu OWJg== X-Gm-Message-State: AOJu0YzzakXmstukf7u9XV2QpQywK/f/dleQopez6VRUertBMYVUaGYR AtmMgU/Y3wEnqS9PBh6Yxb5p8c8kSxhQx2GjmJl4UJ62AnHWuULGNK9xGbDtsnY= X-Gm-Gg: ASbGnct0+W/BaOteQpdEUH0QUnaQqc5dCYHT/fu6OfmyckELFaSx8C8yuD1Xchj1mXl lfyG5YfnyOPQGQHL7MqK+Fiutlk3+p7lfllNLWtqMw8ZhImQvgG4YJTExo2+9vXqtfFV9tqQc6L GjhlqtxtUgHhUgiTYnKkyeoYWyUt9MzMmBVaISBDRlmXBQI+2K7+EWrItV6GAjw+GVUeZemZD5B DlvNkxgeALmUbmmumt0XOyFk6NmI6CfqDTL/69I7bjyUt0CKzpRvVo/iN8pA4JzWXXNtiO1WOUU MS0H1XpPybtEGWvQwBf3tR1J3hmxHiRHBy3k4bsXfn2edBLF0LrhBV9qaf8= X-Google-Smtp-Source: AGHT+IG7gw4jx2q6zm7GfhC3IHyNq9RHygCDIBoLTKyPPvIomKxGNcgKA0n8kq2e6qVdAWDCRPCGsg== X-Received: by 2002:a05:6402:3590:b0:5e5:debf:3f09 with SMTP id 4fb4d7f45d1cf-5f2f86bc653mr1150952a12.27.1744181229829; Tue, 08 Apr 2025 23:47:09 -0700 (PDT) Received: from localhost.localdomain ([2001:4bc9:a46:d00f:b073:3e3:923:aedd]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5f2fbc2cf69sm318413a12.37.2025.04.08.23.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 23:47:09 -0700 (PDT) From: m fally <marlene.fally@gmail.com> To: newlib@sourceware.org Cc: m fally <marlene.fally@gmail.com>, Christian Herber <christian.herber@oss.nxp.com> Subject: [PATCH 02/12] RISC-V: memmove() size optimized version: Use compressed registers only Date: Wed, 9 Apr 2025 08:46:51 +0200 Message-ID: <20250409064701.3435-3-marlene.fally@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250409064701.3435-1-marlene.fally@gmail.com> References: <20250409064701.3435-1-marlene.fally@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org |
Series |
newlib: RISC-V: Optimize memory and string functions for code size
|
|
Commit Message
m fally
April 9, 2025, 6:46 a.m. UTC
Change register t1 to register a4, so that the affected instructions can be compressed. Since now we have less registers available, the following changes need to be made: In the previous version of this function, a4 was used to hold the offset that needs to be added to source and destination addresses before copying any data in the case of source address > destination address. Since a4 now holds the destination address, this offset is not calculated anymore. Instead, the value in a2 (the number of bytes to be copied) is added to the source and destination addresses. Therefore, in the case of source address > destination adress, a value of 1 needs to be subtracted from both addresses before starting the copying process. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com> --- newlib/libc/machine/riscv/memmove.S | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Comments
LGTM On Wed, Apr 9, 2025 at 2:55 PM m fally <marlene.fally@gmail.com> wrote: > > Change register t1 to register a4, so that the affected instructions > can be compressed. Since now we have less registers available, the > following changes need to be made: > In the previous version of this function, a4 was used to hold the offset > that needs to be added to source and destination addresses before copying > any data in the case of source address > destination address. > Since a4 now holds the destination address, this offset is not calculated > anymore. Instead, the value in a2 (the number of bytes to be copied) is added > to the source and destination addresses. Therefore, in the case of > source address > destination adress, a value of 1 needs to be subtracted > from both addresses before starting the copying process. > > Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> > Signed-off-by: m fally <marlene.fally@gmail.com> > --- > newlib/libc/machine/riscv/memmove.S | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/newlib/libc/machine/riscv/memmove.S b/newlib/libc/machine/riscv/memmove.S > index 0f7216a68..123ab3834 100644 > --- a/newlib/libc/machine/riscv/memmove.S > +++ b/newlib/libc/machine/riscv/memmove.S > @@ -16,22 +16,22 @@ > memmove: > beqz a2, 2f > > - mv t1, a0 > + mv a4, a0 > li a3, 1 > bgtu a1, a0, 1f > > li a3, -1 > - addi a4, a2 , -1 > - add t1, t1, a4 > - add a1, a1, a4 > + add a4, a4, a2 > + add a1, a1, a2 > > +3: > + add a4, a4, a3 > + add a1, a1, a3 > 1: > lb a5, 0(a1) > - sb a5, 0(t1) > + sb a5, 0(a4) > add a2, a2, -1 > - add t1, t1, a3 > - add a1, a1, a3 > - bnez a2, 1b > + bnez a2, 3b > > 2: > ret > -- > 2.49.0 >
diff --git a/newlib/libc/machine/riscv/memmove.S b/newlib/libc/machine/riscv/memmove.S index 0f7216a68..123ab3834 100644 --- a/newlib/libc/machine/riscv/memmove.S +++ b/newlib/libc/machine/riscv/memmove.S @@ -16,22 +16,22 @@ memmove: beqz a2, 2f - mv t1, a0 + mv a4, a0 li a3, 1 bgtu a1, a0, 1f li a3, -1 - addi a4, a2 , -1 - add t1, t1, a4 - add a1, a1, a4 + add a4, a4, a2 + add a1, a1, a2 +3: + add a4, a4, a3 + add a1, a1, a3 1: lb a5, 0(a1) - sb a5, 0(t1) + sb a5, 0(a4) add a2, a2, -1 - add t1, t1, a3 - add a1, a1, a3 - bnez a2, 1b + bnez a2, 3b 2: ret