From 9870547d503aed7b0a1ced036dbc251c55673fd9 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 21 Feb 2020 16:14:36 -0800 Subject: [PATCH] Fixes 32bit element selection for SHUFP --- Source/Interface/Core/OpcodeDispatcher.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/Interface/Core/OpcodeDispatcher.cpp b/Source/Interface/Core/OpcodeDispatcher.cpp index 224d7248b..6b719f809 100644 --- a/Source/Interface/Core/OpcodeDispatcher.cpp +++ b/Source/Interface/Core/OpcodeDispatcher.cpp @@ -2554,11 +2554,19 @@ void OpDispatchBuilder::SHUFOp(OpcodeArgs) { Srcs[i] = Src2; } + // 32bit: + // [31:0] = Src1[Selection] + // [63:32] = Src1[Selection] + // [95:64] = Src2[Selection] + // [127:96] = Src2[Selection] + // 64bit: // [63:0] = Src1[Selection] // [127:64] = Src2[Selection] + uint8_t SelectionMask = NumElements - 1; + uint8_t ShiftAmount = __builtin_popcount(SelectionMask); for (uint8_t Element = 0; Element < NumElements; ++Element) { - Dest = _VInsElement(Size, ElementSize, Element, Shuffle & 0b1, Dest, Srcs[Element]); - Shuffle >>= 1; + Dest = _VInsElement(Size, ElementSize, Element, Shuffle & SelectionMask, Dest, Srcs[Element]); + Shuffle >>= ShiftAmount; } StoreResult(FPRClass, Op, Dest, -1);