X-Git-Url: http://git.buserror.net/cgi-bin/gitweb.cgi?p=polintos%2Fscott%2Fpriv.git;a=blobdiff_plain;f=include%2Fc%2Flowlevel%2Farch-x86%2Fbitops.h;h=c92b2cd5e78b8f99567c05389bb97aad2089a598;hp=aa608417ffc368b21e42c465d945c6629b8bd909;hb=1096537bdc1c23affc5eedfba311d37c7bf647bf;hpb=2f2638b54e0d3662d3be465a4035c3f28018907e diff --git a/include/c/lowlevel/arch-x86/bitops.h b/include/c/lowlevel/arch-x86/bitops.h index aa60841..c92b2cd 100644 --- a/include/c/lowlevel/arch-x86/bitops.h +++ b/include/c/lowlevel/arch-x86/bitops.h @@ -1,52 +1,6 @@ -// Bit manipulation functions. These functions are not privileged. - #ifndef _LL_ARCH_BITOPS_H #define _LL_ARCH_BITOPS_H -// Find First Set, counting from 0, undefined if no bits set -static inline int ll_ffs(unsigned long val) -{ - unsigned long ret; - asm("bsfl %1, %0" : "=r" (ret) : "r" (val)); - return ret; -} - -// Find Last Set, counting from 0, undefined if no bits set -static inline int ll_fls(unsigned long val) -{ - unsigned long ret; - asm("bsrl %1, %0" : "=r" (ret) : "r" (val)); - return ret; -} - -// As above, but on 64-bit values, regardless of sizeof(long) -static inline int ll_ffs64(uint64_t val) -{ - if ((uint32_t)val) - return ll_ffs((uint32_t)val); - else - return ll_ffs((uint32_t)(val >> 32)); -} - -static inline int ll_fls64(uint64_t val) -{ - if ((uint32_t)(val >> 32)) - return ll_ffs((uint32_t)(val >> 32)); - else - return ll_ffs((uint32_t)val); -} - -// Set/Clear the nth bit in a multiword bitmap. These functions -// are endian and word-size dependent. - -static inline void ll_multiword_set_bit(unsigned long *bitmap, int bit) -{ - asm("bts %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory"); -} - -static inline void ll_multiword_clear_bit(unsigned long *bitmap, int bit) -{ - asm("btr %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory"); -} +#include #endif