increase max temp regs for StackFrame
diff --git a/test/sf_test.cpp b/test/sf_test.cpp
index ced893b..8988bb0 100644
--- a/test/sf_test.cpp
+++ b/test/sf_test.cpp
@@ -129,6 +129,55 @@
add(rax, sf.p[2]);
add(rax, sf.p[3]);
}
+
+ /*
+ int64_t f(const int64_t a[13]) { return sum-of-a[]; }
+ */
+ void gen13()
+ {
+ StackFrame sf(this, 1, 13);
+ for (int i = 0; i < 13; i++) {
+ mov(sf.t[i], ptr[sf.p[0] + i * 8]);
+ }
+ mov(rax, sf.t[0]);
+ for (int i = 1; i < 13; i++) {
+ add(rax, sf.t[i]);
+ }
+ }
+ /*
+ same as gen13
+ */
+ void gen14()
+ {
+ StackFrame sf(this, 1, 11 | UseRCX | UseRDX);
+ Pack t = sf.t;
+ t.append(rcx);
+ t.append(rdx);
+ for (int i = 0; i < 13; i++) {
+ mov(t[i], ptr[sf.p[0] + i * 8]);
+ }
+ mov(rax, t[0]);
+ for (int i = 1; i < 13; i++) {
+ add(rax, t[i]);
+ }
+ }
+ /*
+ return (1 << 15) - 1;
+ */
+ void gen15()
+ {
+ StackFrame sf(this, 0, 14, 8);
+ Pack t = sf.t;
+ t.append(rax);
+ for (int i = 0; i < 15; i++) {
+ mov(t[i], 1 << i);
+ }
+ mov(qword[rsp], 0);
+ for (int i = 0; i < 15; i++) {
+ add(ptr[rsp], t[i]);
+ }
+ mov(rax, ptr[rsp]);
+ }
};
struct Code2 : Xbyak::CodeGenerator {
@@ -159,6 +208,7 @@
}
};
+
static int errNum = 0;
void check(int x, int y)
{
@@ -282,6 +332,20 @@
int (*f12)(int, int, int, int) = code.getCurr<int (*)(int, int, int, int)>();
code.gen12();
check(24, f12(3, 5, 7, 9));
+
+ {
+ int64_t tbl[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
+ int64_t (*f13)(const int64_t*) = code.getCurr<int64_t (*)(const int64_t*)>();
+ code.gen13();
+ check(91, f13(tbl));
+
+ int64_t (*f14)(const int64_t*) = code.getCurr<int64_t (*)(const int64_t*)>();
+ code.gen14();
+ check(91, f14(tbl));
+ }
+ int (*f15)() = code.getCurr<int (*)()>();
+ code.gen15();
+ check((1 << 15) - 1, f15());
}
void put(const Xbyak::util::Pack& p)
diff --git a/xbyak/xbyak_util.h b/xbyak/xbyak_util.h
index 212e3a7..0154450 100644
--- a/xbyak/xbyak_util.h
+++ b/xbyak/xbyak_util.h
@@ -416,7 +416,7 @@
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 @@
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 @@
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 @@
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 @@
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,7 +567,7 @@
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;
saveNum_ = (std::max)(0, allRegNum - noSaveNum);
const int *tbl = getOrderTbl() + noSaveNum;
@@ -631,7 +632,7 @@
}
int getRegIdx(int& pos) const
{
- assert(pos < 14);
+ assert(pos < maxRegNum);
using namespace Xbyak;
const int *tbl = getOrderTbl();
int r = tbl[pos++];