diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/jit/BitSet.cpp | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/jit/BitSet.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/js/src/jit/BitSet.cpp b/js/src/jit/BitSet.cpp new file mode 100644 index 0000000000..b791ea387c --- /dev/null +++ b/js/src/jit/BitSet.cpp @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: set ts=8 sts=2 et sw=2 tw=80: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "jit/BitSet.h" + +#include <string.h> + +#include "jit/JitAllocPolicy.h" + +using namespace js; +using namespace js::jit; + +bool BitSet::init(TempAllocator& alloc) { + size_t sizeRequired = numWords() * sizeof(*bits_); + + bits_ = (uint32_t*)alloc.allocate(sizeRequired); + if (!bits_) { + return false; + } + + memset(bits_, 0, sizeRequired); + + return true; +} + +bool BitSet::empty() const { + MOZ_ASSERT(bits_); + const uint32_t* bits = bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + if (bits[i]) { + return false; + } + } + return true; +} + +void BitSet::insertAll(const BitSet& other) { + MOZ_ASSERT(bits_); + MOZ_ASSERT(other.numBits_ == numBits_); + MOZ_ASSERT(other.bits_); + + uint32_t* bits = bits_; + const uint32_t* otherBits = other.bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + bits[i] |= otherBits[i]; + } +} + +void BitSet::removeAll(const BitSet& other) { + MOZ_ASSERT(bits_); + MOZ_ASSERT(other.numBits_ == numBits_); + MOZ_ASSERT(other.bits_); + + uint32_t* bits = bits_; + const uint32_t* otherBits = other.bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + bits[i] &= ~otherBits[i]; + } +} + +void BitSet::intersect(const BitSet& other) { + MOZ_ASSERT(bits_); + MOZ_ASSERT(other.numBits_ == numBits_); + MOZ_ASSERT(other.bits_); + + uint32_t* bits = bits_; + const uint32_t* otherBits = other.bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + bits[i] &= otherBits[i]; + } +} + +// returns true if the intersection caused the contents of the set to change. +bool BitSet::fixedPointIntersect(const BitSet& other) { + MOZ_ASSERT(bits_); + MOZ_ASSERT(other.numBits_ == numBits_); + MOZ_ASSERT(other.bits_); + + bool changed = false; + + uint32_t* bits = bits_; + const uint32_t* otherBits = other.bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + uint32_t old = bits[i]; + bits[i] &= otherBits[i]; + + if (!changed && old != bits[i]) { + changed = true; + } + } + return changed; +} + +void BitSet::complement() { + MOZ_ASSERT(bits_); + uint32_t* bits = bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + bits[i] = ~bits[i]; + } +} + +void BitSet::clear() { + MOZ_ASSERT(bits_); + uint32_t* bits = bits_; + for (unsigned int i = 0, e = numWords(); i < e; i++) { + bits[i] = 0; + } +} |