X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Futil.h;h=083ddb2e14e4b6ed8d7344bf7bc77a069a4a6dc9;hp=3dfd6030be08574686a3cbb6b1d8c790775746dc;hb=36a737d734cdc6c6eb0ce9da3183a1f8fa4288e6;hpb=9b25b1a8e4c01e57f2872fe9e825f0dc81329008 diff --git a/src/util.h b/src/util.h index 3dfd6030..083ddb2e 100644 --- a/src/util.h +++ b/src/util.h @@ -30,27 +30,15 @@ # define HOT #endif /* __GNUC__ */ + +#if 0 #ifdef WITH_FUSE -/* - * Compare-and-swap. Equivalent to the folliwng, but executed - * atomically: - * - * Q tmp = *ptr; - * if (tmp == oval) - * *ptr = nval; - * return tmp; - */ #define atomic_inc(ptr) \ __sync_fetch_and_add(ptr, 1) #define atomic_dec(ptr) \ __sync_sub_and_fetch(ptr, 1) - -#define cas(ptr, oval, nval) \ - __sync_val_compare_and_swap(ptr, oval, nval); - -#define cas_bool(ptr, oval, nval) \ - __sync_bool_compare_and_swap(ptr, oval, nval); +#endif #endif #ifndef _NTFS_TYPES_H @@ -88,6 +76,12 @@ typedef unsigned uint; (type *)( (char *)__mptr - offsetof(type,member) );}) #endif +#define DIV_ROUND_UP(numerator, denominator) \ + (((numerator) + (denominator) - 1) / (denominator)) + +#define MODULO_NONZERO(numerator, denominator) \ + (((numerator) % (denominator)) ? ((numerator) % (denominator)) : (denominator)) + #define ARRAY_LEN(array) (sizeof(array) / sizeof((array)[0])) #define ZERO_ARRAY(array) memset(array, 0, sizeof(array)) @@ -187,13 +181,25 @@ extern void print_string(const void *string, size_t len); extern int get_num_path_components(const char *path); -extern ssize_t full_write(int fd, const void *buf, size_t n); - static inline void print_byte_field(const u8 field[], size_t len) { while (len--) printf("%02hhx", *field++); } +static inline u32 bsr32(u32 n) +{ +#if defined(__x86__) || defined(__x86_64__) + asm("bsrl %0, %0;" + : "=r"(n) + : "0" (n)); + return n; +#else + u32 pow = 0; + while ((n >>= 1) != 0) + pow++; + return pow; +#endif +} #endif /* _WIMLIB_UTIL_H */