Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c0e7688 authored by Michael Wright's avatar Michael Wright Committed by Automerger Merge Worker
Browse files

Merge "Cast away signedness of built-ins in BitSet." am: 71f4494b am:...

Merge "Cast away signedness of built-ins in BitSet." am: 71f4494b am: 1baa61b0 am: 5a5f41e1 am: 82c9d4c5

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1360509

Change-Id: Ib6cb011ef8738641aaeadb0503aac2c15c7a6df6
parents dda41f84 82c9d4c5
Loading
Loading
Loading
Loading
+24 −14
Original line number Diff line number Diff line
@@ -46,7 +46,9 @@ struct BitSet32 {
    // Returns the number of marked bits in the set.
    inline uint32_t count() const { return count(value); }

    static inline uint32_t count(uint32_t value) { return __builtin_popcountl(value); }
    static inline uint32_t count(uint32_t value) {
        return static_cast<uint32_t>(__builtin_popcountl(value));
    }

    // Returns true if the bit set does not contain any marked bits.
    inline bool isEmpty() const { return isEmpty(value); }
@@ -128,7 +130,7 @@ struct BitSet32 {
    }

    static inline uint32_t getIndexOfBit(uint32_t value, uint32_t n) {
        return __builtin_popcountl(value & ~(0xffffffffUL >> n));
        return static_cast<uint32_t>(__builtin_popcountl(value & ~(0xffffffffUL >> n)));
    }

    inline bool operator== (const BitSet32& other) const { return value == other.value; }
@@ -153,17 +155,17 @@ private:
    // input, which is only guaranteed to be 16b, not 32. The compiler should optimize this away.
    static inline uint32_t clz_checked(uint32_t value) {
        if (sizeof(unsigned int) == sizeof(uint32_t)) {
            return __builtin_clz(value);
            return static_cast<uint32_t>(__builtin_clz(value));
        } else {
            return __builtin_clzl(value);
            return static_cast<uint32_t>(__builtin_clzl(value));
        }
    }

    static inline uint32_t ctz_checked(uint32_t value) {
        if (sizeof(unsigned int) == sizeof(uint32_t)) {
            return __builtin_ctz(value);
            return static_cast<uint32_t>(__builtin_ctz(value));
        } else {
            return __builtin_ctzl(value);
            return static_cast<uint32_t>(__builtin_ctzl(value));
        }
    }
};
@@ -188,7 +190,9 @@ struct BitSet64 {
    // Returns the number of marked bits in the set.
    inline uint32_t count() const { return count(value); }

    static inline uint32_t count(uint64_t value) { return __builtin_popcountll(value); }
    static inline uint32_t count(uint64_t value) {
        return static_cast<uint32_t>(__builtin_popcountll(value));
    }

    // Returns true if the bit set does not contain any marked bits.
    inline bool isEmpty() const { return isEmpty(value); }
@@ -219,26 +223,32 @@ struct BitSet64 {
    // Result is undefined if all bits are unmarked.
    inline uint32_t firstMarkedBit() const { return firstMarkedBit(value); }

    static inline uint32_t firstMarkedBit(uint64_t value) { return __builtin_clzll(value); }
    static inline uint32_t firstMarkedBit(uint64_t value) {
        return static_cast<uint32_t>(__builtin_clzll(value));
    }

    // Finds the first unmarked bit in the set.
    // Result is undefined if all bits are marked.
    inline uint32_t firstUnmarkedBit() const { return firstUnmarkedBit(value); }

    static inline uint32_t firstUnmarkedBit(uint64_t value) { return __builtin_clzll(~ value); }
    static inline uint32_t firstUnmarkedBit(uint64_t value) {
        return static_cast<uint32_t>(__builtin_clzll(~value));
    }

    // Finds the last marked bit in the set.
    // Result is undefined if all bits are unmarked.
    inline uint32_t lastMarkedBit() const { return lastMarkedBit(value); }

    static inline uint32_t lastMarkedBit(uint64_t value) { return 63 - __builtin_ctzll(value); }
    static inline uint32_t lastMarkedBit(uint64_t value) {
        return static_cast<uint32_t>(63 - __builtin_ctzll(value));
    }

    // Finds the first marked bit in the set and clears it.  Returns the bit index.
    // Result is undefined if all bits are unmarked.
    inline uint32_t clearFirstMarkedBit() { return clearFirstMarkedBit(value); }

    static inline uint32_t clearFirstMarkedBit(uint64_t& value) {
        uint64_t n = firstMarkedBit(value);
        uint32_t n = firstMarkedBit(value);
        clearBit(value, n);
        return n;
    }
@@ -248,7 +258,7 @@ struct BitSet64 {
    inline uint32_t markFirstUnmarkedBit() { return markFirstUnmarkedBit(value); }

    static inline uint32_t markFirstUnmarkedBit(uint64_t& value) {
        uint64_t n = firstUnmarkedBit(value);
        uint32_t n = firstUnmarkedBit(value);
        markBit(value, n);
        return n;
    }
@@ -258,7 +268,7 @@ struct BitSet64 {
    inline uint32_t clearLastMarkedBit() { return clearLastMarkedBit(value); }

    static inline uint32_t clearLastMarkedBit(uint64_t& value) {
        uint64_t n = lastMarkedBit(value);
        uint32_t n = lastMarkedBit(value);
        clearBit(value, n);
        return n;
    }
@@ -268,7 +278,7 @@ struct BitSet64 {
    inline uint32_t getIndexOfBit(uint32_t n) const { return getIndexOfBit(value, n); }

    static inline uint32_t getIndexOfBit(uint64_t value, uint32_t n) {
        return __builtin_popcountll(value & ~(0xffffffffffffffffULL >> n));
        return static_cast<uint32_t>(__builtin_popcountll(value & ~(0xffffffffffffffffULL >> n)));
    }

    inline bool operator== (const BitSet64& other) const { return value == other.value; }