fix build failure
This commit is contained in:
parent
914ba11e3b
commit
584305f1fa
|
@ -678,8 +678,7 @@ struct BlockMatch {
|
||||||
#define MIN_MATCH_SIZE 16
|
#define MIN_MATCH_SIZE 16
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - check whether a block consists only of calls
|
// - see if we can optimize even more
|
||||||
// - see if we can optimize better
|
|
||||||
SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlocks, unsigned char* speedDial) {
|
SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlocks, unsigned char* speedDial) {
|
||||||
unsigned char* buf=stream->getFinalBuf();
|
unsigned char* buf=stream->getFinalBuf();
|
||||||
size_t matchSize=MIN_MATCH_SIZE;
|
size_t matchSize=MIN_MATCH_SIZE;
|
||||||
|
@ -709,7 +708,6 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlock
|
||||||
// search for bigger matches
|
// search for bigger matches
|
||||||
bool wantMore=true;
|
bool wantMore=true;
|
||||||
do {
|
do {
|
||||||
size_t matchCount=0;
|
|
||||||
wantMore=false;
|
wantMore=false;
|
||||||
matchSize+=8;
|
matchSize+=8;
|
||||||
for (size_t i=0; i<matches.size(); i++) {
|
for (size_t i=0; i<matches.size(); i++) {
|
||||||
|
@ -729,13 +727,11 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlock
|
||||||
// this match may be bigger
|
// this match may be bigger
|
||||||
b.len=matchSize;
|
b.len=matchSize;
|
||||||
wantMore=true;
|
wantMore=true;
|
||||||
matchCount++;
|
|
||||||
} else {
|
} else {
|
||||||
// this is the max size
|
// this is the max size
|
||||||
b.done=true;
|
b.done=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//logV("size %d: %d matches",(int)matchSize,(int)matchCount);
|
|
||||||
} while (wantMore);
|
} while (wantMore);
|
||||||
|
|
||||||
// first stage done
|
// first stage done
|
||||||
|
@ -776,144 +772,138 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlock
|
||||||
std::vector<BlockMatch> workMatches;
|
std::vector<BlockMatch> workMatches;
|
||||||
bool newBlocks=false;
|
bool newBlocks=false;
|
||||||
|
|
||||||
// try with a smaller size
|
// try with a smaller size
|
||||||
matchSize=0;
|
matchSize=0;
|
||||||
for (BlockMatch& i: matches) {
|
for (BlockMatch& i: matches) {
|
||||||
if (i.done) continue;
|
if (i.done) continue;
|
||||||
if (i.len>matchSize) matchSize=i.len;
|
if (i.len>matchSize) matchSize=i.len;
|
||||||
|
}
|
||||||
|
|
||||||
|
workMatches.clear();
|
||||||
|
// find matches with matching size
|
||||||
|
for (BlockMatch& i: matches) {
|
||||||
|
if (i.len==matchSize) {
|
||||||
|
// mark it as done and push it
|
||||||
|
workMatches.push_back(i);
|
||||||
|
i.done=true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//while (matchSize>=MIN_MATCH_SIZE) {
|
// check which sub-blocks are viable to make
|
||||||
workMatches.clear();
|
size_t lastOrig=SIZE_MAX;
|
||||||
// find matches with matching size
|
size_t lastOrigOff=0;
|
||||||
for (BlockMatch& i: matches) {
|
int gains=0;
|
||||||
if (i.len==matchSize) {
|
int blockSize=0;
|
||||||
// mark it as done and push it
|
for (size_t i=0; i<=workMatches.size(); i++) {
|
||||||
workMatches.push_back(i);
|
BlockMatch b(SIZE_MAX,SIZE_MAX,0);
|
||||||
i.done=true;
|
if (i<workMatches.size()) b=workMatches[i];
|
||||||
}
|
// unlikely
|
||||||
}
|
if (b.done) continue;
|
||||||
|
|
||||||
// check which sub-blocks are viable to make
|
if (b.orig!=lastOrig) {
|
||||||
size_t lastOrig=SIZE_MAX;
|
if (lastOrig!=SIZE_MAX) {
|
||||||
size_t lastOrigOff=0;
|
// commit previous block and start new one
|
||||||
int gains=0;
|
logV("%x gains: %d",(int)lastOrig,gains);
|
||||||
int blockSize=0;
|
if (gains<=0) {
|
||||||
for (size_t i=0; i<=workMatches.size(); i++) {
|
// don't make a sub-block for these matches since we only have loss
|
||||||
BlockMatch b(SIZE_MAX,SIZE_MAX,0);
|
logV("(LOSSES!)");
|
||||||
if (i<workMatches.size()) b=workMatches[i];
|
for (size_t j=lastOrigOff; j<i; j++) {
|
||||||
// unlikely
|
workMatches[j].done=true;
|
||||||
if (b.done) continue;
|
|
||||||
|
|
||||||
if (b.orig!=lastOrig) {
|
|
||||||
if (lastOrig!=SIZE_MAX) {
|
|
||||||
// commit previous block and start new one
|
|
||||||
logV("%x gains: %d",(int)lastOrig,gains);
|
|
||||||
if (gains<=0) {
|
|
||||||
// don't make a sub-block for these matches since we only have loss
|
|
||||||
logV("(LOSSES!)");
|
|
||||||
for (size_t j=lastOrigOff; j<i; j++) {
|
|
||||||
workMatches[j].done=true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastOrig=b.orig;
|
|
||||||
lastOrigOff=i;
|
|
||||||
if (lastOrig!=SIZE_MAX) {
|
|
||||||
blockSize=estimateBlockSize(&buf[b.orig],b.len,speedDial);
|
|
||||||
} else {
|
|
||||||
blockSize=0;
|
|
||||||
}
|
|
||||||
gains=-4;
|
|
||||||
}
|
}
|
||||||
gains+=(blockSize-3);
|
lastOrig=b.orig;
|
||||||
|
lastOrigOff=i;
|
||||||
|
if (lastOrig!=SIZE_MAX) {
|
||||||
|
blockSize=estimateBlockSize(&buf[b.orig],b.len,speedDial);
|
||||||
|
} else {
|
||||||
|
blockSize=0;
|
||||||
|
}
|
||||||
|
gains=-4;
|
||||||
}
|
}
|
||||||
|
gains+=(blockSize-3);
|
||||||
|
}
|
||||||
|
|
||||||
// make sub-blocks
|
// make sub-blocks
|
||||||
lastOrig=SIZE_MAX;
|
lastOrig=SIZE_MAX;
|
||||||
size_t subBlockID=subBlocks.size();
|
size_t subBlockID=subBlocks.size();
|
||||||
for (BlockMatch& i: workMatches) {
|
for (BlockMatch& i: workMatches) {
|
||||||
// skip invalid matches (yes, this can happen)
|
// skip invalid matches (yes, this can happen)
|
||||||
if (i.done) continue;
|
if (i.done) continue;
|
||||||
|
|
||||||
// create new sub-block if necessary
|
// create new sub-block if necessary
|
||||||
if (i.orig!=lastOrig) {
|
if (i.orig!=lastOrig) {
|
||||||
subBlockID=subBlocks.size();
|
subBlockID=subBlocks.size();
|
||||||
newBlocks=true;
|
newBlocks=true;
|
||||||
logV("new sub-block %d",(int)subBlockID);
|
logV("new sub-block %d",(int)subBlockID);
|
||||||
|
|
||||||
// isolate this sub-block
|
// isolate this sub-block
|
||||||
SafeWriter* newBlock=new SafeWriter;
|
SafeWriter* newBlock=new SafeWriter;
|
||||||
newBlock->init();
|
newBlock->init();
|
||||||
newBlock->write(&buf[i.orig],i.len);
|
newBlock->write(&buf[i.orig],i.len);
|
||||||
newBlock->writeC(0xf9); // ret
|
newBlock->writeC(0xf9); // ret
|
||||||
// padding
|
// padding
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
newBlock->writeC(0);
|
newBlock->writeC(0);
|
||||||
subBlocks.push_back(newBlock);
|
subBlocks.push_back(newBlock);
|
||||||
lastOrig=i.orig;
|
lastOrig=i.orig;
|
||||||
|
|
||||||
// insert call on the original block
|
// insert call on the original block
|
||||||
buf[i.orig]=0xf4;
|
buf[i.orig]=0xf4;
|
||||||
buf[i.orig+1]=subBlockID&0xff;
|
buf[i.orig+1]=subBlockID&0xff;
|
||||||
buf[i.orig+2]=(subBlockID>>8)&0xff;
|
buf[i.orig+2]=(subBlockID>>8)&0xff;
|
||||||
buf[i.orig+3]=(subBlockID>>16)&0xff;
|
buf[i.orig+3]=(subBlockID>>16)&0xff;
|
||||||
buf[i.orig+4]=(subBlockID>>24)&0xff;
|
buf[i.orig+4]=(subBlockID>>24)&0xff;
|
||||||
buf[i.orig+5]=0;
|
buf[i.orig+5]=0;
|
||||||
buf[i.orig+6]=0;
|
buf[i.orig+6]=0;
|
||||||
buf[i.orig+7]=0;
|
buf[i.orig+7]=0;
|
||||||
|
|
||||||
// replace the rest with nop
|
|
||||||
for (size_t j=i.orig+8; j<i.orig+i.len; j++) {
|
|
||||||
buf[j]=0xf1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set match to the last sub-block
|
|
||||||
buf[i.block]=0xf4;
|
|
||||||
buf[i.block+1]=subBlockID&0xff;
|
|
||||||
buf[i.block+2]=(subBlockID>>8)&0xff;
|
|
||||||
buf[i.block+3]=(subBlockID>>16)&0xff;
|
|
||||||
buf[i.block+4]=(subBlockID>>24)&0xff;
|
|
||||||
buf[i.block+5]=0;
|
|
||||||
buf[i.block+6]=0;
|
|
||||||
buf[i.block+7]=0;
|
|
||||||
|
|
||||||
// replace the rest with nop
|
// replace the rest with nop
|
||||||
for (size_t j=i.block+8; j<i.block+i.len; j++) {
|
for (size_t j=i.orig+8; j<i.orig+i.len; j++) {
|
||||||
buf[j]=0xf1;
|
buf[j]=0xf1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalidate overlapping work matches
|
|
||||||
for (BlockMatch& j: workMatches) {
|
|
||||||
if (j.orig!=i.orig) {
|
|
||||||
j.done=true;
|
|
||||||
}
|
|
||||||
if (OVERLAPS(i.block,i.block+i.len,j.block,j.block+j.len)) {
|
|
||||||
j.done=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalidate overlapping matches
|
|
||||||
for (BlockMatch& j: matches) {
|
|
||||||
if (OVERLAPS(i.orig,i.orig+i.len,j.orig,j.orig+j.len) ||
|
|
||||||
OVERLAPS(i.orig,i.orig+i.len,j.block,j.block+j.len) ||
|
|
||||||
OVERLAPS(i.block,i.block+i.len,j.orig,j.orig+j.len) ||
|
|
||||||
OVERLAPS(i.block,i.block+i.len,j.block,j.block+j.len)) {
|
|
||||||
j.done=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (matchSize>=MIN_MATCH_SIZE) {
|
// set match to the last sub-block
|
||||||
//logV("trying next size %d",matchSize);
|
buf[i.block]=0xf4;
|
||||||
//}
|
buf[i.block+1]=subBlockID&0xff;
|
||||||
//}
|
buf[i.block+2]=(subBlockID>>8)&0xff;
|
||||||
|
buf[i.block+3]=(subBlockID>>16)&0xff;
|
||||||
|
buf[i.block+4]=(subBlockID>>24)&0xff;
|
||||||
|
buf[i.block+5]=0;
|
||||||
|
buf[i.block+6]=0;
|
||||||
|
buf[i.block+7]=0;
|
||||||
|
|
||||||
|
// replace the rest with nop
|
||||||
|
for (size_t j=i.block+8; j<i.block+i.len; j++) {
|
||||||
|
buf[j]=0xf1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalidate overlapping work matches
|
||||||
|
for (BlockMatch& j: workMatches) {
|
||||||
|
if (j.orig!=i.orig) {
|
||||||
|
j.done=true;
|
||||||
|
}
|
||||||
|
if (OVERLAPS(i.block,i.block+i.len,j.block,j.block+j.len)) {
|
||||||
|
j.done=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalidate overlapping matches
|
||||||
|
for (BlockMatch& j: matches) {
|
||||||
|
if (OVERLAPS(i.orig,i.orig+i.len,j.orig,j.orig+j.len) ||
|
||||||
|
OVERLAPS(i.orig,i.orig+i.len,j.block,j.block+j.len) ||
|
||||||
|
OVERLAPS(i.block,i.block+i.len,j.orig,j.orig+j.len) ||
|
||||||
|
OVERLAPS(i.block,i.block+i.len,j.block,j.block+j.len)) {
|
||||||
|
j.done=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logV("done!");
|
logV("done!");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue