From nobody Fri Jan 10 15:03:49 2025 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 4YV4fs4ftkz5kTND; Fri, 10 Jan 2025 15:03:49 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YV4fs3vPqz4wwN; Fri, 10 Jan 2025 15:03:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736521429; 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=Or0vvsglCtaLGw+szmpXwhtC1wvq6G53SdMtkmEvez4=; b=T9SL4Om4zTkL7NF9atkfk8zWkfOM6tsS22Oa+Q3hMntG+NvyCxy0HtvozN1hUDkLT2oSym RhUfgCFQi6Fx28Wwylf1u/GAhisKfzi8MFbZ6R2jLVrYhLqM+Updj0t7X/XncrGwS001Jn HyQcx3UMg/yeJZm7s7pSaT63hwplPqxPZlrYCbtbx7lV9F4ksIQnjyEBy8mgqNniWwVDnM H2QxV3vhCMEGFinrckV7Ia7PL8Tf/brkA2i8WpkjI2dKK9OPjirq0oTpT5howuSA47+nNP reOOTWJznO5BYFrU/is/9puC03wQtmjSBjxKKxQiPwRdI8m3ZwRoB3xWBV6dhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736521429; 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=Or0vvsglCtaLGw+szmpXwhtC1wvq6G53SdMtkmEvez4=; b=ipwj/eULDHy1HY0gLJF4DzrE0FnTZf64csVQSQ1qw3TExie/inxIiqf2O619uGmtuIZ0sx txz/NYJRrwosdySceFIT3x+YJh2xAYLtVDo3eg99AI7bFOkh5ypgv1d1qoD90SS5DjlmQD yj6kqTJu4LpnLQGI8TkjQN4ub1qAwreKuSkeDsgs/aacJYZrT9PsCUa+gQjBu8Y85QmQvc SICDQf46+Y4BRDn3wCqPB5VY7v9Z7xYeDqSCzFkbxjdwCXmPb4H+0714BRBiHzTipYcH0s DiRMwPuo/ttLGC8m6GpgzKeIqrjKbQ4IuxCKX2emecS/V/+Tuev16xdPVL5TXA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736521429; a=rsa-sha256; cv=none; b=MPCM3j4WOoFgYQuZr/EnYqYIP8OiV7McdgTST1TbWvCGG4m7EeeFrBkEFRjoWB2ahY2kLW cE7ywm6t9IZOY+In/gUpvKcmxUIOnEqF/ARtVEM8nUFRnLWyiK2S1V1Kq+adnPMqV4NOjA HLnWFcq9JsKV9hjzt27Jg8Iy31kGe3aZQIscXAoiB3/Jh/YxWVsYiIgMVer8tUjn87xm0s nUSmlfNM8/uAT/uAIcb++Ch/RvVLKnEkyNRKcHGqVj5IB2FWGRAaafFsK5twCdGdmo+Ffl guz8S4vyeKyuU7hQ84/2oaAqaOlw83hGy56ryktxV0XQW9jBdfjl8L/j1OoLkg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YV4fs3MXdz2Jf; Fri, 10 Jan 2025 15:03:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50AF3nXJ056965; Fri, 10 Jan 2025 15:03:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50AF3nx3056962; Fri, 10 Jan 2025 15:03:49 GMT (envelope-from git) Date: Fri, 10 Jan 2025 15:03:49 GMT Message-Id: <202501101503.50AF3nx3056962@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: b91003acffe7 - main - lib/libc/aarch64/string: add strspn optimized implementation 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-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: b91003acffe7b50dd6506be15116c6b42fc512c6 Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=b91003acffe7b50dd6506be15116c6b42fc512c6 commit b91003acffe7b50dd6506be15116c6b42fc512c6 Author: Getz Mikalsen AuthorDate: 2024-08-26 18:13:54 +0000 Commit: Robert Clausecker CommitDate: 2025-01-10 15:02:39 +0000 lib/libc/aarch64/string: add strspn optimized implementation This is a port of the Scalar optimized variant of strspn for amd64 to aarch64. It utilizes a LUT to speed up the function, a SIMD variant is still under development. See the DR for benchmark results. Tested by: fuz (exprun) Reviewed by: fuz, emaste Sponsored by: Google LLC (GSoC 2024) PR: 281175 Differential Revision: https://reviews.freebsd.org/D46396 --- lib/libc/aarch64/string/Makefile.inc | 4 +- lib/libc/aarch64/string/strspn.S | 111 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/lib/libc/aarch64/string/Makefile.inc b/lib/libc/aarch64/string/Makefile.inc index ba0947511872..09bfaef963eb 100644 --- a/lib/libc/aarch64/string/Makefile.inc +++ b/lib/libc/aarch64/string/Makefile.inc @@ -21,7 +21,9 @@ AARCH64_STRING_FUNCS= \ # SIMD-enhanced routines not derived from Arm's code MDSRCS+= \ - strcmp.S + strcmp.S \ + strspn.S + # # Add the above functions. Generate an asm file that includes the needed # Arm Optimized Routines file defining the function name to the libc name. diff --git a/lib/libc/aarch64/string/strspn.S b/lib/libc/aarch64/string/strspn.S new file mode 100644 index 000000000000..0ef42c2b737e --- /dev/null +++ b/lib/libc/aarch64/string/strspn.S @@ -0,0 +1,111 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Getz Mikalsen +*/ + +#include + + .weak strspn + .set strspn, __strspn + .text + +ENTRY(__strspn) + + /* check for special cases */ + ldrb w4, [x1] // first character in set + cbz w4, .Lzero // empty set always returns 0 + + mov x15, #1 // preload register with 1 for stores + + // set is only one character + ldrb w5, [x1, #1] // second character in the set + cbz w5, .Lsingle + + stp x29, x30, [sp, #-16]! + mov x29, sp + sub sp, sp, #256 // allocate 256 bytes on the stack + + /* no special case matches -- prepare lookup table */ + mov w3, #28 +0: add x9, sp, x3, lsl #3 + stp xzr, xzr, [x9] + stp xzr, xzr, [x9, #16] + subs w3, w3, #4 + b.cs 0b + + strb w15, [sp, x4] // register first character in set + add x1, x1, #2 + + /* process remaining chars in set */ + .p2align 4 + + +0: ldrb w4, [x1] // next char in set + strb w15, [sp, x5] // register previous char + cbz w4, 1f // NUL encountered? + + ldrb w5, [x1, #1] + add x1, x1, #2 + strb w15, [sp, x4] + cbnz w5, 0b + +1: mov x5, x0 // stash a copy of src + + /* find mismatch */ + .p2align 4 +0: ldrb w8, [x0] + ldrb w9, [sp, x8] + cbz w9, 2f + + ldrb w8, [x0, #1] + ldrb w9, [sp, x8] + cbz w9, 3f + + ldrb w8, [x0, #2] + ldrb w9, [sp, x8] + cbz w9, 4f + + ldrb w8, [x0, #3] + add x0, x0, #4 + ldrb w9, [sp, x8] + cbnz w9, 0b + + sub x0, x0, #3 +4: sub x5, x5, #1 +3: add x0, x0, #1 +2: sub x0, x0, x5 + mov sp, x29 + ldp x29, x30, [sp], #16 + ret + +.Lzero: + mov x0, #0 + ret + +.Lsingle: + ldrb w8, [x0, x5] + cmp w4, w8 + b.ne 1f + + add x5, x5, #1 + ldrb w8, [x0, x5] + cmp w4, w8 + b.ne 1f + + add x5, x5, #1 + ldrb w8, [x0, x5] + cmp w4, w8 + b.ne 1f + + add x5, x5, #1 + ldrb w8, [x0, x5] + add x5, x5, #1 + cmp w4, w8 + b.eq .Lsingle + + sub x5, x5, #1 +1: mov x0, x5 + ret + +END(__strspn)