Commit ef8210d9 by Nicolas Capens

Implement vector packing intrinsics.

BUG=swiftshader:15 Change-Id: Id95a08f82c47ec20bb958358c01f389b6fb5565b
parent 32f9ccef
......@@ -1667,15 +1667,15 @@ void AssemblerX86Base<TraitsType>::punpckh(Type Ty, XmmRegister Dst,
}
template <typename TraitsType>
void AssemblerX86Base<TraitsType>::packss(Type Ty, XmmRegister Dst,
void AssemblerX86Base<TraitsType>::packss(Type DestTy, XmmRegister Dst,
XmmRegister Src) {
AssemblerBuffer::EnsureCapacity ensured(&Buffer);
emitUint8(0x66);
emitRexRB(RexTypeIrrelevant, Dst, Src);
emitUint8(0x0F);
if (Ty == IceType_v4i32 || Ty == IceType_v4f32) {
if (DestTy == IceType_v8i16) {
emitUint8(0x6B);
} else if (Ty == IceType_v8i16) {
} else if (DestTy == IceType_v16i8) {
emitUint8(0x63);
} else {
assert(false && "Unexpected vector pack operand type");
......@@ -1684,16 +1684,16 @@ void AssemblerX86Base<TraitsType>::packss(Type Ty, XmmRegister Dst,
}
template <typename TraitsType>
void AssemblerX86Base<TraitsType>::packss(Type Ty, XmmRegister Dst,
void AssemblerX86Base<TraitsType>::packss(Type DestTy, XmmRegister Dst,
const Address &Src) {
AssemblerBuffer::EnsureCapacity ensured(&Buffer);
emitUint8(0x66);
emitAddrSizeOverridePrefix();
emitRex(RexTypeIrrelevant, Src, Dst);
emitUint8(0x0F);
if (Ty == IceType_v4i32 || Ty == IceType_v4f32) {
if (DestTy == IceType_v8i16) {
emitUint8(0x6B);
} else if (Ty == IceType_v8i16) {
} else if (DestTy == IceType_v16i8) {
emitUint8(0x63);
} else {
assert(false && "Unexpected vector pack operand type");
......@@ -1702,16 +1702,16 @@ void AssemblerX86Base<TraitsType>::packss(Type Ty, XmmRegister Dst,
}
template <typename TraitsType>
void AssemblerX86Base<TraitsType>::packus(Type Ty, XmmRegister Dst,
void AssemblerX86Base<TraitsType>::packus(Type DestTy, XmmRegister Dst,
XmmRegister Src) {
AssemblerBuffer::EnsureCapacity ensured(&Buffer);
emitUint8(0x66);
emitRexRB(RexTypeIrrelevant, Dst, Src);
emitUint8(0x0F);
if (Ty == IceType_v4i32 || Ty == IceType_v4f32) {
if (DestTy == IceType_v8i16) {
emitUint8(0x38);
emitUint8(0x2B);
} else if (Ty == IceType_v8i16) {
} else if (DestTy == IceType_v16i8) {
emitUint8(0x67);
} else {
assert(false && "Unexpected vector pack operand type");
......@@ -1720,17 +1720,17 @@ void AssemblerX86Base<TraitsType>::packus(Type Ty, XmmRegister Dst,
}
template <typename TraitsType>
void AssemblerX86Base<TraitsType>::packus(Type Ty, XmmRegister Dst,
void AssemblerX86Base<TraitsType>::packus(Type DestTy, XmmRegister Dst,
const Address &Src) {
AssemblerBuffer::EnsureCapacity ensured(&Buffer);
emitUint8(0x66);
emitAddrSizeOverridePrefix();
emitRex(RexTypeIrrelevant, Src, Dst);
emitUint8(0x0F);
if (Ty == IceType_v4i32 || Ty == IceType_v4f32) {
if (DestTy == IceType_v8i16) {
emitUint8(0x38);
emitUint8(0x2B);
} else if (Ty == IceType_v8i16) {
} else if (DestTy == IceType_v16i8) {
emitUint8(0x67);
} else {
assert(false && "Unexpected vector pack operand type");
......
......@@ -63,7 +63,9 @@ public:
Trap,
// The intrinsics below are not part of the PNaCl specification.
LoadSubVector,
StoreSubVector
StoreSubVector,
VectorPackSigned,
VectorPackUnsigned
};
/// Operations that can be represented by the AtomicRMW intrinsic.
......
......@@ -4424,6 +4424,30 @@ void TargetX86Base<TraitsType>::lowerIntrinsicCall(
}
return;
}
case Intrinsics::VectorPackSigned: {
Operand *Src0 = Instr->getArg(0);
Operand *Src1 = Instr->getArg(1);
Variable *Dest = Instr->getDest();
auto *T = makeReg(Dest->getType());
auto *Src0RM = legalize(Src0, Legal_Reg | Legal_Mem);
auto *Src1RM = legalize(Src1, Legal_Reg | Legal_Mem);
_movp(T, Src0RM);
_packss(T, Src1RM);
_movp(Dest, T);
return;
}
case Intrinsics::VectorPackUnsigned: {
Operand *Src0 = Instr->getArg(0);
Operand *Src1 = Instr->getArg(1);
Variable *Dest = Instr->getDest();
auto *T = makeReg(Dest->getType());
auto *Src0RM = legalize(Src0, Legal_Reg | Legal_Mem);
auto *Src1RM = legalize(Src1, Legal_Reg | Legal_Mem);
_movp(T, Src0RM);
_packus(T, Src1RM);
_movp(Dest, T);
return;
}
default: // UnknownIntrinsic
Func->setError("Unexpected intrinsic");
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment