From 584305f1fa252deb28846469b7565a678bc7ba4e Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 7 Apr 2025 20:44:25 -0500 Subject: [PATCH] fix build failure --- src/engine/cmdStreamOps.cpp | 242 +++++++++++++++++------------------- 1 file changed, 116 insertions(+), 126 deletions(-) diff --git a/src/engine/cmdStreamOps.cpp b/src/engine/cmdStreamOps.cpp index da400ac52..bd538d935 100644 --- a/src/engine/cmdStreamOps.cpp +++ b/src/engine/cmdStreamOps.cpp @@ -678,8 +678,7 @@ struct BlockMatch { #define MIN_MATCH_SIZE 16 // TODO: -// - check whether a block consists only of calls -// - see if we can optimize better +// - see if we can optimize even more SafeWriter* findSubBlocks(SafeWriter* stream, std::vector& subBlocks, unsigned char* speedDial) { unsigned char* buf=stream->getFinalBuf(); size_t matchSize=MIN_MATCH_SIZE; @@ -709,7 +708,6 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector& subBlock // search for bigger matches bool wantMore=true; do { - size_t matchCount=0; wantMore=false; matchSize+=8; for (size_t i=0; i& subBlock // this match may be bigger b.len=matchSize; wantMore=true; - matchCount++; } else { // this is the max size b.done=true; } } - //logV("size %d: %d matches",(int)matchSize,(int)matchCount); } while (wantMore); // first stage done @@ -776,144 +772,138 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector& subBlock std::vector workMatches; bool newBlocks=false; - // try with a smaller size - matchSize=0; - for (BlockMatch& i: matches) { - if (i.done) continue; - if (i.len>matchSize) matchSize=i.len; + // try with a smaller size + matchSize=0; + for (BlockMatch& i: matches) { + if (i.done) continue; + 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) { - 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; - } - } + // check which sub-blocks are viable to make + size_t lastOrig=SIZE_MAX; + size_t lastOrigOff=0; + int gains=0; + int blockSize=0; + for (size_t i=0; i<=workMatches.size(); i++) { + BlockMatch b(SIZE_MAX,SIZE_MAX,0); + if (iinit(); - newBlock->write(&buf[i.orig],i.len); - newBlock->writeC(0xf9); // ret - // padding - 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); - lastOrig=i.orig; + // isolate this sub-block + SafeWriter* newBlock=new SafeWriter; + newBlock->init(); + newBlock->write(&buf[i.orig],i.len); + newBlock->writeC(0xf9); // ret + // padding + 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); + lastOrig=i.orig; - // insert call on the original block - buf[i.orig]=0xf4; - buf[i.orig+1]=subBlockID&0xff; - buf[i.orig+2]=(subBlockID>>8)&0xff; - buf[i.orig+3]=(subBlockID>>16)&0xff; - buf[i.orig+4]=(subBlockID>>24)&0xff; - buf[i.orig+5]=0; - buf[i.orig+6]=0; - buf[i.orig+7]=0; - - // replace the rest with nop - for (size_t j=i.orig+8; j>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; + // insert call on the original block + buf[i.orig]=0xf4; + buf[i.orig+1]=subBlockID&0xff; + buf[i.orig+2]=(subBlockID>>8)&0xff; + buf[i.orig+3]=(subBlockID>>16)&0xff; + buf[i.orig+4]=(subBlockID>>24)&0xff; + buf[i.orig+5]=0; + buf[i.orig+6]=0; + buf[i.orig+7]=0; // replace the rest with nop - for (size_t j=i.block+8; j=MIN_MATCH_SIZE) { - //logV("trying next size %d",matchSize); - //} - //} + // 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 + for (size_t j=i.block+8; j