зеркало из https://github.com/mozilla/gecko-dev.git
b=542402; add FLOAT64 to typed arrays; r=jorendorff
This commit is contained in:
Родитель
13b46d6623
Коммит
db67dfcafe
|
@ -1508,6 +1508,7 @@ static JSStdName standard_class_names[] = {
|
|||
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Int32Array), NULL},
|
||||
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Uint32Array), NULL},
|
||||
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Float32Array), NULL},
|
||||
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Float64Array), NULL},
|
||||
|
||||
{NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
|
|
@ -115,6 +115,7 @@ JS_PROTO(Uint16Array, 33, js_InitTypedArrayClasses)
|
|||
JS_PROTO(Int32Array, 34, js_InitTypedArrayClasses)
|
||||
JS_PROTO(Uint32Array, 35, js_InitTypedArrayClasses)
|
||||
JS_PROTO(Float32Array, 36, js_InitTypedArrayClasses)
|
||||
JS_PROTO(Float64Array, 37, js_InitTypedArrayClasses)
|
||||
|
||||
#undef SCRIPT_INIT
|
||||
#undef XML_INIT
|
||||
|
|
|
@ -12282,7 +12282,8 @@ TraceRecorder::setElem(int lval_spindex, int idx_spindex, int v_spindex)
|
|||
|
||||
if (isNumber(v)) {
|
||||
if (isPromoteInt(v_ins) &&
|
||||
tarray->type != js::TypedArray::TYPE_FLOAT32) {
|
||||
tarray->type != js::TypedArray::TYPE_FLOAT32 &&
|
||||
tarray->type != js::TypedArray::TYPE_FLOAT64) {
|
||||
LIns *v_ins_int = demote(lir, v_ins);
|
||||
switch (tarray->type) {
|
||||
case js::TypedArray::TYPE_INT8:
|
||||
|
@ -12300,6 +12301,8 @@ TraceRecorder::setElem(int lval_spindex, int idx_spindex, int v_spindex)
|
|||
addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 2));
|
||||
lir->insStore(LIR_sti, v_ins_int, addr_ins, 0);
|
||||
break;
|
||||
case js::TypedArray::TYPE_FLOAT32:
|
||||
case js::TypedArray::TYPE_FLOAT64:
|
||||
default:
|
||||
JS_NOT_REACHED("Unknown typed array in tracer");
|
||||
}
|
||||
|
@ -12324,6 +12327,10 @@ TraceRecorder::setElem(int lval_spindex, int idx_spindex, int v_spindex)
|
|||
addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 2));
|
||||
lir->insStore(LIR_st32f, v_ins, addr_ins, 0);
|
||||
break;
|
||||
case js::TypedArray::TYPE_FLOAT64:
|
||||
addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 3));
|
||||
lir->insStore(LIR_stfi, v_ins, addr_ins, 0);
|
||||
break;
|
||||
default:
|
||||
JS_NOT_REACHED("Unknown typed array type in tracer");
|
||||
}
|
||||
|
@ -13313,6 +13320,10 @@ TraceRecorder::typedArrayElement(jsval& oval, jsval& ival, jsval*& vp, LIns*& v_
|
|||
addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 2));
|
||||
v_ins = lir->insLoad(LIR_ld32f, addr_ins, 0);
|
||||
break;
|
||||
case js::TypedArray::TYPE_FLOAT64:
|
||||
addr_ins = lir->ins2(LIR_piadd, data_ins, lir->ins2i(LIR_pilsh, pidx_ins, 3));
|
||||
v_ins = lir->insLoad(LIR_ldf, addr_ins, 0);
|
||||
break;
|
||||
default:
|
||||
JS_NOT_REACHED("Unknown typed array type in tracer");
|
||||
}
|
||||
|
|
|
@ -312,6 +312,7 @@ template<> inline const int TypeIDOfType<uint16>() { return TypedArray::TYPE_UIN
|
|||
template<> inline const int TypeIDOfType<int32>() { return TypedArray::TYPE_INT32; }
|
||||
template<> inline const int TypeIDOfType<uint32>() { return TypedArray::TYPE_UINT32; }
|
||||
template<> inline const int TypeIDOfType<float>() { return TypedArray::TYPE_FLOAT32; }
|
||||
template<> inline const int TypeIDOfType<double>() { return TypedArray::TYPE_FLOAT64; }
|
||||
|
||||
template<typename NativeType> class TypedArrayTemplate;
|
||||
|
||||
|
@ -322,6 +323,7 @@ typedef TypedArrayTemplate<uint16> Uint16Array;
|
|||
typedef TypedArrayTemplate<int32> Int32Array;
|
||||
typedef TypedArrayTemplate<uint32> Uint32Array;
|
||||
typedef TypedArrayTemplate<float> Float32Array;
|
||||
typedef TypedArrayTemplate<double> Float64Array;
|
||||
|
||||
template<typename NativeType>
|
||||
class TypedArrayTemplate
|
||||
|
@ -896,6 +898,12 @@ class TypedArrayTemplate
|
|||
*dest++ = NativeType(*src++);
|
||||
break;
|
||||
}
|
||||
case TypedArray::TYPE_FLOAT64: {
|
||||
double *src = static_cast<double*>(tarray->data);
|
||||
for (uintN i = 0; i < length; ++i)
|
||||
*dest++ = NativeType(*src++);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
JS_NOT_REACHED("copyFrom with a TypedArray of unknown type");
|
||||
break;
|
||||
|
@ -994,6 +1002,15 @@ TypedArrayTemplate<float>::copyIndexToValue(JSContext *cx, uint32 index, jsval *
|
|||
*vp = JSVAL_VOID;
|
||||
}
|
||||
|
||||
template<>
|
||||
void
|
||||
TypedArrayTemplate<double>::copyIndexToValue(JSContext *cx, uint32 index, jsval *vp)
|
||||
{
|
||||
double val = getIndex(index);
|
||||
if (!js_NewWeaklyRootedNumber(cx, jsdouble(val), vp))
|
||||
*vp = JSVAL_VOID;
|
||||
}
|
||||
|
||||
/***
|
||||
*** JS impl
|
||||
***/
|
||||
|
@ -1108,6 +1125,7 @@ IMPL_TYPED_ARRAY_STATICS(Uint16Array);
|
|||
IMPL_TYPED_ARRAY_STATICS(Int32Array);
|
||||
IMPL_TYPED_ARRAY_STATICS(Uint32Array);
|
||||
IMPL_TYPED_ARRAY_STATICS(Float32Array);
|
||||
IMPL_TYPED_ARRAY_STATICS(Float64Array);
|
||||
|
||||
JSClass TypedArray::fastClasses[TYPE_MAX] = {
|
||||
IMPL_TYPED_ARRAY_FAST_CLASS(Int8Array),
|
||||
|
@ -1116,7 +1134,8 @@ JSClass TypedArray::fastClasses[TYPE_MAX] = {
|
|||
IMPL_TYPED_ARRAY_FAST_CLASS(Uint16Array),
|
||||
IMPL_TYPED_ARRAY_FAST_CLASS(Int32Array),
|
||||
IMPL_TYPED_ARRAY_FAST_CLASS(Uint32Array),
|
||||
IMPL_TYPED_ARRAY_FAST_CLASS(Float32Array)
|
||||
IMPL_TYPED_ARRAY_FAST_CLASS(Float32Array),
|
||||
IMPL_TYPED_ARRAY_FAST_CLASS(Float64Array)
|
||||
};
|
||||
|
||||
JSClass TypedArray::slowClasses[TYPE_MAX] = {
|
||||
|
@ -1126,7 +1145,8 @@ JSClass TypedArray::slowClasses[TYPE_MAX] = {
|
|||
IMPL_TYPED_ARRAY_SLOW_CLASS(Uint16Array),
|
||||
IMPL_TYPED_ARRAY_SLOW_CLASS(Int32Array),
|
||||
IMPL_TYPED_ARRAY_SLOW_CLASS(Uint32Array),
|
||||
IMPL_TYPED_ARRAY_SLOW_CLASS(Float32Array)
|
||||
IMPL_TYPED_ARRAY_SLOW_CLASS(Float32Array),
|
||||
IMPL_TYPED_ARRAY_SLOW_CLASS(Float64Array)
|
||||
};
|
||||
|
||||
JS_FRIEND_API(JSObject *)
|
||||
|
@ -1148,6 +1168,7 @@ js_InitTypedArrayClasses(JSContext *cx, JSObject *obj)
|
|||
INIT_TYPED_ARRAY_CLASS(Int32Array,TYPE_INT32);
|
||||
INIT_TYPED_ARRAY_CLASS(Uint32Array,TYPE_UINT32);
|
||||
INIT_TYPED_ARRAY_CLASS(Float32Array,TYPE_FLOAT32);
|
||||
INIT_TYPED_ARRAY_CLASS(Float64Array,TYPE_FLOAT64);
|
||||
|
||||
proto = js_InitClass(cx, obj, NULL, &ArrayBuffer::jsclass,
|
||||
ArrayBuffer::class_constructor, 1,
|
||||
|
@ -1213,6 +1234,9 @@ TypedArrayConstruct(JSContext *cx, jsint atype, uintN argc, jsval *argv, jsval *
|
|||
case TypedArray::TYPE_FLOAT32:
|
||||
return Float32Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
|
||||
|
||||
case TypedArray::TYPE_FLOAT64:
|
||||
return Float64Array::class_constructor(cx, cx->globalObject, argc, argv, rv);
|
||||
|
||||
default:
|
||||
JS_NOT_REACHED("shouldn't have gotten here");
|
||||
return false;
|
||||
|
|
|
@ -101,6 +101,7 @@ struct JS_FRIEND_API(TypedArray) {
|
|||
TYPE_INT32,
|
||||
TYPE_UINT32,
|
||||
TYPE_FLOAT32,
|
||||
TYPE_FLOAT64,
|
||||
TYPE_MAX
|
||||
};
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ function test()
|
|||
check(function() thrown, todo);
|
||||
}
|
||||
|
||||
var buf;
|
||||
var buf, buf2;
|
||||
|
||||
buf = new ArrayBuffer(100);
|
||||
check(function() buf);
|
||||
|
@ -132,6 +132,9 @@ function test()
|
|||
check(function() (new Int32Array(buf)).length == 1);
|
||||
check(function() (new Uint32Array(buf)).length == 1);
|
||||
check(function() (new Float32Array(buf)).length == 1);
|
||||
checkThrows(function() (new Float64Array(buf)));
|
||||
buf2 = new ArrayBuffer(8);
|
||||
check(function() (new Float64Array(buf2)).length == 1);
|
||||
|
||||
buf = new ArrayBuffer(5);
|
||||
check(function() buf);
|
||||
|
@ -180,7 +183,7 @@ function test()
|
|||
|
||||
print ("done");
|
||||
|
||||
reportCompare(0, TestFailCount, "typed array test failures");
|
||||
reportCompare(0, TestFailCount, "typed array tests");
|
||||
|
||||
exitFunc ('test');
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче