[libc-commits] [PATCH] D110643: [libc] Add support for 128 bit ints in limits.h

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Sep 28 14:09:21 PDT 2021


sivachandra accepted this revision.
sivachandra added inline comments.


================
Comment at: libc/utils/CPP/Limits.h:63
+//   static constexpr __int128_t max() {
+//     return -(~__int128_t(0) + 1);
+//   }
----------------
michaelrj wrote:
> sivachandra wrote:
> > May be just `~__uint128_t(0) - 1`?
> That doesn't work as int max, since it comes out to `0xfffffffffffffffffffffffffffffffe`, as opposed to the `0x7fffffffffffffffffffffffffffffff`. I've changed it to be the most logical way I can think of that doesn't rely on overflow/underflow.
Uh, sorry! Not sure why I put a `-` instead of a `>>`. I wanted to say this:

```
  return ~__uint128_t(0) >> 1;
```


================
Comment at: libc/utils/UnitTest/LibcTest.cpp:57
 }
+template <> std::string describeValue<__int128_t>(__int128_t Value) {
+  std::string S(sizeof(__int128_t) * 2, '0');
----------------
Can we extract into a common function like this:

```
template <typename T128>
cpp::EnableIfType<cpp::IsSame<T128, __int128_t> || cpp::IsSame<T128, __uint128_t>, std::string>
describeValue128(...) {
  ...
}

template <> std::string describeValue<__int128_t>(__int128_t Value) { return describeValue128(Value); }
template <> std::string describeValue<__uint128_t>(__uint128_t Value) { return describeValue128(Value); }
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110643



More information about the libc-commits mailing list