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

[Xen-devel] [XTF] [PATCH] lib.c: added unsigned 64bits division for 32 bits arch



this is a simple implementation of unsigned 64bits divisions
for 32 bits archs.

Signed-off-by: Paul Semel <semelpaul@xxxxxxxxx>
---
 common/lib.c      | 21 +++++++++++++++++++++
 include/xtf/lib.h |  4 ++++
 2 files changed, 25 insertions(+)

diff --git a/common/lib.c b/common/lib.c
index acf4da1..36d5600 100644
--- a/common/lib.c
+++ b/common/lib.c
@@ -68,6 +68,27 @@ int xtf_get_domid(void)
     return domid;
 }
 
+#if defined(__i386__)
+uint32_t __udiv64_32(uint64_t *n, uint32_t base)
+{
+    uint32_t rem;
+    uint32_t high = ((uint32_t *)n)[1];
+
+    ((uint32_t *)n)[1] = 0;
+    if (high >= base) {
+        ((uint32_t *)n)[1] = high / base;
+        high %= base;
+    }
+
+    __asm__("divl %2"
+            : "=a"(((uint32_t*)n)[0]), "=d"(rem)
+            : "rm"(base), "0"(((uint32_t*)n)[0]), "1"(high));
+
+    return rem;
+}
+
+#endif
+
 /*
  * Local variables:
  * mode: C
diff --git a/include/xtf/lib.h b/include/xtf/lib.h
index abf8f25..4479286 100644
--- a/include/xtf/lib.h
+++ b/include/xtf/lib.h
@@ -101,6 +101,10 @@ int xtf_probe_sysctl_interface_version(void);
  */
 int xtf_get_domid(void);
 
+#if defined(__i386__)
+uint32_t __udiv64_32(uint64_t *n, uint32_t base);
+#endif
+
 #endif /* XTF_LIB_H */
 
 /*
-- 
2.16.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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