CHECK_SYMBOL_EXISTS(fmemopen "stdio.h" HAVE_FMEMOPEN)
CHECK_SYMBOL_EXISTS(clock_getcpuclockid "sys/types.h;time.h" HAVE_CLOCK_GETCPUCLOCKID)
CHECK_SYMBOL_EXISTS(RUSAGE_SELF "sys/types.h;sys/resource.h" HAVE_RUSAGE_SELF)
+CHECK_SYMBOL_EXISTS(ffsll "strings.h" HAVE_FFSLL)
IF(ENABLE_PCRE2 MATCHES "ON")
IF(HAVE_PCRE_JIT)
#cmakedefine HAVE_FCNTL_H 1
#cmakedefine HAVE_FETCH_H 1
#cmakedefine HAVE_FIPS_MODE 1
+#cmakedefine HAVE_FFSLL 1
#cmakedefine HAVE_FLOCK 1
#cmakedefine HAVE_FPATHCONF 1
#cmakedefine HAVE_GETPAGESIZE 1
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)
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) {