Re: [PATCH] x86/math64: handle #DE in mul_u64_u64_div_u64()

From: David Laight
Date: Tue Jul 22 2025 - 17:53:53 EST


On Tue, 22 Jul 2025 09:53:21 -0700
"H. Peter Anvin" <hpa@xxxxxxxxx> wrote:

...
>
> Note that -1 for division by zero (not necessarily for overflow) follows from
> most natural division algorithms, and so architectures which don't trap
> on division overflow tend to behave that way.

Do you think that just returning ~0 is enough (maybe with a WARN_ONCE) ?
Code can check for it and the number of false positives would be minimal.

I have wondered about having muldiv(a, b, c, d, errval) that returns 'errval'
if '(a * b + c)/ d' overflows or if 'd' is zero.
Otherwise you are trying to return too many values from a function
(esp. on 32bit).
'asm goto' or 'flags' will only work for x86_64, starts being a real mess
for the generic code.
(Time for a language feature that lets the caller see modifications to
a parameter that is passed by value...)

David