AC_CHECK_FUNCS(inet_ntop poll getline memrchr regcomp)
AC_CHECK_FUNCS(err errx warn warnx getprogname setprogname)
AC_CHECK_FUNCS(posix_memalign memalign valloc)
+AC_CHECK_FUNCS(fls flsl flsll ffs ffsl ffsll)
### Functions provided only on win32
AC_CHECK_FUNCS(localtime_r recvmsg sendmsg usleep)
### Functions used by libusual itself
/* ror32 */
int_check(ror32(1, 1), 0x80000000);
/* ror64 */
- int_check(ror64(1, 1), 0x8000000000000000);
+ ull_check(ror64(1, 1), 0x8000000000000000ULL);
end:;
}
int_check(ffsll(1), 1);
int_check(ffsll(3), 1);
int_check(ffsll((long long)-1), 1);
+ ull_check((1ULL << 63), ror64(1,1));
+ int_check(ffsll(1ULL << 63), 64);
int_check(ffsll(ror64(1,1)), 64);
end:;
}
#define str_check(a, b) tt_str_op(a, ==, b)
#define int_check(a, b) tt_int_op(a, ==, b)
-#define ull_check(a, b) tt_assert_op_type(a, ==, b, unsigned long long, "%llu")
+#define ull_check(a, b) tt_assert_op_type(a, ==, b, uint64_t, "%" PRIu64)
extern struct testcase_t aatree_tests[];
extern struct testcase_t cbtree_tests[];
#endif
#ifndef HAVE_FLS
+#define fls(x) usual_fls(x)
/** Compat: Find last (MSB) set bit, 1-based ofs, 0 if arg == 0 */
static inline int fls(int x) { _FLS(, int); }
#endif
#ifndef HAVE_FLSL
+#define flsl(x) usual_flsl(x)
/** Compat: Find last (MSB) set bit, 1-based ofs, 0 if arg == 0 */
static inline int flsl(long x) { _FLS(l, long); }
#endif
#ifndef HAVE_FLSLL
+#define flsll(x) usual_flsll(x)
/** Compat: Find last (MSB) set bit, 1-based ofs, 0 if arg == 0 */
static inline int flsll(long long x) { _FLS(ll, long long); }
#endif
#undef _FLS
+/*
+ * ffs(int)
+ * ffsl(long)
+ * ffsll(long long)
+ *
+ * find LSB bit set, 1-based ofs, 0 if arg == 0
+ */
+
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define _FFS(sfx, type) \
+ return __builtin_ffs ## sfx((unsigned type)(x))
+#else
+#define _FFS(sfx, type) \
+ unsigned int bit; \
+ unsigned type u = x; \
+ if (!x) return 0; \
+ /* count from smallest bit, assuming small values */ \
+ for (bit = 1; !(u & 1); bit++) { \
+ u >>= 1; \
+ } \
+ return bit
+#endif
+
+#ifndef HAVE_FFS
+#define ffs(x) usual_ffs(x)
+/** Compat: Find first (LSB) set bit, 1-based ofs, 0 if arg == 0 */
+static inline int ffs(int x) { _FFS(, int); }
+#endif
+#ifndef HAVE_FFSL
+#define ffsl(x) usual_ffsl(x)
+/** Compat: Find first (LSB) set bit, 1-based ofs, 0 if arg == 0 */
+static inline int ffsl(long x) { _FFS(l, long); }
+#endif
+#ifndef HAVE_FFSLL
+#define ffsll(x) usual_ffsll(x)
+/** Compat: Find first (LSB) set bit, 1-based ofs, 0 if arg == 0 */
+static inline int ffsll(long long x) { _FFS(ll, long long); }
+#endif
+#undef _FFS
+
#endif