logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Avoid-__builtin_ffs.patch (1324B)


  1. From 09e21bb5d6714687705dc8f2d00a09b3ff3b2436 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Fri, 7 Jun 2019 11:55:26 -0700
  4. Subject: [PATCH] Avoid __builtin_ffs
  5. ---
  6. src/common.h | 5 +----
  7. src/core.c | 2 +-
  8. 2 files changed, 2 insertions(+), 5 deletions(-)
  9. diff --git a/src/common.h b/src/common.h
  10. index 80a3d6e..3c77f48 100644
  11. --- a/src/common.h
  12. +++ b/src/common.h
  13. @@ -77,12 +77,9 @@ static inline int bitcount(unsigned v)
  14. return (((v + (v>>4)) & 0xF0F0F0F) * 0x1010101) >> 24;
  15. }
  16. -/* Return index of first bit [0-31], -1 on zero */
  17. -#define firstbit(v) (__builtin_ffs(v) - 1)
  18. -
  19. /* boost-style foreach bit */
  20. #define foreach_bit(i, m) \
  21. - for (i = firstbit(m); i >= 0; i = firstbit((m) & (~0U << (i + 1))))
  22. + for (i = -1; (m) & ~0U << (i + 1);) if ((m) & 1U << ++i)
  23. /* robust system ioctl calls */
  24. #define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
  25. diff --git a/src/core.c b/src/core.c
  26. index 0d91c0b..20ce0c6 100644
  27. --- a/src/core.c
  28. +++ b/src/core.c
  29. @@ -304,7 +304,7 @@ static void apply_typeA_changes(struct mtdev_state *state,
  30. break;
  31. }
  32. if (id != MT_ID_NULL) {
  33. - slot = firstbit(unused);
  34. + foreach_bit(slot, unused) break;
  35. push_slot_changes(state, &data[i], prop[i], slot, syn);
  36. SETBIT(used, slot);
  37. CLEARBIT(unused, slot);
  38. --
  39. 2.25.0