[PATCH v4 1/2] rust: math: add div64_u64() and div64_u64_round_up()
Alice Ryhl
aliceryhl at google.com
Wed Nov 18 15:23:43 PST 2026
On Thu, Nov 19, 2026 at 07:48:25AM +0900, FUJITA Tomonori wrote:
> From: FUJITA Tomonori <fujita.tomonori at gmail.com>
>
> On 32-bit architectures, dividing a u64 by a u64 with the `/` operator
> makes the compiler emit a call to a compiler runtime function, such as
> __aeabi_uldivmod() on arm. The kernel does not provide these functions,
> so the build fails when Rust code that is also built for 32-bit
> architectures uses `/` on u64.
>
> C code uses the helpers in include/linux/math64.h instead. Add a math
> module with Rust versions of two of them:
>
> - div64_u64(), the same as div64_u64() in C.
> - div64_u64_round_up(), the same as DIV64_U64_ROUND_UP() in C.
>
> On 64-bit architectures, both use `/`. On 32-bit architectures,
> div64_u64() calls the C function. Both panic if the divisor is zero,
> as `/` does.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori at gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl at google.com>
Alice
More information about the linux-riscv
mailing list