From nobody Wed Jan 24 19:44:30 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 4TKvYC05bSz58bY9; Wed, 24 Jan 2024 19:44:31 +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 4TKvYB61kTz45LY; Wed, 24 Jan 2024 19:44:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706125470; 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=JRNnz3DcSsS/vAnCfMtyhZbmFg/4iKKA29VR1nqd48k=; b=ZPbrOG8p+K0nrsrq7uPFv4flZ+KX835utNL2UsfXpt8divGaKTwEQAyv/6zObAfbUFRYK8 ohK47Kka98PoGxf2nAukox2vd6eI+8jAZlrLX68Yl52sb8EQ5yCb8sPPJafS3hSjDb2zYr 4z5ZdXJIf48gaD6QrijGtlsKgpzycjzkBNuAoC8q/v5jMBuPxVzMiCx/yqnjvTwjfkwrmV 6hYqeRR2d6XDkYHtw/YlU2s/oOdZAjwYXV9Sn9XJwJ7BdNhkYqw2BtwWrNyPIVcl43LXRk 3g7TrLLwhdC+OaRathbM+PfC3PrwY0t7x6iRCpZAg1r3Vx+qJ5joKK2/b6Expw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706125470; 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=JRNnz3DcSsS/vAnCfMtyhZbmFg/4iKKA29VR1nqd48k=; b=U8qHYoO3jY89RPaHdVac2M+GjMd6NyJDI7JV9lyiS4oTO2tLkFx8HZej8vXA3FFyjpl0GH r+yRu15XhftYp3+z6mkJn+3eMSMwftFnXbyBigT7t1U0UL/NyenM4k/fUBgiL3JyoHBns4 hm+bcEGviGHWOf37ypUdIesdwxM+L8OPzu03pJQHZQL+Rpt0ZBNJ+dolVviQ4ff19AwuWU ap0fDAF8VH2Ldaw/5oH30Y/p25NJoQDg3H95wp044pOeRN5oP+Xb9y7IKj7LMCo2xCQjY4 rUT2G6UMt8ChvmXaCrAGO+aKyt+u1dxvdRlapTpAj4M0lnjHLxZe61+ZrQSu3g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706125470; a=rsa-sha256; cv=none; b=FdYamtsJZJYVHCPFRTpb7G9q9zdCUdJk6gVeMSfXqHVBIMk9SOcn1sjA4zgdfoOY8XEmM/ 5Gcx2+W/QPNCir35GS9YlHbKKjXlD3cpCrancDQxiD4cDDwyKz1nlXW8V1jRrf9hhGaIDg FQ0CbkGma/ee6KpccK0eqA4vVUR/TbGeglwyoiTUPt55XppJ9LRXoR9S6iQ5Okh+gy7x/S T7dr3di2imWhgwuVFc1/iFWs/ieWGAOM+k2Aa7rKyTZwaNkZ6HRCc+0uAEJjJ+4Vs0puAA j4Qcm7SaQ+ABopFnE9fXxkh3kCmUVdlWA763WfIYmuGQ3F0z9XSmf68gRoVyOw== 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 4TKvYB4glLzS8s; Wed, 24 Jan 2024 19:44:30 +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 40OJiUFM004888; Wed, 24 Jan 2024 19:44:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40OJiUdB004885; Wed, 24 Jan 2024 19:44:30 GMT (envelope-from git) Date: Wed, 24 Jan 2024 19:44:30 GMT Message-Id: <202401241944.40OJiUdB004885@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: 309b30ce8419 - stable/14 - lib/libc/amd64/string: implement strpbrk() 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: 309b30ce8419058b23b285d1c73549890fc174f5 Auto-Submitted: auto-generated The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=309b30ce8419058b23b285d1c73549890fc174f5 commit 309b30ce8419058b23b285d1c73549890fc174f5 Author: Robert Clausecker AuthorDate: 2023-09-25 21:43:12 +0000 Commit: Robert Clausecker CommitDate: 2024-01-24 19:39:24 +0000 lib/libc/amd64/string: implement strpbrk() through strcspn() This lets us use our optimised strcspn() routine for strpbrk() calls. 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/D41980 (cherry picked from commit f4fc317c364f2c81ad3d36763d8e5a60393ddbd1) --- lib/libc/amd64/string/Makefile.inc | 1 + lib/libc/amd64/string/strcspn.S | 18 +++++++++------- lib/libc/amd64/string/strpbrk.c | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/lib/libc/amd64/string/Makefile.inc b/lib/libc/amd64/string/Makefile.inc index 09bf7c8f251e..50c70007e99b 100644 --- a/lib/libc/amd64/string/Makefile.inc +++ b/lib/libc/amd64/string/Makefile.inc @@ -14,6 +14,7 @@ MDSRCS+= \ strcspn.S \ strlen.S \ strnlen.c \ + strpbrk.c \ strspn.S \ timingsafe_bcmp.S \ timingsafe_memcmp.S diff --git a/lib/libc/amd64/string/strcspn.S b/lib/libc/amd64/string/strcspn.S index 648635529e5b..7ebd7a847d67 100644 --- a/lib/libc/amd64/string/strcspn.S +++ b/lib/libc/amd64/string/strcspn.S @@ -33,13 +33,15 @@ #define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ -ARCHFUNCS(strcspn) - ARCHFUNC(strcspn, scalar) + .weak strcspn + .set strcspn, __strcspn +ARCHFUNCS(__strcspn) + ARCHFUNC(__strcspn, scalar) NOARCHFUNC - ARCHFUNC(strcspn, x86_64_v2) -ENDARCHFUNCS(strcspn) + ARCHFUNC(__strcspn, x86_64_v2) +ENDARCHFUNCS(__strcspn) -ARCHENTRY(strcspn, scalar) +ARCHENTRY(__strcspn, scalar) push %rbp # align stack to enable function call mov %rsp, %rbp sub $256, %rsp # allocate space for lookup table @@ -122,7 +124,7 @@ ARCHENTRY(strcspn, scalar) sub (%rsp), %rax # length of prefix before match leave ret -ARCHEND(strcspn, scalar) +ARCHEND(__strcspn, scalar) /* * This kernel uses pcmpistri to do the heavy lifting. @@ -134,7 +136,7 @@ ARCHEND(strcspn, scalar) * 17--32: two pcmpistri per 16 bytes of input * >=33: fall back to look up table */ -ARCHENTRY(strcspn, x86_64_v2) +ARCHENTRY(__strcspn, x86_64_v2) push %rbp mov %rsp, %rbp sub $256, %rsp @@ -389,6 +391,6 @@ ARCHENTRY(strcspn, x86_64_v2) 2: sub %rdi, %rax # number of characters preceding match leave ret -ARCHEND(strcspn, x86_64_v2) +ARCHEND(__strcspn, x86_64_v2) .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/amd64/string/strpbrk.c b/lib/libc/amd64/string/strpbrk.c new file mode 100644 index 000000000000..87f587789991 --- /dev/null +++ b/lib/libc/amd64/string/strpbrk.c @@ -0,0 +1,43 @@ +/*- + * 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 *); + +char * +strpbrk(const char *s, const char *charset) +{ + size_t loc; + + loc = __strcspn(s, charset); + + return (s[loc] == '\0' ? NULL : (char *)&s[loc]); +}