From nobody Mon Dec 25 14:25:36 2023 X-Original-To: dev-commits-src-main@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 4SzKv51cbBz54nDZ; Mon, 25 Dec 2023 14:25:37 +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 4SzKv50jZpz3M1f; Mon, 25 Dec 2023 14:25:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703514337; 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=c3NlY4C7ddOgxnp/VPANc+xqqU4nttC5Fi/Ungnyups=; b=rtmiPMP/CeFE9RY/heVJBTCvMvsT6vY/5Ylw8O3e3z9FBcBeSiwGrRAG9Gx8O8KzrjGHAB kN8U6tbaIXBi7R3RCT6rMRwUqC6C//2E8n8/xdfHiwkYZU698hg6kyesbRe2b+lrU8actR s+QESs/tcnPBs1a/tDLdjJ49nvxoJSTEcZC2oZIQDKQQNlW/gtCquAU66c7tpOXZQ0emr1 015rvOV5/+YFRUb7b/fK7NcCDYAEofbCnp/mzM+agyVM0sDlJNNS/bGICvr6+ou3mSP8pO lQ9xV0owPhEHGldmTruZnEtiIBvWiQ4vcS6lRG1KwkSjaBF7q/XhcnQmaaLB9Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703514337; a=rsa-sha256; cv=none; b=gYFwpiebqmp6BaLSccdHLB1rKU7VObfD1i0A3x850MHDssQ1oFGoWDnWk47M1o+f16hj2L q84qablM3fdmeV9KDporEuskiUup08on6tKDqhiX+vduzoEPJZm+4ExB+T3FzE3gkwQEeU PFjP6E2IAT9E6z2GVVpT6jYGdrLHYjodQSuc8N0bD9hlUCyiCXj3RORJQBFBLPeZrYieUJ rS4FgoMhOUVCQOsqRlnVjF/aUwO0u4SEix2azGJUI56aR2xuthFmw5gIlY+n2I0kVUt29M 5jO9LwEuPC3XjPwGLQ92yhOVHrCetOvx3wy+5jKRCvh1vFCC/fxblZ9zQl7waA== 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=1703514337; 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=c3NlY4C7ddOgxnp/VPANc+xqqU4nttC5Fi/Ungnyups=; b=JJi16m0MVX08GKY7M3PuLFj4ywqj6xuJOKTlPBRvNcBFcoi8I/y/eommtY2ocyH9HkVhee spgmDoJgvJPzvujDBk11MUFCC6oyOR6jL+gv7NEfyIJaTA1oJX00KFeyNvkUvukRuQuGrd m1RaQJ6gCXOroRL9jv4eQaoKZexhzmlIMNt8XVOJBp29KJYuSZd26vUoe6Odqum49kLHdX z0tV1/KJ5yrpb7e0IG8iCHsrtaKxIfX36mJ4ZUJsYZPdtGkKlV1ZmK7caTQbS/Qi6y1mCX jqIHJkB51AF7cCRRjPpSNVN9mITyXFRIdJPBDmajUAXOaMg5uCVFbA1xohGeIQ== 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 4SzKv46t1Sz4k; Mon, 25 Dec 2023 14:25:36 +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 3BPEPa6E022794; Mon, 25 Dec 2023 14:25:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BPEPaJ5022791; Mon, 25 Dec 2023 14:25:36 GMT (envelope-from git) Date: Mon, 25 Dec 2023 14:25:36 GMT Message-Id: <202312251425.3BPEPaJ5022791@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: f4fc317c364f - main - lib/libc/amd64/string: implement strpbrk() through strcspn() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: f4fc317c364f2c81ad3d36763d8e5a60393ddbd1 Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=f4fc317c364f2c81ad3d36763d8e5a60393ddbd1 commit f4fc317c364f2c81ad3d36763d8e5a60393ddbd1 Author: Robert Clausecker AuthorDate: 2023-09-25 21:43:12 +0000 Commit: Robert Clausecker CommitDate: 2023-12-25 13:54:58 +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 --- 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]); +}