[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] xen: Move x86-ism out of muldiv64.c



commit 65efa94cf547fa9d1d2bcf2f6c01ce3c9a69aa86
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Tue Dec 23 23:47:43 2025 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Jan 7 11:53:01 2026 +0000

    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@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 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(-)

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 <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 */
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 <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 */
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
 }
 
 /*
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.