From cb82618f3bf5a9f06e41765ed55a495fde4a0bb7 Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Sat, 27 Jul 2024 18:53:40 +0200 Subject: [PATCH] simplify jump generation in auto-grow mode All jumps are performed relative to the current position, and the encoding is computed based upon jmpAddr - codeOffset. Which means that the encoding is unaffected by the absolute position of the code in memory. Thus, it is not necessary to treat the auto-grow mode differently, the encoding can always be computed eagerly. --- xbyak_aarch64/xbyak_aarch64_code_array.h | 19 ------------------- xbyak_aarch64/xbyak_aarch64_label.h | 6 +----- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/xbyak_aarch64/xbyak_aarch64_code_array.h b/xbyak_aarch64/xbyak_aarch64_code_array.h index 8acaf80..215ea94 100644 --- a/xbyak_aarch64/xbyak_aarch64_code_array.h +++ b/xbyak_aarch64/xbyak_aarch64_code_array.h @@ -100,19 +100,6 @@ class CodeArray { void operator=(const CodeArray &); bool isAllocType() const { return type_ == ALLOC_BUF || type_ == AUTO_GROW; } - // type of partially applied function for encoding - typedef std::function EncFunc; - - struct AddrInfo { - size_t codeOffset; // position to write - size_t jmpAddr; // value to write - EncFunc encFunc; // encoding function - AddrInfo(size_t _codeOffset, size_t _jmpAddr, EncFunc encFunc) : codeOffset(_codeOffset), jmpAddr(_jmpAddr), encFunc(encFunc) {} - uint32_t getVal() const { return encFunc((int64_t)(jmpAddr - codeOffset) * CSIZE); } - }; - - typedef std::list AddrInfoList; - AddrInfoList addrInfoList_; const Type type_; #ifdef XBYAK_USE_MMAP_ALLOCATOR MmapAllocator defaultAllocator_; @@ -149,10 +136,6 @@ class CodeArray { void calcJmpAddress() { if (isCalledCalcJmpAddress_) return; - for (AddrInfoList::const_iterator i = addrInfoList_.begin(), ie = addrInfoList_.end(); i != ie; ++i) { - uint32_t disp = i->getVal(); - rewrite(i->codeOffset, disp); - } isCalledCalcJmpAddress_ = true; } @@ -193,7 +176,6 @@ class CodeArray { bool setProtectModeRW(bool throwException = true) { return setProtectMode(PROTECT_RW, throwException); } void resetSize() { size_ = 0; - addrInfoList_.clear(); isCalledCalcJmpAddress_ = false; } void clearCodeArray() { @@ -241,7 +223,6 @@ class CodeArray { uint32_t *const data = top_ + offset; *data = disp; } - void save(size_t offset, size_t jmpAddr, const EncFunc &encFunc) { addrInfoList_.push_back(AddrInfo(offset, jmpAddr, encFunc)); } bool isAutoGrow() const { return type_ == AUTO_GROW; } bool isCalledCalcJmpAddress() const { return isCalledCalcJmpAddress_; } /** diff --git a/xbyak_aarch64/xbyak_aarch64_label.h b/xbyak_aarch64/xbyak_aarch64_label.h index 1c88c83..5855b6d 100644 --- a/xbyak_aarch64/xbyak_aarch64_label.h +++ b/xbyak_aarch64/xbyak_aarch64_label.h @@ -88,11 +88,7 @@ class LabelManager { const size_t offset = jmp->endOfJmp; int64_t labelOffset = (addrOffset - offset) * CSIZE; uint32_t disp = jmp->encFunc(labelOffset); - if (base_->isAutoGrow()) { - base_->save(offset, addrOffset, jmp->encFunc); - } else { - base_->rewrite(offset, disp); - } + base_->rewrite(offset, disp); undefList.erase(itr); } }