[libc] Make UInt<T> trivially copyable
authorMikhail R. Gadelha <mikhail@igalia.com>
Thu, 20 Apr 2023 16:00:04 +0000 (13:00 -0300)
committerMikhail R. Gadelha <mikhail@igalia.com>
Thu, 20 Apr 2023 16:01:19 +0000 (13:01 -0300)
This patch defaults the copy constructor and copy operator so it can be
used with __builtin_bit_cast

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D148794

libc/src/__support/UInt.h

index 2cbd3dfea6fb8e66bbf3043ec097598bfb3cbe65..c151689c3bbb931950ab3557e0e91552af18bd28 100644 (file)
@@ -35,12 +35,9 @@ template <size_t Bits> struct UInt {
   static constexpr uint64_t low(uint64_t v) { return v & MASK32; }
   static constexpr uint64_t high(uint64_t v) { return (v >> 32) & MASK32; }
 
-  constexpr UInt() {}
+  constexpr UInt() = default;
 
-  constexpr UInt(const UInt<Bits> &other) {
-    for (size_t i = 0; i < WORDCOUNT; ++i)
-      val[i] = other.val[i];
-  }
+  constexpr UInt(const UInt<Bits> &other) = default;
 
   template <size_t OtherBits> constexpr UInt(const UInt<OtherBits> &other) {
     if (OtherBits >= Bits) {
@@ -90,11 +87,7 @@ template <size_t Bits> struct UInt {
     return uint8_t(uint64_t(*this));
   }
 
-  UInt<Bits> &operator=(const UInt<Bits> &other) {
-    for (size_t i = 0; i < WORDCOUNT; ++i)
-      val[i] = other.val[i];
-    return *this;
-  }
+  UInt<Bits> &operator=(const UInt<Bits> &other) = default;
 
   constexpr bool is_zero() const {
     for (size_t i = 0; i < WORDCOUNT; ++i) {