Re: [PATCH v3] rust: time: implement `Debug` for `Delta`
From: FUJITA Tomonori
Date: Thu Nov 26 2026 - 06:30:43 EST
On Thu, 26 Nov 2026 11:51:14 +0100
Andreas Hindborg <a.hindborg@xxxxxxxxxx> 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.
[1] https://lore.kernel.org/rust-for-linux/20261118224826.2491684-1-tomo@xxxxxxxxxxxx/