Message ID | 20250406200323.52380-1-ericsalem@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 72E7C385DDDF for <patchwork@sourceware.org>; Sun, 6 Apr 2025 20:04:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72E7C385DDDF 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=HdyBp0x8 X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id 3AA09385DDD6 for <newlib@sourceware.org>; Sun, 6 Apr 2025 20:03:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AA09385DDD6 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 3AA09385DDD6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::82a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743969807; cv=none; b=RJC/oINHBWOSpqiSA02W9OCY9dfh0tIzDtMF+O+gXw32ct4pjsIExCUjl6AX0AjVBkfdBEdV3i9fUnVGPHdhKP7wOCSZk0L4WrgO24KArphwShhDMqTbq3qytVPDc7k0nsgVPUslq+wvA5ok2u8pYbQUu2WSr5KKyVS6PCYVj2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743969807; c=relaxed/simple; bh=Vn+gV71emu8LeT1wePv5Mj4W8VD88qWFOnT2ZM4bpn8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v1ZAsgohFSvgdmtZo13VCZwpCZarURXgEjMwPlFm443LfcN1zrcdeqGSW5XbEqj1UUc6O16xEFxUpoh4LbguUR2yMxhryQkkt9STa1A+0JORz7JKz/IdoraAuClcsf2+ri6AXfJXd6+clW5hXUYOrcsTLTado1m1NBZs2bdIm8A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AA09385DDD6 Received: by mail-qt1-x82a.google.com with SMTP id d75a77b69052e-476af5479feso36418281cf.2 for <newlib@sourceware.org>; Sun, 06 Apr 2025 13:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743969806; x=1744574606; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=wLzrJWG+8pOtKwpKNTfrqhxroI3zf0BQydxNCsB9LjU=; b=HdyBp0x8y4GbnMwi6aTxLglY8xygU4bhwd4EFILGdjLS6alFsxWSBoxXf++GHrRIRK 8Hk7Ic0zrYcGw6KV70ktoAcSL08S8oMNjnzNAVtah+/ZRjhy0Zu0TEhyqagik88kwfo5 ACfidOqEEGydWmRqZO2hXWJ9ayIi5XmIUf/REA9TQC9KsHTUmz3VKMs0Df3k+L+kJZzL oxBEIluA48OuincYlI7Tx5M99Thon4AvQ4oMLpk9iwQAFgf3HM2h2poNUU0DNIsKBRio M5SNm99pXVCURp14h36YqLBYYekJ2wHO4yapjJ0C/UaHRByOpT2g5/wPl3PGWaOTRnTt pzKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743969806; x=1744574606; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wLzrJWG+8pOtKwpKNTfrqhxroI3zf0BQydxNCsB9LjU=; b=IVVdBQkrruLKC6Crp8euTHXhYEwG/koRDmCHS6JaOBLhA6uRCCwT9IGV8hwxOuEHLm ATjFTAt48yZSvRieE3FqAzunUuZhWLzJPU+T2q1qDSA5zvk/vvP4Dme4RSAK3GqTYDlZ IouMO7O3TZFHthhfuw2W2vrZpOHTC98hHZiY6zqcjgsunYLGWwbDRucsuXU1GcLPfcCf sFU7mnZcjFryeA4VAMLTjowCsoziXAmB8iFj24gjGZits5WX4P30AIul4NqedaycXa2J 3HT8rgvhYJEhcf3+L9ig90b8bMgvO5vRkSJocTAx8E7mYSiTBDW4wE8EWxOntYqk5QCT /vlg== X-Gm-Message-State: AOJu0Ywcr+PKVe7QRdebPEQJZvGzTqk0esjGMDZ6WoGQarhKjMGHbZIj 6tUdCL7tWqbF3zAwCdajV8cqlwCkMxjVJmfxgk+h75wimiKJJ8Nc8MV1VA== X-Gm-Gg: ASbGnctO0OxDOoClvlb/eDCpkJTIIa4oHl05yOkPUm0OL31ZejIqluG08emPWqLwQvv CzdflvZPBuj1RU7dX6rVLqAyIx37kIO1U6Cc557gDqAvfLvTgFigDT3/gAcS97/nWz97GfLGzpa KC3444ekwU5d56cJ0CBcUnCGvNx1EG8J+BsyQnZtcMHF5HStSLXOVGEcQHexHONRWHIqczsRVHr Ce6janWgaFdeYiwUT//D+1C1IYxlHgH2MCnTVoDfWqm1Muai9azXFmcSwmx+4x/mUXO6dcjVeW8 vUm423QJAZ6AiQVAC9yDS3ZlXhR+1xXzSo4bXv5c6cGIpBLjvPhQnLPnQ8V+yEmFmFf7q0e1ApB xcg== X-Google-Smtp-Source: AGHT+IE49NkcTxj9F2qv3oDPjDkTT5ufF3QxlvsYeEeBobSQb8vevFcqzGHqo9beQoOLIXsTy2ThEg== X-Received: by 2002:ad4:5ae3:0:b0:6e8:f3b0:fa33 with SMTP id 6a1803df08f44-6f00debc8c8mr182699496d6.8.1743969806258; Sun, 06 Apr 2025 13:03:26 -0700 (PDT) Received: from fedora.. (c-73-176-204-61.hsd1.il.comcast.net. [73.176.204.61]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ef0f164dc6sm49321726d6.120.2025.04.06.13.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 13:03:25 -0700 (PDT) From: Eric Salem <ericsalem@gmail.com> To: newlib@sourceware.org Subject: [PATCH] newlib: riscv: Remove unnecessary byte load/store for stpcpy()/strcpy() Date: Sun, 6 Apr 2025 15:03:23 -0500 Message-ID: <20250406200323.52380-1-ericsalem@gmail.com> X-Mailer: git-send-email 2.49.0 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, 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: riscv: Remove unnecessary byte load/store for stpcpy()/strcpy()
|
|
Commit Message
Eric Salem
April 6, 2025, 8:03 p.m. UTC
For architectures where XLEN is 32 bits, when detecting a null byte, a word is read at a time. Once a null is found in the word, its precise location is then determined. Make clear to the compiler that if the first three bytes are not null, the last byte must be null, and does not need to be read from the source string, since its value is always zero. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com> --- newlib/libc/machine/riscv/rv_string.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Comments
Kito, this patch seemed to slip through the cracks. Could you please review? Thanks -- Jeff J. On Sun, Apr 6, 2025 at 4:04 PM Eric Salem <ericsalem@gmail.com> wrote: > For architectures where XLEN is 32 bits, when detecting a null byte, a > word is read at a time. Once a null is found in the word, its precise > location is then determined. Make clear to the compiler that if the > first three bytes are not null, the last byte must be null, and does not > need to be read from the source string, since its value is always zero. > > Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> > Signed-off-by: Eric Salem <ericsalem@gmail.com> > --- > newlib/libc/machine/riscv/rv_string.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/newlib/libc/machine/riscv/rv_string.h > b/newlib/libc/machine/riscv/rv_string.h > index 362f66a024bf..7754303064c9 100644 > --- a/newlib/libc/machine/riscv/rv_string.h > +++ b/newlib/libc/machine/riscv/rv_string.h > @@ -82,8 +82,8 @@ static __inline char *__libc_strcpy(char *dst, const > char *src, bool ret_start) > if (!(*dst++ = src[0])) return dst0; > if (!(*dst++ = src[1])) return dst0; > if (!(*dst++ = src[2])) return dst0; > - if (!(*dst++ = src[3])) return dst0; > #if __riscv_xlen == 64 > + if (!(*dst++ = src[3])) return dst0; > if (!(*dst++ = src[4])) return dst0; > if (!(*dst++ = src[5])) return dst0; > if (!(*dst++ = src[6])) return dst0; > @@ -94,13 +94,13 @@ static __inline char *__libc_strcpy(char *dst, const > char *src, bool ret_start) > if (!(*dst++ = src[0])) return dst - 1; > if (!(*dst++ = src[1])) return dst - 1; > if (!(*dst++ = src[2])) return dst - 1; > - if (!(*dst++ = src[3])) return dst - 1; > #if __riscv_xlen == 64 > + if (!(*dst++ = src[3])) return dst - 1; > if (!(*dst++ = src[4])) return dst - 1; > if (!(*dst++ = src[5])) return dst - 1; > if (!(*dst++ = src[6])) return dst - 1; > - dst0 = dst; > #endif > + dst0 = dst; > } > > *dst = 0; > -- > 2.49.0 > >
This patch LGTM, thanks :) On Tue, Apr 15, 2025 at 6:19 AM Jeff Johnston <jjohnstn@redhat.com> wrote: > > Kito, this patch seemed to slip through the cracks. Could you please review? > > Thanks > > -- Jeff J. > > On Sun, Apr 6, 2025 at 4:04 PM Eric Salem <ericsalem@gmail.com> wrote: >> >> For architectures where XLEN is 32 bits, when detecting a null byte, a >> word is read at a time. Once a null is found in the word, its precise >> location is then determined. Make clear to the compiler that if the >> first three bytes are not null, the last byte must be null, and does not >> need to be read from the source string, since its value is always zero. >> >> Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> >> Signed-off-by: Eric Salem <ericsalem@gmail.com> >> --- >> newlib/libc/machine/riscv/rv_string.h | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/newlib/libc/machine/riscv/rv_string.h b/newlib/libc/machine/riscv/rv_string.h >> index 362f66a024bf..7754303064c9 100644 >> --- a/newlib/libc/machine/riscv/rv_string.h >> +++ b/newlib/libc/machine/riscv/rv_string.h >> @@ -82,8 +82,8 @@ static __inline char *__libc_strcpy(char *dst, const char *src, bool ret_start) >> if (!(*dst++ = src[0])) return dst0; >> if (!(*dst++ = src[1])) return dst0; >> if (!(*dst++ = src[2])) return dst0; >> - if (!(*dst++ = src[3])) return dst0; >> #if __riscv_xlen == 64 >> + if (!(*dst++ = src[3])) return dst0; >> if (!(*dst++ = src[4])) return dst0; >> if (!(*dst++ = src[5])) return dst0; >> if (!(*dst++ = src[6])) return dst0; >> @@ -94,13 +94,13 @@ static __inline char *__libc_strcpy(char *dst, const char *src, bool ret_start) >> if (!(*dst++ = src[0])) return dst - 1; >> if (!(*dst++ = src[1])) return dst - 1; >> if (!(*dst++ = src[2])) return dst - 1; >> - if (!(*dst++ = src[3])) return dst - 1; >> #if __riscv_xlen == 64 >> + if (!(*dst++ = src[3])) return dst - 1; >> if (!(*dst++ = src[4])) return dst - 1; >> if (!(*dst++ = src[5])) return dst - 1; >> if (!(*dst++ = src[6])) return dst - 1; >> - dst0 = dst; >> #endif >> + dst0 = dst; >> } >> >> *dst = 0; >> -- >> 2.49.0 >>
Thanks. Patch pushed. -- Jeff J. On Tue, Apr 15, 2025 at 9:02 AM Kito Cheng <kito.cheng@gmail.com> wrote: > This patch LGTM, thanks :) > > On Tue, Apr 15, 2025 at 6:19 AM Jeff Johnston <jjohnstn@redhat.com> wrote: > > > > Kito, this patch seemed to slip through the cracks. Could you please > review? > > > > Thanks > > > > -- Jeff J. > > > > On Sun, Apr 6, 2025 at 4:04 PM Eric Salem <ericsalem@gmail.com> wrote: > >> > >> For architectures where XLEN is 32 bits, when detecting a null byte, a > >> word is read at a time. Once a null is found in the word, its precise > >> location is then determined. Make clear to the compiler that if the > >> first three bytes are not null, the last byte must be null, and does not > >> need to be read from the source string, since its value is always zero. > >> > >> Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> > >> Signed-off-by: Eric Salem <ericsalem@gmail.com> > >> --- > >> newlib/libc/machine/riscv/rv_string.h | 6 +++--- > >> 1 file changed, 3 insertions(+), 3 deletions(-) > >> > >> diff --git a/newlib/libc/machine/riscv/rv_string.h > b/newlib/libc/machine/riscv/rv_string.h > >> index 362f66a024bf..7754303064c9 100644 > >> --- a/newlib/libc/machine/riscv/rv_string.h > >> +++ b/newlib/libc/machine/riscv/rv_string.h > >> @@ -82,8 +82,8 @@ static __inline char *__libc_strcpy(char *dst, const > char *src, bool ret_start) > >> if (!(*dst++ = src[0])) return dst0; > >> if (!(*dst++ = src[1])) return dst0; > >> if (!(*dst++ = src[2])) return dst0; > >> - if (!(*dst++ = src[3])) return dst0; > >> #if __riscv_xlen == 64 > >> + if (!(*dst++ = src[3])) return dst0; > >> if (!(*dst++ = src[4])) return dst0; > >> if (!(*dst++ = src[5])) return dst0; > >> if (!(*dst++ = src[6])) return dst0; > >> @@ -94,13 +94,13 @@ static __inline char *__libc_strcpy(char *dst, > const char *src, bool ret_start) > >> if (!(*dst++ = src[0])) return dst - 1; > >> if (!(*dst++ = src[1])) return dst - 1; > >> if (!(*dst++ = src[2])) return dst - 1; > >> - if (!(*dst++ = src[3])) return dst - 1; > >> #if __riscv_xlen == 64 > >> + if (!(*dst++ = src[3])) return dst - 1; > >> if (!(*dst++ = src[4])) return dst - 1; > >> if (!(*dst++ = src[5])) return dst - 1; > >> if (!(*dst++ = src[6])) return dst - 1; > >> - dst0 = dst; > >> #endif > >> + dst0 = dst; > >> } > >> > >> *dst = 0; > >> -- > >> 2.49.0 > >> > >
diff --git a/newlib/libc/machine/riscv/rv_string.h b/newlib/libc/machine/riscv/rv_string.h index 362f66a024bf..7754303064c9 100644 --- a/newlib/libc/machine/riscv/rv_string.h +++ b/newlib/libc/machine/riscv/rv_string.h @@ -82,8 +82,8 @@ static __inline char *__libc_strcpy(char *dst, const char *src, bool ret_start) if (!(*dst++ = src[0])) return dst0; if (!(*dst++ = src[1])) return dst0; if (!(*dst++ = src[2])) return dst0; - if (!(*dst++ = src[3])) return dst0; #if __riscv_xlen == 64 + if (!(*dst++ = src[3])) return dst0; if (!(*dst++ = src[4])) return dst0; if (!(*dst++ = src[5])) return dst0; if (!(*dst++ = src[6])) return dst0; @@ -94,13 +94,13 @@ static __inline char *__libc_strcpy(char *dst, const char *src, bool ret_start) if (!(*dst++ = src[0])) return dst - 1; if (!(*dst++ = src[1])) return dst - 1; if (!(*dst++ = src[2])) return dst - 1; - if (!(*dst++ = src[3])) return dst - 1; #if __riscv_xlen == 64 + if (!(*dst++ = src[3])) return dst - 1; if (!(*dst++ = src[4])) return dst - 1; if (!(*dst++ = src[5])) return dst - 1; if (!(*dst++ = src[6])) return dst - 1; - dst0 = dst; #endif + dst0 = dst; } *dst = 0;