Skip to content

Commit

Permalink
simplify jump generation in auto-grow mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
neumannt committed Jul 27, 2024
1 parent f43f7e8 commit cb82618
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
19 changes: 0 additions & 19 deletions xbyak_aarch64/xbyak_aarch64_code_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t(int64_t)> 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<AddrInfo> AddrInfoList;
AddrInfoList addrInfoList_;
const Type type_;
#ifdef XBYAK_USE_MMAP_ALLOCATOR
MmapAllocator defaultAllocator_;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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_; }
/**
Expand Down
6 changes: 1 addition & 5 deletions xbyak_aarch64/xbyak_aarch64_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit cb82618

Please sign in to comment.