aboutsummaryrefslogtreecommitdiffstats
path: root/src/xbyak/xbyak_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/xbyak/xbyak_util.h')
-rw-r--r--src/xbyak/xbyak_util.h50
1 files changed, 14 insertions, 36 deletions
diff --git a/src/xbyak/xbyak_util.h b/src/xbyak/xbyak_util.h
index 0f6aada..0154450 100644
--- a/src/xbyak/xbyak_util.h
+++ b/src/xbyak/xbyak_util.h
@@ -416,7 +416,7 @@ const int UseRCX = 1 << 6;
const int UseRDX = 1 << 7;
class Pack {
- static const size_t maxTblNum = 10;
+ static const size_t maxTblNum = 15;
const Xbyak::Reg64 *tbl_[maxTblNum];
size_t n_;
public:
@@ -476,7 +476,7 @@ public:
const Xbyak::Reg64& operator[](size_t n) const
{
if (n >= n_) {
- fprintf(stderr, "ERR Pack bad n=%d\n", (int)n);
+ fprintf(stderr, "ERR Pack bad n=%d(%d)\n", (int)n, (int)n_);
throw Error(ERR_BAD_PARAMETER);
}
return *tbl_[n];
@@ -518,6 +518,7 @@ class StackFrame {
static const int rcxPos = 3;
static const int rdxPos = 2;
#endif
+ static const int maxRegNum = 14; // maxRegNum = 16 - rsp - rax
Xbyak::CodeGenerator *code_;
int pNum_;
int tNum_;
@@ -527,7 +528,7 @@ class StackFrame {
int P_;
bool makeEpilog_;
Xbyak::Reg64 pTbl_[4];
- Xbyak::Reg64 tTbl_[10];
+ Xbyak::Reg64 tTbl_[maxRegNum];
Pack p_;
Pack t_;
StackFrame(const StackFrame&);
@@ -539,7 +540,7 @@ public:
make stack frame
@param sf [in] this
@param pNum [in] num of function parameter(0 <= pNum <= 4)
- @param tNum [in] num of temporary register(0 <= tNum <= 10, with UseRCX, UseRDX)
+ @param tNum [in] num of temporary register(0 <= tNum, with UseRCX, UseRDX) #{pNum + tNum [+rcx] + [rdx]} <= 14
@param stackSizeByte [in] local stack size
@param makeEpilog [in] automatically call close() if true
@@ -566,27 +567,17 @@ public:
using namespace Xbyak;
if (pNum < 0 || pNum > 4) throw Error(ERR_BAD_PNUM);
const int allRegNum = pNum + tNum_ + (useRcx_ ? 1 : 0) + (useRdx_ ? 1 : 0);
- if (allRegNum < pNum || allRegNum > 14) throw Error(ERR_BAD_TNUM);
+ if (tNum_ < 0 || allRegNum > maxRegNum) throw Error(ERR_BAD_TNUM);
const Reg64& _rsp = code->rsp;
- const AddressFrame& _ptr = code->ptr;
saveNum_ = (std::max)(0, allRegNum - noSaveNum);
const int *tbl = getOrderTbl() + noSaveNum;
- P_ = saveNum_ + (stackSizeByte + 7) / 8;
- if (P_ > 0 && (P_ & 1) == 0) P_++; // here (rsp % 16) == 8, then increment P_ for 16 byte alignment
- P_ *= 8;
- if (P_ > 0) code->sub(_rsp, P_);
-#ifdef XBYAK64_WIN
- for (int i = 0; i < (std::min)(saveNum_, 4); i++) {
- code->mov(_ptr [_rsp + P_ + (i + 1) * 8], Reg64(tbl[i]));
- }
- for (int i = 4; i < saveNum_; i++) {
- code->mov(_ptr [_rsp + P_ - 8 * (saveNum_ - i)], Reg64(tbl[i]));
- }
-#else
for (int i = 0; i < saveNum_; i++) {
- code->mov(_ptr [_rsp + P_ - 8 * (saveNum_ - i)], Reg64(tbl[i]));
+ code->push(Reg64(tbl[i]));
}
-#endif
+ P_ = (stackSizeByte + 7) / 8;
+ if (P_ > 0 && (P_ & 1) == (saveNum_ & 1)) P_++; // (rsp % 16) == 8, then increment P_ for 16 byte alignment
+ P_ *= 8;
+ if (P_ > 0) code->sub(_rsp, P_);
int pos = 0;
for (int i = 0; i < pNum; i++) {
pTbl_[i] = Xbyak::Reg64(getRegIdx(pos));
@@ -607,21 +598,11 @@ public:
{
using namespace Xbyak;
const Reg64& _rsp = code_->rsp;
- const AddressFrame& _ptr = code_->ptr;
const int *tbl = getOrderTbl() + noSaveNum;
-#ifdef XBYAK64_WIN
- for (int i = 0; i < (std::min)(saveNum_, 4); i++) {
- code_->mov(Reg64(tbl[i]), _ptr [_rsp + P_ + (i + 1) * 8]);
- }
- for (int i = 4; i < saveNum_; i++) {
- code_->mov(Reg64(tbl[i]), _ptr [_rsp + P_ - 8 * (saveNum_ - i)]);
- }
-#else
+ if (P_ > 0) code_->add(_rsp, P_);
for (int i = 0; i < saveNum_; i++) {
- code_->mov(Reg64(tbl[i]), _ptr [_rsp + P_ - 8 * (saveNum_ - i)]);
+ code_->pop(Reg64(tbl[saveNum_ - 1 - i]));
}
-#endif
- if (P_ > 0) code_->add(_rsp, P_);
if (callRet) code_->ret();
}
@@ -633,9 +614,6 @@ public:
} catch (std::exception& e) {
printf("ERR:StackFrame %s\n", e.what());
exit(1);
- } catch (...) {
- printf("ERR:StackFrame otherwise\n");
- exit(1);
}
}
private:
@@ -654,7 +632,7 @@ private:
}
int getRegIdx(int& pos) const
{
- assert(pos < 14);
+ assert(pos < maxRegNum);
using namespace Xbyak;
const int *tbl = getOrderTbl();
int r = tbl[pos++];