From nobody Thu Sep 10 19:50:20 2026 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 4hgpDr6zcDz6rDjk for ; Thu, 10 Sep 2026 19:50:20 +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 4hgpDr6RXlz4gBp for ; Thu, 10 Sep 2026 19:50:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789069820; 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=JT/n+oim+wC3JHyg9uUKKt9TqavAERMAEWbzFpsYa2eXOabCnF4MHXij0hXUAMWq042xUz YuXgo7/SkypSymUT+MiakDEnfkjAt5q8ZjWm45iWt7s2QI7KOK1ZgxmZLAcmDDmK1x+XzX 7toMqQ31grp6cedOPOAr+KvrZepcNVV4E/sEVAQ89aazq1f/CtzMhi3YRImGN6CDU/S9nH OFEMHsbQT0ZbPR9zPQnd40d0o5EFN6fsb+y0ch4GT1beqLZWFQ0ewe6GfKd/MG9gUQ/q8Q ELWDQAL5N5a+IdO/PmZXEjfM0bIFeMkRH2rRqJacbXSncxmxtV/sAZ30yJ1hcQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789069820; b=Dvj7wWohVXCjySfcJuXCPAF6ya72p8UnT6QcBLuAwBKSz0owclIMbrgzCurCoxjNnXeGAB wEef1H3q0sqdP/K8rL2qtPmDADrunV41mt7YTSjPL9K+/B2h/5kn1yxxanSMk6whPTxqUp /AjxVbfohSCR4kF7HosS+YeAQbQ29MpZwwt63xvJ8eSmCnkFAMZZeMfJv6ID0b/yAjM6ts jTN9k/g0IedZ1MBkAYdPccHeHdIrPo2FOzcs8wudV5GBJAo2fuJiin8ast+bX3w81v+np5 VBOkFzY1DOQ2QsllNjxVqSbX7s3Yz0ZL9EhW86mi7Q+cMlBMzlPiwctwLCQHTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789069820; 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=XUjXq6ZI8uXmDRWsKwQSRp9VxcDI++c5uVZZqwGEUbDdA4lhErxm8T3RpoSmyvCZgcECX+ iJdfO7493iPXHeyqYB1u/iswA300YfPajlinlTJ0xPQmN0X9AAFBnUqz5jcppu0oNM6Rj5 o+nzYqBMf/6ws6M4d+68MpmsvhTa3+3FJzcH3T/18j9KmNO/EEZtTwPB44XsNPojVqduXX mhjeSMUDyH7lqK4PZ0lX9lue/m9CxQct7Mfu5mGgJxSeUbypHv6i1LDniLJ9FWBvzGFTaH lHSPqwmPBHnnLGFbsd1B1PGptQIabmDsHSUz/6aQ4cRDpUZoaWfPsG0b/Jj8zQ== 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 4hgpDr5V0xzhsW for ; Thu, 10 Sep 2026 19:50:20 +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 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 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 \