Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for multibyte nop sequences #54

Merged
merged 1 commit into from Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions xbyak/xbyak.h
Expand Up @@ -2390,6 +2390,36 @@ class CodeGenerator : public CodeArray {
#ifdef XBYAK_UNDEF_JNL
#undef jnl
#endif

void nop(int size = 1)
{
/*
AMD and Intel seem to agree on the same sequences for up to 9 bytes:
https://support.amd.com/TechDocs/55723_SOG_Fam_17h_Processors_3.00.pdf
https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf
*/
static const uint8_t nopSeq[9][9] = {
{0x90},
{0x66, 0x90},
{0x0F, 0x1F, 0x00},
{0x0F, 0x1F, 0x40, 0x00},
{0x0F, 0x1F, 0x44, 0x00, 0x00},
{0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00},
{0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00},
{0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x66, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
};
static const int numSeq = sizeof(nopSeq) / sizeof(nopSeq[0]);
while (size) {
int len = size > numSeq ? numSeq : size;
const uint8_t *seq = nopSeq[len - 1];
for (int i = 0; i < len; i++) {
db(seq[i]);
}
size -= len;
}
}

#ifndef XBYAK_DONT_READ_LIST
#include "xbyak_mnemonic.h"
void align(int x = 16)
Expand Down
1 change: 0 additions & 1 deletion xbyak/xbyak_mnemonic.h
Expand Up @@ -497,7 +497,6 @@ void mulss(const Xmm& xmm, const Operand& op) { opGen(xmm, op, 0x59, 0xF3, isXMM
void mulx(const Reg32e& r1, const Reg32e& r2, const Operand& op) { opGpr(r1, r2, op, T_F2 | T_0F38, 0xf6, true); }
void mwait() { db(0x0F); db(0x01); db(0xC9); }
void neg(const Operand& op) { opR_ModM(op, 0, 3, 0xF6); }
void nop() { db(0x90); }
void not_(const Operand& op) { opR_ModM(op, 0, 2, 0xF6); }
void or_(const Operand& op, uint32 imm) { opRM_I(op, imm, 0x08, 1); }
void or_(const Operand& op1, const Operand& op2) { opRM_RM(op1, op2, 0x08); }
Expand Down