From nobody Fri Aug 18 01:21:25 2023 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 4RRkbp2Rtmz4qR3s; Fri, 18 Aug 2023 01:21: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RRkbp0QNbz3PvL; Fri, 18 Aug 2023 01:21:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692321686; 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=AlqkZIVUvmVH35mJHB2LlcyphjVhndtOdsYdc3Pi0lg=; b=C0Ce2d6cmNyEChmc1FEQWtanhLVWTytPqExRxCPDR426ueUelVHCUj9wjAatMeH2J1x+M+ Ne4c31s4SRECl38ETS3rWs8hs1/A+p/koXaAMLqhDHmA9BBaEAQPrvLdNdZhz0jRqa/Ljw oSY3v9nUNSz5l1xb2/hssDkS4MQ6IPacBQrnGhL5RLhhi0LGeRFyZ3qS/FBkpIVkd/N2dH WVggL0k4dw9SFAQcMqne7yHNL1B9d4/lF2yihaoqPIhoG2dda41ah2IIAXNeblyb3E3NVZ 4vBvb+jxXNqPDsK74G77bmbQshll3zoEb+GYdnhFWohoGrPb6IrGTqR6oW885w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692321686; 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=AlqkZIVUvmVH35mJHB2LlcyphjVhndtOdsYdc3Pi0lg=; b=nngpsQ1ZUuckQXcqpe5d/nZQ3RZKh6E5KbZU2Dat4xQbDjSPyyD2ANeQr0maDmro8lwjUN zgucPpdv2wIegeTYOAFdLYCzveCYExh/CYNI/nhAlznUjH+smcRMmVchRl+LSBucqvi6OJ KWD89Tse8Utb/VFhvgt2+RbKIXzxJVI7841ACeI2P+X8NIOCfh4W1IzajjWNEZpoEP/1/C 5DuTOFOOYEnr4Zk5Il+SZK94e/nbETEAJTHS2CoUHU50wFCmJTpmAM9odH/nKV8gKAIrf0 Jk8MzNfrjWPSimefWQTWAjjTWab1tC45maEbD/CswPZwvVaIu8uL8rfWImy5CA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692321686; a=rsa-sha256; cv=none; b=iVn7gJrR0itUgFfrGq9bg0WjVPW2CLiFE8nOqJgDX3RpiMbLBdHrFrS8uAHOOMMQg2kgJK 9jS/cNGJXeiwE0AZZv0N1JQnMYh6HrYmT9AuBY75beQ/BQj2QI4Db2yYVVeohZJxKtwwku Trk1R74SpSVuvk+NpBE5zq85UA4XBYGV0E4RgeIoBUfmBR1p+CE5IclMgICRYeD6cghLK1 4yzOfJwLqTXYyvZ+VnJ8PMpkiHobabxbnx94IkqPmZqChyycFwXhD/mfb1eATDQq4isUbT 6aBo8HUWl+WjAktH8spAZqpjNglFDBSTf6Kej1X24Zd64G361ekWUFDnHUZmKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RRkbn6cj1zwlv; Fri, 18 Aug 2023 01:21:25 +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 37I1LPj5024074; Fri, 18 Aug 2023 01:21:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37I1LPTc024071; Fri, 18 Aug 2023 01:21:25 GMT (envelope-from git) Date: Fri, 18 Aug 2023 01:21:25 GMT Message-Id: <202308180121.37I1LPTc024071@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: b80ea452375f - main - LinuxKPI: implement mul_u64_u64_div_u64() 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b80ea452375f52a3ab7d82a9aef10da0d89985d9 Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=b80ea452375f52a3ab7d82a9aef10da0d89985d9 commit b80ea452375f52a3ab7d82a9aef10da0d89985d9 Author: Bjoern A. Zeeb AuthorDate: 2023-05-16 20:55:00 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-08-18 01:20:39 +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 Submitted by: cperciva MFC after: 10 days Reviewed by: cperciva, dwmalone Differential Revision: https://reviews.freebsd.org/D40120 --- sys/compat/linuxkpi/common/include/linux/math64.h | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/math64.h b/sys/compat/linuxkpi/common/include/linux/math64.h index 1b00fd71e69f..e4ddce5b823e 100644 --- a/sys/compat/linuxkpi/common/include/linux/math64.h +++ b/sys/compat/linuxkpi/common/include/linux/math64.h @@ -106,6 +106,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) {