From 65efa94cf547fa9d1d2bcf2f6c01ce3c9a69aa86 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Tue, 23 Dec 2025 23:47:43 +0000 Subject: [PATCH] xen: Move x86-ism out of muldiv64.c Having an #ifdef CONFIG_X86 section in a common library is rude. Furthermore, for x86 the main logic is 6 bytes, meaning it's ripe for inlining. Create an x86-specific asm/muldiv.h implementing arch_muldiv64(). Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- xen/arch/x86/include/asm/muldiv64.h | 20 ++++++++++++++++++++ xen/include/xen/muldiv64.h | 8 ++++++++ xen/lib/muldiv64.c | 8 -------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 xen/arch/x86/include/asm/muldiv64.h diff --git a/xen/arch/x86/include/asm/muldiv64.h b/xen/arch/x86/include/asm/muldiv64.h new file mode 100644 index 0000000000..07449292ff --- /dev/null +++ b/xen/arch/x86/include/asm/muldiv64.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef X86_MULDIV64_H +#define X86_MULDIV64_H + +#include + +static inline uint64_t attr_const arch_muldiv64(uint64_t a, uint32_t b, uint32_t c) +{ + asm_inline ( + "mulq %[b]\n\t" + "divq %[c]" + : "+a" (a) + : [b] "rm" ((uint64_t)b), [c] "rm" ((uint64_t)c) + : "rdx" ); + + return a; +} +#define arch_muldiv64 arch_muldiv64 + +#endif /* X86_MULDIV64_H */ diff --git a/xen/include/xen/muldiv64.h b/xen/include/xen/muldiv64.h index 6141f5c401..8243b97279 100644 --- a/xen/include/xen/muldiv64.h +++ b/xen/include/xen/muldiv64.h @@ -4,6 +4,10 @@ #include +#if __has_include() +# include +#endif + uint64_t attr_const generic_muldiv64(uint64_t a, uint32_t b, uint32_t c); /* @@ -12,7 +16,11 @@ uint64_t attr_const generic_muldiv64(uint64_t a, uint32_t b, uint32_t c); */ static inline uint64_t attr_const muldiv64(uint64_t a, uint32_t b, uint32_t c) { +#ifdef arch_muldiv64 + return arch_muldiv64(a, b, c); +#else return generic_muldiv64(a, b, c); +#endif } #endif /* XEN_MULDIV64_H */ diff --git a/xen/lib/muldiv64.c b/xen/lib/muldiv64.c index 545a9bad19..53847a6ed4 100644 --- a/xen/lib/muldiv64.c +++ b/xen/lib/muldiv64.c @@ -2,13 +2,6 @@ uint64_t generic_muldiv64(uint64_t a, uint32_t b, uint32_t c) { -#ifdef CONFIG_X86 - asm ( "mulq %1; divq %2" : "+a" (a) - : "rm" ((uint64_t)b), "rm" ((uint64_t)c) - : "rdx" ); - - return a; -#else union { uint64_t ll; struct { @@ -31,7 +24,6 @@ uint64_t generic_muldiv64(uint64_t a, uint32_t b, uint32_t c) res.l.low = (((rh % c) << 32) + (uint32_t)rl) / c; return res.ll; -#endif } /*