From 5799281bda2f9a174b825de4058c5e8c9aa5b27f Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Sat, 1 Jun 2024 02:38:46 -0400 Subject: Capabilities generator inclusive join and misc (#4237) --- source/core/core.natvis | 82 +++++++++++++++++--------------------------- source/core/slang-uint-set.h | 80 +++++++++++++++++++++++------------------- 2 files changed, 76 insertions(+), 86 deletions(-) (limited to 'source/core') diff --git a/source/core/core.natvis b/source/core/core.natvis index 2448e2c88..f2547b3fe 100644 --- a/source/core/core.natvis +++ b/source/core/core.natvis @@ -55,62 +55,44 @@ + {{ {map.m_values} }} + + map.m_values + map + + + + + {{ {dict} }} + + dict + + + + + {{ size={dict._count} }} + + + m_dict._count + m_dict.kvPairs.head + next + value + + + + + {{ size={m_count} }} - m_count - m_bucketCountMinusOne + 1 - - - - - + m_count - pBucket = m_hashMap - - - - - - isDeleted = m_marks.m_buffer.m_count > (iBucket*2+1)/32 - ? ((m_marks.m_buffer.m_buffer[(iBucket*2+1)/32]&(1<<(iBucket*2+1)%32)) != 0) - : 0 - - - isEmpty = m_marks.m_buffer.m_count > (iBucket*2)/32 - ? ((m_marks.m_buffer.m_buffer[(iBucket*2)/32]&(1<<(iBucket*2)%32)) == 0) - : 1 - - - *(m_hashMap + iBucket) - - iBucket++ - - + m_kvPairs.head + next + value + - - {{ size={dict._count} }} - - - m_dict._count - m_dict.kvPairs.head - next - value - - - - - {{ size={m_count} }} - - - m_count - m_kvPairs.head - next - value - - - pointer empty diff --git a/source/core/slang-uint-set.h b/source/core/slang-uint-set.h index 22ca457b0..7e08500fd 100644 --- a/source/core/slang-uint-set.h +++ b/source/core/slang-uint-set.h @@ -14,19 +14,9 @@ namespace Slang { -template -constexpr static Index computeElementShift() +constexpr Index intLog2(unsigned x) { - Index currentShift = 0; - Index currentShiftValue = 1; - - while (currentShiftValue != sizeof(T) * 8) - { - currentShift++; - currentShiftValue *= 2; - } - - return currentShift; + return x == 1 ? 0 : 1 + intLog2(x >> 1); } static inline Index bitscanForward(uint64_t in) @@ -65,13 +55,12 @@ public: constexpr static Index kElementSize = sizeof(Element) * 8; ///< The number of bits in an element. This also determines how many values a element can hold. constexpr static Index kElementMask = kElementSize - 1; ///< Mask to get shift from an index - constexpr static Index kElementShift = computeElementShift(); ///< How many bits to shift to get Element index from an index. 5 for 2^5=32 elements in a uint32_t. 6 for 2^6=64 in a uint64_t. + constexpr static Index kElementShift = intLog2(sizeof(Element)*8); ///< How many bits to shift to get Element index from an index. 5 for 2^5=32 elements in a uint32_t. 6 for 2^6=64 in a uint64_t. UIntSet() {} UIntSet(const UIntSet& other) { m_buffer = other.m_buffer; } UIntSet(UIntSet && other) { *this = (_Move(other)); } UIntSet(UInt maxVal) { resizeAndClear(maxVal); } - UIntSet(List buffer) { m_buffer = buffer; } UIntSet& operator=(UIntSet&& other); UIntSet& operator=(const UIntSet& other); @@ -81,7 +70,7 @@ public: /// Return the count of all bits directly represented Int getCount() const { return Int(m_buffer.getCount()) * kElementSize; } - List& getBuffer() { return m_buffer; } + const List& getBuffer() const { return m_buffer; } /// Resize such that val can be stored and clear contents void resizeAndClear(UInt val); @@ -101,6 +90,9 @@ public: /// Add a value inline void add(UInt val); inline void add(const UIntSet& val); + inline void addRange(const List& other); + + inline void addRawElement(Element val, Index bitOffset); /// Remove a value inline void remove(UInt val); @@ -145,37 +137,38 @@ public: { friend class UIntSet; private: - const List* context; - Index block = 0; - Element processedElement = 0; - uint64_t LSB = 0; + const List* m_context; + Index m_block = 0; + Element m_processedElement = 0; + uint64_t m_LSB = 0; void clearLSB() { - LSB = bitscanForward(processedElement); - processedElement &= processedElement - 1; + m_LSB = bitscanForward(m_processedElement); + m_processedElement &= m_processedElement - 1; } - public: - Iterator(const List* inContext) + + Iterator(const List* context) { - context = inContext; + m_context = context; } + public: Element operator*() { - return Element(LSB + (kElementSize * block)); + return Element(m_LSB + (kElementSize * m_block)); } Iterator& operator++() { - while (processedElement == 0) + while (m_processedElement == 0) { - block++; - if (block >= context->getCount()) + m_block++; + if (m_block >= m_context->getCount()) { return *this; } - processedElement = (*context)[block]; + m_processedElement = (*m_context)[m_block]; } clearLSB(); return *this; @@ -186,8 +179,8 @@ public: } bool operator==(const Iterator& other) const { - return other.block == this->block - && other.processedElement == this->processedElement; + return other.m_block == this->m_block + && other.m_processedElement == this->m_processedElement; } bool operator!=(const Iterator& other) const { @@ -200,19 +193,21 @@ public: if (m_buffer.getCount() == 0) return tmp; - tmp.processedElement = m_buffer[0]; - if (tmp.processedElement == 0) + tmp.m_processedElement = m_buffer[0]; + if (tmp.m_processedElement == 0) + { tmp++; + return tmp; + } tmp.clearLSB(); - return tmp; } Iterator end() const { Iterator tmp(&m_buffer); - tmp.block = m_buffer.getCount(); - tmp.processedElement = 0; + tmp.m_block = m_buffer.getCount(); + tmp.m_processedElement = 0; return tmp; } @@ -307,6 +302,19 @@ inline void UIntSet::add(const UIntSet& other) m_buffer[i] |= other.m_buffer[i]; } +inline void UIntSet::addRange(const List& other) +{ + for (auto i : other) + add(i); +} + +inline void UIntSet::addRawElement(Element other, Index elementIndex) +{ + if(this->m_buffer.getCount() <= elementIndex) + resizeBackingBufferDirectly(elementIndex+1); + m_buffer[elementIndex] |= other; +} + template List UIntSet::getElements() const { -- cgit v1.2.3