libxc: Define xc_ffs{8,16,32,64} functions. Use them.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 6 Jan 2009 09:14:39 +0000 (09:14 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 6 Jan 2009 09:14:39 +0000 (09:14 +0000)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
tools/libxc/xc_pagetab.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h
tools/libxc/xc_ptrace.c
tools/libxc/xg_private.c

index 8c628b4404a4f960f6dbeb78ad0b3c69dc7b6c8e..824cbbe988b7bf942e1dc551a88a5ce95d94c987 100644 (file)
@@ -4,7 +4,6 @@
  * Function to translate virtual to physical addresses.
  */
 #include "xc_private.h"
-#include <strings.h>
 
 #define CR0_PG  0x80000000
 #define CR4_PAE 0x20
@@ -77,7 +76,7 @@ unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
 
     /* Walk the pagetables */
     for (level = pt_levels; level > 0; level--) {
-        paddr += ((virt & mask) >> (ffsll(mask) - 1)) * size;
+        paddr += ((virt & mask) >> (xc_ffs64(mask) - 1)) * size;
         map = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, 
                                    paddr >>PAGE_SHIFT);
         if (!map) 
index 5990415d9e52c4dd5162ff1ae6f5f4bc9898d227..e0613b9e4f7023981a4f61a247b186977e510090 100644 (file)
@@ -639,6 +639,33 @@ int write_exact(int fd, const void *data, size_t size)
     return 0;
 }
 
+int xc_ffs8(uint8_t x)
+{
+    int i;
+    for ( i = 0; i < 8; i++ )
+        if ( x & (1u << i) )
+            return i+1;
+    return 0;
+}
+
+int xc_ffs16(uint16_t x)
+{
+    uint8_t h = x>>8, l = x;
+    return l ? xc_ffs8(l) : h ? xc_ffs8(h) + 8 : 0;
+}
+
+int xc_ffs32(uint32_t x)
+{
+    uint16_t h = x>>16, l = x;
+    return l ? xc_ffs16(l) : h ? xc_ffs16(h) + 16 : 0;
+}
+
+int xc_ffs64(uint64_t x)
+{
+    uint32_t h = x>>32, l = x;
+    return l ? xc_ffs32(l) : h ? xc_ffs32(h) + 32 : 0;
+}
+
 /*
  * Local variables:
  * mode: C
index ef8e3d2f7a4c5209793190b04e527736cdaf2f89..d95bd0675d04ea46741cb6caf9998b29b56caf42 100644 (file)
@@ -218,4 +218,9 @@ int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu);
 int read_exact(int fd, void *data, size_t size);
 int write_exact(int fd, const void *data, size_t size);
 
+int xc_ffs8(uint8_t x);
+int xc_ffs16(uint16_t x);
+int xc_ffs32(uint32_t x);
+int xc_ffs64(uint64_t x);
+
 #endif /* __XC_PRIVATE_H__ */
index 094bf165dfd8f5a673d9d66120f1cf289206f7ae..4fe67e934353fda7425d469c69e8b7ab24e08149 100644 (file)
@@ -44,8 +44,7 @@ static uint64_t                         online_cpumap;
 static uint64_t                         regs_valid;
 static vcpu_guest_context_any_t      ctxt[MAX_VIRT_CPUS];
 
-extern int ffsll(long long int);
-#define FOREACH_CPU(cpumap, i)  for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) )
+#define FOREACH_CPU(cpumap, i)  for ( cpumap = online_cpumap; (i = xc_ffs64(cpumap)); cpumap &= ~(1 << (index - 1)) )
 
 static int
 fetch_regs(int xc_handle, int cpu, int *online)
@@ -136,7 +135,7 @@ online_vcpus_changed(uint64_t cpumap)
     uint64_t changed_cpumap = cpumap ^ online_cpumap;
     int index;
 
-    while ( (index = ffsll(changed_cpumap)) ) {
+    while ( (index = xc_ffs64(changed_cpumap)) ) {
         if ( cpumap & (1 << (index - 1)) )
         {
             if (handlers.td_create) handlers.td_create(index - 1);
index 544d089cdfbc1a433855630f0c4e3156d398454a..36eb1c7758be13fb6a1c5a24c429e14bb6f43bd5 100644 (file)
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <zlib.h>
-#include <strings.h>
 #include <malloc.h>
 
 #include "xg_private.h"