Vector: Refactor PSHUFBOpImpl. This will be reused for AVX128

This commit is contained in:
Ryan Houdek 2024-06-19 06:25:15 -07:00
parent 3919ec9692
commit 4eebca93e3
No known key found for this signature in database
2 changed files with 15 additions and 11 deletions

View File

@ -1144,7 +1144,7 @@ private:
Ref PSADBWOpImpl(OpcodeArgs, const X86Tables::DecodedOperand& Src1Op, const X86Tables::DecodedOperand& Src2Op);
Ref PSHUFBOpImpl(OpcodeArgs, const X86Tables::DecodedOperand& Src1, const X86Tables::DecodedOperand& Src2);
Ref PSHUFBOpImpl(uint8_t SrcSize, Ref Src1, Ref Src2);
Ref PSIGNImpl(OpcodeArgs, size_t ElementSize, Ref Src1, Ref Src2);

View File

@ -1004,11 +1004,7 @@ template void OpDispatchBuilder::VPUNPCKHOp<2>(OpcodeArgs);
template void OpDispatchBuilder::VPUNPCKHOp<4>(OpcodeArgs);
template void OpDispatchBuilder::VPUNPCKHOp<8>(OpcodeArgs);
Ref OpDispatchBuilder::PSHUFBOpImpl(OpcodeArgs, const X86Tables::DecodedOperand& Src1, const X86Tables::DecodedOperand& Src2) {
Ref Src1Node = LoadSource(FPRClass, Op, Src1, Op->Flags);
Ref Src2Node = LoadSource(FPRClass, Op, Src2, Op->Flags);
const auto SrcSize = GetSrcSize(Op);
Ref OpDispatchBuilder::PSHUFBOpImpl(uint8_t SrcSize, Ref Src1, Ref Src2) {
const auto Is256Bit = SrcSize == Core::CPUState::XMM_AVX_REG_SIZE;
// We perform the 256-bit version as two 128-bit operations due to
@ -1026,25 +1022,33 @@ Ref OpDispatchBuilder::PSHUFBOpImpl(OpcodeArgs, const X86Tables::DecodedOperand&
const uint8_t MaskImm = SrcSize == 8 ? 0b1000'0111 : 0b1000'1111;
Ref MaskVector = _VectorImm(SrcSize, 1, MaskImm);
Ref MaskedIndices = _VAnd(SrcSize, SrcSize, Src2Node, MaskVector);
Ref MaskedIndices = _VAnd(SrcSize, SrcSize, Src2, MaskVector);
Ref Low = _VTBL1(SanitizedSrcSize, Src1Node, MaskedIndices);
Ref Low = _VTBL1(SanitizedSrcSize, Src1, MaskedIndices);
if (!Is256Bit) {
return Low;
}
Ref HighSrc1 = _VInsElement(SrcSize, 16, 0, 1, Src1Node, Src1Node);
Ref HighSrc1 = _VInsElement(SrcSize, 16, 0, 1, Src1, Src1);
Ref High = _VTBL1(SanitizedSrcSize, HighSrc1, MaskedIndices);
return _VInsElement(SrcSize, 16, 1, 0, Low, High);
}
void OpDispatchBuilder::PSHUFBOp(OpcodeArgs) {
Ref Result = PSHUFBOpImpl(Op, Op->Dest, Op->Src[0]);
const auto SrcSize = GetSrcSize(Op);
Ref Src1 = LoadSource(FPRClass, Op, Op->Dest, Op->Flags);
Ref Src2 = LoadSource(FPRClass, Op, Op->Src[0], Op->Flags);
Ref Result = PSHUFBOpImpl(SrcSize, Src1, Src2);
StoreResult(FPRClass, Op, Result, -1);
}
void OpDispatchBuilder::VPSHUFBOp(OpcodeArgs) {
Ref Result = PSHUFBOpImpl(Op, Op->Src[0], Op->Src[1]);
const auto SrcSize = GetSrcSize(Op);
Ref Src1 = LoadSource(FPRClass, Op, Op->Src[0], Op->Flags);
Ref Src2 = LoadSource(FPRClass, Op, Op->Src[1], Op->Flags);
Ref Result = PSHUFBOpImpl(SrcSize, Src1, Src2);
StoreResult(FPRClass, Op, Result, -1);
}