ia64/xen-unstable

changeset 5200:dd205ff2ce8a

bitkeeper revision 1.1591 (4299ea37xQ46OSnnhSi-IyVI2uATLw)

Bit-scanning function take offset/size as an int, not a long, and
return an int. This allows some small optimisation in code produced
for x86/64.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun May 29 16:13:43 2005 +0000 (2005-05-29)
parents d371fa731bc1
children da85abbfc7c0
files xen/arch/x86/bitops.c xen/include/asm-x86/bitops.h
line diff
     1.1 --- a/xen/arch/x86/bitops.c	Sun May 29 14:05:00 2005 +0000
     1.2 +++ b/xen/arch/x86/bitops.c	Sun May 29 16:13:43 2005 +0000
     1.3 @@ -2,8 +2,8 @@
     1.4  #include <xen/bitops.h>
     1.5  #include <xen/lib.h>
     1.6  
     1.7 -unsigned long __find_first_bit(
     1.8 -    const unsigned long *addr, unsigned long size)
     1.9 +unsigned int __find_first_bit(
    1.10 +    const unsigned long *addr, unsigned int size)
    1.11  {
    1.12      unsigned long d0, d1, res;
    1.13  
    1.14 @@ -13,29 +13,29 @@ unsigned long __find_first_bit(
    1.15          "   je 1f\n\t"
    1.16          "   lea -"STR(BITS_PER_LONG/8)"(%2),%2\n\t"
    1.17          "   bsf (%2),%0\n"
    1.18 -        "1: sub %5,%2\n\t"
    1.19 -        "   shl $3,%2\n\t"
    1.20 -        "   add %2,%0"
    1.21 +        "1: sub %%ebx,%%edi\n\t"
    1.22 +        "   shl $3,%%edi\n\t"
    1.23 +        "   add %%edi,%%eax"
    1.24          : "=&a" (res), "=&c" (d0), "=&D" (d1)
    1.25          : "1" ((size + BITS_PER_LONG - 1) / BITS_PER_LONG),
    1.26 -          "2" (addr), "b" (addr) : "memory" );
    1.27 +          "2" (addr), "b" ((int)(long)addr) : "memory" );
    1.28  
    1.29      return res;
    1.30  }
    1.31  
    1.32 -unsigned long __find_next_bit(
    1.33 -    const unsigned long *addr, unsigned long size, unsigned long offset)
    1.34 +unsigned int __find_next_bit(
    1.35 +    const unsigned long *addr, unsigned int size, unsigned int offset)
    1.36  {
    1.37      const unsigned long *p = addr + (offset / BITS_PER_LONG);
    1.38 -    unsigned long set, bit = offset & (BITS_PER_LONG - 1);
    1.39 +    unsigned int set, bit = offset & (BITS_PER_LONG - 1);
    1.40  
    1.41      ASSERT(offset < size);
    1.42  
    1.43      if ( bit != 0 )
    1.44      {
    1.45          /* Look for a bit in the first word. */
    1.46 -        __asm__ ( "bsf %1,%0" 
    1.47 -                  : "=r" (set) : "r" (*p >> bit), "0" (BITS_PER_LONG) );
    1.48 +        __asm__ ( "bsf %1,%%"__OP"ax"
    1.49 +                  : "=a" (set) : "r" (*p >> bit), "0" (BITS_PER_LONG) );
    1.50          if ( set < (BITS_PER_LONG - bit) )
    1.51              return (offset + set);
    1.52          offset += BITS_PER_LONG - bit;
    1.53 @@ -50,8 +50,8 @@ unsigned long __find_next_bit(
    1.54      return (offset + set);
    1.55  }
    1.56  
    1.57 -unsigned long __find_first_zero_bit(
    1.58 -    const unsigned long *addr, unsigned long size)
    1.59 +unsigned int __find_first_zero_bit(
    1.60 +    const unsigned long *addr, unsigned int size)
    1.61  {
    1.62      unsigned long d0, d1, d2, res;
    1.63  
    1.64 @@ -62,28 +62,28 @@ unsigned long __find_first_zero_bit(
    1.65          "   lea -"STR(BITS_PER_LONG/8)"(%2),%2\n\t"
    1.66          "   xor (%2),%3\n\t"
    1.67          "   bsf %3,%0\n"
    1.68 -        "1: sub %6,%2\n\t"
    1.69 -        "   shl $3,%2\n\t"
    1.70 -        "   add %2,%0"
    1.71 +        "1: sub %%ebx,%%edi\n\t"
    1.72 +        "   shl $3,%%edi\n\t"
    1.73 +        "   add %%edi,%%edx"
    1.74          : "=&d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
    1.75          : "1" ((size + BITS_PER_LONG - 1) / BITS_PER_LONG),
    1.76 -          "2" (addr), "b" (addr), "3" (-1L) : "memory" );
    1.77 +          "2" (addr), "b" ((int)(long)addr), "3" (-1L) : "memory" );
    1.78  
    1.79      return res;
    1.80  }
    1.81  
    1.82 -unsigned long __find_next_zero_bit(
    1.83 -    const unsigned long *addr, unsigned long size, unsigned long offset)
    1.84 +unsigned int __find_next_zero_bit(
    1.85 +    const unsigned long *addr, unsigned int size, unsigned int offset)
    1.86  {
    1.87      const unsigned long *p = addr + (offset / BITS_PER_LONG);
    1.88 -    unsigned long set, bit = offset & (BITS_PER_LONG - 1);
    1.89 +    unsigned int set, bit = offset & (BITS_PER_LONG - 1);
    1.90  
    1.91      ASSERT(offset < size);
    1.92  
    1.93      if ( bit != 0 )
    1.94      {
    1.95          /* Look for zero in the first word. */
    1.96 -        __asm__ ( "bsf %1,%0" : "=r" (set) : "r" (~(*p >> bit)) );
    1.97 +        __asm__ ( "bsf %1,%%"__OP"ax" : "=a" (set) : "r" (~(*p >> bit)) );
    1.98          if ( set < (BITS_PER_LONG - bit) )
    1.99              return (offset + set);
   1.100          offset += BITS_PER_LONG - bit;
     2.1 --- a/xen/include/asm-x86/bitops.h	Sun May 29 14:05:00 2005 +0000
     2.2 +++ b/xen/include/asm-x86/bitops.h	Sun May 29 16:13:43 2005 +0000
     2.3 @@ -248,20 +248,20 @@ static __inline__ int variable_test_bit(
     2.4   constant_test_bit((nr),(addr)) : \
     2.5   variable_test_bit((nr),(addr)))
     2.6  
     2.7 -extern unsigned long __find_first_bit(
     2.8 -    const unsigned long *addr, unsigned long size);
     2.9 -extern unsigned long __find_next_bit(
    2.10 -    const unsigned long *addr, unsigned long size, unsigned long offset);
    2.11 -extern unsigned long __find_first_zero_bit(
    2.12 -    const unsigned long *addr, unsigned long size);
    2.13 -extern unsigned long __find_next_zero_bit(
    2.14 -    const unsigned long *addr, unsigned long size, unsigned long offset);
    2.15 +extern unsigned int __find_first_bit(
    2.16 +    const unsigned long *addr, unsigned int size);
    2.17 +extern unsigned int __find_next_bit(
    2.18 +    const unsigned long *addr, unsigned int size, unsigned int offset);
    2.19 +extern unsigned int __find_first_zero_bit(
    2.20 +    const unsigned long *addr, unsigned int size);
    2.21 +extern unsigned int __find_next_zero_bit(
    2.22 +    const unsigned long *addr, unsigned int size, unsigned int offset);
    2.23  
    2.24  /* return index of first bit set in val or BITS_PER_LONG when no bit is set */
    2.25 -static inline unsigned long __scanbit(unsigned long val)
    2.26 +static inline unsigned int __scanbit(unsigned long val)
    2.27  {
    2.28  	__asm__ ( "bsf %1,%0" : "=r" (val) : "r" (val), "0" (BITS_PER_LONG) );
    2.29 -	return val;
    2.30 +	return (unsigned int)val;
    2.31  }
    2.32  
    2.33  /**
    2.34 @@ -320,10 +320,10 @@ static inline unsigned long __scanbit(un
    2.35   * Returns the bit-number of the first set bit. If no bits are set then the
    2.36   * result is undefined.
    2.37   */
    2.38 -static __inline__ unsigned long find_first_set_bit(unsigned long word)
    2.39 +static __inline__ unsigned int find_first_set_bit(unsigned long word)
    2.40  {
    2.41  	__asm__ ( "bsf %1,%0" : "=r" (word) : "r" (word) );
    2.42 -	return word;
    2.43 +	return (unsigned int)word;
    2.44  }
    2.45  
    2.46  /**