From nobody Fri Apr 24 15:29:25 2026 X-Original-To: dev-commits-src-branches@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 4g2H1x5y7yz6bSZh for ; Fri, 24 Apr 2026 15:29:25 +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" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g2H1x42NFz3Dgk for ; Fri, 24 Apr 2026 15:29:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777044565; 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=y5zptyctvgZ7juYsJv2Q3eBaZWEx0ILp+KtddduZpco=; b=Eck1xjddGOZfMd/qwwnY8nR38uupTcgDzPvd9F4x3sRS7DdCPXJmS0jvfQBnhwisWxbI9G 1UfIRmgfcZq18951pVRKXZYxHZEhMwi0DIIst5slO2usgU51uxjcEuO9O0lPOYA/Sks2d4 MOcFONsxjCbAT/Oxlo4A8fiEihwp68W641Bcsk3SoiPIYizEqv4ACxt/y8O3jouoaSb7TB Zj32kZvjCt6m37+Iqb3RumJonDdr+WZMngpRYkMi+o7C/jJ5lCQkBBzHa7XDQSGM7Vyb6B T+HtBNDOkiOuOP14Lnq5yZwNHwetWmh+cA6P+HZ/NiCm0dpgIWAYh+dhN9284g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777044565; a=rsa-sha256; cv=none; b=iDbypkKGLQ8AE9wE2eG4L8lANR36U7Vq6/D0c4gq37NeQGvxoeV/tMqDGhLZsmYyk3oCo+ kIDuSJuwW/7RrLMhBAcAKA3mVrr0ZjOMdPPfHigOa48hCzEoDBn497h/RfE47h+WjKRMPD IEuJaRbVOFf5g4uMqC79DV3jlgrWr0H9XQjjJCcXsWyl6mRPKWDp9QMcYhbI8sI3M4Vj5R VO1qJRQSnIau6h/DCjim+zBrEwmpl/AxPc6DOiDlg/p6VCh+ehu0NV4JG60Bqe5bCDings miO8lt6bFaX/mqxsfjWxv5dzseXNskDGSr3fEE9nuWTtGdAZrtkn1+i9jD+CYg== 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=1777044565; 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=y5zptyctvgZ7juYsJv2Q3eBaZWEx0ILp+KtddduZpco=; b=aAcBZ3Lv/mDnnsaD70o4s9ruqJnXAcH/JN+bSepVlgGDbVGyGE69fa5dd8w4f1J5cSXhGT oVDLOgrlr5YSVaCYGar4MbXKGYMm7F2tlBD4VKQoCLXv59T6kBqpmjbdpqUkVvk/4aUCaY zqIYPr5530w6/GS8lIdP+MGYY0oBXT2vqJtNWDglCriZ8Y0M3rmtm6gTWCMPIc7VyPwoBw RY7mTD1FRnddxev8yo1xNfbVf92EiW9gf4dLtaD3LGb16s2+R9Tbap1GxZcO6t5KGHo8X2 2Hia4ylIeggwsIuMpwGi0BId3lb7uvhV3OgzkYpJfYxIb3DRXErG2PWIQqfipA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g2H1x3TZYz17cR for ; Fri, 24 Apr 2026 15:29:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 35ef0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 24 Apr 2026 15:29:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: d100ff6c09c9 - stable/15 - libkern: Add libcalls for ffs and __ffsdi2 List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/15 X-Git-Reftype: branch X-Git-Commit: d100ff6c09c97babda963d2c295601650faeeebf Auto-Submitted: auto-generated Date: Fri, 24 Apr 2026 15:29:25 +0000 Message-Id: <69eb8c55.35ef0.7db8de48@gitrepo.freebsd.org> The branch stable/15 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=d100ff6c09c97babda963d2c295601650faeeebf commit d100ff6c09c97babda963d2c295601650faeeebf Author: John Baldwin AuthorDate: 2026-01-31 17:20:50 +0000 Commit: John Baldwin CommitDate: 2026-04-24 15:26:39 +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 (cherry picked from commit 4c822dd4a15c533c08271b2286da949fffafc89e) --- 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);