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 <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Andrew Cooper committed 2026-01-07 11:53:01 +00:00
1 parent 7a459b8df7
commit 65efa94cf5
3 files changed
+28 -8

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef X86_MULDIV64_H
#define X86_MULDIV64_H
#include <xen/stdint.h>
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 */
+8
View File
@@ -4,6 +4,10 @@
#include <xen/stdint.h>
#if __has_include(<asm/muldiv64.h>)
# include <asm/muldiv64.h>
#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 */
-8
View File
@@ -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
}
/*
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.