| Message ID | cover.1746628687.git.ericsalem@gmail.com |
|---|---|
| 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 3D8183857C5D for <patchwork@sourceware.org>; Wed, 7 May 2025 14:48:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D8183857C5D 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=eIOsuVsD X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id 45C2A3858D34 for <newlib@sourceware.org>; Wed, 7 May 2025 14:46:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45C2A3858D34 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 45C2A3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1746629206; cv=none; b=xSTtJs3a5aM31BfOP2vcSqG6y07xKaDKlNxsGnuYbTk4NKy3EXKEl1ihtmTtOPzp3zEn8syBq7cAq0SXjqAfz+iaumqcYG97aoITh2hortHq2B/pSMD4xq1tizcH5t82Tl4lakqb8eeqZRUUwafm4P64+VL43qPYWZujoqjQCzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1746629206; c=relaxed/simple; bh=Yi9FtrGi90NsX0mx957GU9SAUv7EG0W4lbzm3isCrOY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pPKAysLvfnTxy7gzkGiLOi/fvRXeJg2mG//kgCLX2KjDyz2G34r7H6PDfQDtv3ibSfBhODQQQIiZDHvXPrgHGrmE4scxt0tqti/fakvw2vFhM7c/xa1rdtTpRp60xN77BwFZZRjpH+Nlu9nqtUb29ltc1+SHb/LEI6bXWLODPBI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45C2A3858D34 Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-7c9677cd6d7so795245185a.3 for <newlib@sourceware.org>; Wed, 07 May 2025 07:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746629205; x=1747234005; 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=PBUB8gaKHFVm6lbEdG57VBFjCyFMTThV8jC3IHVGMa4=; b=eIOsuVsD/9NL8y8khEM7vCULqnsJv9uu2YY6wc7Je+Z5a6JkU1sd6goPUC1wGDCgJr XyvKiruaQDkoy1OvaCAEUqoqRBsC+9z0gNiESPqMwdQjlrramBr9nVZc0CtBm0O33yIM vfSKiKP0pJd+rWpOBjGkIXL7ei524p6/+6tu4EsknEenw2XWv0nyMjzxJ8jKMRNgP1+x 1G9LQ4DehRwWfY/nxvvYqRFcRi4goG1UWdojb6SRYqvL0iCgzMdqI2b8lJ1G+RpbYLR5 J3GQWdryLJ/KeGHqKuAZSuDTCXQwRYai7iRS5jfgvrCTKPOMPdmE5r1fYvUVj48kRdDc ruuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746629205; x=1747234005; 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=PBUB8gaKHFVm6lbEdG57VBFjCyFMTThV8jC3IHVGMa4=; b=l0ZfV13yAdNKDrY4yQHh1/kNYF70KcF91hM76tjpaNkVuHbsOacVm8aADmXV3VszhR sRDxbXrHBmYoRsVNxtLAENONu06YPoEBp6FGt2+uuJUnTuf+Lzx6bdJmd03h5IrpYREy k6hweQI8x7KsDjD65wTDJbsK+nLsxbIlmdSZlBGrwqBWVI7zPoBDnVpVD8MNT6LSTpRz T59bbcQbKnaec+dPr63r8OvLFCYGY9J8tC11LyNhzdh0qKooAUYodgqDmmcKopGIQBA7 gZx8boa/wECOf0pTTbjxLOGhOlYNdTrl/HY6QvK3IjcFgsvtGV0OiM5XPifi9z1EwPKG 0/kg== X-Gm-Message-State: AOJu0YwSx8iYL/HFgCvDfz9mzetfCtDOHGKkcL2whqQ+72yZyfj0XN/v Z2V3hsJuUgIJrVGwgjnkLVhklgYHbGQ8i4nPlpWNNvUtWqQX4/KuB4Kw+2QJ X-Gm-Gg: ASbGncuWw+O3f3YAzCsA0JfF0sXOlc+WGfxEX87KL3Yu172C6eV8jbSZKN/DdhKihMr 02Gepeakq4ePaz7oLckPmnTUN6KQOD3dapPqbPfH1clMtjwg6E+4hOUVz2DrZXwC9nVFCOWv1Ni SQq3C53udumSFO1XtrTE/7h3jI07AxQqss85Nnfkbmjj3gCX0JFb9Nvj0tSzoYI3gkS4DM8mZY/ 677e7L40L1SgchvsoC0MaLXm72TmE3wY4IstzMMMGQTTwZEwayhoHcrB/YOJiMvjanToElyUsJ/ O830pggNPJmBUqMJRtd/jqtNEmo7Mnug1kyWJh2JH8F49axO2kDyd8ppgzapVCHxjjkJ/xr3EA= = X-Google-Smtp-Source: AGHT+IFqL6WIevCU4BiXF8B+Xz9AX9kugd+sV3h9E58mT3EvcRf0O+vjivnDfIl59+NUSKrpjjyQIA== X-Received: by 2002:a05:620a:448a:b0:7c7:82a6:ec7c with SMTP id af79cd13be357-7caf737ac30mr516205085a.4.1746629205355; Wed, 07 May 2025 07:46:45 -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 af79cd13be357-7caf75d8fe2sm157522385a.97.2025.05.07.07.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 07:46:45 -0700 (PDT) From: Eric Salem <ericsalem@gmail.com> To: newlib@sourceware.org, Kito Cheng <kito.cheng@gmail.com> Subject: [PATCH v2 0/3] newlib: riscv: Add and optimize memchr() and memrchr() functions Date: Wed, 7 May 2025 09:46:40 -0500 Message-ID: <cover.1746628687.git.ericsalem@gmail.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: Add and optimize memchr() and memrchr() functions
|
|
Message
Eric Salem
May 7, 2025, 2:46 p.m. UTC
The RISC-V port currently does not have its own implementations of memchr() and memrchr(). Instead it uses the stock version that's common to any port that omits its own implementations. This patch series adds port-specific implementations of both. It improves upon the algorithm that's currently used, and also uses RISC-V extensions when available. The proposed implementations were benchmarked on a Raspberry Pi Pico 2. A 2 KB buffer was was used, and an offset into the buffer ranging from 0-2047 was set where the matching byte would be found. To ensure that the benchmarking is objective as possible, a range of addresses with various alignments were tested so neither algorithm had an advantage. Addresses divided by eight with a remainder of 0-7 were used for the benchmark. For example: 0x20002a80 0x20003289 0x20003a92 0x2000429b 0x20004aa4 0x200052b5 0x20005ac6 0x200062d7 In all cases except two, the proposed memchr() was faster than the existing. For those two cases they were tied, and both had an offset of zero and unaligned addresses for the buffer. A total of 16,384 cases were tested. The existing memrchr() implementation currently does misaligned accesses, and so could not be benchmarked properly on the Pico 2. But considering that every word load is misaligned, the proposed implementation will be faster since it does aligned accesses only. The algorithm was also improved upon in the same fashion as memchr(), along with using RISC-V extensions when available. The final commit in this series is for regenerating a configuration file. As described elsewhere,[1][2] this file doesn't need to be part of the series. It's included only to aid in testing the changes without having to manually regenerate the file. [1] https://sourceware.org/newlib/faq.html#q8 [2] https://sourceware.org/pipermail/newlib/2025/021500.html Changes in v2: - Renamed macro used for register size - Link to v1: https://sourceware.org/pipermail/newlib/2025/021738.html Eric Salem (3): newlib: riscv: Add memchr() and memrchr() implementations newlib: riscv: Optimize memchr() and memrchr() newlib: Regenerate configuration file newlib/Makefile.in | 41 +++++- newlib/libc/machine/riscv/Makefile.inc | 2 +- newlib/libc/machine/riscv/memchr.c | 160 ++++++++++++++++++++++ newlib/libc/machine/riscv/memrchr.c | 180 +++++++++++++++++++++++++ newlib/libc/machine/riscv/rv_string.h | 45 ++++++- newlib/libc/machine/riscv/xlenint.h | 7 + 6 files changed, 426 insertions(+), 9 deletions(-) create mode 100644 newlib/libc/machine/riscv/memchr.c create mode 100644 newlib/libc/machine/riscv/memrchr.c