From nobody Wed Nov 29 16:38:00 2023 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 4SgQ3s1tp7z52wwk; Wed, 29 Nov 2023 16:38:01 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SgQ3s0qlcz3Grg; Wed, 29 Nov 2023 16:38:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701275881; 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=HZpgGiK04wiK9KSdpYnMuF9uxQOZyP4dqTPTOBrL0Js=; b=cMJ6a+dRxTPahgz+sG72nSCh20NTiTmc/H+Czzeko/fNQSRrxtELfZsjBmQ+3nhqpO6cMt aijexZm+QP4jkI9XTpvZhZlAtpIJKZMyGp7AqXSWhPQraE0Wb87BtTwv2UY1D1SgjmWXhL FHXIWiitT95J3Ur8TnzzLKDY/CwWMZlCE4UPiXzwaTcpGR5zxuJ8V0ksskYZDU7RcupoQU TUsBBjFzEHPUKdaiKmGz2eebIgHLPiBceqC6WBSn2Nhhhu1fIBTWZ4ETyF2el8bO88pw3P NTcpV5fti5M+tR0DYoQvo+GpBq5+f0/EspORKKs5QPv+YsMJdypQJIo7f0Kb0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701275881; 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=HZpgGiK04wiK9KSdpYnMuF9uxQOZyP4dqTPTOBrL0Js=; b=e+q0W2V4jXGKt+NtjdZiCKyetHRDeENFy+MdVNK96WqdMhlrvxKtNSCkZrxPNhm0wLJqvJ GMM5l4ISg9vlRUwI0p2ahw2p/GedNEzm1I6D/+Xz91fi/3stwhcQnXSq9HbvC5G08uJwfF KFWi86jC/QRYkVg7/jmnpj/HjL2eEk9CDpWl++ASLOGIxl9ZMHNQHCzutMKRpieRGaoAbd uhond5TBRwNZ/dzCItGuPvwnfnm/EiEsrXbd8DeOC2kowDK7MWMcEhUORxRgLyBxMLvATJ zMzLD49CsHP6xi01+jbXbU0Tha9LSRiiq20LBVIxNUJCtfiRJTET7h+dGFtQQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701275881; a=rsa-sha256; cv=none; b=hM+XcRLAakWwZvEE6ByyaXYrUwKYHCwQF4Gvy5hRNHX3OouKrcoUBBIw+ana5LFiZHSTY6 imT2lfbgt7uMERebk9IggYEgYUOrBrT9Uclj0Fzs0tzuachkCRi3Un1wCrSC9Qc+CJL4Ej QsW5eYW4KP2aJ1Os03MQl80M2i5on0gnH8R5W7/nGJXl6mW+gIjKRofbthvCz0JULsSqyB 7sihQPxTwSAW8aI4Tt2F3swIysH9puuN6SGF9iEHoxo3tKEPHRATEKdmQYfluqIlP/Yyxl NWuJFTjIjqUknb/qrc1L4nEvPjSbJsHI8kRDJHDWJ/Z1Jh5cGVvjgWfMQMgwQQ== 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 4SgQ3r6wThz1Bwh; Wed, 29 Nov 2023 16:38:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3ATGc0G3044731; Wed, 29 Nov 2023 16:38:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ATGc0Fj044728; Wed, 29 Nov 2023 16:38:00 GMT (envelope-from git) Date: Wed, 29 Nov 2023 16:38:00 GMT Message-Id: <202311291638.3ATGc0Fj044728@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: f0d33323feab - stable/13 - LinuxKPI: implement mul_u64_u64_div_u64() 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f0d33323feab22b2550437132b8ee89f2086b310 Auto-Submitted: auto-generated The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=f0d33323feab22b2550437132b8ee89f2086b310 commit f0d33323feab22b2550437132b8ee89f2086b310 Author: Bjoern A. Zeeb AuthorDate: 2023-05-16 20:55:00 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-11-29 16:36:04 +0000 LinuxKPI: implement mul_u64_u64_div_u64() Implement mul_u64_u64_div_u64() for an updated iwlwifi driver (though we do not yet use it there; it is used for in-kernel ptp on wifi). Sponsored by: The FreeBSD Foundation (cherry picked from commit b80ea452375f52a3ab7d82a9aef10da0d89985d9) Unbalanced parentheses broke the build; re-balance. Fixes: b80ea452375f ("LinuxKPI: implement mul_u64_u64_div_u64()") (cherry picked from commit dabbbebcb0f5ced163454cd08b78e551b4a365b5) linuxkpi math: fix kassert in math64.h Include in math64.h, so that KASSERT and bool are defined, to allow compilation to succeed after b80ea452375f52a3ab7d82a9aef10da0d89985d9 and dabbbebcb0f5... (cherry picked from commit b6a61d6836d90ff2756d804eb981a02b0828f496) --- sys/compat/linuxkpi/common/include/linux/math64.h | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/math64.h b/sys/compat/linuxkpi/common/include/linux/math64.h index 1b00fd71e69f..cae5e30b08df 100644 --- a/sys/compat/linuxkpi/common/include/linux/math64.h +++ b/sys/compat/linuxkpi/common/include/linux/math64.h @@ -29,6 +29,7 @@ #define _LINUXKPI_LINUX_MATH64_H #include +#include #define do_div(n, base) ({ \ uint32_t __base = (base); \ @@ -106,6 +107,54 @@ mul_u64_u32_div(uint64_t x, uint32_t y, uint32_t div) return ((x / div) * y + (rem * y) / div); } +static inline uint64_t +mul_u64_u64_div_u64(uint64_t x, uint64_t y, uint64_t z) +{ + uint64_t res, rem; + uint64_t x1, y1, y1z; + + res = rem = 0; + x1 = x; + y1z = y / z; + y1 = y - y1z * z; + + /* + * INVARIANT: x * y = res * z + rem + (y1 + y1z * z) * x1 + * INVARIANT: y1 < z + * INVARIANT: rem < z + */ + while (x1 > 0) { + /* Handle low bit. */ + if (x1 & 1) { + x1 &= ~1; + res += y1z; + rem += y1; + if ((rem < y1) || (rem >= z)) { + res += 1; + rem -= z; + } + } + + /* Shift x1 right and (y1 + y1z * z) left */ + x1 >>= 1; + if ((y1 * 2 < y1) || (y1 * 2 >= z)) { + y1z = y1z * 2 + 1; + y1 = y1 * 2 - z; + } else { + y1z *= 2; + y1 *= 2; + } + } + + KASSERT(res * z + rem == x * y, ("%s: res %ju * z %ju + rem %ju != " + "x %ju * y %ju", __func__, (uintmax_t)res, (uintmax_t)z, + (uintmax_t)rem, (uintmax_t)x, (uintmax_t)y)); + KASSERT(rem < z, ("%s: rem %ju >= z %ju\n", __func__, + (uintmax_t)rem, (uintmax_t)z)); + + return (res); +} + static inline uint64_t mul_u64_u32_shr(uint64_t x, uint32_t y, unsigned int shift) {