aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-10-06 23:33:17 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-10-06 23:33:17 +0100
commita30002b1c83196a621aa6d6bd24b91d39f312ca2 (patch)
tree3b30ce385daef4f2fa4249ab5ebe414c51c11dc0 /src
parentcdbacf2b135fc49a84df1d0790c2ba77d6d763b7 (diff)
downloadrspamd-a30002b1c83196a621aa6d6bd24b91d39f312ca2.tar.gz
rspamd-a30002b1c83196a621aa6d6bd24b91d39f312ca2.zip
[Minor] Detect ffsll presence in a target system
Diffstat (limited to 'src')
-rw-r--r--src/libutil/printf.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 8eaab0c40..50d9d8b37 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -349,6 +349,36 @@ rspamd_uint64_print (guint64 in, gchar *out)
return ndigits;
}
+static inline int
+rspamd_ffsll(long long n)
+{
+#ifdef __has_builtin
+# if __has_builtin(__builtin_ffsll)
+ return __builtin_ffsll(n);
+# elif __has_builtin(__builtin_ctzll)
+ if (n == 0) {
+ return 0;
+ }
+
+ return __builtin_ctzll(n) + 1;
+# endif
+#endif /* __has_builtin */
+
+#ifdef HAVE_FFSL
+ return ffsl(n);
+#else
+ if (n == 0) {
+ return 0;
+ }
+
+ int bit;
+ for (bit = 1; !(n & 1); bit++) {
+ n = ((unsigned long long) n) >> 1;
+ }
+ return bit;
+#endif
+}
+
static gchar *
rspamd_sprintf_num (gchar *buf, gchar *last, guint64 ui64, gchar zero,
guint hexadecimal, guint binary, guint width)
@@ -383,7 +413,7 @@ rspamd_sprintf_num (gchar *buf, gchar *last, guint64 ui64, gchar zero,
len = (temp + sizeof (temp)) - p;
}
else if (binary > 0) {
- int first_bit = MIN(sizeof(temp), ffsll(ui64));
+ int first_bit = MIN(sizeof(temp), rspamd_ffsll(ui64));
p = temp + sizeof(temp);
for (int i = 0; i <= first_bit; i ++, ui64 >>= 1) {