mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v5 3/3] rust: math: add signed division and remainder helpers
Date: Sat, 31 Oct 2026 20:58:27 +0900 (JST)	[thread overview]
Message-ID: <20261031.205827.850721536535565586.tomo@flapping.org> (raw)
In-Reply-To: <20261031103206.24051-4-chenhan0017.work@gmail.com>

On Sat, 31 Oct 2026 18:32:06 +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() for an i64 dividend and divisor, and div_s64_rem()
> for an i64 dividend and an i32 divisor. The latter returns an i64 quotient
> and an i32 remainder, matching the results of the C helper without
> exposing its output pointer. Delta's rem_nanos() uses the remainder and
> converts it to i64. Both helpers retain Rust's signed operator semantics
> and unconditional panic checks, using the existing C helpers on 32-bit.
> 
> Keep the Delta API and its panic conditions unchanged. Document the
> quotient and remainder semantics and link to the corresponding C header.
> 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>

Reviewed-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

Two nits, only if you respin for other reasons:

The second sentence of the SAFETY comment in div_s64_rem() could be
shorter. The old comment in time.rs said enough:

    // SAFETY: `rem` is in the stack, so we can always provide a valid
    // pointer to it.

The helpers have no examples. A doctest for each would also run as a
KUnit test for the valid inputs on both 32-bit and 64-bit.

      reply	other threads:[~2026-10-31 11:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 10:32 [PATCH v5 0/3] rust: time: fix Delta arithmetic and add math helpers chenhan
2026-10-31 10:32 ` [PATCH v5 1/3] rust: time: rename the rem_nanos() divisor chenhan
2026-10-31 10:32 ` [PATCH v5 2/3] rust: time: make Delta division and remainder fail consistently chenhan
2026-10-31 11:44   ` FUJITA Tomonori
2026-10-31 10:32 ` [PATCH v5 3/3] rust: math: add signed division and remainder helpers chenhan
2026-10-31 11:58   ` FUJITA Tomonori [this message]

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=20261031.205827.850721536535565586.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®