mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: FUJITA Tomonori <tomo@flapping.org>
Cc: 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,
	boqun@kernel.org, daniel.almeida@collabora.com,
	tamird@kernel.org, acourbot@nvidia.com, work@onurozkan.dev,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] rust: time: implement `Debug` for `Delta`
Date: Thu, 26 Nov 2026 13:01:48 +0100	[thread overview]
Message-ID: <87o6bbu7gz.fsf@t14s.mail-host-address-is-not-set> (raw)
In-Reply-To: <20261126.202530.1337423276496737821.tomo@flapping.org>

"FUJITA Tomonori" <tomo@flapping.org> writes:

> On Thu, 26 Nov 2026 11:51:14 +0100
> Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
>> +    fn fmt(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result {
>> +        let value = U::repr_to_i64(self.value);
>> +
>> +        if value < 0 {
>> +            f.write_str("-")?;
>> +        }
>> +
>> +        // `unsigned_abs` is used because the magnitude of `i64::MIN` is not
>> +        // representable as an `i64`.
>> +        let mut magnitude = value.unsigned_abs();
>> +
>> +        // Split the magnitude into groups of three digits, least significant
>> +        // group first. A `u64` holds at most 20 digits, so 7 groups suffice.
>> +        //
>> +        // Dividing by the constant keeps the compiler from emitting a check for
>> +        // a division by zero with a potential panic.
>> +        let mut groups = [0u64; 7];
>> +        let mut used = 0;
>> +
>> +        for group in groups.iter_mut() {
>> +            *group = magnitude % 1000;
>> +            magnitude /= 1000;
>
> Code that uses this Debug impl fails to build on 32-bit ARM, for
> example the doctests:
>
> ld.lld-20: error: undefined symbol: __aeabi_uldivmod
>>>> referenced by doctests_kernel_generated.ea22ff07120af58c-cgu.0
>>>>               rust/doctests_kernel_generated.o:(<kernel::fmt::Adapter<&kernel::time::Delta<kernel::time::Jiffy>> as core::fmt::Debug>::fmt) in archive vmlinux.a
>
> div64_u64() in my series [1] should work here:
>
>     let quotient = div64_u64(magnitude, 1000);
>     *group = magnitude - quotient * 1000;
>     magnitude = quotient;
>
> If you prefer, we could also add div_u64_rem() to the math module.

Ah, thanks. I'll re-spin on top of that series, adding the remainder function.

Best regards,
Andreas Hindborg



      reply	other threads:[~2026-11-26 12:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 10:51 Andreas Hindborg
2026-11-26 11:25 ` FUJITA Tomonori
2026-11-26 12:01   ` Andreas Hindborg [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=87o6bbu7gz.fsf@t14s.mail-host-address-is-not-set \
    --to=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=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.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=tomo@flapping.org \
    --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®