ref: 2d84d9d4932d6d3880559442195bfd929e2e970a
parent: def82520105802fbe8d1e95f74fdcf636b91bb67
author: Lennart Augustsson <lennart@augustsson.net>
date: Sun Oct 6 08:47:47 EDT 2024
Try harder to define FFS correctly.
--- a/src/runtime/config-unix-32.h
+++ b/src/runtime/config-unix-32.h
@@ -4,4 +4,7 @@
//#define WORD_SIZE 32
#undef FFS
+#if _POSIX_VERSION >= 200112L
#define FFS ffs
+#endif
+
--- a/src/runtime/config-unix-64.h
+++ b/src/runtime/config-unix-64.h
@@ -45,11 +45,21 @@
/*
* Find First Set
- * This macro must be defined.
+ * This macro should be defined.
* It returns the number of the least significant bit that is set.
* Numberings starts from 1. If no bit is set, it should return 0.
*/
+#if defined(__gnu_linux__) || defined(__APPLE__) || defined(__FreeBSD__)
+/* Only some platforms have 64 bit ffsl function directly. */
#define FFS ffsl
+#elif defined(__GNUC__)
+/* GCC has ffsl as a builtin. */
+#define FFS __builtin_ffsl
+/* CLANG has ffsl as a builtin. */
+#elif defined(__clang__) && __has_builtin(__builtin__ffsl)
+#define FFS __builtin_ffsl
+#endif
+
/*
* This is the character used for comma-separation in printf.