From nobody Mon Dec 25 14:25:44 2023 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 4SzKvF2l71z54nKJ; Mon, 25 Dec 2023 14:25:45 +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 4SzKvF0g4rz3MZr; Mon, 25 Dec 2023 14:25:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703514345; 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=8cgXLKwTk53PkK9lqGMUxofa50jD8Ziqk/e+wZybA5I=; b=aKEpFo7nGtDDXc7AZ8qjBALz62UYvOOX6Db89McOAaKUdNNA7imXcKQrmfyVIe+YDIxPsz WYcQ+jZ+ptwQg8f33BASTuKZ3AHNPhFA3J1N9NfHAIUltoZyfgKsR/+Y9JT382DK3GcquZ r0uFp5ayB2XieyawiNTsW3SdlAN8OfkS+PKg8lmAw8VpyL8C6AKVwkoFc/goCr/KYinO6i +wcQcDXsRuZN5N1v9HDH7J3x/ZpDx7c5Cl9Eso6PzwqE4DYf4hpM9+FuBzSpCFf3WcJ+CU S8ogimV1uA7VVYncsvTjSKEHpIWfxhIYupbAP6Rv+31VxVHkxWjwobyjljRmvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703514345; a=rsa-sha256; cv=none; b=LiwRyB01H6RIKMP6vAvr6sQHfBnwlOcrbHJQz0NO7X5IdOZKj/oBaHc/tKrRHJnwHWPJ5+ lF90eD2MS1WoW+bUUrGeAxyJ2xtS5tJVxY0aPM0iOk6FWT6AOGaTbxl8V7HkpLZ16Jwred y4yshmvzhRb1L7nmnpXoi8f29XJIwbEWBDnBZO0LaS4gaGD1gAZ+MgXGue9rFD/umksYxd qa3iEOdCzaj26A38q0Y8TgTzcUT6H6HV8Nyk1bNFAap9b2apNzI/w0VkEyxGEK/4OVKAEL 2DDaZuFMU1xMgctn70BbkIvYdnk6MUvxYsiHlLpdBxyx/OVfxkAzwsg69t743Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703514345; 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=8cgXLKwTk53PkK9lqGMUxofa50jD8Ziqk/e+wZybA5I=; b=Ls8sbn8WvEtgqyImtJ/q0W56rKiQX0BoxckOyR1I8NAvrq7bJop3ThDcJcmY1M235zQ7H5 lVdPeSKRvfAXH0fGsIzEmpa0izrfeyWknmhyADi9lBOSwK86oNfRa9BvOcXPZQbyuaRnUo jqQfix5veURGVKxSPoDDGN2SLGwsnVmjFtTeXwBFWanfyk4L7idnlNd0Bp+kDdJyOeaCC2 6h6t7RJ6jrklIEnj+ymm9RQUsy4+Fn+kgY3z+qTfa4BaZmFs/zXb8JaN+vAmzqUChdlY/M ykQ48ynOBANGunRJbfo5eJoB0bJ3rJxOdvW4c4aGXBez8JegbsXzUcQmOhu8og== 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 4SzKvD5kykzSK; Mon, 25 Dec 2023 14:25:44 +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 3BPEPiAE023128; Mon, 25 Dec 2023 14:25:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BPEPi00023125; Mon, 25 Dec 2023 14:25:44 GMT (envelope-from git) Date: Mon, 25 Dec 2023 14:25:44 GMT Message-Id: <202312251425.3BPEPi00023125@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Clausecker Subject: git: fd2ecd91aeee - main - 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/main X-Git-Reftype: branch X-Git-Commit: fd2ecd91aeeeab579c769c9a39f90b4bd4a493a9 Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=fd2ecd91aeeeab579c769c9a39f90b4bd4a493a9 commit fd2ecd91aeeeab579c769c9a39f90b4bd4a493a9 Author: Robert Clausecker AuthorDate: 2023-10-24 03:52:01 +0000 Commit: Robert Clausecker CommitDate: 2023-12-25 13:55:30 +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 --- 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); +}