Merge pull request #1809 from wtdcode/perf_improvement

Some performance improvement
This commit is contained in:
Wu ChenXu 2022-01-04 22:27:19 +08:00 committed by GitHub
commit 89bfdaf2ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 8 deletions

View File

@ -17,12 +17,17 @@
void MCInst_Init(MCInst *inst)
{
#if 0
// this loop consumes 2% of the whole disasm work
unsigned int i;
for (i = 0; i < 48; i++) {
inst->Operands[i].Kind = kInvalid;
inst->Operands[i].ImmVal = 0;
}
#endif
// unnecessary to initialize in loop . its expensive and inst->size shuold be honored
inst->Operands[0].Kind = kInvalid;
inst->Operands[0].ImmVal = 0;
inst->Opcode = 0;
inst->OpcodePub = 0;

View File

@ -1147,13 +1147,13 @@ static int getID(struct InternalInstruction *insn)
}
}
if (getIDWithAttrMask(&instructionID, insn, attrMask)) {
return -1;
}
/* The following clauses compensate for limitations of the tables. */
if (insn->mode != MODE_64BIT &&
insn->vectorExtensionType != TYPE_NO_VEX_XOP) {
if (getIDWithAttrMask(&instructionID, insn, attrMask)) {
return -1;
}
/*
* The tables can't distinquish between cases where the W-bit is used to
* select register size and cases where its a required part of the opcode.
@ -1218,6 +1218,9 @@ static int getID(struct InternalInstruction *insn)
return 0;
}
if (getIDWithAttrMask(&instructionID, insn, attrMask)) {
return -1;
}
if ((insn->mode == MODE_16BIT || insn->hasOpSize) &&
!(attrMask & ATTR_OPSIZE)) {
@ -1438,15 +1441,15 @@ static int readModRM(struct InternalInstruction* insn)
if (insn->consumedModRM)
return 0;
insn->modRMOffset = (uint8_t)(insn->readerCursor - insn->startLocation);
insn->modRMOffset = (uint8_t)(insn->readerCursor - insn->startLocation);
if (consumeByte(insn, &insn->modRM))
return -1;
insn->consumedModRM = true;
// save original ModRM for later reference
insn->orgModRM = insn->modRM;
// save original ModRM for later reference
insn->orgModRM = insn->modRM;
// handle MOVcr, MOVdr, MOVrc, MOVrd by pretending they have MRM.mod = 3
if ((insn->firstByte == 0x0f && insn->opcodeType == TWOBYTE) &&

12
cs.c
View File

@ -554,6 +554,15 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI
postprinter((csh)handle, insn, buffer, mci);
#ifndef CAPSTONE_DIET
char *tab = strchr (buffer, '\t');
if (tab) {
*tab = 0;
}
strncpy (insn->mnemonic, buffer, sizeof (insn->mnemonic) - 1);
if (tab) {
strcpy (insn->op_str, tab + 1);
}
#if 0
// fill in mnemonic & operands
// find first space or tab
mnem = insn->mnemonic;
@ -568,6 +577,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI
}
*mnem = '\0';
#endif
// we might have customized mnemonic
if (handle->mnem_list) {
@ -588,6 +598,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI
}
}
#if 0
// copy @op_str
if (*sp) {
// find the next non-space char
@ -598,6 +609,7 @@ static void fill_insn(struct cs_struct *handle, cs_insn *insn, char *buffer, MCI
} else
insn->op_str[0] = '\0';
#endif
#endif
}
// how many bytes will we skip when encountering data (CS_OPT_SKIPDATA)?