logo

oasis

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

0004-Add-portable-fallbacks-for-__builtin_clz-ll.patch (1136B)


  1. From b87edf043bc03527ac702d1fdc678e930f77a082 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Mon, 6 Sep 2021 19:55:08 -0700
  4. Subject: [PATCH] Add portable fallbacks for __builtin_clz[ll]
  5. ---
  6. softfp.c | 26 ++++++++++++++++++++++++++
  7. 1 file changed, 26 insertions(+)
  8. diff --git a/softfp.c b/softfp.c
  9. index 2a1aad0..801ecc3 100644
  10. --- a/softfp.c
  11. +++ b/softfp.c
  12. @@ -35,7 +35,25 @@ static inline int clz32(uint32_t a)
  13. if (a == 0) {
  14. r = 32;
  15. } else {
  16. +#ifdef __GNUC__
  17. r = __builtin_clz(a);
  18. +#else
  19. + int t;
  20. +
  21. + t = ((a & 0xffff0000) == 0) << 4;
  22. + a >>= 16 - t;
  23. + r = t;
  24. + t = ((a & 0xff00) == 0) << 3;
  25. + a >>= 8 - t;
  26. + r |= t;
  27. + t = ((a & 0xf0) == 0) << 2;
  28. + a >>= 4 - t;
  29. + r |= t;
  30. + t = ((a & 0xc) == 0) << 1;
  31. + a >>= 2 - t;
  32. + r |= t;
  33. + r += 2 - a & -((a & 2) == 0);
  34. +#endif
  35. }
  36. return r;
  37. }
  38. @@ -47,7 +65,15 @@ static inline int clz64(uint64_t a)
  39. r = 64;
  40. } else
  41. {
  42. +#ifdef __GNUC__
  43. r = __builtin_clzll(a);
  44. +#else
  45. + int t;
  46. +
  47. + t = ((a & 0xffffffff00000000) == 0) << 8;
  48. + a >>= 32 - t;
  49. + r = t | clz32(a);
  50. +#endif
  51. }
  52. return r;
  53. }
  54. --
  55. 2.32.0