[PATCH] D86547: [compiler-rt][builtins] Use c[tl]zsi macro instead of __builtin_c[tl]z

Ayke via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 17 05:07:32 PST 2022


aykevl accepted this revision.
aykevl added a comment.
This revision is now accepted and ready to land.

Looks good to me.



================
Comment at: compiler-rt/lib/builtins/fp_extend.h:32-39
 #if defined __LP64__
   return __builtin_clzl(a);
 #else
   if (a & REP_C(0xffffffff00000000))
-    return __builtin_clz(a >> 32);
+    return clzsi(a >> 32);
   else
+    return 32 + clzsi(a & REP_C(0xffffffff));
----------------
Perhaps more reliable would be the following:

```
#if ULONG_MAX == 0xFFFFFFFFFFFFFFFF
  return __builtin_clzl(a);
#elif ULLONG_MAX == 0xFFFFFFFFFFFFFFFF
  return __builtin_clzll(a);
#else
  #error Unsupported platform
#endif
```

This is what I've also used in int_types.h to detect clzsi etc. It probably would need to be tested on some more architectures though (32 and 64 bit).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86547/new/

https://reviews.llvm.org/D86547



More information about the cfe-commits mailing list