23
23
#include < cstdint>
24
24
#include < type_traits>
25
25
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
-
36
26
namespace Fortran ::common {
37
27
38
28
template <bool IS_SIGNED = false > class Int128 {
@@ -43,15 +33,18 @@ template <bool IS_SIGNED = false> class Int128 {
43
33
constexpr Int128 (unsigned n) : low_{n} {}
44
34
constexpr Int128 (unsigned long n) : low_{n} {}
45
35
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
+ }
55
48
constexpr Int128 (const Int128 &) = default;
56
49
constexpr Int128 (Int128 &&) = default;
57
50
constexpr Int128 &operator =(const Int128 &) = default ;
@@ -256,8 +249,10 @@ template <bool IS_SIGNED = false> class Int128 {
256
249
}
257
250
258
251
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
+ }
261
256
constexpr int LeadingZeroes () const {
262
257
if (high_ == 0 ) {
263
258
return 64 + LeadingZeroBitCount (low_);
@@ -266,7 +261,13 @@ template <bool IS_SIGNED = false> class Int128 {
266
261
}
267
262
}
268
263
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
270
271
};
271
272
272
273
using UnsignedInt128 = Int128<false >;
@@ -299,7 +300,4 @@ template <int BITS>
299
300
using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
300
301
301
302
} // namespace Fortran::common
302
-
303
- #undef SWAP
304
-
305
303
#endif
0 commit comments