[libc-commits] [PATCH] D117684: [libc] Use __builtin_clz to find leading 1 in hypot

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jan 19 09:49:57 PST 2022


sivachandra accepted this revision.
sivachandra added inline comments.
This revision is now accepted and ready to land.


================
Comment at: libc/src/__support/FPUtil/Hypot.h:31
 template <>
-inline uint32_t find_leading_one<uint32_t>(uint32_t mant, int &shift_length) {
+inline uint32_t find_leading_one<unsigned int>(unsigned int mant,
+                                               int &shift_length) {
----------------
Nit: Use `unsigned int` here?


================
Comment at: libc/src/__support/FPUtil/Hypot.h:35
+  if (mant > 0) {
+    shift_length = 31 - __builtin_clz(mant);
   }
----------------
cratonica wrote:
> sivachandra wrote:
> > Use a pattern like `sizeof(unsigned int) - 1` instead of hard coding here and below. For, in the `unsigned long` case, `63 - <...>`can be more than the width of `unsigned long`.
> Note that this assumes CHAR_BIT is 8, but I can't #include <climits> according to the lint rules.
Assuming that a byte is 8 bits wide is going to be almost always right on real world systems :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117684



More information about the libc-commits mailing list