diff options
Diffstat (limited to '3rdparty/asmjit/src/asmjit/core/zonelist.h')
-rw-r--r-- | 3rdparty/asmjit/src/asmjit/core/zonelist.h | 139 |
1 files changed, 71 insertions, 68 deletions
diff --git a/3rdparty/asmjit/src/asmjit/core/zonelist.h b/3rdparty/asmjit/src/asmjit/core/zonelist.h index bc726deca94..8980240ef43 100644 --- a/3rdparty/asmjit/src/asmjit/core/zonelist.h +++ b/3rdparty/asmjit/src/asmjit/core/zonelist.h @@ -1,25 +1,7 @@ -// AsmJit - Machine code generation for C++ +// This file is part of AsmJit project <https://asmjit.com> // -// * Official AsmJit Home Page: https://asmjit.com -// * Official Github Repository: https://github.com/asmjit/asmjit -// -// Copyright (c) 2008-2020 The AsmJit Authors -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. +// See asmjit.h or LICENSE.md for license and copyright information +// SPDX-License-Identifier: Zlib #ifndef ASMJIT_CORE_ZONELIST_H_INCLUDED #define ASMJIT_CORE_ZONELIST_H_INCLUDED @@ -31,25 +13,36 @@ ASMJIT_BEGIN_NAMESPACE //! \addtogroup asmjit_zone //! \{ -// ============================================================================ -// [asmjit::ZoneListNode] -// ============================================================================ - //! Node used by \ref ZoneList template. template<typename NodeT> class ZoneListNode { public: ASMJIT_NONCOPYABLE(ZoneListNode) - NodeT* _listNodes[Globals::kLinkCount]; + //! \name Constants + //! \{ + + enum : size_t { + kNodeIndexPrev = 0, + kNodeIndexNext = 1 + }; + + //! \} + + //! \name Members + //! \{ + + NodeT* _listNodes[2]; + + //! \} //! \name Construction & Destruction //! \{ - inline ZoneListNode() noexcept + ASMJIT_INLINE_NODEBUG ZoneListNode() noexcept : _listNodes { nullptr, nullptr } {} - inline ZoneListNode(ZoneListNode&& other) noexcept + ASMJIT_INLINE_NODEBUG ZoneListNode(ZoneListNode&& other) noexcept : _listNodes { other._listNodes[0], other._listNodes[1] } {} //! \} @@ -57,39 +50,49 @@ public: //! \name Accessors //! \{ - inline bool hasPrev() const noexcept { return _listNodes[Globals::kLinkPrev] != nullptr; } - inline bool hasNext() const noexcept { return _listNodes[Globals::kLinkNext] != nullptr; } + ASMJIT_INLINE_NODEBUG bool hasPrev() const noexcept { return _listNodes[kNodeIndexPrev] != nullptr; } + ASMJIT_INLINE_NODEBUG bool hasNext() const noexcept { return _listNodes[kNodeIndexNext] != nullptr; } - inline NodeT* prev() const noexcept { return _listNodes[Globals::kLinkPrev]; } - inline NodeT* next() const noexcept { return _listNodes[Globals::kLinkNext]; } + ASMJIT_INLINE_NODEBUG NodeT* prev() const noexcept { return _listNodes[kNodeIndexPrev]; } + ASMJIT_INLINE_NODEBUG NodeT* next() const noexcept { return _listNodes[kNodeIndexNext]; } //! \} }; -// ============================================================================ -// [asmjit::ZoneList<T>] -// ============================================================================ - //! Zone allocated list container that uses nodes of `NodeT` type. template <typename NodeT> class ZoneList { public: ASMJIT_NONCOPYABLE(ZoneList) - NodeT* _bounds[Globals::kLinkCount]; + //! \name Constants + //! \{ + + enum : size_t { + kNodeIndexFirst = 0, + kNodeIndexLast = 1 + }; + + //! \} + + //! \name Members + //! \{ + + NodeT* _nodes[2] {}; + + //! \} //! \name Construction & Destruction //! \{ - inline ZoneList() noexcept - : _bounds { nullptr, nullptr } {} + ASMJIT_INLINE_NODEBUG ZoneList() noexcept {} - inline ZoneList(ZoneList&& other) noexcept - : _bounds { other._bounds[0], other._bounds[1] } {} + ASMJIT_INLINE_NODEBUG ZoneList(ZoneList&& other) noexcept + : _nodes { other._nodes[0], other._nodes[1] } {} - inline void reset() noexcept { - _bounds[0] = nullptr; - _bounds[1] = nullptr; + ASMJIT_INLINE_NODEBUG void reset() noexcept { + _nodes[0] = nullptr; + _nodes[1] = nullptr; } //! \} @@ -97,33 +100,33 @@ public: //! \name Accessors //! \{ - inline bool empty() const noexcept { return _bounds[0] == nullptr; } - inline NodeT* first() const noexcept { return _bounds[Globals::kLinkFirst]; } - inline NodeT* last() const noexcept { return _bounds[Globals::kLinkLast]; } + ASMJIT_INLINE_NODEBUG bool empty() const noexcept { return _nodes[0] == nullptr; } + ASMJIT_INLINE_NODEBUG NodeT* first() const noexcept { return _nodes[kNodeIndexFirst]; } + ASMJIT_INLINE_NODEBUG NodeT* last() const noexcept { return _nodes[kNodeIndexLast]; } //! \} //! \name Utilities //! \{ - inline void swap(ZoneList& other) noexcept { - std::swap(_bounds[0], other._bounds[0]); - std::swap(_bounds[1], other._bounds[1]); + ASMJIT_INLINE_NODEBUG void swap(ZoneList& other) noexcept { + std::swap(_nodes[0], other._nodes[0]); + std::swap(_nodes[1], other._nodes[1]); } - // Can be used to both prepend and append. + // Can be used to both append and prepend. inline void _addNode(NodeT* node, size_t dir) noexcept { - NodeT* prev = _bounds[dir]; + NodeT* prev = _nodes[dir]; node->_listNodes[!dir] = prev; - _bounds[dir] = node; + _nodes[dir] = node; if (prev) prev->_listNodes[dir] = node; else - _bounds[!dir] = node; + _nodes[!dir] = node; } - // Can be used to both prepend and append. + // Can be used to both append and prepend. inline void _insertNode(NodeT* ref, NodeT* node, size_t dir) noexcept { ASMJIT_ASSERT(ref != nullptr); @@ -134,24 +137,24 @@ public: if (next) next->_listNodes[!dir] = node; else - _bounds[dir] = node; + _nodes[dir] = node; node->_listNodes[!dir] = prev; node->_listNodes[ dir] = next; } - inline void append(NodeT* node) noexcept { _addNode(node, Globals::kLinkLast); } - inline void prepend(NodeT* node) noexcept { _addNode(node, Globals::kLinkFirst); } + ASMJIT_INLINE_NODEBUG void append(NodeT* node) noexcept { _addNode(node, kNodeIndexLast); } + ASMJIT_INLINE_NODEBUG void prepend(NodeT* node) noexcept { _addNode(node, kNodeIndexFirst); } - inline void insertAfter(NodeT* ref, NodeT* node) noexcept { _insertNode(ref, node, Globals::kLinkNext); } - inline void insertBefore(NodeT* ref, NodeT* node) noexcept { _insertNode(ref, node, Globals::kLinkPrev); } + ASMJIT_INLINE_NODEBUG void insertAfter(NodeT* ref, NodeT* node) noexcept { _insertNode(ref, node, NodeT::kNodeIndexNext); } + ASMJIT_INLINE_NODEBUG void insertBefore(NodeT* ref, NodeT* node) noexcept { _insertNode(ref, node, NodeT::kNodeIndexPrev); } inline NodeT* unlink(NodeT* node) noexcept { NodeT* prev = node->prev(); NodeT* next = node->next(); - if (prev) { prev->_listNodes[1] = next; node->_listNodes[0] = nullptr; } else { _bounds[0] = next; } - if (next) { next->_listNodes[0] = prev; node->_listNodes[1] = nullptr; } else { _bounds[1] = prev; } + if (prev) { prev->_listNodes[1] = next; node->_listNodes[0] = nullptr; } else { _nodes[0] = next; } + if (next) { next->_listNodes[0] = prev; node->_listNodes[1] = nullptr; } else { _nodes[1] = prev; } node->_listNodes[0] = nullptr; node->_listNodes[1] = nullptr; @@ -160,36 +163,36 @@ public: } inline NodeT* popFirst() noexcept { - NodeT* node = _bounds[0]; + NodeT* node = _nodes[0]; ASMJIT_ASSERT(node != nullptr); NodeT* next = node->next(); - _bounds[0] = next; + _nodes[0] = next; if (next) { next->_listNodes[0] = nullptr; node->_listNodes[1] = nullptr; } else { - _bounds[1] = nullptr; + _nodes[1] = nullptr; } return node; } inline NodeT* pop() noexcept { - NodeT* node = _bounds[1]; + NodeT* node = _nodes[1]; ASMJIT_ASSERT(node != nullptr); NodeT* prev = node->prev(); - _bounds[1] = prev; + _nodes[1] = prev; if (prev) { prev->_listNodes[1] = nullptr; node->_listNodes[0] = nullptr; } else { - _bounds[0] = nullptr; + _nodes[0] = nullptr; } return node; |