From nobody Thu Sep 10 19:50:20 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 4hgpDy1xFLz6rDrj for ; Thu, 10 Sep 2026 19:50:26 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hgpDy05Jlz4gdl for ; Thu, 10 Sep 2026 19:50:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789069826; 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=qAT8PPtSYhv3p4gZ5FDkrWlx6PiVmoMoCAjDK56m6JM=; b=Hyqt9eVDgN+HtjXT24jaKeG6JXj/2AOzrXdTFG4JHgITCsEjAdAkrDqr01PjZZo4wcnQ9a CiSulw2l9m9ITciPZaQm9xTqHQFkYGoy++wcpahhTNB8ndEG007xauR2KXQbeQZ0pvB+SV tcxkhQe48hj1nsMhtYs4nLRU6zDOB9WTHU452nQcwGrMGmPr9hmEpi2skXviXZjoTg8xev qxGouFMtdlsK+QJ2lTmCUZ80U8UPSy3eg6oRW3QKiXQRn38JWnxfLDSJPpI3NMvKo/RB7o 3PKqtnqxndhZJuna9T+8aTCHG1DQzJ+vKDNRS8UU5KTI2bG/obv0K6ifhYdMWA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789069826; b=NYj2ASZBktODWhv91bWbfvcYs5zkq1jafln99uqy1X438mzkz4NvVJUJcPFii9qB7C3Ca9 8kvpZMZtfDKWQhDLgvbdaskHG1KZLJHJ1dkpPQGQOS9ZHPGvX2tgqGHR3TdS/h52BFUBXQ Oq0S3Jqb90Q6gGvUzPuHD8kezrRIcP7WqaTEuX7COu6Mwlr4a6gLP4SD4yd2T1tjmdn7ID odIDLXHC0dZ7kmviMwvAE/4j+xTb6+UzlSZpGXo5AIrCmfOQBYsQcJVR/5w7ZWovOsG5rL a9Cte59zQMY9ctqsIXP5tM0hGI3xOT38L1IDNW1XRG2tGfClQqQ4Qw4WAQOLiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789069826; 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=qAT8PPtSYhv3p4gZ5FDkrWlx6PiVmoMoCAjDK56m6JM=; b=fL3j+BV6wxFz34c3JmhBihRFlu69mkOV8jb3G6nvtNSHLAjDe+0s+Tct9xT3xAbANZrIpV Z8YSKfs8b74HDc/4phZlFeHEqKi93WjrOmMGmTPwgEiSVnWxNr3zvsrXah5TzMwy/jMOkl 77/PNBvtcyJ8c3Aa9/USS6JC5S5WTRMXomyElhwgEcn81bney0X4eCYkN+7409EQitMQiS hzjBlR/f2PeLErxT+/icXJEoMpB/b+p6GZuExYvsNK7xHgypODEhWlsR4XyI8jU/xNSiEA fn48+xkIWXf0c/SkmYCrRZs7t0aHA6z1RlfazoWqx9d8NsWPCEhuXG3L+VfE0g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hgpDx61XbzjCv for ; Thu, 10 Sep 2026 19:50:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1ece1 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 10 Sep 2026 19:50:20 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron Subject: git: d4820dc1e6cb - main - linuxkpi: Add `int_sqrt()` 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d4820dc1e6cb9ec9d8d3ef030f143c69f92228cd Auto-Submitted: auto-generated Date: Thu, 10 Sep 2026 19:50:20 +0000 Message-Id: <6aa309fc.1ece1.471b8562@gitrepo.freebsd.org> The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=d4820dc1e6cb9ec9d8d3ef030f143c69f92228cd commit d4820dc1e6cb9ec9d8d3ef030f143c69f92228cd Author: Jean-Sébastien Pédron AuthorDate: 2026-08-15 18:30:35 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2026-09-10 19:39:32 +0000 linuxkpi: Add `int_sqrt()` The implementation comes from `isqrt64()` in `sys/cam/cam_iosched.c`. It is modified to take an `unsigned long` and return an `unsigned int`. The i915 DRM driver started to use it in Linux 6.15. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58251 --- sys/compat/linuxkpi/common/include/linux/math.h | 3 ++ sys/compat/linuxkpi/common/src/linux_math.c | 43 +++++++++++++++++++++++++ sys/conf/files | 2 ++ sys/modules/linuxkpi/Makefile | 1 + 4 files changed, 49 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/math.h b/sys/compat/linuxkpi/common/include/linux/math.h index 1d50e011f66d..777d989c041f 100644 --- a/sys/compat/linuxkpi/common/include/linux/math.h +++ b/sys/compat/linuxkpi/common/include/linux/math.h @@ -64,6 +64,9 @@ }) #endif +unsigned long linuxkpi_int_sqrt(unsigned long val); +#define int_sqrt(x) linuxkpi_int_sqrt(x) + static inline uintmax_t mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor) { diff --git a/sys/compat/linuxkpi/common/src/linux_math.c b/sys/compat/linuxkpi/common/src/linux_math.c new file mode 100644 index 000000000000..29e538c5d9c9 --- /dev/null +++ b/sys/compat/linuxkpi/common/src/linux_math.c @@ -0,0 +1,43 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2015 Netflix, Inc. + */ + +#include + +/* + * Based on the implementation of `isqrt64()` from `sys/cam/cam_iosched.c` as + * of FreeBSD commit 153446ecd740702af00cf9b09d8cd39f6d397dd3. The return value + * was changed from `uint64_t` to `unsigned long`. + */ +unsigned long +linuxkpi_int_sqrt(unsigned long val) +{ + unsigned long res = 0; + unsigned long bit = 1ULL << (sizeof(unsigned long) * NBBY - 2); + + /* + * Find the largest power of 4 smaller than val. + */ + while (bit > val) + bit >>= 2; + + /* + * Accumulate the answer, one bit at a time (we keep moving + * them over since 2 is the square root of 4 and we test + * powers of 4). We accumulate where we find the bit, but + * the successive shifts land the bit in the right place + * by the end. + */ + while (bit != 0) { + if (val >= res + bit) { + val -= res + bit; + res = (res >> 1) + bit; + } else + res >>= 1; + bit >>= 2; + } + + return res; +} diff --git a/sys/conf/files b/sys/conf/files index 8dd5a6a6873b..c6655459187f 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -4740,6 +4740,8 @@ compat/linuxkpi/common/src/linux_kthread.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_lock.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" +compat/linuxkpi/common/src/linux_math.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_mhi.c optional compat_linuxkpi wlan \ compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_netdev.c optional compat_linuxkpi \ diff --git a/sys/modules/linuxkpi/Makefile b/sys/modules/linuxkpi/Makefile index 35dc19f93185..97319194946e 100644 --- a/sys/modules/linuxkpi/Makefile +++ b/sys/modules/linuxkpi/Makefile @@ -19,6 +19,7 @@ SRCS= linux_compat.c \ linux_kobject.c \ linux_kthread.c \ linux_lock.c \ + linux_math.c \ linux_netdev.c \ linux_page.c \ linuxkpi_page_pool.c \