From nobody Sat Jan 31 17:21:31 2026 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 4f3KRc0q8Wz6QYLF for ; Sat, 31 Jan 2026 17:21:32 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f3KRb63Vxz3k8c for ; Sat, 31 Jan 2026 17:21:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769880091; 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=h4Qd0FS3eHsfox7ZabarcRxnZk+DX6iX/atxhaJ4hm0=; b=awt23X6DO4G0g8Zz5yO9eJlU2trUQT2Mbk8Yl3Xt1SKoP/NP4p0f6TrreQ3VGo9ij+8OmI HYKkVZ78jDAp80rm5nIL5hq6N1UgGiLOGnbCqDgvOowcFNTs59qUwneepyrMw+XIKpyv1q UQ+DqWBtsdRgs+wgf4GPsApGNYCYNgOWVZAYjJ4throllmbgofnl6P1YbWqFIZlLaIO8AY 0bWw6sU5UJWEVkZ4xhAjPc9AEZWT4q37IqIHmvmZv4TnrICwdmrXCXzfBN9ag6VvAGDm+v hJhpGl5c8KavjgG/VyVccWm19Nc+Q4U9/6kxIcEw211MBDGCQcWb9K/9KRjv7Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769880091; a=rsa-sha256; cv=none; b=wcj/7dQiRHfdf/3QmySWzYuLaX8smWLI79GByYDXsQUXWkhFliVXclpWI88liDHLHDEvPJ Tb3DeKcrIXrQHzgpx8YiAaKhqg6wSeSkqm8atvWnS6CsZkCvKNIV5NQ7Lp5GiQnZ/PESEr +F84zHuEdhj5dfkls9d6LtZYOh1TmnbglpzjKUhbaC6YVJHjzRX9ItkxCKVnU0qHlm+FrK sH8SR37THaQmDJvs04mKdMCJ93QV0AdjvEEtVH6dbPW+u2v9TaeMmCp1SPDW2htnGOXmLy aQKZr6cBct+c+cAXUj00CUW2He/+tcXnaOczjOv31AQv3VsTkqv5HeuC1nnsTQ== 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=1769880091; 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=h4Qd0FS3eHsfox7ZabarcRxnZk+DX6iX/atxhaJ4hm0=; b=KbeTHyMioJnPrxK3tCtGj5GHyfVs4k0wMA3VMKmc607nnZCnguG2LMsshVC570qVylUTNm /Ji/ofK76lKKUQH8uVtds0YAOd90UY0yrqg42XTWamlXGwLXlTqYRHIdgsYwfE2lEizQIQ 9ALYtHS5/Go5maBtPq7pAjHwIZm6Fqrk8KHTQWkAi1/KAQpFmLklIu1KqkKA3/e509bHPu mUisgBMkgm9vGAqV93pBhvRiy/HoKW8KUOrR5wwQZjdmkOjFfOfTG9eEFIPRRg9KXCQTB3 /F4ivUL+gDvsqdW67ao7XXrhqgsuIeAz11WkkYprznlP5EbrfWWMFD66o7+WHg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f3KRb5ZJfz13gL for ; Sat, 31 Jan 2026 17:21:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1c90e by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 31 Jan 2026 17:21:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 4c822dd4a15c - main - libkern: Add libcalls for ffs and __ffsdi2 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4c822dd4a15c533c08271b2286da949fffafc89e Auto-Submitted: auto-generated Date: Sat, 31 Jan 2026 17:21:31 +0000 Message-Id: <697e3a1b.1c90e.7866f183@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4c822dd4a15c533c08271b2286da949fffafc89e commit 4c822dd4a15c533c08271b2286da949fffafc89e Author: John Baldwin AuthorDate: 2026-01-31 17:20:50 +0000 Commit: John Baldwin CommitDate: 2026-01-31 17:20:50 +0000 libkern: Add libcalls for ffs and __ffsdi2 These are needed when compiling a RISC-V kernel with GCC which does not inline __builtin_ffs*. The __ffsdi2 is adapated from the previous ffsl.c. This partially reverts commit f4db342d44198973c1c7b9005d0c5683a582707e. Reviewed by: mhorne Differential Revision: https://reviews.freebsd.org/D54967 --- sys/libkern/ffs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ sys/libkern/ffsdi2.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ sys/libkern/quad.h | 1 + 3 files changed, 95 insertions(+) diff --git a/sys/libkern/ffs.c b/sys/libkern/ffs.c new file mode 100644 index 000000000000..e0308ef76bae --- /dev/null +++ b/sys/libkern/ffs.c @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + */ + +int ffs(int mask); + +/* + * Find First Set bit + */ +int +ffs(int mask) +{ + int bit; + + if (mask == 0) + return (0); + for (bit = 1; !(mask & 1); bit++) + mask = (unsigned int)mask >> 1; + return (bit); +} diff --git a/sys/libkern/ffsdi2.c b/sys/libkern/ffsdi2.c new file mode 100644 index 000000000000..33e255a26dc6 --- /dev/null +++ b/sys/libkern/ffsdi2.c @@ -0,0 +1,47 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 + +/* + * Find First Set bit + */ +int +__ffsdi2(quad_t mask) +{ + int bit; + + if (mask == 0) + return (0); + for (bit = 1; !(mask & 1); bit++) + mask = (quad_t)mask >> 1; + return (bit); +} diff --git a/sys/libkern/quad.h b/sys/libkern/quad.h index 59b3da44dbaa..cbb94ab98828 100644 --- a/sys/libkern/quad.h +++ b/sys/libkern/quad.h @@ -102,6 +102,7 @@ quad_t __ashrdi3(quad_t, qshift_t); int __cmpdi2(quad_t a, quad_t b); quad_t __divdi3(quad_t a, quad_t b); quad_t __divmoddi4(quad_t a, quad_t b, quad_t *rem); +int __ffsdi2(quad_t a); quad_t __lshrdi3(quad_t, qshift_t); quad_t __moddi3(quad_t a, quad_t b); u_quad_t __qdivrem(u_quad_t u, u_quad_t v, u_quad_t *rem);