mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 20:44:37 +03:00
Attempt to fix remaining issues (maintenance mode)
This commit is contained in:
@@ -54,6 +54,9 @@
|
|||||||
#if ASMJIT_CC_GCC
|
#if ASMJIT_CC_GCC
|
||||||
# pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
# pragma GCC diagnostic ignored "-Wbool-operation"
|
# pragma GCC diagnostic ignored "-Wbool-operation"
|
||||||
|
# if ASMJIT_CC_GCC_GE(8, 0, 0)
|
||||||
|
# pragma GCC diagnostic ignored "-Wclass-memaccess"
|
||||||
|
# endif
|
||||||
#endif // ASMJIT_CC_GCC
|
#endif // ASMJIT_CC_GCC
|
||||||
|
|
||||||
// [MSC]
|
// [MSC]
|
||||||
|
|||||||
@@ -627,89 +627,6 @@ Error ZoneBitVector::fill(size_t from, size_t to, bool value) noexcept {
|
|||||||
return kErrorOk;
|
return kErrorOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// [asmjit::ZoneStackBase - Init / Reset]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
Error ZoneStackBase::_init(ZoneHeap* heap, size_t middleIndex) noexcept {
|
|
||||||
ZoneHeap* oldHeap = _heap;
|
|
||||||
|
|
||||||
if (oldHeap) {
|
|
||||||
Block* block = _block[kSideLeft];
|
|
||||||
while (block) {
|
|
||||||
Block* next = block->getNext();
|
|
||||||
oldHeap->release(block, kBlockSize);
|
|
||||||
block = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
_heap = nullptr;
|
|
||||||
_block[kSideLeft] = nullptr;
|
|
||||||
_block[kSideRight] = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (heap) {
|
|
||||||
Block* block = static_cast<Block*>(heap->alloc(kBlockSize));
|
|
||||||
if (ASMJIT_UNLIKELY(!block))
|
|
||||||
return DebugUtils::errored(kErrorNoHeapMemory);
|
|
||||||
|
|
||||||
block->_link[kSideLeft] = nullptr;
|
|
||||||
block->_link[kSideRight] = nullptr;
|
|
||||||
block->_start = (uint8_t*)block + middleIndex;
|
|
||||||
block->_end = (uint8_t*)block + middleIndex;
|
|
||||||
|
|
||||||
_heap = heap;
|
|
||||||
_block[kSideLeft] = block;
|
|
||||||
_block[kSideRight] = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
return kErrorOk;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// [asmjit::ZoneStackBase - Ops]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
Error ZoneStackBase::_prepareBlock(uint32_t side, size_t initialIndex) noexcept {
|
|
||||||
ASMJIT_ASSERT(isInitialized());
|
|
||||||
|
|
||||||
Block* prev = _block[side];
|
|
||||||
ASMJIT_ASSERT(!prev->isEmpty());
|
|
||||||
|
|
||||||
Block* block = _heap->allocT<Block>(kBlockSize);
|
|
||||||
if (ASMJIT_UNLIKELY(!block))
|
|
||||||
return DebugUtils::errored(kErrorNoHeapMemory);
|
|
||||||
|
|
||||||
block->_link[ side] = nullptr;
|
|
||||||
block->_link[!side] = prev;
|
|
||||||
block->_start = (uint8_t*)block + initialIndex;
|
|
||||||
block->_end = (uint8_t*)block + initialIndex;
|
|
||||||
|
|
||||||
prev->_link[side] = block;
|
|
||||||
_block[side] = block;
|
|
||||||
|
|
||||||
return kErrorOk;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZoneStackBase::_cleanupBlock(uint32_t side, size_t middleIndex) noexcept {
|
|
||||||
Block* block = _block[side];
|
|
||||||
ASMJIT_ASSERT(block->isEmpty());
|
|
||||||
|
|
||||||
Block* prev = block->_link[!side];
|
|
||||||
if (prev) {
|
|
||||||
ASMJIT_ASSERT(prev->_link[side] == block);
|
|
||||||
_heap->release(block, kBlockSize);
|
|
||||||
|
|
||||||
prev->_link[side] = nullptr;
|
|
||||||
_block[side] = prev;
|
|
||||||
}
|
|
||||||
else if (_block[!side] == prev && prev->isEmpty()) {
|
|
||||||
// If the container becomes empty center both pointers in the remaining block.
|
|
||||||
prev->_start = (uint8_t*)prev + middleIndex;
|
|
||||||
prev->_end = (uint8_t*)prev + middleIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// [asmjit::ZoneHashBase - Utilities]
|
// [asmjit::ZoneHashBase - Utilities]
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -908,52 +825,6 @@ UNIT(base_ZoneBitVector) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNIT(base_zonestack) {
|
|
||||||
Zone zone(8096 - Zone::kZoneOverhead);
|
|
||||||
ZoneHeap heap(&zone);
|
|
||||||
ZoneStack<int> stack;
|
|
||||||
|
|
||||||
INFO("ZoneStack<int> contains %d elements per one Block", ZoneStack<int>::kNumBlockItems);
|
|
||||||
|
|
||||||
EXPECT(stack.init(&heap) == kErrorOk);
|
|
||||||
EXPECT(stack.isEmpty(), "Stack must be empty after `init()`");
|
|
||||||
|
|
||||||
EXPECT(stack.append(42) == kErrorOk);
|
|
||||||
EXPECT(!stack.isEmpty() , "Stack must not be empty after an item has been appended");
|
|
||||||
EXPECT(stack.pop() == 42, "Stack.pop() must return the item that has been appended last");
|
|
||||||
EXPECT(stack.isEmpty() , "Stack must be empty after the last element has been removed");
|
|
||||||
|
|
||||||
EXPECT(stack.prepend(43) == kErrorOk);
|
|
||||||
EXPECT(!stack.isEmpty() , "Stack must not be empty after an item has been prepended");
|
|
||||||
EXPECT(stack.popFirst() == 43, "Stack.popFirst() must return the item that has been prepended last");
|
|
||||||
EXPECT(stack.isEmpty() , "Stack must be empty after the last element has been removed");
|
|
||||||
|
|
||||||
int i;
|
|
||||||
int iMin =-100;
|
|
||||||
int iMax = 100000;
|
|
||||||
|
|
||||||
INFO("Adding items from %d to %d to the stack", iMin, iMax);
|
|
||||||
for (i = 1; i <= iMax; i++) stack.append(i);
|
|
||||||
for (i = 0; i >= iMin; i--) stack.prepend(i);
|
|
||||||
|
|
||||||
INFO("Validating popFirst()");
|
|
||||||
for (i = iMin; i <= iMax; i++) {
|
|
||||||
int item = stack.popFirst();
|
|
||||||
EXPECT(i == item, "Item '%d' didn't match the item '%d' popped", i, item);
|
|
||||||
}
|
|
||||||
EXPECT(stack.isEmpty());
|
|
||||||
|
|
||||||
INFO("Adding items from %d to %d to the stack", iMin, iMax);
|
|
||||||
for (i = 0; i >= iMin; i--) stack.prepend(i);
|
|
||||||
for (i = 1; i <= iMax; i++) stack.append(i);
|
|
||||||
|
|
||||||
INFO("Validating pop()");
|
|
||||||
for (i = iMax; i >= iMin; i--) {
|
|
||||||
int item = stack.pop();
|
|
||||||
EXPECT(i == item, "Item '%d' didn't match the item '%d' popped", i, item);
|
|
||||||
}
|
|
||||||
EXPECT(stack.isEmpty());
|
|
||||||
}
|
|
||||||
#endif // ASMJIT_TEST
|
#endif // ASMJIT_TEST
|
||||||
|
|
||||||
} // asmjit namespace
|
} // asmjit namespace
|
||||||
|
|||||||
@@ -1005,207 +1005,6 @@ public:
|
|||||||
size_t _capacity; //!< Capacity of the bit-vector (in bits).
|
size_t _capacity; //!< Capacity of the bit-vector (in bits).
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// [asmjit::ZoneStackBase]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
class ZoneStackBase {
|
|
||||||
public:
|
|
||||||
enum Side {
|
|
||||||
kSideLeft = 0,
|
|
||||||
kSideRight = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
kBlockSize = ZoneHeap::kHiMaxSize
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Block {
|
|
||||||
ASMJIT_INLINE Block* getPrev() const noexcept { return _link[kSideLeft]; }
|
|
||||||
ASMJIT_INLINE void setPrev(Block* block) noexcept { _link[kSideLeft] = block; }
|
|
||||||
|
|
||||||
ASMJIT_INLINE Block* getNext() const noexcept { return _link[kSideRight]; }
|
|
||||||
ASMJIT_INLINE void setNext(Block* block) noexcept { _link[kSideRight] = block; }
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE T* getStart() const noexcept { return static_cast<T*>(_start); }
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE void setStart(T* start) noexcept { _start = static_cast<void*>(start); }
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE T* getEnd() const noexcept { return static_cast<T*>(_end); }
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE void setEnd(T* end) noexcept { _end = static_cast<void*>(end); }
|
|
||||||
|
|
||||||
ASMJIT_INLINE bool isEmpty() const noexcept { return _start == _end; }
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE T* getData() const noexcept {
|
|
||||||
return static_cast<T*>(static_cast<void*>((uint8_t*)this + sizeof(Block)));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE bool canPrepend() const noexcept {
|
|
||||||
return _start > getData<void>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ASMJIT_INLINE bool canAppend() const noexcept {
|
|
||||||
size_t kNumBlockItems = (kBlockSize - sizeof(Block)) / sizeof(T);
|
|
||||||
size_t kBlockEnd = sizeof(Block) + kNumBlockItems * sizeof(T);
|
|
||||||
return (uintptr_t)_end - (uintptr_t)this < kBlockEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block* _link[2]; //!< Next and previous blocks.
|
|
||||||
void* _start; //!< Pointer to the start of the array.
|
|
||||||
void* _end; //!< Pointer to the end of the array.
|
|
||||||
};
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Construction / Destruction]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ASMJIT_INLINE ZoneStackBase() noexcept {
|
|
||||||
_heap = nullptr;
|
|
||||||
_block[0] = nullptr;
|
|
||||||
_block[1] = nullptr;
|
|
||||||
}
|
|
||||||
ASMJIT_INLINE ~ZoneStackBase() noexcept { reset(); }
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Init / Reset]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ASMJIT_INLINE bool isInitialized() const noexcept { return _heap != nullptr; }
|
|
||||||
ASMJIT_API Error _init(ZoneHeap* heap, size_t middleIndex) noexcept;
|
|
||||||
ASMJIT_INLINE Error reset() noexcept { return _init(nullptr, 0); }
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Accessors]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//! Get a `ZoneHeap` attached to this container.
|
|
||||||
ASMJIT_INLINE ZoneHeap* getHeap() const noexcept { return _heap; }
|
|
||||||
|
|
||||||
ASMJIT_INLINE bool isEmpty() const noexcept {
|
|
||||||
ASMJIT_ASSERT(isInitialized());
|
|
||||||
return _block[0] == _block[1] && _block[0]->isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Ops]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ASMJIT_API Error _prepareBlock(uint32_t side, size_t initialIndex) noexcept;
|
|
||||||
ASMJIT_API void _cleanupBlock(uint32_t side, size_t middleIndex) noexcept;
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Members]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ZoneHeap* _heap; //!< ZoneHeap used to allocate data.
|
|
||||||
Block* _block[2]; //!< First and last blocks.
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// [asmjit::ZoneStack<T>]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class ZoneStack : public ZoneStackBase {
|
|
||||||
public:
|
|
||||||
enum {
|
|
||||||
kNumBlockItems = static_cast<int>((kBlockSize - sizeof(Block)) / sizeof(T)),
|
|
||||||
kStartBlockIndex = static_cast<int>(sizeof(Block)),
|
|
||||||
kMidBlockIndex = static_cast<int>(kStartBlockIndex + (kNumBlockItems / 2) * sizeof(T)),
|
|
||||||
kEndBlockIndex = static_cast<int>(kStartBlockIndex + kNumBlockItems * sizeof(T))
|
|
||||||
};
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Construction / Destruction]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ASMJIT_INLINE ZoneStack() noexcept {}
|
|
||||||
ASMJIT_INLINE ~ZoneStack() noexcept {}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Init / Reset]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ASMJIT_INLINE Error init(ZoneHeap* heap) noexcept { return _init(heap, kMidBlockIndex); }
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// [Ops]
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ASMJIT_INLINE Error prepend(T item) noexcept {
|
|
||||||
ASMJIT_ASSERT(isInitialized());
|
|
||||||
Block* block = _block[kSideLeft];
|
|
||||||
|
|
||||||
if (!block->canPrepend<T>()) {
|
|
||||||
ASMJIT_PROPAGATE(_prepareBlock(kSideLeft, kEndBlockIndex));
|
|
||||||
block = _block[kSideLeft];
|
|
||||||
}
|
|
||||||
|
|
||||||
T* ptr = block->getStart<T>() - 1;
|
|
||||||
ASMJIT_ASSERT(ptr >= block->getData<T>() && ptr < block->getData<T>() + kNumBlockItems);
|
|
||||||
*ptr = item;
|
|
||||||
block->setStart<T>(ptr);
|
|
||||||
return kErrorOk;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASMJIT_INLINE Error append(T item) noexcept {
|
|
||||||
ASMJIT_ASSERT(isInitialized());
|
|
||||||
Block* block = _block[kSideRight];
|
|
||||||
|
|
||||||
if (!block->canAppend<T>()) {
|
|
||||||
ASMJIT_PROPAGATE(_prepareBlock(kSideRight, kStartBlockIndex));
|
|
||||||
block = _block[kSideRight];
|
|
||||||
}
|
|
||||||
|
|
||||||
T* ptr = block->getEnd<T>();
|
|
||||||
ASMJIT_ASSERT(ptr >= block->getData<T>() && ptr < block->getData<T>() + kNumBlockItems);
|
|
||||||
|
|
||||||
*ptr++ = item;
|
|
||||||
block->setEnd(ptr);
|
|
||||||
return kErrorOk;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASMJIT_INLINE T popFirst() noexcept {
|
|
||||||
ASMJIT_ASSERT(isInitialized());
|
|
||||||
ASMJIT_ASSERT(!isEmpty());
|
|
||||||
|
|
||||||
Block* block = _block[kSideLeft];
|
|
||||||
ASMJIT_ASSERT(!block->isEmpty());
|
|
||||||
|
|
||||||
T* ptr = block->getStart<T>();
|
|
||||||
T item = *ptr++;
|
|
||||||
|
|
||||||
block->setStart(ptr);
|
|
||||||
if (block->isEmpty())
|
|
||||||
_cleanupBlock(kSideLeft, kMidBlockIndex);
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASMJIT_INLINE T pop() noexcept {
|
|
||||||
ASMJIT_ASSERT(isInitialized());
|
|
||||||
ASMJIT_ASSERT(!isEmpty());
|
|
||||||
|
|
||||||
Block* block = _block[kSideRight];
|
|
||||||
ASMJIT_ASSERT(!block->isEmpty());
|
|
||||||
|
|
||||||
T* ptr = block->getEnd<T>();
|
|
||||||
T item = *--ptr;
|
|
||||||
|
|
||||||
block->setEnd(ptr);
|
|
||||||
if (block->isEmpty())
|
|
||||||
_cleanupBlock(kSideRight, kMidBlockIndex);
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// [asmjit::ZoneHashNode]
|
// [asmjit::ZoneHashNode]
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
@@ -3870,7 +3870,8 @@ EmitModSib_LabelRip_X86:
|
|||||||
else if (!(rmInfo & kX86MemInfo_67H_X86)) {
|
else if (!(rmInfo & kX86MemInfo_67H_X86)) {
|
||||||
// ESP|RSP can't be used as INDEX in pure SIB mode, however, VSIB mode
|
// ESP|RSP can't be used as INDEX in pure SIB mode, however, VSIB mode
|
||||||
// allows XMM4|YMM4|ZMM4 (that's why the check is before the label).
|
// allows XMM4|YMM4|ZMM4 (that's why the check is before the label).
|
||||||
if (ASMJIT_UNLIKELY(rxReg == X86Gp::kIdSp)) goto InvalidAddressIndex;
|
if (ASMJIT_UNLIKELY(rxReg == X86Gp::kIdSp))
|
||||||
|
goto InvalidAddressIndex;
|
||||||
|
|
||||||
EmitModVSib:
|
EmitModVSib:
|
||||||
rxReg &= 0x7;
|
rxReg &= 0x7;
|
||||||
|
|||||||
Reference in New Issue
Block a user