block_of_code: Optimize nops

This commit is contained in:
MerryMage 2016-08-26 13:46:19 +01:00
parent 0102951bdd
commit 9901ed0f51
2 changed files with 40 additions and 5 deletions

View file

@ -139,6 +139,45 @@ void BlockOfCode::CallFunction(const void* fn) {
} }
} }
void BlockOfCode::nop(size_t size) {
switch (size) {
case 0:
return;
case 1:
db(0x90);
return;
case 2:
db(0x66); db(0x90);
return;
case 3:
db(0x0f); db(0x1f); db(0x00);
return;
case 4:
db(0x0f); db(0x1f); db(0x40); db(0x00);
return;
case 5:
db(0x0f); db(0x1f); db(0x44); db(0x00); db(0x00);
return;
case 6:
db(0x66); db(0x0f); db(0x1f); db(0x44); db(0x00); db(0x00);
return;
case 7:
db(0x0f); db(0x1f); db(0x80); db(0x00); db(0x00); db(0x00); db(0x00);
return;
case 8:
db(0x0f); db(0x1f); db(0x84); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00);
return;
case 9:
db(0x66); db(0x0f); db(0x1f); db(0x84); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00);
return;
case 10:
default:
db(0x66); db(0x2e); db(0x0f); db(0x1f); db(0x84); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00);
nop(size - 10);
return;
}
}
void BlockOfCode::SetCodePtr(CodePtr ptr) { void BlockOfCode::SetCodePtr(CodePtr ptr) {
// The "size" defines where top_, the insertion point, is. // The "size" defines where top_, the insertion point, is.
size_t required_size = reinterpret_cast<const u8*>(ptr) - getCode(); size_t required_size = reinterpret_cast<const u8*>(ptr) - getCode();

View file

@ -80,11 +80,7 @@ public:
} }
void int3() { db(0xCC); } void int3() { db(0xCC); }
void nop(size_t size = 0) { void nop(size_t size = 0);
for (size_t i = 0; i < size; i++) {
db(0x90);
}
}
void SetCodePtr(CodePtr ptr); void SetCodePtr(CodePtr ptr);
void EnsurePatchLocationSize(CodePtr begin, size_t size); void EnsurePatchLocationSize(CodePtr begin, size_t size);