From: FUJITA Tomonori <tomo@flapping.org>
To: chenhan0017.work@gmail.com
Cc: rust-for-linux@vger.kernel.org, a.hindborg@kernel.org,
boqun@kernel.org, fujita.tomonori@gmail.com, frederic@kernel.org,
lyude@redhat.com, tglx@kernel.org, anna-maria@linutronix.de,
jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org,
daniel.almeida@collabora.com, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev,
miguel.ojeda.sandonis@gmail.com, tomo@flapping.org,
georgeandrout13@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] rust: math: add signed division and remainder helpers
Date: Wed, 21 Oct 2026 18:37:00 +0900 (JST) [thread overview]
Message-ID: <20261021.183700.735437784476089878.tomo@flapping.org> (raw)
In-Reply-To: <20261017111134.22546-4-chenhan0017.work@gmail.com>
On Sat, 17 Oct 2026 19:11:34 +0800
chenhan <chenhan0017.work@gmail.com> wrote:
> Delta's division and remainder implementations operate on integers and
> do not depend on time units. Move them into a math module to provide a
> common home for arithmetic helpers, with Delta as the initial user.
>
> Expose div64_s64() and rem_s64() so driver crates can use these operations
> without constructing time values. The division helper takes two i64
> operands; the remainder helper takes an i64 dividend and an i32 divisor
> and returns an i64. Both keep Rust's signed operator semantics, including
> the unconditional panic checks, and use the existing C helpers on 32-bit.
>
> Keep the Delta API and its panic documentation unchanged. This is separate
> from the preceding behavior fix so that introducing the math module is
> not required for a backport.
>
> Assisted-by: LLM
> Signed-off-by: chenhan <chenhan0017.work@gmail.com>
> ---
> rust/kernel/lib.rs | 1 +
> rust/kernel/math.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++
> rust/kernel/time.rs | 49 ++++------------------------------
> 3 files changed, 70 insertions(+), 44 deletions(-)
> create mode 100644 rust/kernel/math.rs
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index 4d5c96ddc49c..60c2af705b47 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -98,6 +98,7 @@
> pub mod kunit;
> pub mod list;
> pub mod maple_tree;
> +pub mod math;
> pub mod miscdevice;
> pub mod mm;
> pub mod module;
> diff --git a/rust/kernel/math.rs b/rust/kernel/math.rs
> new file mode 100644
> index 000000000000..34ca097caac9
> --- /dev/null
> +++ b/rust/kernel/math.rs
> @@ -0,0 +1,64 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Integer arithmetic helpers.
//! C header: [`include/linux/math64.h`](srctree/include/linux/math64.h).
?
> +/// Returns the remainder of an [`i64`] dividend divided by an [`i32`] divisor.
> +///
> +/// A non-zero remainder has the sign of `dividend`.
> +///
> +/// # Panics
> +///
> +/// Panics if `divisor` is zero, or if `dividend` is [`i64::MIN`] and `divisor` is `-1`.
> +#[inline]
> +pub fn rem_s64(dividend: i64, divisor: i32) -> i64 {
How about matching the C function? Something like:
pub fn div_s64_rem(dividend: i64, divisor: i32) -> (i64, i32)
next prev parent reply other threads:[~2026-10-21 9:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 11:11 [PATCH v3 0/3] rust: time: fix Delta arithmetic and add math helpers chenhan
2026-10-17 11:11 ` [PATCH v3 1/3] rust: time: rename the rem_nanos() divisor chenhan
2026-10-21 7:33 ` FUJITA Tomonori
2026-10-17 11:11 ` [PATCH v3 2/3] rust: time: make Delta division and remainder fail consistently chenhan
2026-10-17 11:11 ` [PATCH v3 3/3] rust: math: add signed division and remainder helpers chenhan
2026-10-21 9:16 ` FUJITA Tomonori
2026-10-21 9:37 ` FUJITA Tomonori [this message]
2026-10-23 13:06 ` chenhan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261021.183700.735437784476089878.tomo@flapping.org \
--to=tomo@flapping.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=chenhan0017.work@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=georgeandrout13@gmail.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tamird@kernel.org \
--cc=tglx@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®