From nobody Wed Jan 24 19:44:38 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TKvYM1SM5z58bbV; Wed, 24 Jan 2024 19:44:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TKvYL4d56z45mK; Wed, 24 Jan 2024 19:44:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706125478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GrzbsZ93eGgsfc6aFhnRRVArk7y6epf+Y5mrwirMVyE=; b=LE/wdcWZpnHi2gcy9aDW7eJtuavF7RK+rXlOggzQlZm/RFYbqRzEnU8Y4yuOj1s0DEmPig yQ/YFxenexTQxhk70/vHa6/C/w9nmHaLGf4mUdg3IFRVVAef1Ef7ylHnzg+3vK3AwKt/Ap DeC01qy8wBySWs5mhiie3vny7ogzWWxp3+RF/RNWjZxRF8L9ddffatX/noWMgbltJfp0Q7 Me0g4dbohcMI7elDvtEyQMrueOcFw4iO12mUXfegxg4IdDiqEhcZahbF5OzHGco2VNl2YX hXr+pKiDAEclq0W6+o6GH7ALXExn1dENyS9ghN6Yyt8t3IKUin52j6ewaY5IsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706125478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GrzbsZ93eGgsfc6aFhnRRVArk7y6epf+Y5mrwirMVyE=; b=SROpn8gVvQ31GIRgmj5tqm6WmOjE5xlWSdt/kJ+wJQoLaACxBF2lMZGxJK5g5hpKA2CYpz FJB2HSQxvcTvZjwXWyPLO1IUcFG7HvmRGvsc54mSOtRNBn4A+8F/L0Me5XeYoWdwwh6MPe lJ/6vI9SoeEjW2E82oU7tw8fImMGgAWwj9Xp6IW8y+dMDrqJWrIW1AVcZB/i1vrsvyddh4 /gI91LT5NP9TP+QBq34koFJ3aeFEBpKS7uqIiLUApKqKHyZopF/k75OE3ulyTvzmKMcG96 TBYabdQMYqVhetmsnlc2EBzSS5DwLxXxAJLa1DV47v35Z4lD2T/F+5zUMJhOPA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706125478; a=rsa-sha256; cv=none; b=NQ9cdT52xci+cty2KXpolf6PPXeaeLblSMhROHIQgqu0LKB1wGGAxg13HH4OpNBVEPjt93 12fZ2xUFE+03WXtnhq+Fu5m0KgsQC1xc8h2gNh3n6sUTNE2SSRrl1coxvnZchrVt4XMZkf jlkfuEjNwBPQYn4AmHfhzWX/o0zqHlha3kpC57JKK3F8kKFoNQWifBXhghteoye/J50dyG re5ybAZQlenz6SXUlY06MRjVxx8y+Fr1MVBZKtEk0TBa3thXkN6SRRkQXgpfkzpj9zN/bf zDU8NAyJNFYJiZEH4V2DrGHDkJKSZDqvSVxNPOfHJvexcj+TsS6V72ympGzlRw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TKvYL3kfnzRkL; Wed, 24 Jan 2024 19:44:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40OJicuh005225; Wed, 24 Jan 2024 19:44:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40OJicwC005222; Wed, 24 Jan 2024 19:44:38 GMT (envelope-from git) Date: Wed, 24 Jan 2024 19:44:38 GMT Message-Id: <202401241944.40OJicwC005222@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: 265fb89aba2a - stable/14 - lib/libc/amd64/string: implement strsep() through strcspn() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 265fb89aba2a6504f0a055e47ce6a72b1eecacf1 Auto-Submitted: auto-generated The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=265fb89aba2a6504f0a055e47ce6a72b1eecacf1 commit 265fb89aba2a6504f0a055e47ce6a72b1eecacf1 Author: Robert Clausecker AuthorDate: 2023-10-24 03:52:01 +0000 Commit: Robert Clausecker CommitDate: 2024-01-24 19:39:26 +0000 lib/libc/amd64/string: implement strsep() through strcspn() The strsep() function is basically strcspn() with extra steps. On amd64, we now have an optimised implementation of strcspn(), so instead of implementing the inner loop manually, just call into the optimised routine. Sponsored by: The FreeBSD Foundation Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Revision: https://reviews.freebsd.org/D42346 (cherry picked from commit fd2ecd91aeeeab579c769c9a39f90b4bd4a493a9) --- lib/libc/amd64/string/Makefile.inc | 1 + lib/libc/amd64/string/strsep.c | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/lib/libc/amd64/string/Makefile.inc b/lib/libc/amd64/string/Makefile.inc index 2baa631fb3fa..ee396f98eccc 100644 --- a/lib/libc/amd64/string/Makefile.inc +++ b/lib/libc/amd64/string/Makefile.inc @@ -17,6 +17,7 @@ MDSRCS+= \ strnlen.c \ strpbrk.c \ strrchr.S \ + strsep.c \ strspn.S \ timingsafe_bcmp.S \ timingsafe_memcmp.S diff --git a/lib/libc/amd64/string/strsep.c b/lib/libc/amd64/string/strsep.c new file mode 100644 index 000000000000..9fda56d7e135 --- /dev/null +++ b/lib/libc/amd64/string/strsep.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2023 The FreeBSD Foundation + * + * This software was developed by Robert Clausecker + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE + */ + +#include +#include + +size_t __strcspn(const char *, const char *); + +/* + * We have a fast strcspn() on amd64. Use it over a direct + * implementation of strsep for better performance. + */ +char * +strsep(char **stringp, const char *delim) +{ + size_t n; + char *s; + + s = *stringp; + if (s == NULL) + return (NULL); + + n = __strcspn(s, delim); + if (s[n] == '\0') + *stringp = NULL; + else { + s[n] = '\0'; + *stringp = s + n + 1; + } + + return (s); +}