Format code

This commit is contained in:
offtkp 2024-08-28 23:08:42 +03:00
parent 8e19ccd507
commit 96afa3d8ee
1 changed files with 15 additions and 11 deletions

View File

@ -333,8 +333,9 @@ static void GenerateTcbAccess(const ZydisDecodedOperand* operands, Xbyak::CodeGe
static void GenerateINSERTQ(const ZydisDecodedOperand* operands, Xbyak::CodeGenerator& c) {
// INSERTQ Instruction Reference
// Inserts bits from the lower 64 bits of the source operand into the lower 64 bits of the destination operand
// No other bits in the lower 64 bits of the destination are modified. The upper 64 bits of the destination are undefined.
// Inserts bits from the lower 64 bits of the source operand into the lower 64 bits of the
// destination operand No other bits in the lower 64 bits of the destination are modified. The
// upper 64 bits of the destination are undefined.
// There's two forms of the instruction:
// INSERTQ xmm1, xmm2, imm8, imm8
@ -352,14 +353,15 @@ static void GenerateINSERTQ(const ZydisDecodedOperand* operands, Xbyak::CodeGene
// xmm1 starting at the bit position specified by
// xmm2[77:72].
// A value of zero in the field length is defined as a length of 64. If the length field is 0 and the bit index
// is 0, bits 63:0 of the source operand are inserted. For any other value of the bit index, the results are
// undefined.
// A value of zero in the field length is defined as a length of 64. If the length field is 0
// and the bit index is 0, bits 63:0 of the source operand are inserted. For any other value of
// the bit index, the results are undefined.
bool immediateForm = operands[2].type == ZYDIS_OPERAND_TYPE_IMMEDIATE &&
operands[3].type == ZYDIS_OPERAND_TYPE_IMMEDIATE;
if (operands[0].type != ZYDIS_OPERAND_TYPE_REGISTER || operands[1].type != ZYDIS_OPERAND_TYPE_REGISTER) {
if (operands[0].type != ZYDIS_OPERAND_TYPE_REGISTER ||
operands[1].type != ZYDIS_OPERAND_TYPE_REGISTER) {
ASSERT_MSG("operands 0 and 1 must be registers.");
}
@ -408,14 +410,16 @@ static void GenerateINSERTQ(const ZydisDecodedOperand* operands, Xbyak::CodeGene
RestoreRegisters(c, {scratch1, scratch2, mask});
} else {
if (operands[2].type != ZYDIS_OPERAND_TYPE_UNUSED || operands[3].type != ZYDIS_OPERAND_TYPE_UNUSED) {
if (operands[2].type != ZYDIS_OPERAND_TYPE_UNUSED ||
operands[3].type != ZYDIS_OPERAND_TYPE_UNUSED) {
ASSERT_MSG("operands 2 and 3 must be unused for register form.");
}
const Xbyak::Reg64 scratch1 = AllocateScratchRegister({}, 64).cvt64();
const Xbyak::Reg64 scratch2 = AllocateScratchRegister({&scratch1}, 64).cvt64();
const Xbyak::Reg64 index = AllocateScratchRegister({&scratch1, &scratch2}, 64).cvt64();
const Xbyak::Reg64 mask = AllocateScratchRegister({&scratch1, &scratch2, &index}, 64).cvt64();
const Xbyak::Reg64 mask =
AllocateScratchRegister({&scratch1, &scratch2, &index}, 64).cvt64();
SaveRegisters(c, {scratch1, scratch2, index, mask});
@ -423,8 +427,8 @@ static void GenerateINSERTQ(const ZydisDecodedOperand* operands, Xbyak::CodeGene
c.pextrq(index, src, 1);
c.mov(mask, index);
c.mov(scratch1, 64); // for the cmovz below
c.and_(mask, 0x3F); // mask now holds the length
c.mov(scratch1, 64); // for the cmovz below
c.and_(mask, 0x3F); // mask now holds the length
c.cmovz(mask, scratch1); // Check if length is 0, if so, set to 64
// Get index to insert at