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

From: Oleg Nesterov
Date: Fri Jul 25 2025 - 06:17:11 EST


On 07/24, H. Peter Anvin wrote:
>
> On July 24, 2025 4:14:26 AM PDT, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >Finally. If we really want to optimize this function as much as possible,
> >we can add the CONFIG_CC_HAS_ASM_GOTO_OUTPUT version as Peter suggests.
> >I guess this should work:

...

> >> Forgot to mention... Not that I think this is a good idea, but if we don't
> >> use BUG/WARN, we can probably add EX_FLAG_ and do something like below.

...

> Seems good to me.

Thanks, but which one? "asm goto" or EX_FLAG_XXX_AX hack?

As for the latter. I took another look at asm/extable_fixup_types.h
and it turns out we don't need a new EX_FLAG_, this version

static inline u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div)
{
u64 q;

asm ("mulq %2; 1: divq %3; 2:\n"
_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_IMM_REG | EX_DATA_IMM(-1))
: "=a" (q)
: "a" (a), "rm" (mul), "rm" (div)
: "rdx");

return q;
}

seems to work and I guess it is the absolute winner performance wise.

But to me the main question is: Peter, David, do we want to add
BUG and/or WARN into mul_u64_u64_div_u64??? If yes, then this version
won't work.

Oleg.