[libc-commits] [PATCH] D132184: [libc] add division to UInt

Tue Ly via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Aug 30 21:47:37 PDT 2022


lntue accepted this revision.
lntue added inline comments.


================
Comment at: libc/src/__support/UInt.h:252
+  // to the zeroth power returns 1.
+  constexpr void exp(uint64_t power) {
+    UInt<Bits> result = 1;
----------------
I think the conventional name for this function is `pown` or `pow_n`.  `exp` name is kind of reserved for `e^x` function.


================
Comment at: libc/src/__support/UInt.h:261
+      power = power >> 1;
+      cur_power = cur_power * cur_power;
+    }
----------------
Can this be replaced with `cur_power *= cur_power`?


================
Comment at: libc/src/__support/UInt.h:320-325
+        // TODO(michaelrj): use builtins?
+        uint64_t num = val[i - 1];
+        while (num < (uint64_t(1) << ((sizeof(uint64_t) * 8) - 1))) {
+          num <<= 1;
+          ++leading_zeroes;
+        }
----------------
Since you already included `builtin_wrappers.h` here, this part can be reduced to
```
leading_zeroes += fputil::unsafe_clz(val[i-1]);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132184



More information about the libc-commits mailing list