2011-03-01 03:06:56 +08:00
|
|
|
//===-- X86ShuffleDecode.cpp - X86 shuffle decode logic -------------------===//
|
2010-09-03 02:40:13 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Define several functions to decode x86 specific shuffle semantics into a
|
|
|
|
// generic vector mask.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-18 03:18:59 +08:00
|
|
|
#include "X86ShuffleDecode.h"
|
2010-09-03 02:40:13 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Vector Mask Decoding
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-18 03:18:59 +08:00
|
|
|
namespace llvm {
|
2010-09-03 02:40:13 +08:00
|
|
|
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask) {
|
2010-09-03 06:43:39 +08:00
|
|
|
// Defaults the copying the dest value.
|
|
|
|
ShuffleMask.push_back(0);
|
|
|
|
ShuffleMask.push_back(1);
|
|
|
|
ShuffleMask.push_back(2);
|
|
|
|
ShuffleMask.push_back(3);
|
|
|
|
|
|
|
|
// Decode the immediate.
|
|
|
|
unsigned ZMask = Imm & 15;
|
|
|
|
unsigned CountD = (Imm >> 4) & 3;
|
|
|
|
unsigned CountS = (Imm >> 6) & 3;
|
|
|
|
|
|
|
|
// CountS selects which input element to use.
|
|
|
|
unsigned InVal = 4+CountS;
|
|
|
|
// CountD specifies which element of destination to update.
|
|
|
|
ShuffleMask[CountD] = InVal;
|
|
|
|
// ZMask zaps values, potentially overriding the CountD elt.
|
|
|
|
if (ZMask & 1) ShuffleMask[0] = SM_SentinelZero;
|
|
|
|
if (ZMask & 2) ShuffleMask[1] = SM_SentinelZero;
|
|
|
|
if (ZMask & 4) ShuffleMask[2] = SM_SentinelZero;
|
|
|
|
if (ZMask & 8) ShuffleMask[3] = SM_SentinelZero;
|
|
|
|
}
|
|
|
|
|
2010-09-03 05:51:11 +08:00
|
|
|
// <3,1> or <6,7,2,3>
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask) {
|
2010-09-03 05:51:11 +08:00
|
|
|
for (unsigned i = NElts/2; i != NElts; ++i)
|
|
|
|
ShuffleMask.push_back(NElts+i);
|
2010-09-03 02:40:13 +08:00
|
|
|
|
2010-09-03 05:51:11 +08:00
|
|
|
for (unsigned i = NElts/2; i != NElts; ++i)
|
|
|
|
ShuffleMask.push_back(i);
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 05:51:11 +08:00
|
|
|
// <0,2> or <0,1,4,5>
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask) {
|
2010-09-03 05:51:11 +08:00
|
|
|
for (unsigned i = 0; i != NElts/2; ++i)
|
|
|
|
ShuffleMask.push_back(i);
|
2010-09-03 02:40:13 +08:00
|
|
|
|
2010-09-03 05:51:11 +08:00
|
|
|
for (unsigned i = 0; i != NElts/2; ++i)
|
|
|
|
ShuffleMask.push_back(NElts+i);
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
|
2012-02-06 15:17:51 +08:00
|
|
|
/// DecodePSHUFMask - This decodes the shuffle masks for pshufd, and vpermilp*.
|
|
|
|
/// VT indicates the type of the vector allowing it to handle different
|
|
|
|
/// datatypes and vector widths.
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodePSHUFMask(EVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask) {
|
2012-02-06 15:17:51 +08:00
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
|
|
|
|
|
|
|
unsigned NumLanes = VT.getSizeInBits() / 128;
|
|
|
|
unsigned NumLaneElts = NumElts / NumLanes;
|
|
|
|
|
2012-05-02 16:03:44 +08:00
|
|
|
unsigned NewImm = Imm;
|
2012-02-06 15:17:51 +08:00
|
|
|
for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
|
|
|
|
for (unsigned i = 0; i != NumLaneElts; ++i) {
|
|
|
|
ShuffleMask.push_back(NewImm % NumLaneElts + l);
|
|
|
|
NewImm /= NumLaneElts;
|
|
|
|
}
|
|
|
|
if (NumLaneElts == 4) NewImm = Imm; // reload imm
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-02 16:03:44 +08:00
|
|
|
void DecodePSHUFHWMask(EVT VT, unsigned Imm,
|
|
|
|
SmallVectorImpl<int> &ShuffleMask) {
|
2012-05-03 15:12:59 +08:00
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
2012-05-02 16:03:44 +08:00
|
|
|
|
|
|
|
for (unsigned l = 0; l != NumElts; l += 8) {
|
|
|
|
unsigned NewImm = Imm;
|
|
|
|
for (unsigned i = 0, e = 4; i != e; ++i) {
|
|
|
|
ShuffleMask.push_back(l + i);
|
|
|
|
}
|
|
|
|
for (unsigned i = 4, e = 8; i != e; ++i) {
|
|
|
|
ShuffleMask.push_back(l + 4 + (NewImm & 3));
|
|
|
|
NewImm >>= 2;
|
|
|
|
}
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-02 16:03:44 +08:00
|
|
|
void DecodePSHUFLWMask(EVT VT, unsigned Imm,
|
|
|
|
SmallVectorImpl<int> &ShuffleMask) {
|
2012-05-03 15:12:59 +08:00
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
2012-05-02 16:03:44 +08:00
|
|
|
|
|
|
|
for (unsigned l = 0; l != NumElts; l += 8) {
|
|
|
|
unsigned NewImm = Imm;
|
|
|
|
for (unsigned i = 0, e = 4; i != e; ++i) {
|
|
|
|
ShuffleMask.push_back(l + (NewImm & 3));
|
|
|
|
NewImm >>= 2;
|
|
|
|
}
|
|
|
|
for (unsigned i = 4, e = 8; i != e; ++i) {
|
|
|
|
ShuffleMask.push_back(l + i);
|
|
|
|
}
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 15:17:51 +08:00
|
|
|
/// DecodeSHUFPMask - This decodes the shuffle masks for shufp*. VT indicates
|
|
|
|
/// the type of the vector allowing it to handle different datatypes and vector
|
|
|
|
/// widths.
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodeSHUFPMask(EVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask) {
|
2011-11-29 15:49:05 +08:00
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
|
|
|
|
|
|
|
unsigned NumLanes = VT.getSizeInBits() / 128;
|
|
|
|
unsigned NumLaneElts = NumElts / NumLanes;
|
|
|
|
|
2012-05-02 16:03:44 +08:00
|
|
|
unsigned NewImm = Imm;
|
2012-02-06 15:17:51 +08:00
|
|
|
for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
|
2011-11-29 15:49:05 +08:00
|
|
|
// Part that reads from dest.
|
|
|
|
for (unsigned i = 0; i != NumLaneElts/2; ++i) {
|
2012-02-06 15:17:51 +08:00
|
|
|
ShuffleMask.push_back(NewImm % NumLaneElts + l);
|
2011-11-29 15:49:05 +08:00
|
|
|
NewImm /= NumLaneElts;
|
|
|
|
}
|
|
|
|
// Part that reads from src.
|
|
|
|
for (unsigned i = 0; i != NumLaneElts/2; ++i) {
|
2012-02-06 15:17:51 +08:00
|
|
|
ShuffleMask.push_back(NewImm % NumLaneElts + NumElts + l);
|
2011-11-29 15:49:05 +08:00
|
|
|
NewImm /= NumLaneElts;
|
|
|
|
}
|
|
|
|
if (NumLaneElts == 4) NewImm = Imm; // reload imm
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 15:17:51 +08:00
|
|
|
/// DecodeUNPCKHMask - This decodes the shuffle masks for unpckhps/unpckhpd
|
|
|
|
/// and punpckh*. VT indicates the type of the vector allowing it to handle
|
|
|
|
/// different datatypes and vector widths.
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodeUNPCKHMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
|
2011-11-22 09:57:35 +08:00
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
|
|
|
|
|
|
|
// Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate
|
|
|
|
// independently on 128-bit lanes.
|
|
|
|
unsigned NumLanes = VT.getSizeInBits() / 128;
|
|
|
|
if (NumLanes == 0 ) NumLanes = 1; // Handle MMX
|
|
|
|
unsigned NumLaneElts = NumElts / NumLanes;
|
|
|
|
|
2012-02-06 15:17:51 +08:00
|
|
|
for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
|
|
|
|
for (unsigned i = l + NumLaneElts/2, e = l + NumLaneElts; i != e; ++i) {
|
2011-11-22 09:57:35 +08:00
|
|
|
ShuffleMask.push_back(i); // Reads from dest/src1
|
|
|
|
ShuffleMask.push_back(i+NumElts); // Reads from src/src2
|
|
|
|
}
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 13:31:16 +08:00
|
|
|
/// DecodeUNPCKLMask - This decodes the shuffle masks for unpcklps/unpcklpd
|
2012-02-06 15:17:51 +08:00
|
|
|
/// and punpckl*. VT indicates the type of the vector allowing it to handle
|
|
|
|
/// different datatypes and vector widths.
|
2012-03-20 14:42:26 +08:00
|
|
|
void DecodeUNPCKLMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
|
2011-03-03 01:23:43 +08:00
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
|
|
|
|
2011-07-27 06:03:40 +08:00
|
|
|
// Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate
|
|
|
|
// independently on 128-bit lanes.
|
|
|
|
unsigned NumLanes = VT.getSizeInBits() / 128;
|
|
|
|
if (NumLanes == 0 ) NumLanes = 1; // Handle MMX
|
|
|
|
unsigned NumLaneElts = NumElts / NumLanes;
|
2011-03-03 01:23:43 +08:00
|
|
|
|
2012-02-06 15:17:51 +08:00
|
|
|
for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
|
|
|
|
for (unsigned i = l, e = l + NumLaneElts/2; i != e; ++i) {
|
2011-11-22 09:57:35 +08:00
|
|
|
ShuffleMask.push_back(i); // Reads from dest/src1
|
|
|
|
ShuffleMask.push_back(i+NumElts); // Reads from src/src2
|
2011-03-03 01:23:43 +08:00
|
|
|
}
|
2010-09-03 02:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 15:17:51 +08:00
|
|
|
void DecodeVPERM2X128Mask(EVT VT, unsigned Imm,
|
2012-03-20 14:42:26 +08:00
|
|
|
SmallVectorImpl<int> &ShuffleMask) {
|
2012-04-17 13:54:54 +08:00
|
|
|
if (Imm & 0x88)
|
|
|
|
return; // Not a shuffle
|
|
|
|
|
2011-08-13 05:48:26 +08:00
|
|
|
unsigned HalfSize = VT.getVectorNumElements()/2;
|
|
|
|
unsigned FstHalfBegin = (Imm & 0x3) * HalfSize;
|
|
|
|
unsigned SndHalfBegin = ((Imm >> 4) & 0x3) * HalfSize;
|
|
|
|
|
2012-05-02 16:03:44 +08:00
|
|
|
for (unsigned i = FstHalfBegin, e = FstHalfBegin+HalfSize; i != e; ++i)
|
2011-08-13 05:48:26 +08:00
|
|
|
ShuffleMask.push_back(i);
|
2012-05-02 16:03:44 +08:00
|
|
|
for (unsigned i = SndHalfBegin, e = SndHalfBegin+HalfSize; i != e; ++i)
|
2011-08-13 05:48:26 +08:00
|
|
|
ShuffleMask.push_back(i);
|
|
|
|
}
|
|
|
|
|
2011-02-18 03:18:59 +08:00
|
|
|
} // llvm namespace
|