Skip to content

Commit

Permalink
[release/9.0] Fix encoding for certain k-mask instructions (#107249)
Browse files Browse the repository at this point in the history
* Fix encoding for certain k-mask instructions

* Update instr.h

* Update Runtime_107146.cs

* Update src/coreclr/jit/emitxarch.cpp

Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>

---------

Co-authored-by: EgorBo <egorbo@gmail.com>
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
Co-authored-by: Jeff Schwartz <jeffschw@microsoft.com>
  • Loading branch information
4 people authored Sep 4, 2024
1 parent 31528d0 commit 48fd63c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 29 deletions.
19 changes: 18 additions & 1 deletion src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ bool emitter::IsKInstruction(instruction ins)
return (flags & KInstruction) != 0;
}

//------------------------------------------------------------------------
// IsKInstructionWithLBit: Does this instruction require K register and
// LBIT_IN_3BYTE_VEX_PREFIX bit.
//
// Arguments:
// ins - The instruction to check.
//
// Returns:
// `true` if this instruction requires K register and
// LBIT_IN_3BYTE_VEX_PREFIX bit.
//
bool emitter::IsKInstructionWithLBit(instruction ins)
{
insFlags flags = CodeGenInterface::instInfo[ins];
return (flags & KInstructionWithLBit) != 0;
}

bool emitter::IsAVXOnlyInstruction(instruction ins)
{
return (ins >= INS_FIRST_AVX_INSTRUCTION) && (ins <= INS_LAST_AVX_INSTRUCTION);
Expand Down Expand Up @@ -1495,7 +1512,7 @@ emitter::code_t emitter::AddVexPrefix(instruction ins, code_t code, emitAttr att

code |= DEFAULT_3BYTE_VEX_PREFIX;

if (attr == EA_32BYTE)
if ((attr == EA_32BYTE) || IsKInstructionWithLBit(ins))
{
// Set L bit to 1 in case of instructions that operate on 256-bits.
code |= LBIT_IN_3BYTE_VEX_PREFIX;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/emitxarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static bool IsPermuteVar2xInstruction(instruction ins);
static bool IsAVXVNNIInstruction(instruction ins);
static bool IsBMIInstruction(instruction ins);
static bool IsKInstruction(instruction ins);
static bool IsKInstructionWithLBit(instruction ins);

static regNumber getBmiRegNumber(instruction ins);
static regNumber getSseShiftRegNumber(instruction ins);
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ enum insFlags : uint64_t
Encoding_EVEX = 1ULL << 40,

KInstruction = 1ULL << 41,
KInstructionWithLBit = 1ULL << 42,

// EVEX feature: embedded broadcast
INS_Flags_EmbeddedBroadcastSupported = 1ULL << 42,
INS_Flags_EmbeddedBroadcastSupported = 1ULL << 43,

// TODO-Cleanup: Remove this flag and its usage from TARGET_XARCH
INS_FLAGS_DONT_CARE = 0x00ULL,
Expand Down
Loading

0 comments on commit 48fd63c

Please sign in to comment.