ia64/xen-unstable

changeset 18989:f6b92526e916

libxc: Define xc_ffs{8,16,32,64} functions. Use them.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 06 09:14:39 2009 +0000 (2009-01-06)
parents d77f66f89c04
children 74430e4c047f
files 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
line diff
     1.1 --- a/tools/libxc/xc_pagetab.c	Mon Jan 05 11:55:24 2009 +0000
     1.2 +++ b/tools/libxc/xc_pagetab.c	Tue Jan 06 09:14:39 2009 +0000
     1.3 @@ -4,7 +4,6 @@
     1.4   * Function to translate virtual to physical addresses.
     1.5   */
     1.6  #include "xc_private.h"
     1.7 -#include <strings.h>
     1.8  
     1.9  #define CR0_PG  0x80000000
    1.10  #define CR4_PAE 0x20
    1.11 @@ -77,7 +76,7 @@ unsigned long xc_translate_foreign_addre
    1.12  
    1.13      /* Walk the pagetables */
    1.14      for (level = pt_levels; level > 0; level--) {
    1.15 -        paddr += ((virt & mask) >> (ffsll(mask) - 1)) * size;
    1.16 +        paddr += ((virt & mask) >> (xc_ffs64(mask) - 1)) * size;
    1.17          map = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, 
    1.18                                     paddr >>PAGE_SHIFT);
    1.19          if (!map) 
     2.1 --- a/tools/libxc/xc_private.c	Mon Jan 05 11:55:24 2009 +0000
     2.2 +++ b/tools/libxc/xc_private.c	Tue Jan 06 09:14:39 2009 +0000
     2.3 @@ -639,6 +639,33 @@ int write_exact(int fd, const void *data
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +int xc_ffs8(uint8_t x)
     2.8 +{
     2.9 +    int i;
    2.10 +    for ( i = 0; i < 8; i++ )
    2.11 +        if ( x & (1u << i) )
    2.12 +            return i+1;
    2.13 +    return 0;
    2.14 +}
    2.15 +
    2.16 +int xc_ffs16(uint16_t x)
    2.17 +{
    2.18 +    uint8_t h = x>>8, l = x;
    2.19 +    return l ? xc_ffs8(l) : h ? xc_ffs8(h) + 8 : 0;
    2.20 +}
    2.21 +
    2.22 +int xc_ffs32(uint32_t x)
    2.23 +{
    2.24 +    uint16_t h = x>>16, l = x;
    2.25 +    return l ? xc_ffs16(l) : h ? xc_ffs16(h) + 16 : 0;
    2.26 +}
    2.27 +
    2.28 +int xc_ffs64(uint64_t x)
    2.29 +{
    2.30 +    uint32_t h = x>>32, l = x;
    2.31 +    return l ? xc_ffs32(l) : h ? xc_ffs32(h) + 32 : 0;
    2.32 +}
    2.33 +
    2.34  /*
    2.35   * Local variables:
    2.36   * mode: C
     3.1 --- a/tools/libxc/xc_private.h	Mon Jan 05 11:55:24 2009 +0000
     3.2 +++ b/tools/libxc/xc_private.h	Tue Jan 06 09:14:39 2009 +0000
     3.3 @@ -218,4 +218,9 @@ int xc_flush_mmu_updates(int xc_handle, 
     3.4  int read_exact(int fd, void *data, size_t size);
     3.5  int write_exact(int fd, const void *data, size_t size);
     3.6  
     3.7 +int xc_ffs8(uint8_t x);
     3.8 +int xc_ffs16(uint16_t x);
     3.9 +int xc_ffs32(uint32_t x);
    3.10 +int xc_ffs64(uint64_t x);
    3.11 +
    3.12  #endif /* __XC_PRIVATE_H__ */
     4.1 --- a/tools/libxc/xc_ptrace.c	Mon Jan 05 11:55:24 2009 +0000
     4.2 +++ b/tools/libxc/xc_ptrace.c	Tue Jan 06 09:14:39 2009 +0000
     4.3 @@ -44,8 +44,7 @@ static uint64_t                         
     4.4  static uint64_t                         regs_valid;
     4.5  static vcpu_guest_context_any_t      ctxt[MAX_VIRT_CPUS];
     4.6  
     4.7 -extern int ffsll(long long int);
     4.8 -#define FOREACH_CPU(cpumap, i)  for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) )
     4.9 +#define FOREACH_CPU(cpumap, i)  for ( cpumap = online_cpumap; (i = xc_ffs64(cpumap)); cpumap &= ~(1 << (index - 1)) )
    4.10  
    4.11  static int
    4.12  fetch_regs(int xc_handle, int cpu, int *online)
    4.13 @@ -136,7 +135,7 @@ online_vcpus_changed(uint64_t cpumap)
    4.14      uint64_t changed_cpumap = cpumap ^ online_cpumap;
    4.15      int index;
    4.16  
    4.17 -    while ( (index = ffsll(changed_cpumap)) ) {
    4.18 +    while ( (index = xc_ffs64(changed_cpumap)) ) {
    4.19          if ( cpumap & (1 << (index - 1)) )
    4.20          {
    4.21              if (handlers.td_create) handlers.td_create(index - 1);
     5.1 --- a/tools/libxc/xg_private.c	Mon Jan 05 11:55:24 2009 +0000
     5.2 +++ b/tools/libxc/xg_private.c	Tue Jan 06 09:14:39 2009 +0000
     5.3 @@ -7,7 +7,6 @@
     5.4  #include <stdlib.h>
     5.5  #include <unistd.h>
     5.6  #include <zlib.h>
     5.7 -#include <strings.h>
     5.8  #include <malloc.h>
     5.9  
    5.10  #include "xg_private.h"