Bug 898347 - Make typed array use type repr constants (Part 2/6) r=sfink

This commit is contained in:
Nicholas D. Matsakis 2013-08-12 22:00:50 -04:00
parent c221aaeb9c
commit 97bcf2ebda
20 changed files with 262 additions and 265 deletions

View File

@ -35,6 +35,7 @@
#include "jsnum.h"
#include "jsprf.h"
#include "builtin/TypeRepresentation.h"
#include "ctypes/Library.h"
#include "vm/TypedArrayObject.h"
@ -2145,29 +2146,29 @@ bool CanConvertTypedArrayItemTo(JSObject *baseType, JSObject *valObj, JSContext
}
TypeCode elementTypeCode;
switch (JS_GetArrayBufferViewType(valObj)) {
case TypedArrayObject::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_INT8:
elementTypeCode = TYPE_int8_t;
break;
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
elementTypeCode = TYPE_uint8_t;
break;
case TypedArrayObject::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_INT16:
elementTypeCode = TYPE_int16_t;
break;
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_UINT16:
elementTypeCode = TYPE_uint16_t;
break;
case TypedArrayObject::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT32:
elementTypeCode = TYPE_int32_t;
break;
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
elementTypeCode = TYPE_uint32_t;
break;
case TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
elementTypeCode = TYPE_float32_t;
break;
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
elementTypeCode = TYPE_float64_t;
break;
default:

View File

@ -3486,9 +3486,9 @@ static bool
TypedArrayRequiresFloatingPoint(TypedArrayObject *tarr)
{
uint32_t type = tarr->type();
return (type == TypedArrayObject::TYPE_UINT32 ||
type == TypedArrayObject::TYPE_FLOAT32 ||
type == TypedArrayObject::TYPE_FLOAT64);
return (type == ScalarTypeRepresentation::TYPE_UINT32 ||
type == ScalarTypeRepresentation::TYPE_FLOAT32 ||
type == ScalarTypeRepresentation::TYPE_FLOAT64);
}
static bool
@ -4664,11 +4664,11 @@ ICSetElem_TypedArray::Compiler::generateStubCode(MacroAssembler &masm)
regs.take(scratchReg);
Register secondScratch = regs.takeAny();
if (type_ == TypedArrayObject::TYPE_FLOAT32 || type_ == TypedArrayObject::TYPE_FLOAT64) {
if (type_ == ScalarTypeRepresentation::TYPE_FLOAT32 || type_ == ScalarTypeRepresentation::TYPE_FLOAT64) {
masm.ensureDouble(value, FloatReg0, &failure);
masm.storeToTypedFloatArray(type_, FloatReg0, dest);
EmitReturnFromIC(masm);
} else if (type_ == TypedArrayObject::TYPE_UINT8_CLAMPED) {
} else if (type_ == ScalarTypeRepresentation::TYPE_UINT8_CLAMPED) {
Label notInt32;
masm.branchTestInt32(Assembler::NotEqual, value, &notInt32);
masm.unboxInt32(value, secondScratch);
@ -5589,7 +5589,7 @@ ICGetProp_TypedArrayLength::Compiler::generateStubCode(MacroAssembler &masm)
masm.loadObjClass(obj, scratch);
masm.branchPtr(Assembler::Below, scratch, ImmWord(&TypedArrayObject::classes[0]), &failure);
masm.branchPtr(Assembler::AboveOrEqual, scratch,
ImmWord(&TypedArrayObject::classes[TypedArrayObject::TYPE_MAX]), &failure);
ImmWord(&TypedArrayObject::classes[ScalarTypeRepresentation::TYPE_MAX]), &failure);
// Load length from fixed slot.
masm.loadValue(Address(obj, TypedArrayObject::lengthOffset()), R0);

View File

@ -6547,7 +6547,7 @@ template <typename T>
static inline void
StoreToTypedArray(MacroAssembler &masm, int arrayType, const LAllocation *value, const T &dest)
{
if (arrayType == TypedArrayObject::TYPE_FLOAT32 || arrayType == TypedArrayObject::TYPE_FLOAT64) {
if (arrayType == ScalarTypeRepresentation::TYPE_FLOAT32 || arrayType == ScalarTypeRepresentation::TYPE_FLOAT64) {
masm.storeToTypedFloatArray(arrayType, ToFloatRegister(value), dest);
} else {
if (value->isConstant())

View File

@ -11,6 +11,7 @@
#include "jsautooplen.h"
#include "builtin/Eval.h"
#include "builtin/TypeRepresentation.h"
#include "frontend/SourceNotes.h"
#include "jit/BaselineFrame.h"
#include "jit/BaselineInspector.h"
@ -6502,7 +6503,7 @@ IonBuilder::getElemTryTypedStatic(bool *emitted, MDefinition *obj, MDefinition *
{
JS_ASSERT(*emitted == false);
int arrayType = TypedArrayObject::TYPE_MAX;
ScalarTypeRepresentation::Type arrayType;
if (!ElementAccessIsTypedArray(obj, index, &arrayType))
return true;
@ -6562,7 +6563,7 @@ IonBuilder::getElemTryTyped(bool *emitted, MDefinition *obj, MDefinition *index)
{
JS_ASSERT(*emitted == false);
int arrayType = TypedArrayObject::TYPE_MAX;
ScalarTypeRepresentation::Type arrayType;
if (!ElementAccessIsTypedArray(obj, index, &arrayType))
return true;
@ -6903,7 +6904,8 @@ IonBuilder::convertShiftToMaskForStaticTypedArray(MDefinition *id,
}
bool
IonBuilder::jsop_getelem_typed(MDefinition *obj, MDefinition *index, int arrayType)
IonBuilder::jsop_getelem_typed(MDefinition *obj, MDefinition *index,
ScalarTypeRepresentation::Type arrayType)
{
types::StackTypeSet *types = types::TypeScript::BytecodeTypes(script(), pc);
@ -6929,19 +6931,19 @@ IonBuilder::jsop_getelem_typed(MDefinition *obj, MDefinition *index, int arrayTy
// uint32 reads that may produce either doubles or integers.
MIRType knownType;
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case TypedArrayObject::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT32:
knownType = MIRType_Int32;
break;
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
knownType = allowDouble ? MIRType_Double : MIRType_Int32;
break;
case TypedArrayObject::TYPE_FLOAT32:
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT64:
knownType = MIRType_Double;
break;
default:
@ -6975,18 +6977,18 @@ IonBuilder::jsop_getelem_typed(MDefinition *obj, MDefinition *index, int arrayTy
// will bailout when we read a double.
bool needsBarrier = true;
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case TypedArrayObject::TYPE_INT32:
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_UINT32:
if (types->hasType(types::Type::Int32Type()))
needsBarrier = false;
break;
case TypedArrayObject::TYPE_FLOAT32:
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT64:
if (allowDouble)
needsBarrier = false;
break;
@ -7047,7 +7049,7 @@ IonBuilder::setElemTryTypedStatic(bool *emitted, MDefinition *object,
{
JS_ASSERT(*emitted == false);
int arrayType = TypedArrayObject::TYPE_MAX;
ScalarTypeRepresentation::Type arrayType;
if (!ElementAccessIsTypedArray(object, index, &arrayType))
return true;
@ -7097,7 +7099,7 @@ IonBuilder::setElemTryTyped(bool *emitted, MDefinition *object,
{
JS_ASSERT(*emitted == false);
int arrayType = TypedArrayObject::TYPE_MAX;
ScalarTypeRepresentation::Type arrayType;
if (!ElementAccessIsTypedArray(object, index, &arrayType))
return true;
@ -7305,7 +7307,7 @@ IonBuilder::jsop_setelem_dense(types::StackTypeSet::DoubleConversion conversion,
bool
IonBuilder::jsop_setelem_typed(int arrayType,
IonBuilder::jsop_setelem_typed(ScalarTypeRepresentation::Type arrayType,
SetElemSafety safety,
MDefinition *obj, MDefinition *id, MDefinition *value)
{
@ -7340,7 +7342,7 @@ IonBuilder::jsop_setelem_typed(int arrayType,
// Clamp value to [0, 255] for Uint8ClampedArray.
MDefinition *toWrite = value;
if (arrayType == TypedArrayObject::TYPE_UINT8_CLAMPED) {
if (arrayType == ScalarTypeRepresentation::TYPE_UINT8_CLAMPED) {
toWrite = MClampToUint8::New(value);
current->add(toWrite->toInstruction());
}
@ -7413,7 +7415,7 @@ IonBuilder::jsop_length_fastPath()
return true;
}
if (objTypes && objTypes->getTypedArrayType() != TypedArrayObject::TYPE_MAX) {
if (objTypes && objTypes->getTypedArrayType() != ScalarTypeRepresentation::TYPE_MAX) {
current->pop();
MInstruction *length = getTypedArrayLength(obj);
current->add(length);

View File

@ -439,12 +439,12 @@ class IonBuilder : public MIRGenerator
bool jsop_bindname(PropertyName *name);
bool jsop_getelem();
bool jsop_getelem_dense(MDefinition *obj, MDefinition *index);
bool jsop_getelem_typed(MDefinition *obj, MDefinition *index, int arrayType);
bool jsop_getelem_typed(MDefinition *obj, MDefinition *index, ScalarTypeRepresentation::Type arrayType);
bool jsop_setelem();
bool jsop_setelem_dense(types::StackTypeSet::DoubleConversion conversion,
SetElemSafety safety,
MDefinition *object, MDefinition *index, MDefinition *value);
bool jsop_setelem_typed(int arrayType,
bool jsop_setelem_typed(ScalarTypeRepresentation::Type arrayType,
SetElemSafety safety,
MDefinition *object, MDefinition *index, MDefinition *value);
bool jsop_length();
@ -529,7 +529,8 @@ class IonBuilder : public MIRGenerator
// Array intrinsics.
InliningStatus inlineUnsafePutElements(CallInfo &callInfo);
bool inlineUnsafeSetDenseArrayElement(CallInfo &callInfo, uint32_t base);
bool inlineUnsafeSetTypedArrayElement(CallInfo &callInfo, uint32_t base, int arrayType);
bool inlineUnsafeSetTypedArrayElement(CallInfo &callInfo, uint32_t base,
ScalarTypeRepresentation::Type arrayType);
InliningStatus inlineNewDenseArray(CallInfo &callInfo);
InliningStatus inlineNewDenseArrayForSequentialExecution(CallInfo &callInfo);
InliningStatus inlineNewDenseArrayForParallelExecution(CallInfo &callInfo);

View File

@ -10,6 +10,7 @@
#include "jsproxy.h"
#include "builtin/TypeRepresentation.h"
#include "jit/CodeGenerator.h"
#include "jit/Ion.h"
#include "jit/IonLinker.h"
@ -1067,7 +1068,7 @@ GenerateTypedArrayLength(JSContext *cx, MacroAssembler &masm, IonCache::StubAtta
// Implement the negated version of JSObject::isTypedArray predicate.
masm.loadObjClass(object, tmpReg);
masm.branchPtr(Assembler::Below, tmpReg, ImmWord(&TypedArrayObject::classes[0]), &failures);
masm.branchPtr(Assembler::AboveOrEqual, tmpReg, ImmWord(&TypedArrayObject::classes[TypedArrayObject::TYPE_MAX]), &failures);
masm.branchPtr(Assembler::AboveOrEqual, tmpReg, ImmWord(&TypedArrayObject::classes[ScalarTypeRepresentation::TYPE_MAX]), &failures);
// Load length.
masm.loadTypedOrValue(Address(object, TypedArrayObject::lengthOffset()), output);
@ -2461,8 +2462,8 @@ GetElementIC::canAttachTypedArrayElement(JSObject *obj, const Value &idval,
// The output register is not yet specialized as a float register, the only
// way to accept float typed arrays for now is to return a Value type.
int arrayType = obj->as<TypedArrayObject>().type();
bool floatOutput = arrayType == TypedArrayObject::TYPE_FLOAT32 ||
arrayType == TypedArrayObject::TYPE_FLOAT64;
bool floatOutput = arrayType == ScalarTypeRepresentation::TYPE_FLOAT32 ||
arrayType == ScalarTypeRepresentation::TYPE_FLOAT64;
return !floatOutput || output.hasValue();
}

View File

@ -9,6 +9,7 @@
#include "jsinfer.h"
#include "jsprf.h"
#include "builtin/TypeRepresentation.h"
#include "jit/Bailouts.h"
#include "jit/BaselineFrame.h"
#include "jit/BaselineIC.h"
@ -276,23 +277,23 @@ MacroAssembler::loadFromTypedArray(int arrayType, const T &src, AnyRegister dest
Label *fail)
{
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_INT8:
load8SignExtend(src, dest.gpr());
break;
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
load8ZeroExtend(src, dest.gpr());
break;
case TypedArrayObject::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_INT16:
load16SignExtend(src, dest.gpr());
break;
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_UINT16:
load16ZeroExtend(src, dest.gpr());
break;
case TypedArrayObject::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT32:
load32(src, dest.gpr());
break;
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
if (dest.isFloat()) {
load32(src, temp);
convertUInt32ToDouble(temp, dest.fpu());
@ -302,9 +303,9 @@ MacroAssembler::loadFromTypedArray(int arrayType, const T &src, AnyRegister dest
j(Assembler::Signed, fail);
}
break;
case TypedArrayObject::TYPE_FLOAT32:
case TypedArrayObject::TYPE_FLOAT64:
if (arrayType == TypedArrayObject::TYPE_FLOAT32)
case ScalarTypeRepresentation::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT64:
if (arrayType == ScalarTypeRepresentation::TYPE_FLOAT32)
loadFloatAsDouble(src, dest.fpu());
else
loadDouble(src, dest.fpu());
@ -326,16 +327,16 @@ MacroAssembler::loadFromTypedArray(int arrayType, const T &src, const ValueOpera
bool allowDouble, Register temp, Label *fail)
{
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case TypedArrayObject::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT32:
loadFromTypedArray(arrayType, src, AnyRegister(dest.scratchReg()), InvalidReg, NULL);
tagValue(JSVAL_TYPE_INT32, dest.scratchReg(), dest);
break;
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
// Don't clobber dest when we could fail, instead use temp.
load32(src, temp);
test32(temp, temp);
@ -360,8 +361,8 @@ MacroAssembler::loadFromTypedArray(int arrayType, const T &src, const ValueOpera
tagValue(JSVAL_TYPE_INT32, temp, dest);
}
break;
case TypedArrayObject::TYPE_FLOAT32:
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT64:
loadFromTypedArray(arrayType, src, AnyRegister(ScratchFloatReg), dest.scratchReg(), NULL);
boxDouble(ScratchFloatReg, dest);
break;

View File

@ -561,17 +561,17 @@ class MacroAssembler : public MacroAssemblerSpecific
template<typename S, typename T>
void storeToTypedIntArray(int arrayType, const S &value, const T &dest) {
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
store8(value, dest);
break;
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
store16(value, dest);
break;
case TypedArrayObject::TYPE_INT32:
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_UINT32:
store32(value, dest);
break;
default:
@ -586,11 +586,11 @@ class MacroAssembler : public MacroAssemblerSpecific
canonicalizeDouble(value);
#endif
switch (arrayType) {
case TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
convertDoubleToFloat(value, ScratchFloatReg);
storeFloat(ScratchFloatReg, dest);
break;
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
storeDouble(value, dest);
break;
default:

View File

@ -2214,7 +2214,7 @@ LIRGenerator::visitLoadTypedArrayElement(MLoadTypedArrayElement *ins)
// We need a temp register for Uint32Array with known double result.
LDefinition tempDef = LDefinition::BogusTemp();
if (ins->arrayType() == TypedArrayObject::TYPE_UINT32 && ins->type() == MIRType_Double)
if (ins->arrayType() == ScalarTypeRepresentation::TYPE_UINT32 && ins->type() == MIRType_Double)
tempDef = temp();
LLoadTypedArrayElement *lir = new LLoadTypedArrayElement(elements, index, tempDef);

View File

@ -1004,7 +1004,7 @@ IonBuilder::inlineUnsafePutElements(CallInfo &callInfo)
// We can only inline setelem on dense arrays that do not need type
// barriers and on typed arrays.
int arrayType;
ScalarTypeRepresentation::Type arrayType;
if ((!ElementAccessIsDenseNative(obj, id) ||
PropertyWriteNeedsTypeBarrier(cx, current, &obj, NULL,
&elem, /* canModify = */ false)) &&
@ -1035,7 +1035,7 @@ IonBuilder::inlineUnsafePutElements(CallInfo &callInfo)
continue;
}
int arrayType;
ScalarTypeRepresentation::Type arrayType;
if (ElementAccessIsTypedArray(obj, id, &arrayType)) {
if (!inlineUnsafeSetTypedArrayElement(callInfo, base, arrayType))
return InliningStatus_Error;
@ -1072,7 +1072,7 @@ IonBuilder::inlineUnsafeSetDenseArrayElement(CallInfo &callInfo, uint32_t base)
bool
IonBuilder::inlineUnsafeSetTypedArrayElement(CallInfo &callInfo,
uint32_t base,
int arrayType)
ScalarTypeRepresentation::Type arrayType)
{
// Note: we do not check the conditions that are asserted as true
// in intrinsic_UnsafePutElements():

View File

@ -2454,7 +2454,8 @@ jit::ElementAccessIsDenseNative(MDefinition *obj, MDefinition *id)
}
bool
jit::ElementAccessIsTypedArray(MDefinition *obj, MDefinition *id, int *arrayType)
jit::ElementAccessIsTypedArray(MDefinition *obj, MDefinition *id,
ScalarTypeRepresentation::Type *arrayType)
{
if (obj->mightBeType(MIRType_String))
return false;
@ -2466,8 +2467,8 @@ jit::ElementAccessIsTypedArray(MDefinition *obj, MDefinition *id, int *arrayType
if (!types)
return false;
*arrayType = types->getTypedArrayType();
return *arrayType != TypedArrayObject::TYPE_MAX;
*arrayType = (ScalarTypeRepresentation::Type) types->getTypedArrayType();
return *arrayType != ScalarTypeRepresentation::TYPE_MAX;
}
bool

View File

@ -5146,31 +5146,32 @@ class MArrayConcat
class MLoadTypedArrayElement
: public MBinaryInstruction
{
int arrayType_;
ScalarTypeRepresentation::Type arrayType_;
MLoadTypedArrayElement(MDefinition *elements, MDefinition *index, int arrayType)
MLoadTypedArrayElement(MDefinition *elements, MDefinition *index,
ScalarTypeRepresentation::Type arrayType)
: MBinaryInstruction(elements, index), arrayType_(arrayType)
{
setResultType(MIRType_Value);
setMovable();
JS_ASSERT(elements->type() == MIRType_Elements);
JS_ASSERT(index->type() == MIRType_Int32);
JS_ASSERT(arrayType >= 0 && arrayType < TypedArrayObject::TYPE_MAX);
JS_ASSERT(arrayType >= 0 && arrayType < ScalarTypeRepresentation::TYPE_MAX);
}
public:
INSTRUCTION_HEADER(LoadTypedArrayElement)
static MLoadTypedArrayElement *New(MDefinition *elements, MDefinition *index, int arrayType) {
static MLoadTypedArrayElement *New(MDefinition *elements, MDefinition *index, ScalarTypeRepresentation::Type arrayType) {
return new MLoadTypedArrayElement(elements, index, arrayType);
}
int arrayType() const {
ScalarTypeRepresentation::Type arrayType() const {
return arrayType_;
}
bool fallible() const {
// Bailout if the result does not fit in an int32.
return arrayType_ == TypedArrayObject::TYPE_UINT32 && type() == MIRType_Int32;
return arrayType_ == ScalarTypeRepresentation::TYPE_UINT32 && type() == MIRType_Int32;
}
MDefinition *elements() const {
return getOperand(0);
@ -5200,7 +5201,7 @@ class MLoadTypedArrayElementHole
setResultType(MIRType_Value);
setMovable();
JS_ASSERT(index->type() == MIRType_Int32);
JS_ASSERT(arrayType >= 0 && arrayType < TypedArrayObject::TYPE_MAX);
JS_ASSERT(arrayType >= 0 && arrayType < ScalarTypeRepresentation::TYPE_MAX);
}
public:
@ -5217,7 +5218,7 @@ class MLoadTypedArrayElementHole
return allowDouble_;
}
bool fallible() const {
return arrayType_ == TypedArrayObject::TYPE_UINT32 && !allowDouble_;
return arrayType_ == ScalarTypeRepresentation::TYPE_UINT32 && !allowDouble_;
}
TypePolicy *typePolicy() {
return this;
@ -5242,7 +5243,7 @@ class MLoadTypedArrayElementStatic
: MUnaryInstruction(ptr), typedArray_(typedArray), fallible_(true)
{
int type = typedArray_->type();
if (type == TypedArrayObject::TYPE_FLOAT32 || type == TypedArrayObject::TYPE_FLOAT64)
if (type == ScalarTypeRepresentation::TYPE_FLOAT32 || type == ScalarTypeRepresentation::TYPE_FLOAT64)
setResultType(MIRType_Double);
else
setResultType(MIRType_Int32);
@ -5299,7 +5300,7 @@ class MStoreTypedArrayElement
setMovable();
JS_ASSERT(elements->type() == MIRType_Elements);
JS_ASSERT(index->type() == MIRType_Int32);
JS_ASSERT(arrayType >= 0 && arrayType < TypedArrayObject::TYPE_MAX);
JS_ASSERT(arrayType >= 0 && arrayType < ScalarTypeRepresentation::TYPE_MAX);
}
public:
@ -5314,13 +5315,13 @@ class MStoreTypedArrayElement
return arrayType_;
}
bool isByteArray() const {
return (arrayType_ == TypedArrayObject::TYPE_INT8 ||
arrayType_ == TypedArrayObject::TYPE_UINT8 ||
arrayType_ == TypedArrayObject::TYPE_UINT8_CLAMPED);
return (arrayType_ == ScalarTypeRepresentation::TYPE_INT8 ||
arrayType_ == ScalarTypeRepresentation::TYPE_UINT8 ||
arrayType_ == ScalarTypeRepresentation::TYPE_UINT8_CLAMPED);
}
bool isFloatArray() const {
return (arrayType_ == TypedArrayObject::TYPE_FLOAT32 ||
arrayType_ == TypedArrayObject::TYPE_FLOAT64);
return (arrayType_ == ScalarTypeRepresentation::TYPE_FLOAT32 ||
arrayType_ == ScalarTypeRepresentation::TYPE_FLOAT64);
}
TypePolicy *typePolicy() {
return this;
@ -5364,7 +5365,7 @@ class MStoreTypedArrayElementHole
JS_ASSERT(elements->type() == MIRType_Elements);
JS_ASSERT(length->type() == MIRType_Int32);
JS_ASSERT(index->type() == MIRType_Int32);
JS_ASSERT(arrayType >= 0 && arrayType < TypedArrayObject::TYPE_MAX);
JS_ASSERT(arrayType >= 0 && arrayType < ScalarTypeRepresentation::TYPE_MAX);
}
public:
@ -5380,13 +5381,13 @@ class MStoreTypedArrayElementHole
return arrayType_;
}
bool isByteArray() const {
return (arrayType_ == TypedArrayObject::TYPE_INT8 ||
arrayType_ == TypedArrayObject::TYPE_UINT8 ||
arrayType_ == TypedArrayObject::TYPE_UINT8_CLAMPED);
return (arrayType_ == ScalarTypeRepresentation::TYPE_INT8 ||
arrayType_ == ScalarTypeRepresentation::TYPE_UINT8 ||
arrayType_ == ScalarTypeRepresentation::TYPE_UINT8_CLAMPED);
}
bool isFloatArray() const {
return (arrayType_ == TypedArrayObject::TYPE_FLOAT32 ||
arrayType_ == TypedArrayObject::TYPE_FLOAT64);
return (arrayType_ == ScalarTypeRepresentation::TYPE_FLOAT32 ||
arrayType_ == ScalarTypeRepresentation::TYPE_FLOAT64);
}
TypePolicy *typePolicy() {
return this;
@ -8423,7 +8424,8 @@ typedef Vector<MDefinition *, 8, IonAllocPolicy> MDefinitionVector;
// Helper functions used to decide how to build MIR.
bool ElementAccessIsDenseNative(MDefinition *obj, MDefinition *id);
bool ElementAccessIsTypedArray(MDefinition *obj, MDefinition *id, int *arrayType);
bool ElementAccessIsTypedArray(MDefinition *obj, MDefinition *id,
ScalarTypeRepresentation::Type *arrayType);
bool ElementAccessIsPacked(JSContext *cx, MDefinition *obj);
bool ElementAccessHasExtraIndexedProperty(JSContext *cx, MDefinition *obj);
MIRType DenseNativeElementType(JSContext *cx, MDefinition *obj);

View File

@ -1118,17 +1118,23 @@ MToInt32::computeRange()
static Range *GetTypedArrayRange(int type)
{
switch (type) {
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case TypedArrayObject::TYPE_UINT8: return new Range(0, UINT8_MAX);
case TypedArrayObject::TYPE_UINT16: return new Range(0, UINT16_MAX);
case TypedArrayObject::TYPE_UINT32: return new Range(0, UINT32_MAX);
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8:
return new Range(0, UINT8_MAX);
case ScalarTypeRepresentation::TYPE_UINT16:
return new Range(0, UINT16_MAX);
case ScalarTypeRepresentation::TYPE_UINT32:
return new Range(0, UINT32_MAX);
case TypedArrayObject::TYPE_INT8: return new Range(INT8_MIN, INT8_MAX);
case TypedArrayObject::TYPE_INT16: return new Range(INT16_MIN, INT16_MAX);
case TypedArrayObject::TYPE_INT32: return new Range(INT32_MIN, INT32_MAX);
case ScalarTypeRepresentation::TYPE_INT8:
return new Range(INT8_MIN, INT8_MAX);
case ScalarTypeRepresentation::TYPE_INT16:
return new Range(INT16_MIN, INT16_MAX);
case ScalarTypeRepresentation::TYPE_INT32:
return new Range(INT32_MIN, INT32_MAX);
case TypedArrayObject::TYPE_FLOAT32:
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT64:
break;
}

View File

@ -508,23 +508,23 @@ StoreTypedArrayPolicy::adjustValueInput(MInstruction *ins, int arrayType,
value->type() == MIRType_Value);
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case TypedArrayObject::TYPE_INT32:
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_UINT32:
if (value->type() != MIRType_Int32) {
value = MTruncateToInt32::New(value);
ins->block()->insertBefore(ins, value->toInstruction());
}
break;
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
// IonBuilder should have inserted ClampToUint8.
JS_ASSERT(value->type() == MIRType_Int32);
break;
case TypedArrayObject::TYPE_FLOAT32:
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT64:
if (value->type() != MIRType_Double) {
value = MToDouble::New(value);
ins->block()->insertBefore(ins, value->toInstruction());

View File

@ -1323,7 +1323,7 @@ JS_InitStandardClasses(JSContext *cx, JSObject *objArg)
#define CLASP(name) (&name##Class)
#define OCLASP(name) (&name##Object::class_)
#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[TypedArrayObject::type])
#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeRepresentation::type])
#define EAGER_ATOM(name) NAME_OFFSET(name)
#define EAGER_CLASS_ATOM(name) NAME_OFFSET(name)
#define EAGER_ATOM_AND_CLASP(name) EAGER_CLASS_ATOM(name), CLASP(name)

View File

@ -2090,7 +2090,7 @@ StackTypeSet::getTypedArrayType()
if (clasp && IsTypedArrayClass(clasp))
return clasp - &TypedArrayObject::classes[0];
return TypedArrayObject::TYPE_MAX;
return ScalarTypeRepresentation::TYPE_MAX;
}
bool

View File

@ -56,19 +56,18 @@
macro(Intl, 37, js_InitIntlClass) \
macro(Type, 38, js_InitBinaryDataClasses) \
macro(Data, 39, js_InitBinaryDataClasses) \
macro(uint8, 40, js_InitBinaryDataClasses) \
macro(uint16, 41, js_InitBinaryDataClasses) \
macro(uint32, 42, js_InitBinaryDataClasses) \
macro(uint64, 43, js_InitBinaryDataClasses) \
macro(uint8Clamped, 40, js_InitBinaryDataClasses) \
macro(uint8, 41, js_InitBinaryDataClasses) \
macro(uint16, 42, js_InitBinaryDataClasses) \
macro(uint32, 43, js_InitBinaryDataClasses) \
macro(int8, 44, js_InitBinaryDataClasses) \
macro(int16, 45, js_InitBinaryDataClasses) \
macro(int32, 46, js_InitBinaryDataClasses) \
macro(int64, 47, js_InitBinaryDataClasses) \
macro(float32, 48, js_InitBinaryDataClasses) \
macro(float64, 49, js_InitBinaryDataClasses) \
macro(ArrayType, 50, js_InitBinaryDataClasses) \
macro(StructType, 51, js_InitBinaryDataClasses) \
macro(ArrayTypeObject, 52, js_InitBinaryDataClasses) \
macro(GeneratorFunction, 53, js_InitIteratorClasses) \
macro(float32, 47, js_InitBinaryDataClasses) \
macro(float64, 48, js_InitBinaryDataClasses) \
macro(ArrayType, 49, js_InitBinaryDataClasses) \
macro(StructType, 50, js_InitBinaryDataClasses) \
macro(ArrayTypeObject, 51, js_InitBinaryDataClasses) \
macro(GeneratorFunction, 52, js_InitIteratorClasses) \
#endif /* jsprototypes_h */

View File

@ -70,16 +70,16 @@ enum StructuredDataType {
SCTAG_TRANSFER_MAP,
SCTAG_TYPED_ARRAY_OBJECT,
SCTAG_TYPED_ARRAY_V1_MIN = 0xFFFF0100,
SCTAG_TYPED_ARRAY_V1_INT8 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_INT8,
SCTAG_TYPED_ARRAY_V1_UINT8 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_UINT8,
SCTAG_TYPED_ARRAY_V1_INT16 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_INT16,
SCTAG_TYPED_ARRAY_V1_UINT16 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_UINT16,
SCTAG_TYPED_ARRAY_V1_INT32 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_INT32,
SCTAG_TYPED_ARRAY_V1_UINT32 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_UINT32,
SCTAG_TYPED_ARRAY_V1_FLOAT32 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_FLOAT32,
SCTAG_TYPED_ARRAY_V1_FLOAT64 = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_FLOAT64,
SCTAG_TYPED_ARRAY_V1_UINT8_CLAMPED = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_UINT8_CLAMPED,
SCTAG_TYPED_ARRAY_V1_MAX = SCTAG_TYPED_ARRAY_V1_MIN + TypedArrayObject::TYPE_MAX - 1,
SCTAG_TYPED_ARRAY_V1_INT8 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_INT8,
SCTAG_TYPED_ARRAY_V1_UINT8 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_UINT8,
SCTAG_TYPED_ARRAY_V1_INT16 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_INT16,
SCTAG_TYPED_ARRAY_V1_UINT16 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_UINT16,
SCTAG_TYPED_ARRAY_V1_INT32 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_INT32,
SCTAG_TYPED_ARRAY_V1_UINT32 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_UINT32,
SCTAG_TYPED_ARRAY_V1_FLOAT32 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_FLOAT32,
SCTAG_TYPED_ARRAY_V1_FLOAT64 = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_FLOAT64,
SCTAG_TYPED_ARRAY_V1_UINT8_CLAMPED = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_UINT8_CLAMPED,
SCTAG_TYPED_ARRAY_V1_MAX = SCTAG_TYPED_ARRAY_V1_MIN + ScalarTypeRepresentation::TYPE_MAX - 1,
SCTAG_END_OF_BUILTIN_TYPES
};
@ -272,7 +272,7 @@ js_GetSCOffset(JSStructuredCloneWriter* writer)
JS_STATIC_ASSERT(SCTAG_END_OF_BUILTIN_TYPES <= JS_SCTAG_USER_MIN);
JS_STATIC_ASSERT(JS_SCTAG_USER_MIN <= JS_SCTAG_USER_MAX);
JS_STATIC_ASSERT(TypedArrayObject::TYPE_INT8 == 0);
JS_STATIC_ASSERT(ScalarTypeRepresentation::TYPE_INT8 == 0);
namespace js {
@ -1015,7 +1015,7 @@ bool
JSStructuredCloneReader::readTypedArray(uint32_t arrayType, uint32_t nelems, Value *vp,
bool v1Read)
{
if (arrayType > TypedArrayObject::TYPE_UINT8_CLAMPED) {
if (arrayType > ScalarTypeRepresentation::TYPE_UINT8_CLAMPED) {
JS_ReportErrorNumber(context(), js_GetErrorMessage, NULL,
JSMSG_SC_BAD_SERIALIZED_DATA, "unhandled typed array element type");
return false;
@ -1046,31 +1046,31 @@ JSStructuredCloneReader::readTypedArray(uint32_t arrayType, uint32_t nelems, Val
RootedObject obj(context(), NULL);
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_INT8:
obj = JS_NewInt8ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8:
obj = JS_NewUint8ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_INT16:
obj = JS_NewInt16ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_UINT16:
obj = JS_NewUint16ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT32:
obj = JS_NewInt32ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
obj = JS_NewUint32ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
obj = JS_NewFloat32ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
obj = JS_NewFloat64ArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
obj = JS_NewUint8ClampedArrayWithBuffer(context(), buffer, byteOffset, nelems);
break;
default:
@ -1102,18 +1102,18 @@ static size_t
bytesPerTypedArrayElement(uint32_t arrayType)
{
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
return sizeof(uint8_t);
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
return sizeof(uint16_t);
case TypedArrayObject::TYPE_INT32:
case TypedArrayObject::TYPE_UINT32:
case TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
return sizeof(uint32_t);
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
return sizeof(uint64_t);
default:
MOZ_ASSUME_UNREACHABLE("unknown TypedArrayObject type");
@ -1127,7 +1127,7 @@ bytesPerTypedArrayElement(uint32_t arrayType)
bool
JSStructuredCloneReader::readV1ArrayBuffer(uint32_t arrayType, uint32_t nelems, Value *vp)
{
JS_ASSERT(arrayType <= TypedArrayObject::TYPE_UINT8_CLAMPED);
JS_ASSERT(arrayType <= ScalarTypeRepresentation::TYPE_UINT8_CLAMPED);
uint32_t nbytes = nelems * bytesPerTypedArrayElement(arrayType);
JSObject *obj = ArrayBufferObject::create(context(), nbytes);
@ -1138,18 +1138,18 @@ JSStructuredCloneReader::readV1ArrayBuffer(uint32_t arrayType, uint32_t nelems,
JS_ASSERT(buffer.byteLength() == nbytes);
switch (arrayType) {
case TypedArrayObject::TYPE_INT8:
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
return in.readArray((uint8_t*) buffer.dataPointer(), nelems);
case TypedArrayObject::TYPE_INT16:
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
return in.readArray((uint16_t*) buffer.dataPointer(), nelems);
case TypedArrayObject::TYPE_INT32:
case TypedArrayObject::TYPE_UINT32:
case TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
return in.readArray((uint32_t*) buffer.dataPointer(), nelems);
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
return in.readArray((uint64_t*) buffer.dataPointer(), nelems);
default:
MOZ_ASSUME_UNREACHABLE("unknown TypedArrayObject type");

View File

@ -1392,15 +1392,15 @@ ArrayBufferViewObject::trace(JSTracer *trc, JSObject *obj)
}
template<typename NativeType> static inline const int TypeIDOfType();
template<> inline const int TypeIDOfType<int8_t>() { return TypedArrayObject::TYPE_INT8; }
template<> inline const int TypeIDOfType<uint8_t>() { return TypedArrayObject::TYPE_UINT8; }
template<> inline const int TypeIDOfType<int16_t>() { return TypedArrayObject::TYPE_INT16; }
template<> inline const int TypeIDOfType<uint16_t>() { return TypedArrayObject::TYPE_UINT16; }
template<> inline const int TypeIDOfType<int32_t>() { return TypedArrayObject::TYPE_INT32; }
template<> inline const int TypeIDOfType<uint32_t>() { return TypedArrayObject::TYPE_UINT32; }
template<> inline const int TypeIDOfType<float>() { return TypedArrayObject::TYPE_FLOAT32; }
template<> inline const int TypeIDOfType<double>() { return TypedArrayObject::TYPE_FLOAT64; }
template<> inline const int TypeIDOfType<uint8_clamped>() { return TypedArrayObject::TYPE_UINT8_CLAMPED; }
template<> inline const int TypeIDOfType<int8_t>() { return ScalarTypeRepresentation::TYPE_INT8; }
template<> inline const int TypeIDOfType<uint8_t>() { return ScalarTypeRepresentation::TYPE_UINT8; }
template<> inline const int TypeIDOfType<int16_t>() { return ScalarTypeRepresentation::TYPE_INT16; }
template<> inline const int TypeIDOfType<uint16_t>() { return ScalarTypeRepresentation::TYPE_UINT16; }
template<> inline const int TypeIDOfType<int32_t>() { return ScalarTypeRepresentation::TYPE_INT32; }
template<> inline const int TypeIDOfType<uint32_t>() { return ScalarTypeRepresentation::TYPE_UINT32; }
template<> inline const int TypeIDOfType<float>() { return ScalarTypeRepresentation::TYPE_FLOAT32; }
template<> inline const int TypeIDOfType<double>() { return ScalarTypeRepresentation::TYPE_FLOAT64; }
template<> inline const int TypeIDOfType<uint8_clamped>() { return ScalarTypeRepresentation::TYPE_UINT8_CLAMPED; }
template<typename NativeType> static inline const bool ElementTypeMayBeDouble() { return false; }
template<> inline const bool ElementTypeMayBeDouble<uint32_t>() { return true; }
@ -1564,7 +1564,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
JS_ASSERT(sizeof(NativeType) <= 4);
uint32_t n = ToUint32(d);
setIndex(tarray, index, NativeType(n));
} else if (ArrayTypeID() == TypedArrayObject::TYPE_UINT8_CLAMPED) {
} else if (ArrayTypeID() == ScalarTypeRepresentation::TYPE_UINT8_CLAMPED) {
// The uint8_clamped type has a special rounding converter
// for doubles.
setIndex(tarray, index, NativeType(d));
@ -2412,50 +2412,50 @@ class TypedArrayObjectTemplate : public TypedArrayObject
unsigned srclen = tarray->length();
switch (tarray->type()) {
case TypedArrayObject::TYPE_INT8: {
case ScalarTypeRepresentation::TYPE_INT8: {
int8_t *src = static_cast<int8_t*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED: {
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED: {
uint8_t *src = static_cast<uint8_t*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_INT16: {
case ScalarTypeRepresentation::TYPE_INT16: {
int16_t *src = static_cast<int16_t*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_UINT16: {
case ScalarTypeRepresentation::TYPE_UINT16: {
uint16_t *src = static_cast<uint16_t*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_INT32: {
case ScalarTypeRepresentation::TYPE_INT32: {
int32_t *src = static_cast<int32_t*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_UINT32: {
case ScalarTypeRepresentation::TYPE_UINT32: {
uint32_t *src = static_cast<uint32_t*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_FLOAT32: {
case ScalarTypeRepresentation::TYPE_FLOAT32: {
float *src = static_cast<float*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_FLOAT64: {
case ScalarTypeRepresentation::TYPE_FLOAT64: {
double *src = static_cast<double*>(tarray->viewData());
for (unsigned i = 0; i < srclen; ++i)
*dest++ = NativeType(*src++);
@ -2492,50 +2492,50 @@ class TypedArrayObjectTemplate : public TypedArrayObject
js_memcpy(srcbuf, tarray->viewData(), byteLength);
switch (tarray->type()) {
case TypedArrayObject::TYPE_INT8: {
case ScalarTypeRepresentation::TYPE_INT8: {
int8_t *src = (int8_t*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_UINT8:
case TypedArrayObject::TYPE_UINT8_CLAMPED: {
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED: {
uint8_t *src = (uint8_t*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_INT16: {
case ScalarTypeRepresentation::TYPE_INT16: {
int16_t *src = (int16_t*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_UINT16: {
case ScalarTypeRepresentation::TYPE_UINT16: {
uint16_t *src = (uint16_t*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_INT32: {
case ScalarTypeRepresentation::TYPE_INT32: {
int32_t *src = (int32_t*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_UINT32: {
case ScalarTypeRepresentation::TYPE_UINT32: {
uint32_t *src = (uint32_t*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_FLOAT32: {
case ScalarTypeRepresentation::TYPE_FLOAT32: {
float *src = (float*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
break;
}
case TypedArrayObject::TYPE_FLOAT64: {
case ScalarTypeRepresentation::TYPE_FLOAT64: {
double *src = (double*) srcbuf;
for (unsigned i = 0; i < tarray->length(); ++i)
*dest++ = NativeType(*src++);
@ -2566,55 +2566,55 @@ class TypedArrayObjectTemplate : public TypedArrayObject
class Int8ArrayObject : public TypedArrayObjectTemplate<int8_t> {
public:
enum { ACTUAL_TYPE = TYPE_INT8 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_INT8 };
static const JSProtoKey key = JSProto_Int8Array;
static const JSFunctionSpec jsfuncs[];
};
class Uint8ArrayObject : public TypedArrayObjectTemplate<uint8_t> {
public:
enum { ACTUAL_TYPE = TYPE_UINT8 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_UINT8 };
static const JSProtoKey key = JSProto_Uint8Array;
static const JSFunctionSpec jsfuncs[];
};
class Int16ArrayObject : public TypedArrayObjectTemplate<int16_t> {
public:
enum { ACTUAL_TYPE = TYPE_INT16 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_INT16 };
static const JSProtoKey key = JSProto_Int16Array;
static const JSFunctionSpec jsfuncs[];
};
class Uint16ArrayObject : public TypedArrayObjectTemplate<uint16_t> {
public:
enum { ACTUAL_TYPE = TYPE_UINT16 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_UINT16 };
static const JSProtoKey key = JSProto_Uint16Array;
static const JSFunctionSpec jsfuncs[];
};
class Int32ArrayObject : public TypedArrayObjectTemplate<int32_t> {
public:
enum { ACTUAL_TYPE = TYPE_INT32 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_INT32 };
static const JSProtoKey key = JSProto_Int32Array;
static const JSFunctionSpec jsfuncs[];
};
class Uint32ArrayObject : public TypedArrayObjectTemplate<uint32_t> {
public:
enum { ACTUAL_TYPE = TYPE_UINT32 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_UINT32 };
static const JSProtoKey key = JSProto_Uint32Array;
static const JSFunctionSpec jsfuncs[];
};
class Float32ArrayObject : public TypedArrayObjectTemplate<float> {
public:
enum { ACTUAL_TYPE = TYPE_FLOAT32 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_FLOAT32 };
static const JSProtoKey key = JSProto_Float32Array;
static const JSFunctionSpec jsfuncs[];
};
class Float64ArrayObject : public TypedArrayObjectTemplate<double> {
public:
enum { ACTUAL_TYPE = TYPE_FLOAT64 };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_FLOAT64 };
static const JSProtoKey key = JSProto_Float64Array;
static const JSFunctionSpec jsfuncs[];
};
class Uint8ClampedArrayObject : public TypedArrayObjectTemplate<uint8_clamped> {
public:
enum { ACTUAL_TYPE = TYPE_UINT8_CLAMPED };
enum { ACTUAL_TYPE = ScalarTypeRepresentation::TYPE_UINT8_CLAMPED };
static const JSProtoKey key = JSProto_Uint8ClampedArray;
static const JSFunctionSpec jsfuncs[];
};
@ -3393,31 +3393,31 @@ TypedArrayObject::copyTypedArrayElement(uint32_t index, MutableHandleValue vp)
JS_ASSERT(index < length());
switch (type()) {
case TYPE_INT8:
case ScalarTypeRepresentation::TYPE_INT8:
TypedArrayObjectTemplate<int8_t>::copyIndexToValue(this, index, vp);
break;
case TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8:
TypedArrayObjectTemplate<uint8_t>::copyIndexToValue(this, index, vp);
break;
case TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
TypedArrayObjectTemplate<uint8_clamped>::copyIndexToValue(this, index, vp);
break;
case TYPE_INT16:
case ScalarTypeRepresentation::TYPE_INT16:
TypedArrayObjectTemplate<int16_t>::copyIndexToValue(this, index, vp);
break;
case TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_UINT16:
TypedArrayObjectTemplate<uint16_t>::copyIndexToValue(this, index, vp);
break;
case TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT32:
TypedArrayObjectTemplate<int32_t>::copyIndexToValue(this, index, vp);
break;
case TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
TypedArrayObjectTemplate<uint32_t>::copyIndexToValue(this, index, vp);
break;
case TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
TypedArrayObjectTemplate<float>::copyIndexToValue(this, index, vp);
break;
case TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
TypedArrayObjectTemplate<double>::copyIndexToValue(this, index, vp);
break;
default:
@ -3735,7 +3735,7 @@ IMPL_TYPED_ARRAY_STATICS(Float32Array);
IMPL_TYPED_ARRAY_STATICS(Float64Array);
IMPL_TYPED_ARRAY_STATICS(Uint8ClampedArray);
Class TypedArrayObject::classes[TYPE_MAX] = {
Class TypedArrayObject::classes[ScalarTypeRepresentation::TYPE_MAX] = {
IMPL_TYPED_ARRAY_FAST_CLASS(Int8Array),
IMPL_TYPED_ARRAY_FAST_CLASS(Uint8Array),
IMPL_TYPED_ARRAY_FAST_CLASS(Int16Array),
@ -3747,7 +3747,7 @@ Class TypedArrayObject::classes[TYPE_MAX] = {
IMPL_TYPED_ARRAY_FAST_CLASS(Uint8ClampedArray)
};
Class TypedArrayObject::protoClasses[TYPE_MAX] = {
Class TypedArrayObject::protoClasses[ScalarTypeRepresentation::TYPE_MAX] = {
IMPL_TYPED_ARRAY_PROTO_CLASS(Int8Array),
IMPL_TYPED_ARRAY_PROTO_CLASS(Uint8Array),
IMPL_TYPED_ARRAY_PROTO_CLASS(Int16Array),
@ -3994,23 +3994,23 @@ bool
js::IsTypedArrayConstructor(HandleValue v, uint32_t type)
{
switch (type) {
case TypedArrayObject::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_INT8:
return IsNativeFunction(v, Int8ArrayObject::class_constructor);
case TypedArrayObject::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8:
return IsNativeFunction(v, Uint8ArrayObject::class_constructor);
case TypedArrayObject::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_INT16:
return IsNativeFunction(v, Int16ArrayObject::class_constructor);
case TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_UINT16:
return IsNativeFunction(v, Uint16ArrayObject::class_constructor);
case TypedArrayObject::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_INT32:
return IsNativeFunction(v, Int32ArrayObject::class_constructor);
case TypedArrayObject::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_UINT32:
return IsNativeFunction(v, Uint32ArrayObject::class_constructor);
case TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
return IsNativeFunction(v, Float32ArrayObject::class_constructor);
case TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
return IsNativeFunction(v, Float64ArrayObject::class_constructor);
case TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
return IsNativeFunction(v, Uint8ClampedArrayObject::class_constructor);
}
MOZ_ASSUME_UNREACHABLE("unexpected typed array type");

View File

@ -10,6 +10,8 @@
#include "jsapi.h"
#include "jsobj.h"
#include "builtin/TypeRepresentation.h"
#include "gc/Barrier.h"
#include "js/Class.h"
typedef struct JSProperty JSProperty;
@ -280,27 +282,8 @@ class TypedArrayObject : public ArrayBufferViewObject
static const size_t DATA_SLOT = 7; // private slot, based on alloc kind
public:
enum {
TYPE_INT8 = 0,
TYPE_UINT8,
TYPE_INT16,
TYPE_UINT16,
TYPE_INT32,
TYPE_UINT32,
TYPE_FLOAT32,
TYPE_FLOAT64,
/*
* Special type that's a uint8_t, but assignments are clamped to 0 .. 255.
* Treat the raw data type as a uint8_t.
*/
TYPE_UINT8_CLAMPED,
TYPE_MAX
};
static Class classes[TYPE_MAX];
static Class protoClasses[TYPE_MAX];
static Class classes[ScalarTypeRepresentation::TYPE_MAX];
static Class protoClasses[ScalarTypeRepresentation::TYPE_MAX];
static bool obj_lookupGeneric(JSContext *cx, HandleObject obj, HandleId id,
MutableHandleObject objp, MutableHandleShape propp);
@ -369,18 +352,18 @@ class TypedArrayObject : public ArrayBufferViewObject
static uint32_t slotWidth(int atype) {
switch (atype) {
case js::TypedArrayObject::TYPE_INT8:
case js::TypedArrayObject::TYPE_UINT8:
case js::TypedArrayObject::TYPE_UINT8_CLAMPED:
case ScalarTypeRepresentation::TYPE_INT8:
case ScalarTypeRepresentation::TYPE_UINT8:
case ScalarTypeRepresentation::TYPE_UINT8_CLAMPED:
return 1;
case js::TypedArrayObject::TYPE_INT16:
case js::TypedArrayObject::TYPE_UINT16:
case ScalarTypeRepresentation::TYPE_INT16:
case ScalarTypeRepresentation::TYPE_UINT16:
return 2;
case js::TypedArrayObject::TYPE_INT32:
case js::TypedArrayObject::TYPE_UINT32:
case js::TypedArrayObject::TYPE_FLOAT32:
case ScalarTypeRepresentation::TYPE_INT32:
case ScalarTypeRepresentation::TYPE_UINT32:
case ScalarTypeRepresentation::TYPE_FLOAT32:
return 4;
case js::TypedArrayObject::TYPE_FLOAT64:
case ScalarTypeRepresentation::TYPE_FLOAT64:
return 8;
default:
MOZ_ASSUME_UNREACHABLE("invalid typed array type");
@ -405,14 +388,14 @@ inline bool
IsTypedArrayClass(const Class *clasp)
{
return &TypedArrayObject::classes[0] <= clasp &&
clasp < &TypedArrayObject::classes[TypedArrayObject::TYPE_MAX];
clasp < &TypedArrayObject::classes[ScalarTypeRepresentation::TYPE_MAX];
}
inline bool
IsTypedArrayProtoClass(const Class *clasp)
{
return &TypedArrayObject::protoClasses[0] <= clasp &&
clasp < &TypedArrayObject::protoClasses[TypedArrayObject::TYPE_MAX];
clasp < &TypedArrayObject::protoClasses[ScalarTypeRepresentation::TYPE_MAX];
}
bool