Print this page
5288 x86 bitmap inline asm functions duplicate code
*** 34,116 ****
extern "C" {
#endif
#if !defined(__lint) && defined(__GNUC__)
extern __GNU_INLINE int
highbit(ulong_t i)
{
! long __value = -1l;
- #if defined(__amd64)
- __asm__(
- "bsrq %1,%0"
- : "+r" (__value)
- : "r" (i)
- : "cc");
- #elif defined(__i386)
__asm__(
! "bsrl %1,%0"
! : "+r" (__value)
: "r" (i)
: "cc");
! #else
! #error "port me"
! #endif
! return ((int)(__value + 1));
}
extern __GNU_INLINE int
lowbit(ulong_t i)
{
! long __value = -1l;
- #if defined(__amd64)
- __asm__(
- "bsfq %1,%0"
- : "+r" (__value)
- : "r" (i)
- : "cc");
- #elif defined(__i386)
__asm__(
! "bsfl %1,%0"
! : "+r" (__value)
: "r" (i)
: "cc");
! #else
! #error "port me"
! #endif
! return ((int)(__value + 1));
}
extern __GNU_INLINE uint_t
atomic_btr32(uint32_t *memory, uint_t bitnum)
{
! uint8_t __value;
- #if defined(__amd64)
- __asm__ __volatile__(
- "lock;"
- "btrl %2, (%0);"
- "setc %1"
- : "+r" (memory), "+r" (__value)
- : "ir" (bitnum)
- : "cc");
- #elif defined(__i386)
__asm__ __volatile__(
"lock;"
! "btrl %2, (%0);"
"setc %1"
! : "+r" (memory), "=r" (__value)
: "ir" (bitnum)
: "cc");
! #else
! #error "port me"
! #endif
! return ((uint_t)__value);
}
#endif /* !__lint && __GNUC__ */
#ifdef __cplusplus
}
#endif
--- 34,97 ----
extern "C" {
#endif
#if !defined(__lint) && defined(__GNUC__)
+ #if defined(__amd64)
+ #define __SUF "q"
+ #elif defined(__i386)
+ #define __SUF "l"
+ #else
+ #error "port me"
+ #endif
+
extern __GNU_INLINE int
highbit(ulong_t i)
{
! long value = -1l;
__asm__(
! "bsr" __SUF " %1,%0"
! : "+r" (value)
: "r" (i)
: "cc");
!
! return ((int)(value + 1));
}
extern __GNU_INLINE int
lowbit(ulong_t i)
{
! long value = -1l;
__asm__(
! "bsf" __SUF " %1,%0"
! : "+r" (value)
: "r" (i)
: "cc");
!
! return ((int)(value + 1));
}
extern __GNU_INLINE uint_t
atomic_btr32(uint32_t *memory, uint_t bitnum)
{
! uint8_t value;
__asm__ __volatile__(
"lock;"
! "btrl %2,%0;"
"setc %1"
! : "+m" (*memory), "=r" (value)
: "ir" (bitnum)
: "cc");
!
! return ((uint_t)value);
}
+ #undef __SUF
+
#endif /* !__lint && __GNUC__ */
#ifdef __cplusplus
}
#endif