Bug 1025475: SIMD: Fold SIMD created values into SimdConstants; r=sunfish

This commit is contained in:
Benjamin Bouvier 2014-08-13 15:08:25 +02:00
parent 62d25f8b05
commit 48ef37ca1b
2 changed files with 35 additions and 0 deletions

View File

@ -588,6 +588,39 @@ MConstant::canProduceFloat32() const
return true;
}
MDefinition*
MSimdValueX4::foldsTo(TempAllocator &alloc)
{
DebugOnly<MIRType> scalarType = SimdTypeToScalarType(type());
for (size_t i = 0; i < 4; ++i) {
MDefinition *op = getOperand(i);
if (!op->isConstant())
return this;
JS_ASSERT(op->type() == scalarType);
}
SimdConstant cst;
switch (type()) {
case MIRType_Int32x4: {
int32_t a[4];
for (size_t i = 0; i < 4; ++i)
a[i] = getOperand(i)->toConstant()->value().toInt32();
cst = SimdConstant::CreateX4(a);
break;
}
case MIRType_Float32x4: {
float a[4];
for (size_t i = 0; i < 4; ++i)
a[i] = getOperand(i)->toConstant()->value().toNumber();
cst = SimdConstant::CreateX4(a);
break;
}
default: MOZ_ASSUME_UNREACHABLE("unexpected type in MSimdValueX4::foldsTo");
}
return MSimdConstant::New(alloc, cst, type());
}
MCloneLiteral *
MCloneLiteral::New(TempAllocator &alloc, MDefinition *obj)
{

View File

@ -1268,6 +1268,8 @@ class MSimdValueX4 : public MQuaternaryInstruction
bool congruentTo(const MDefinition *ins) const {
return congruentIfOperandsEqual(ins);
}
MDefinition *foldsTo(TempAllocator &alloc);
};
// A constant SIMD value.