Skip to content

Commit 96a3678

Browse files
kkwliMark Danial
authored andcommitted
address review comments
1 parent 0c25a34 commit 96a3678

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

flang/include/flang/Common/uint128.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
#include <cstdint>
2424
#include <type_traits>
2525

26-
#if FLANG_LITTLE_ENDIAN
27-
#define SWAP(a, i, b, j) \
28-
a{i}, b { j }
29-
#elif FLANG_BIG_ENDIAN
30-
#define SWAP(a, i, b, j) \
31-
b{j}, a { i }
32-
#else
33-
#error host endianness is not known
34-
#endif
35-
3626
namespace Fortran::common {
3727

3828
template <bool IS_SIGNED = false> class Int128 {
@@ -43,15 +33,18 @@ template <bool IS_SIGNED = false> class Int128 {
4333
constexpr Int128(unsigned n) : low_{n} {}
4434
constexpr Int128(unsigned long n) : low_{n} {}
4535
constexpr Int128(unsigned long long n) : low_{n} {}
46-
constexpr Int128(int n)
47-
: SWAP(low_, static_cast<std::uint64_t>(n), high_,
48-
-static_cast<std::uint64_t>(n < 0)) {}
49-
constexpr Int128(long n)
50-
: SWAP(low_, static_cast<std::uint64_t>(n), high_,
51-
-static_cast<std::uint64_t>(n < 0)) {}
52-
constexpr Int128(long long n)
53-
: SWAP(low_, static_cast<std::uint64_t>(n), high_,
54-
-static_cast<std::uint64_t>(n < 0)) {}
36+
constexpr Int128(int n) {
37+
low_ = static_cast<std::uint64_t>(n);
38+
high_ = -static_cast<std::uint64_t>(n < 0);
39+
}
40+
constexpr Int128(long n) {
41+
low_ = static_cast<std::uint64_t>(n);
42+
high_ = -static_cast<std::uint64_t>(n < 0);
43+
}
44+
constexpr Int128(long long n) {
45+
low_ = static_cast<std::uint64_t>(n);
46+
high_ = -static_cast<std::uint64_t>(n < 0);
47+
}
5548
constexpr Int128(const Int128 &) = default;
5649
constexpr Int128(Int128 &&) = default;
5750
constexpr Int128 &operator=(const Int128 &) = default;
@@ -256,8 +249,10 @@ template <bool IS_SIGNED = false> class Int128 {
256249
}
257250

258251
private:
259-
constexpr Int128(std::uint64_t hi, std::uint64_t lo)
260-
: SWAP(low_, lo, high_, hi) {}
252+
constexpr Int128(std::uint64_t hi, std::uint64_t lo) {
253+
low_ = lo;
254+
high_ = hi;
255+
}
261256
constexpr int LeadingZeroes() const {
262257
if (high_ == 0) {
263258
return 64 + LeadingZeroBitCount(low_);
@@ -266,7 +261,13 @@ template <bool IS_SIGNED = false> class Int128 {
266261
}
267262
}
268263
static constexpr std::uint64_t topBit{std::uint64_t{1} << 63};
269-
std::uint64_t SWAP(low_, 0, high_, 0);
264+
#if FLANG_LITTLE_ENDIAN
265+
std::uint64_t low_{0}, high_{0};
266+
#elif FLANG_BIG_ENDIAN
267+
std::uint64_t high_{0}, low_{0};
268+
#else
269+
#error host endianness is not known
270+
#endif
270271
};
271272

272273
using UnsignedInt128 = Int128<false>;
@@ -299,7 +300,4 @@ template <int BITS>
299300
using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
300301

301302
} // namespace Fortran::common
302-
303-
#undef SWAP
304-
305303
#endif

0 commit comments

Comments
 (0)